New ContentProvider initialization for testing.

Using this turns off app ops checks.

Change-Id: If29d4ca2fe9ddf1a1663d3a824b2f0afe7375862
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index ff3e843..612f1af 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 @@
     }
 
     /**
+     * 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 @@
      * @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 @@
                 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();
         }