summaryrefslogtreecommitdiff
path: root/core/java/android/content/ContentResolver.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-08-11 20:53:18 -0700
committerJeff Sharkey <jsharkey@android.com>2013-08-11 20:56:15 -0700
commit08da7a1143b0c9cfb703971d882e0886bbd7d9de (patch)
treec4af63f07435ec1153a5e7194385a642409905aa /core/java/android/content/ContentResolver.java
parentb9be11c370712cfc4d54aef9202e61092b96960d (diff)
API to discover granted Uri permissions.
Now that granted Uri permissions can be persisted across reboots, offer APIs to discover them. Returns incoming or outgoing grants matching the requested flags and mask. Add helper method to discover "open" documents using this new API and filtering for non-documents. Require that callers own at least of the filtering packages to avoid exposing all grants. Switch internal grant tracking to use ArrayMap. Change-Id: I0a755f221d0d160b411f8d3cfc48279b64345733
Diffstat (limited to 'core/java/android/content/ContentResolver.java')
-rw-r--r--core/java/android/content/ContentResolver.java57
1 files changed, 54 insertions, 3 deletions
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 243c91a95edc..45fed2defce5 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -16,8 +16,6 @@
package android.content;
-import dalvik.system.CloseGuard;
-
import android.accounts.Account;
import android.app.ActivityManagerNative;
import android.app.ActivityThread;
@@ -44,7 +42,8 @@ import android.os.UserHandle;
import android.text.TextUtils;
import android.util.EventLog;
import android.util.Log;
-import android.util.Pair;
+
+import dalvik.system.CloseGuard;
import java.io.File;
import java.io.FileInputStream;
@@ -1389,6 +1388,58 @@ public abstract class ContentResolver {
}
/**
+ * Return list of all Uri permissions that have been granted <em>to</em> the
+ * calling package, and which exactly match the requested flags. For
+ * example, to return all Uris that the calling application has
+ * <em>non-persistent</em> read access to:
+ *
+ * <pre class="prettyprint">
+ * getIncomingUriPermissionGrants(Intent.FLAG_GRANT_READ_URI_PERMISSION,
+ * Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_PERSIST_GRANT_URI_PERMISSION);
+ * </pre>
+ *
+ * @param modeFlags any combination of
+ * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION},
+ * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}, or
+ * {@link Intent#FLAG_PERSIST_GRANT_URI_PERMISSION}.
+ * @param modeMask mask indicating which flags must match.
+ */
+ public Uri[] getIncomingUriPermissionGrants(int modeFlags, int modeMask) {
+ try {
+ return ActivityManagerNative.getDefault()
+ .getGrantedUriPermissions(null, getPackageName(), modeFlags, modeMask);
+ } catch (RemoteException e) {
+ return new Uri[0];
+ }
+ }
+
+ /**
+ * Return list of all Uri permissions that have been granted <em>from</em> the
+ * calling package, and which exactly match the requested flags. For
+ * example, to return all Uris that the calling application has granted
+ * <em>non-persistent</em> read access to:
+ *
+ * <pre class="prettyprint">
+ * getOutgoingUriPermissionGrants(Intent.FLAG_GRANT_READ_URI_PERMISSION,
+ * Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_PERSIST_GRANT_URI_PERMISSION);
+ * </pre>
+ *
+ * @param modeFlags any combination of
+ * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION},
+ * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}, or
+ * {@link Intent#FLAG_PERSIST_GRANT_URI_PERMISSION}.
+ * @param modeMask mask indicating which flags must match.
+ */
+ public Uri[] getOutgoingUriPermissionGrants(int modeFlags, int modeMask) {
+ try {
+ return ActivityManagerNative.getDefault()
+ .getGrantedUriPermissions(getPackageName(), null, modeFlags, modeMask);
+ } catch (RemoteException e) {
+ return new Uri[0];
+ }
+ }
+
+ /**
* Start an asynchronous sync operation. If you want to monitor the progress
* of the sync you may register a SyncObserver. Only values of the following
* types may be used in the extras bundle: