summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Felipe Leme <felipeal@google.com> 2018-04-03 10:53:58 -0700
committer Felipe Leme <felipeal@google.com> 2018-04-03 14:17:30 -0700
commit163eaee6dad4c77bde463d3bfb5d13a7586cc538 (patch)
tree3ff3a09f9963ef49aec92894c471dcdd3c9ab61e
parent9dad4aef1ef58859f4e0fc5707078d681d06fd9e (diff)
Fixed logic that parses URI to handle special case of Documents directory.
Also implemente delete() on provider. Test: manual verification Test: modified testResetGranted() to use Documents directory Test: atest CtsAppSecurityHostTestCases:ScopedDirectoryAccessTest Fixes: 77356487 Change-Id: Ib568a63902a6c750ccc23f074ca75f2807306fd1
-rw-r--r--src/com/android/documentsui/ScopedAccessProvider.java38
-rw-r--r--src/com/android/documentsui/prefs/ScopedAccessLocalPreferences.java5
2 files changed, 37 insertions, 6 deletions
diff --git a/src/com/android/documentsui/ScopedAccessProvider.java b/src/com/android/documentsui/ScopedAccessProvider.java
index 035c86361..e98375e6c 100644
--- a/src/com/android/documentsui/ScopedAccessProvider.java
+++ b/src/com/android/documentsui/ScopedAccessProvider.java
@@ -34,6 +34,7 @@ import static com.android.documentsui.base.SharedMinimal.getUriPermission;
import static com.android.documentsui.prefs.ScopedAccessLocalPreferences.PERMISSION_ASK_AGAIN;
import static com.android.documentsui.prefs.ScopedAccessLocalPreferences.PERMISSION_GRANTED;
import static com.android.documentsui.prefs.ScopedAccessLocalPreferences.PERMISSION_NEVER_ASK;
+import static com.android.documentsui.prefs.ScopedAccessLocalPreferences.clearScopedAccessPreferences;
import static com.android.documentsui.prefs.ScopedAccessLocalPreferences.getAllPackages;
import static com.android.documentsui.prefs.ScopedAccessLocalPreferences.getAllPermissions;
import static com.android.documentsui.prefs.ScopedAccessLocalPreferences.setScopedAccessPermissionStatus;
@@ -351,10 +352,20 @@ public class ScopedAccessProvider extends ContentProvider {
Log.w(TAG, "could not parse uuid and directory on " + uri);
continue;
}
- final String uuid = Providers.ROOT_ID_DEVICE.equals(uuidAndDir[0])
- ? null // primary
- : uuidAndDir[0]; // external volume
- final String dir = uuidAndDir.length == 1 ? null : uuidAndDir[1];
+ // TODO(b/72055774): to make things uglier, the Documents directory in the primary
+ // storage is a special case as its URI is "$ROOT_ID_HOME", instead of
+ // "${ROOT_ID_DEVICE}/Documents. This is another reason to move this logic to the
+ // provider...
+ final String uuid, dir;
+ if (Providers.ROOT_ID_HOME.equals(uuidAndDir[0])) {
+ uuid = null;
+ dir = Environment.DIRECTORY_DOCUMENTS;
+ } else {
+ uuid = Providers.ROOT_ID_DEVICE.equals(uuidAndDir[0])
+ ? null // primary
+ : uuidAndDir[0]; // external volume
+ dir = uuidAndDir.length == 1 ? null : uuidAndDir[1];
+ }
permissions
.add(new Permission(uriPermission.packageName, uuid, dir, PERMISSION_GRANTED));
}
@@ -373,7 +384,24 @@ public class ScopedAccessProvider extends ContentProvider {
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
- throw new UnsupportedOperationException("delete(): unsupported " + uri);
+ if (sMatcher.match(uri) != URI_PERMISSIONS) {
+ throw new UnsupportedOperationException("delete(): unsupported " + uri);
+ }
+
+ if (DEBUG) {
+ Log.v(TAG, "delete(" + uri + "): " + Arrays.toString(selectionArgs));
+ }
+
+ // TODO(b/72055774): add unit tests for invalid input
+ checkArgument(selectionArgs != null && selectionArgs.length == 1,
+ "Must have exactly 1 args: package_name" + Arrays.toString(selectionArgs));
+ final String packageName = selectionArgs[0];
+
+ // Delete just our preferences - the URI permissions is handled externally
+ // TODO(b/72055774): move logic to revoke permissions here, so AppStorageSettings does
+ // not need to call am.clearGrantedUriPermissions(packageName) (then we could remove that
+ // method from ActivityManager)
+ return clearScopedAccessPreferences(getContext(), packageName);
}
@Override
diff --git a/src/com/android/documentsui/prefs/ScopedAccessLocalPreferences.java b/src/com/android/documentsui/prefs/ScopedAccessLocalPreferences.java
index 5b3accc81..2efcf1e83 100644
--- a/src/com/android/documentsui/prefs/ScopedAccessLocalPreferences.java
+++ b/src/com/android/documentsui/prefs/ScopedAccessLocalPreferences.java
@@ -100,21 +100,24 @@ public class ScopedAccessLocalPreferences {
getPrefs(context).edit().putInt(key, status).apply();
}
- public static void clearScopedAccessPreferences(Context context, String packageName) {
+ public static int clearScopedAccessPreferences(Context context, String packageName) {
final String keySubstring = "|" + packageName + "|";
final SharedPreferences prefs = getPrefs(context);
Editor editor = null;
+ int removed = 0;
for (final String key : prefs.getAll().keySet()) {
if (key.contains(keySubstring)) {
if (editor == null) {
editor = prefs.edit();
}
editor.remove(key);
+ removed ++;
}
}
if (editor != null) {
editor.apply();
}
+ return removed;
}
private static String getScopedAccessDenialsKey(String packageName, @Nullable String uuid,