summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dianne Hackborn <hackbod@google.com> 2013-02-26 13:35:11 -0800
committer Dianne Hackborn <hackbod@google.com> 2013-02-26 13:35:11 -0800
commit7e6f976c87714d9c42c376fca5b6c8ef7865e672 (patch)
treee9b643511492c732cf31d45a8b5a28312dd424e2
parent1bf1af60a3ec3da69aafbe1fe93c17312cb3e00e (diff)
App ops: turn off content provider ops when running under test.
Change-Id: I3a5084d195de29122b2f5f2a13b5d4f92f22fa92
-rw-r--r--core/java/android/content/ContentProvider.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index e9b800dc305a..ff3e843916ad 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -101,6 +101,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
private String mWritePermission;
private PathPermission[] mPathPermissions;
private boolean mExported;
+ private boolean mNoPerms;
private Transport mTransport = new Transport();
@@ -523,10 +524,12 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
/** @hide */
public final void setAppOps(int readOp, int writeOp) {
- mTransport.mAppOpsManager = (AppOpsManager)mContext.getSystemService(
- Context.APP_OPS_SERVICE);
- mTransport.mReadOp = readOp;
- mTransport.mWriteOp = writeOp;
+ if (!mNoPerms) {
+ mTransport.mAppOpsManager = (AppOpsManager)mContext.getSystemService(
+ Context.APP_OPS_SERVICE);
+ mTransport.mReadOp = readOp;
+ mTransport.mWriteOp = writeOp;
+ }
}
/** @hide */
@@ -1191,6 +1194,16 @@ 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();
}