use of android.content.UriPermission in project android_frameworks_base by ResurrectionRemix.
the class OpenExternalDirectoryActivity method getIntentForExistingPermission.
private static Intent getIntentForExistingPermission(OpenExternalDirectoryActivity activity, boolean isRoot, File root, File file) {
final String packageName = activity.getCallingPackage();
final ContentProviderClient storageClient = activity.getExternalStorageClient();
final Uri grantedUri = getGrantedUriPermission(activity, storageClient, file);
final Uri rootUri = root.equals(file) ? grantedUri : getGrantedUriPermission(activity, storageClient, root);
if (DEBUG)
Log.d(TAG, "checking if " + packageName + " already has permission for " + grantedUri + " or its root (" + rootUri + ")");
final ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
for (UriPermission uriPermission : am.getGrantedUriPermissions(packageName).getList()) {
final Uri uri = uriPermission.getUri();
if (uri == null) {
Log.w(TAG, "null URI for " + uriPermission);
continue;
}
if (uri.equals(grantedUri) || uri.equals(rootUri)) {
if (DEBUG)
Log.d(TAG, packageName + " already has permission: " + uriPermission);
return createGrantedUriPermissionsIntent(grantedUri);
}
}
if (DEBUG)
Log.d(TAG, packageName + " does not have permission for " + grantedUri);
return null;
}
use of android.content.UriPermission in project android_frameworks_base by crdroidandroid.
the class ActivityManagerProxy method getGrantedUriPermissions.
@Override
public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName, int userId) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeString(packageName);
data.writeInt(userId);
mRemote.transact(GET_GRANTED_URI_PERMISSIONS_TRANSACTION, data, reply, 0);
reply.readException();
@SuppressWarnings("unchecked") final ParceledListSlice<UriPermission> perms = ParceledListSlice.CREATOR.createFromParcel(reply);
data.recycle();
reply.recycle();
return perms;
}
use of android.content.UriPermission in project android_frameworks_base by crdroidandroid.
the class MtpDocumentsProvider method onCreate.
@Override
public boolean onCreate() {
sSingleton = this;
mContext = getContext();
mResources = getContext().getResources();
mMtpManager = new MtpManager(getContext());
mResolver = getContext().getContentResolver();
mDeviceToolkits = new HashMap<Integer, DeviceToolkit>();
mDatabase = new MtpDatabase(getContext(), MtpDatabaseConstants.FLAG_DATABASE_IN_FILE);
mRootScanner = new RootScanner(mResolver, mMtpManager, mDatabase);
mAppFuse = new AppFuse(TAG, new AppFuseCallback());
mIntentSender = new ServiceIntentSender(getContext());
// after booting.
try {
final int bootCount = Settings.Global.getInt(mResolver, Settings.Global.BOOT_COUNT, -1);
final int lastBootCount = mDatabase.getLastBootCount();
if (bootCount != -1 && bootCount != lastBootCount) {
mDatabase.setLastBootCount(bootCount);
final List<UriPermission> permissions = mResolver.getOutgoingPersistedUriPermissions();
final Uri[] uris = new Uri[permissions.size()];
for (int i = 0; i < permissions.size(); i++) {
uris[i] = permissions.get(i).getUri();
}
mDatabase.cleanDatabase(uris);
}
} catch (SQLiteDiskIOException error) {
// It can happen due to disk shortage.
Log.e(TAG, "Failed to clean database.", error);
return false;
}
// TODO: Mount AppFuse on demands.
try {
mAppFuse.mount(getContext().getSystemService(StorageManager.class));
} catch (IOException error) {
Log.e(TAG, "Failed to start app fuse.", error);
return false;
}
resume();
return true;
}
use of android.content.UriPermission in project cw-omnibus by commonsguy.
the class DocumentStorageService method load.
private void load(Uri document) {
try {
boolean weHavePermission = false;
boolean isContent = ContentResolver.SCHEME_CONTENT.equals(document.getScheme());
if (isContent) {
int perms = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
getContentResolver().takePersistableUriPermission(document, perms);
for (UriPermission perm : getContentResolver().getPersistedUriPermissions()) {
if (perm.getUri().equals(document)) {
weHavePermission = true;
}
}
} else {
weHavePermission = true;
}
if (weHavePermission) {
try {
InputStream is = getContentResolver().openInputStream(document);
try {
String text = slurp(is);
DocumentFile docFile;
if (isContent) {
docFile = DocumentFile.fromSingleUri(this, document);
} else {
docFile = DocumentFile.fromFile(new File(document.getPath()));
}
EventBus.getDefault().post(new DocumentLoadedEvent(document, text, docFile.getName(), docFile.canWrite()));
} finally {
is.close();
}
} catch (Exception e) {
Log.e(getClass().getSimpleName(), "Exception loading " + document.toString(), e);
EventBus.getDefault().post(new DocumentLoadErrorEvent(document, e));
}
} else {
Log.e(getClass().getSimpleName(), "We failed to get permissions for " + document.toString());
EventBus.getDefault().post(new DocumentPermissionFailureEvent(document));
}
} catch (SecurityException e) {
Log.e(getClass().getSimpleName(), "Exception getting permissions for " + document.toString(), e);
EventBus.getDefault().post(new DocumentPermissionFailureEvent(document));
}
}
use of android.content.UriPermission in project platform_frameworks_base by android.
the class OpenExternalDirectoryActivity method getIntentForExistingPermission.
private static Intent getIntentForExistingPermission(OpenExternalDirectoryActivity activity, boolean isRoot, File root, File file) {
final String packageName = activity.getCallingPackage();
final ContentProviderClient storageClient = activity.getExternalStorageClient();
final Uri grantedUri = getGrantedUriPermission(activity, storageClient, file);
final Uri rootUri = root.equals(file) ? grantedUri : getGrantedUriPermission(activity, storageClient, root);
if (DEBUG)
Log.d(TAG, "checking if " + packageName + " already has permission for " + grantedUri + " or its root (" + rootUri + ")");
final ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
for (UriPermission uriPermission : am.getGrantedUriPermissions(packageName).getList()) {
final Uri uri = uriPermission.getUri();
if (uri == null) {
Log.w(TAG, "null URI for " + uriPermission);
continue;
}
if (uri.equals(grantedUri) || uri.equals(rootUri)) {
if (DEBUG)
Log.d(TAG, packageName + " already has permission: " + uriPermission);
return createGrantedUriPermissionsIntent(grantedUri);
}
}
if (DEBUG)
Log.d(TAG, packageName + " does not have permission for " + grantedUri);
return null;
}
Aggregations