diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java index 9b9f796a16078..a3252ed2f40ce 100644 --- a/core/java/android/content/ContentProvider.java +++ b/core/java/android/content/ContentProvider.java @@ -32,6 +32,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.Process; +import android.util.Log; import java.io.File; import java.io.FileNotFoundException; @@ -76,6 +77,8 @@ import java.util.ArrayList; * cross-process calls.
*/ public abstract class ContentProvider implements ComponentCallbacks { + private static final String TAG = "ContentProvider"; + /* * Note: if you add methods to ContentProvider, you must add similar methods to * MockContentProvider. @@ -831,4 +834,34 @@ public abstract class ContentProvider implements ComponentCallbacks { public Bundle call(String method, String request, Bundle args) { return null; } + + /** + * Shuts down this instance of the ContentProvider. It is useful when writing tests that use + * the ContentProvider. + *+ * If a unittest starts the ContentProvider in its test(..() methods, it could run into sqlite + * errors "disk I/O error" or "corruption" in the following scenario: + *
+ * tearDown() in the unittests should call this method to have ContentProvider gracefully
+ * shutdown all database connections.
+ */
+ public void shutdown() {
+ Log.w(TAG, "implement ContentProvider shutdown() to make sure all database " +
+ "connections are gracefully shutdown");
+ }
}
diff --git a/test-runner/src/android/test/ProviderTestCase.java b/test-runner/src/android/test/ProviderTestCase.java
index e1172cf21ff7b..1ffda2681e1b8 100644
--- a/test-runner/src/android/test/ProviderTestCase.java
+++ b/test-runner/src/android/test/ProviderTestCase.java
@@ -73,6 +73,18 @@ public abstract class ProviderTestCase
+ * Calls {@link android.content.ContentProvider#shutdown()} on the
+ * {@link android.content.ContentProvider} represented by {@link #mProvider}
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ mProvider.shutdown();
+ super.tearDown();
+ }
+
public MockContentResolver getMockContentResolver() {
return mResolver;
}
diff --git a/test-runner/src/android/test/ProviderTestCase2.java b/test-runner/src/android/test/ProviderTestCase2.java
index 1fb5538d6ef2f..feb5ef464fbdf 100644
--- a/test-runner/src/android/test/ProviderTestCase2.java
+++ b/test-runner/src/android/test/ProviderTestCase2.java
@@ -140,6 +140,18 @@ public abstract class ProviderTestCase2
+ * Calls {@link android.content.ContentProvider#shutdown()} on the
+ * {@link android.content.ContentProvider} represented by {@link #mProvider}.
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ mProvider.shutdown();
+ super.tearDown();
+ }
+
/**
* Gets the {@link MockContentResolver} created by this class during initialization. You
* must use the methods of this resolver to access the provider under test.