Java Code Examples for android.content.ContentProvider#getUserIdFromUri()

The following examples show how to use android.content.ContentProvider#getUserIdFromUri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void grantPermissionFromUser(Uri uri, String pkg, String callingPkg, boolean allSlices) {
    verifyCaller(callingPkg);
    getContext().enforceCallingOrSelfPermission(permission.MANAGE_SLICE_PERMISSIONS,
            "Slice granting requires MANAGE_SLICE_PERMISSIONS");
    int userId = Binder.getCallingUserHandle().getIdentifier();
    if (allSlices) {
        mPermissions.grantFullAccess(pkg, userId);
    } else {
        // When granting, grant to all slices in the provider.
        Uri grantUri = uri.buildUpon()
                .path("")
                .build();
        int providerUser = ContentProvider.getUserIdFromUri(grantUri, userId);
        String providerPkg = getProviderPkg(grantUri, providerUser);
        mPermissions.grantSliceAccess(pkg, userId, providerPkg, providerUser, grantUri);
    }
    long ident = Binder.clearCallingIdentity();
    try {
        mContext.getContentResolver().notifyChange(uri, null);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 2
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public Uri[] getPinnedSlices(String pkg) {
    verifyCaller(pkg);
    int callingUser = Binder.getCallingUserHandle().getIdentifier();
    ArrayList<Uri> ret = new ArrayList<>();
    synchronized (mLock) {
        for (PinnedSliceState state : mPinnedSlicesByUri.values()) {
            if (Objects.equals(pkg, state.getPkg())) {
                Uri uri = state.getUri();
                int userId = ContentProvider.getUserIdFromUri(uri, callingUser);
                if (userId == callingUser) {
                    ret.add(ContentProvider.getUriWithoutUserId(uri));
                }
            }
        }
    }
    return ret.toArray(new Uri[ret.size()]);
}
 
Example 3
Source File: GrantedUriPermissions.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static GrantedUriPermissions grantUri(IActivityManager am, Uri uri,
        int sourceUid, String targetPackage, int targetUserId, int grantFlags, String tag,
        GrantedUriPermissions curPerms) {
    try {
        int sourceUserId = ContentProvider.getUserIdFromUri(uri,
                UserHandle.getUserId(sourceUid));
        uri = ContentProvider.getUriWithoutUserId(uri);
        if (curPerms == null) {
            curPerms = new GrantedUriPermissions(am, grantFlags, sourceUid, tag);
        }
        am.grantUriPermissionFromOwner(curPerms.mPermissionOwner, sourceUid, targetPackage,
                uri, grantFlags, sourceUserId, targetUserId);
        curPerms.mUris.add(uri);
    } catch (RemoteException e) {
        Slog.e("JobScheduler", "AM dead");
    }
    return curPerms;
}
 
Example 4
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void enforceAccess(String pkg, Uri uri) throws RemoteException {
    if (checkAccess(pkg, uri, Binder.getCallingUid(), Binder.getCallingPid())
            != PERMISSION_GRANTED) {
        int userId = ContentProvider.getUserIdFromUri(uri,
                Binder.getCallingUserHandle().getIdentifier());
        if (!Objects.equals(pkg, getProviderPkg(uri, userId))) {
            throw new SecurityException("Access to slice " + uri + " is required");
        }
    }
    enforceCrossUser(pkg, uri);
}
 
Example 5
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int checkSlicePermission(Uri uri, String pkg, int pid, int uid,
        String[] autoGrantPermissions) {
    int userId = UserHandle.getUserId(uid);
    if (pkg == null) {
        for (String p : mContext.getPackageManager().getPackagesForUid(uid)) {
            if (checkSlicePermission(uri, p, pid, uid, autoGrantPermissions)
                    == PERMISSION_GRANTED) {
                return PERMISSION_GRANTED;
            }
        }
        return PERMISSION_DENIED;
    }
    if (hasFullSliceAccess(pkg, userId)) {
        return PackageManager.PERMISSION_GRANTED;
    }
    if (mPermissions.hasPermission(pkg, userId, uri)) {
        return PackageManager.PERMISSION_GRANTED;
    }
    if (autoGrantPermissions != null) {
        // Need to own the Uri to call in with permissions to grant.
        enforceOwner(pkg, uri, userId);
        for (String perm : autoGrantPermissions) {
            if (mContext.checkPermission(perm, pid, uid) == PERMISSION_GRANTED) {
                int providerUser = ContentProvider.getUserIdFromUri(uri, userId);
                String providerPkg = getProviderPkg(uri, providerUser);
                mPermissions.grantSliceAccess(pkg, userId, providerPkg, providerUser, uri);
                return PackageManager.PERMISSION_GRANTED;
            }
        }
    }
    // Fallback to allowing uri permissions through.
    if (mContext.checkUriPermission(uri, pid, uid, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
            == PERMISSION_GRANTED) {
        return PackageManager.PERMISSION_GRANTED;
    }
    return PackageManager.PERMISSION_DENIED;
}
 
Example 6
Source File: SlicePermissionManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public boolean hasPermission(String pkg, int userId, Uri uri) {
    PkgUser pkgUser = new PkgUser(pkg, userId);
    SliceClientPermissions client = getClient(pkgUser);
    int providerUserId = ContentProvider.getUserIdFromUri(uri, userId);
    return client.hasFullAccess()
            || client.hasPermission(ContentProvider.getUriWithoutUserId(uri), providerUserId);
}
 
Example 7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 8
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 10
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 14
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 15
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 16
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 17
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private int resolveUserId(Uri uri) {
    return ContentProvider.getUserIdFromUri(uri, getUserId());
}
 
Example 18
Source File: InputContentInfo.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs {@link InputContentInfo} object with additional link URI.
 *
 * @param contentUri Content URI to be exported from the input method.
 * This cannot be {@code null}.
 * @param description A {@link ClipDescription} object that contains the metadata of
 * {@code contentUri} such as MIME type(s). This object cannot be {@code null}. Also
 * {@link ClipDescription#getLabel()} should be describing the content specified by
 * {@code contentUri} for accessibility reasons.
 * @param linkUri An optional {@code http} or {@code https} URI. The editor author may provide
 * a way to navigate the user to the specified web page if this is not {@code null}.
 * @throws InvalidParameterException if any invalid parameter is specified.
 */
public InputContentInfo(@NonNull Uri contentUri, @NonNull ClipDescription description,
        @Nullable Uri linkUri) {
    validateInternal(contentUri, description, linkUri, true /* throwException */);
    mContentUri = contentUri;
    mContentUriOwnerUserId =
            ContentProvider.getUserIdFromUri(mContentUri, UserHandle.myUserId());
    mDescription = description;
    mLinkUri = linkUri;
}