Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3316d35 authored by Grace Kloba's avatar Grace Kloba Committed by Bart Sears
Browse files

DO NOT MERGE

cherry-pick https://android-git.corp.google.com/g/#change,29843 from eclair-mr2
This will cherry-pick SHA1: 58def690

This will workaround the following three bugs which are occuring because
the webview DB is getting corrupted:

http://b/issue?id=2338178
http://b/issue?id=2278210
http://b/issue?id=2405650

Here are the comments from the eclair-mr2 CL:

If openOrCreateDatabase() throws an exception, delete
the old db and re-do it. If it still fails, something
bad happens, like the directory may have the different
permission. Let it throw as WebView needs the db.

Fix http://b/issue?id=2179339
parent e88192b9
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;
import android.webkit.CookieManager.Cookie;
@@ -174,7 +175,16 @@ public class WebViewDatabase {
    public static synchronized WebViewDatabase getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new WebViewDatabase();
            mDatabase = context.openOrCreateDatabase(DATABASE_FILE, 0, null);
            try {
                mDatabase = context
                        .openOrCreateDatabase(DATABASE_FILE, 0, null);
            } catch (SQLiteException e) {
                // try again by deleting the old db and create a new one
                if (context.deleteDatabase(DATABASE_FILE)) {
                    mDatabase = context.openOrCreateDatabase(DATABASE_FILE, 0,
                            null);
                }
            }

            // mDatabase should not be null, 
            // the only case is RequestAPI test has problem to create db 
@@ -194,8 +204,16 @@ public class WebViewDatabase {
                mDatabase.setLockingEnabled(false);
            }

            mCacheDatabase = context.openOrCreateDatabase(CACHE_DATABASE_FILE,
                    0, null);
            try {
                mCacheDatabase = context.openOrCreateDatabase(
                        CACHE_DATABASE_FILE, 0, null);
            } catch (SQLiteException e) {
                // try again by deleting the old db and create a new one
                if (context.deleteDatabase(CACHE_DATABASE_FILE)) {
                    mCacheDatabase = context.openOrCreateDatabase(
                            CACHE_DATABASE_FILE, 0, null);
                }
            }

            // mCacheDatabase should not be null, 
            // the only case is RequestAPI test has problem to create db