summaryrefslogtreecommitdiffstats
path: root/core/java/android/content/ContentProvider.java
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2009-10-22 08:36:42 +0900
committerDaisuke Miyakawa <dmiyakawa@google.com>2009-12-04 17:48:44 +0900
commit8280c2b15f6875b2d387c05df23d264864eb9cd5 (patch)
tree509308daa0d9bd8807182788068c74bf3be8627c /core/java/android/content/ContentProvider.java
parent3077f7df2eaf4127438d4337a9a25766261b02ee (diff)
downloadframeworks_base-8280c2b15f6875b2d387c05df23d264864eb9cd5.zip
frameworks_base-8280c2b15f6875b2d387c05df23d264864eb9cd5.tar.gz
frameworks_base-8280c2b15f6875b2d387c05df23d264864eb9cd5.tar.bz2
Implement new MockContentProvider. Also make ContentProvider aware of the class.
Rename the old MockContentProvider to MockIContentProvider since it is more appropriate name. Detail: Current developers inevitably depend on the backend used by ContentProvider, which is useful but not ideal nor "testable" from the view of them. Current MockContentResolver only accepts exact "ContentProvider" class, not IContentProvider interface, since we want to hide "IContentProvider" while the old MockContentProvider implements IContentProvider and as a result some methods we want to hide may be exposed to the public SDK now and probably for the future. On the other hand, ContentProvider is not interface but an exact class heavily depends on the internal logic and not suitable for external developers to use for tests. The new MockContentProvider introduces the mock implementation for ContentProvider. It extends ContentProvider, so "is" ContentProvider, but tries to avoid depending on any backend System like IPC in Android, etc. This should be useful from the view of application developers who do not want to be confused with ContentProvider/ContentResolver backend implementation "at all" and want to use MockContentResolver without any other ContentProvider implementations tightly connected to the external worlds.
Diffstat (limited to 'core/java/android/content/ContentProvider.java')
-rw-r--r--core/java/android/content/ContentProvider.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index a341c9b..8d90b83 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -67,6 +67,11 @@ import java.util.ArrayList;
* process a request is coming from.</p>
*/
public abstract class ContentProvider implements ComponentCallbacks {
+ /*
+ * Note: if you add methods to ContentProvider, you must add similar methods to
+ * MockContentProvider.
+ */
+
private Context mContext = null;
private int mMyUid;
private String mReadPermission;
@@ -75,6 +80,33 @@ public abstract class ContentProvider implements ComponentCallbacks {
private Transport mTransport = new Transport();
+ public ContentProvider() {
+ }
+
+ /**
+ * Constructor just for mocking.
+ *
+ * @param context A Context object which should be some mock instance (like the
+ * instance of {@link android.test.mock.MockContext}).
+ * @param readPermission The read permision you want this instance should have in the
+ * test, which is available via {@link #getReadPermission()}.
+ * @param writePermission The write permission you want this instance should have
+ * in the test, which is available via {@link #getWritePermission()}.
+ * @param pathPermissions The PathPermissions you want this instance should have
+ * in the test, which is available via {@link #getPathPermissions()}.
+ * @hide
+ */
+ public ContentProvider(
+ Context context,
+ String readPermission,
+ String writePermission,
+ PathPermission[] pathPermissions) {
+ mContext = context;
+ mReadPermission = readPermission;
+ mWritePermission = writePermission;
+ mPathPermissions = pathPermissions;
+ }
+
/**
* Given an IContentProvider, try to coerce it back to the real
* ContentProvider object if it is running in the local process. This can