Fix Strict Mode violation in SnapshotProvider.
Don't initialise the database helper until we need it - doing
it in onCreate hits the disk.
Bug: 5090265
Change-Id: I84ddde4da46452804fd3030ef1a49c4ba6eb69b4
diff --git a/src/com/android/browser/provider/SnapshotProvider.java b/src/com/android/browser/provider/SnapshotProvider.java
index 49557f7..c0aad23 100644
--- a/src/com/android/browser/provider/SnapshotProvider.java
+++ b/src/com/android/browser/provider/SnapshotProvider.java
@@ -106,7 +106,6 @@
@Override
public boolean onCreate() {
- mOpenHelper = new SnapshotDatabaseHelper(getContext());
IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_EJECT);
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
getContext().registerReceiver(mExternalStorageReceiver, filter);
@@ -117,13 +116,15 @@
@Override
public void onReceive(Context context, Intent intent) {
- try {
- mOpenHelper.close();
- } catch (Throwable t) {
- // We failed to close the open helper, which most likely means
- // another thread is busy attempting to open the database
- // or use the database. Let that thread try to gracefully
- // deal with the error
+ if (mOpenHelper != null) {
+ try {
+ mOpenHelper.close();
+ } catch (Throwable t) {
+ // We failed to close the open helper, which most likely means
+ // another thread is busy attempting to open the database
+ // or use the database. Let that thread try to gracefully
+ // deal with the error
+ }
}
}
};
@@ -132,6 +133,9 @@
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
try {
+ if (mOpenHelper == null) {
+ mOpenHelper = new SnapshotDatabaseHelper(getContext());
+ }
return mOpenHelper.getWritableDatabase();
} catch (Throwable t) {
return null;
@@ -145,6 +149,9 @@
if (Environment.MEDIA_MOUNTED.equals(state)
|| Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
try {
+ if (mOpenHelper == null) {
+ mOpenHelper = new SnapshotDatabaseHelper(getContext());
+ }
return mOpenHelper.getReadableDatabase();
} catch (Throwable t) {
return null;