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

Commit 18ce9856 authored by Winson Chung's avatar Winson Chung Committed by Adam Cohen
Browse files

Ignoring specific db exception DO NOT MERGE

Bug 18554839.

Change-Id: I80f2dd62297eea671f2d129ae22263e72e506ae4
(cherry picked from commit 5f05913f)
parent ae5f7ce8
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDiskIOException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteReadOnlyDatabaseException;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
@@ -26,8 +27,8 @@ import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;

import com.android.launcher3.compat.AppWidgetManagerCompat;

import java.io.ByteArrayOutputStream;
@@ -165,16 +166,26 @@ public class WidgetPreviewLoader {
                LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
        final String lastVersionName = sp.getString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, null);
        final String versionName = android.os.Build.VERSION.INCREMENTAL;
        final boolean isLollipopOrGreater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
        if (!versionName.equals(lastVersionName)) {
            // clear all the previews whenever the system version changes, to ensure that previews
            // are up-to-date for any apps that might have been updated with the system
            try {
                // clear all the previews whenever the system version changes, to ensure that
                // previews are up-to-date for any apps that might have been updated with the system
                clearDb();

            } catch (SQLiteReadOnlyDatabaseException e) {
                if (isLollipopOrGreater) {
                    // Workaround for Bug. 18554839, if we fail to clear the db due to the read-only
                    // issue, then ignore this error and leave the old previews
                } else {
                    throw e;
                }
            } finally {
                SharedPreferences.Editor editor = sp.edit();
                editor.putString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, versionName);
                editor.commit();
            }
        }
    }

    public void recreateDb() {
        LauncherAppState app = LauncherAppState.getInstance();