From 9fb2e0c1b69205ed9341b5611bf5fb8d90969665 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Fri, 27 Apr 2012 15:58:24 +0100 Subject: [PATCH] Backout 6b5668320ce4 (bug 749493) for android startup crashes --- mobile/android/base/db/DBUtils.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mobile/android/base/db/DBUtils.java b/mobile/android/base/db/DBUtils.java index 5dc61b1af73c..ddf47044018d 100644 --- a/mobile/android/base/db/DBUtils.java +++ b/mobile/android/base/db/DBUtils.java @@ -10,7 +10,6 @@ import org.mozilla.gecko.sync.Utils; import android.content.ContentValues; import android.content.Context; import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteDatabaseLockedException; import android.database.sqlite.SQLiteOpenHelper; import android.os.Build; import android.text.TextUtils; @@ -73,19 +72,22 @@ public class DBUtils { } public static void ensureDatabaseIsNotLocked(SQLiteOpenHelper dbHelper, String databasePath) { - try { - dbHelper.getWritableDatabase(); - } catch (SQLiteDatabaseLockedException e) { - Log.d(LOGTAG, "Database is locked, trying to forcefully unlock the database file: " + databasePath); + SQLiteDatabase db = dbHelper.getWritableDatabase(); + + // The returned writable database is read-only, this probably means that the + // database is permanently locked due to a crash or a non-clean quit in Fennec. + // We can assume it's safe to forcefully unlock the database file in this case + // as all database access happens through this content provider (see bug 741718). + if (db.isReadOnly()) { + // Close read-only connection, we don't want to use it + dbHelper.close(); + + Log.d(LOGTAG, "Database is in read-only mode, trying to forcefully unlock the database file: " + databasePath); // Forcefully unlock the database file GeckoAppShell.unlockDatabaseFile(databasePath); - // This call should not throw if the forced unlocking - // actually fixed the situation. - dbHelper.getWritableDatabase(); - - // TODO: maybe check if the database is still locked and let the + // TODO: maybe check if the connection is still read-only and let the // user know that the device needs rebooting? } }