Loading core/java/android/content/ContentProvider.java +16 −10 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -1168,6 +1169,15 @@ public abstract class ContentProvider implements ComponentCallbacks2 { return mTransport; } /** * 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. Loading @@ -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. Loading @@ -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(); } Loading test-runner/src/android/test/ProviderTestCase.java +2 −2 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public abstract class ProviderTestCase<T extends ContentProvider> mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); mProvider = mProviderClass.newInstance(); mProvider.attachInfo(mProviderContext, null); mProvider.attachInfoForTesting(mProviderContext, null); assertNotNull(mProvider); mResolver.addProvider(mProviderAuthority, getProvider()); } Loading Loading @@ -108,7 +108,7 @@ public abstract class ProviderTestCase<T extends ContentProvider> DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); T provider = providerClass.newInstance(); provider.attachInfo(context, null); provider.attachInfoForTesting(context, null); resolver.addProvider(authority, provider); return resolver; Loading test-runner/src/android/test/ProviderTestCase2.java +2 −2 Original line number Diff line number Diff line Loading @@ -140,7 +140,7 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); mProvider = mProviderClass.newInstance(); mProvider.attachInfo(mProviderContext, null); mProvider.attachInfoForTesting(mProviderContext, null); assertNotNull(mProvider); mResolver.addProvider(mProviderAuthority, getProvider()); } Loading Loading @@ -219,7 +219,7 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); T provider = providerClass.newInstance(); provider.attachInfo(context, null); provider.attachInfoForTesting(context, null); resolver.addProvider(authority, provider); return resolver; Loading test-runner/src/android/test/RenamingDelegatingContext.java +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public class RenamingDelegatingContext extends ContextWrapper { if (allowAccessToExistingFilesAndDbs) { mContext.makeExistingFilesAndDbsAccessible(); } mProvider.attachInfo(mContext, null); mProvider.attachInfoForTesting(mContext, null); return mProvider; } Loading Loading
core/java/android/content/ContentProvider.java +16 −10 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -1168,6 +1169,15 @@ public abstract class ContentProvider implements ComponentCallbacks2 { return mTransport; } /** * 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. Loading @@ -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. Loading @@ -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(); } Loading
test-runner/src/android/test/ProviderTestCase.java +2 −2 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public abstract class ProviderTestCase<T extends ContentProvider> mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); mProvider = mProviderClass.newInstance(); mProvider.attachInfo(mProviderContext, null); mProvider.attachInfoForTesting(mProviderContext, null); assertNotNull(mProvider); mResolver.addProvider(mProviderAuthority, getProvider()); } Loading Loading @@ -108,7 +108,7 @@ public abstract class ProviderTestCase<T extends ContentProvider> DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); T provider = providerClass.newInstance(); provider.attachInfo(context, null); provider.attachInfoForTesting(context, null); resolver.addProvider(authority, provider); return resolver; Loading
test-runner/src/android/test/ProviderTestCase2.java +2 −2 Original line number Diff line number Diff line Loading @@ -140,7 +140,7 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro mProviderContext = new IsolatedContext(mResolver, targetContextWrapper); mProvider = mProviderClass.newInstance(); mProvider.attachInfo(mProviderContext, null); mProvider.attachInfoForTesting(mProviderContext, null); assertNotNull(mProvider); mResolver.addProvider(mProviderAuthority, getProvider()); } Loading Loading @@ -219,7 +219,7 @@ public abstract class ProviderTestCase2<T extends ContentProvider> extends Andro DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql); T provider = providerClass.newInstance(); provider.attachInfo(context, null); provider.attachInfoForTesting(context, null); resolver.addProvider(authority, provider); return resolver; Loading
test-runner/src/android/test/RenamingDelegatingContext.java +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ public class RenamingDelegatingContext extends ContextWrapper { if (allowAccessToExistingFilesAndDbs) { mContext.makeExistingFilesAndDbsAccessible(); } mProvider.attachInfo(mContext, null); mProvider.attachInfoForTesting(mContext, null); return mProvider; } Loading