Bug 843029 - Add more retries to ensureDatabaseIsNotLocked r=blassey r=lucasr a=lsblakk
--- a/mobile/android/base/db/DBUtils.java
+++ b/mobile/android/base/db/DBUtils.java
@@ -6,16 +6,18 @@ package org.mozilla.gecko.db;
import org.mozilla.gecko.GeckoAppShell;
import android.content.ContentValues;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import android.util.Log;
+import java.io.IOException;
+
public class DBUtils {
private static final String LOGTAG = "GeckoDBUtils";
public static final String qualifyColumn(String table, String column) {
return table + "." + column;
}
// This is available in Android >= 11. Implemented locally to be
@@ -59,24 +61,25 @@ public class DBUtils {
}
if (!aValues.containsKey(aNewKey)) {
aValues.put(aNewKey, value);
}
}
public static void ensureDatabaseIsNotLocked(SQLiteOpenHelper dbHelper, String databasePath) {
- try {
- dbHelper.getWritableDatabase();
- } catch (Exception e) {
- Log.d(LOGTAG, "Database is locked, trying to kill any zombie processes: " + databasePath);
-
- GeckoAppShell.killAnyZombies();
-
- // 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
- // user know that the device needs rebooting?
+ for (int retries = 0; retries < 5; retries++) {
+ try {
+ // Try a simple test and exit the loop
+ dbHelper.getWritableDatabase();
+ return;
+ } catch (Exception e) {
+ // Things could get very bad if we don't find a way to unlock the DB
+ Log.d(LOGTAG, "Database is locked, trying to kill any zombie processes: " + databasePath);
+ GeckoAppShell.killAnyZombies();
+ try {
+ Thread.sleep(retries * 100);
+ } catch (InterruptedException ie) { }
+ }
}
+ Log.d(LOGTAG, "Failed to unlock database");
}
}