summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-02-26 15:02:06 -0800
committerDianne Hackborn <hackbod@google.com>2013-02-26 16:16:14 -0800
commit334d9aebc28f7d5213b1671997488b3e3f118e29 (patch)
treeb6fc253e257b391ac5055162c042bd90711444ed /core/java/android
parentd0d209ed4d6280b6e1203eebe823f04f9db766c0 (diff)
New ContentProvider initialization for testing.
Using this turns off app ops checks. Change-Id: If29d4ca2fe9ddf1a1663d3a824b2f0afe7375862
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/content/ContentProvider.java26
1 files changed, 16 insertions, 10 deletions
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index ff3e843916ad..612f1af807a9 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -16,6 +16,7 @@
package android.content;
+import static android.content.pm.PackageManager.GET_PROVIDERS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import android.app.AppOpsManager;
@@ -1169,6 +1170,15 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
}
/**
+ * Like {@link #attachInfo(Context, android.content.pm.ProviderInfo)}, but for use
+ * when directly instantiating the provider for testing.
+ * @hide
+ */
+ public void attachInfoForTesting(Context context, ProviderInfo info) {
+ attachInfo(context, info, true);
+ }
+
+ /**
* After being instantiated, this is called to tell the content provider
* about itself.
*
@@ -1176,12 +1186,18 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @param info Registered information about this content provider
*/
public void attachInfo(Context context, ProviderInfo info) {
+ attachInfo(context, info, false);
+ }
+
+ private void attachInfo(Context context, ProviderInfo info, boolean testing) {
/*
* We may be using AsyncTask from binder threads. Make it init here
* so its static handler is on the main thread.
*/
AsyncTask.init();
+ mNoPerms = testing;
+
/*
* Only allow it to be set once, so after the content service gives
* this to us clients can't change it.
@@ -1194,16 +1210,6 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
setWritePermission(info.writePermission);
setPathPermissions(info.pathPermissions);
mExported = info.exported;
- mNoPerms = false;
- } else {
- // We enter here because the content provider is being instantiated
- // as a mock. We don't have any information about the provider (such
- // as its required permissions), and also want to avoid doing app op
- // checks since these aren't real calls coming in and we may not be
- // able to get the app ops service at all (if the test is using something
- // like the IsolatedProvider). So set this to true, to prevent us
- // from enabling app ops on this object.
- mNoPerms = true;
}
ContentProvider.this.onCreate();
}