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

Commit f4e5a1a1 authored by Tracy Zhou's avatar Tracy Zhou Committed by Android (Google) Code Review
Browse files

Merge "Special handling when a db for one grid option is not setup yet" into ub-launcher3-rvc-dev

parents 07034645 ed5f3082
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public class DbDowngradeHelperTest {
        }
        helper.close();

        helper = new DatabaseHelper(mContext, DB_FILE) {
        helper = new DatabaseHelper(mContext, DB_FILE, false) {
            @Override
            public void onOpen(SQLiteDatabase db) { }
        };
@@ -161,7 +161,7 @@ public class DbDowngradeHelperTest {

        DbDowngradeHelper.updateSchemaFile(mSchemaFile, LauncherProvider.SCHEMA_VERSION, mContext);

        DatabaseHelper dbHelper = new DatabaseHelper(mContext, DB_FILE) {
        DatabaseHelper dbHelper = new DatabaseHelper(mContext, DB_FILE, false) {
            @Override
            public void onOpen(SQLiteDatabase db) { }
        };
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public class RestoreDbTaskTest {
        private final long mProfileId;

        MyDatabaseHelper(long profileId) {
            super(RuntimeEnvironment.application, null);
            super(RuntimeEnvironment.application, null, false);
            mProfileId = profileId;
        }

+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3;

import static com.android.launcher3.Utilities.getDevicePrefs;
import static com.android.launcher3.Utilities.getPointString;
import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
import static com.android.launcher3.settings.SettingsActivity.GRID_OPTIONS_PREFERENCE_KEY;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
@@ -69,6 +70,9 @@ public class InvariantDeviceProfile {
    public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
            new MainThreadInitializedObject<>(InvariantDeviceProfile::new);

    public static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size";
    public static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count";

    private static final String KEY_IDP_GRID_NAME = "idp_grid_name";

    private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
@@ -165,6 +169,10 @@ public class InvariantDeviceProfile {
        if (!newGridName.equals(gridName)) {
            Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
        }
        Utilities.getPrefs(context).edit()
                .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numHotseatIcons)
                .putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, getPointString(numColumns, numRows))
                .apply();

        mConfigMonitor = new ConfigMonitor(context,
                APPLY_CONFIG_AT_RUNTIME.get() ? this::onConfigChanged : this::killProcess);
+17 −9
Original line number Diff line number Diff line
@@ -146,7 +146,8 @@ public class LauncherProvider extends ContentProvider {
     */
    protected synchronized void createDbIfNotExists() {
        if (mOpenHelper == null) {
            mOpenHelper = DatabaseHelper.createDatabaseHelper(getContext());
            mOpenHelper = DatabaseHelper.createDatabaseHelper(
                    getContext(), false /* forMigration */);

            if (RestoreDbTask.isPending(getContext())) {
                if (!RestoreDbTask.performRestore(getContext(), mOpenHelper,
@@ -430,7 +431,8 @@ public class LauncherProvider extends ContentProvider {
                                    InvariantDeviceProfile.INSTANCE.get(getContext()).dbFile,
                                    Favorites.TMP_TABLE,
                                    () -> mOpenHelper,
                                    () -> DatabaseHelper.createDatabaseHelper(getContext())));
                                    () -> DatabaseHelper.createDatabaseHelper(
                                            getContext(), true /* forMigration */)));
                    return result;
                }
            }
@@ -441,7 +443,8 @@ public class LauncherProvider extends ContentProvider {
                            prepForMigration(
                                    arg /* dbFile */,
                                    Favorites.PREVIEW_TABLE_NAME,
                                    () -> DatabaseHelper.createDatabaseHelper(getContext(), arg),
                                    () -> DatabaseHelper.createDatabaseHelper(
                                            getContext(), arg, true /* forMigration */),
                                    () -> mOpenHelper));
                    return result;
                }
@@ -609,20 +612,22 @@ public class LauncherProvider extends ContentProvider {
    public static class DatabaseHelper extends NoLocaleSQLiteHelper implements
            LayoutParserCallback {
        private final Context mContext;
        private final boolean mForMigration;
        private int mMaxItemId = -1;
        private int mMaxScreenId = -1;
        private boolean mBackupTableExists;

        static DatabaseHelper createDatabaseHelper(Context context) {
            return createDatabaseHelper(context, null);
        static DatabaseHelper createDatabaseHelper(Context context, boolean forMigration) {
            return createDatabaseHelper(context, null, forMigration);
        }

        static DatabaseHelper createDatabaseHelper(Context context, String dbName) {
        static DatabaseHelper createDatabaseHelper(Context context, String dbName,
                boolean forMigration) {
            if (dbName == null) {
                dbName = MULTI_DB_GRID_MIRATION_ALGO.get() ? InvariantDeviceProfile.INSTANCE.get(
                        context).dbFile : LauncherFiles.LAUNCHER_DB;
            }
            DatabaseHelper databaseHelper = new DatabaseHelper(context, dbName);
            DatabaseHelper databaseHelper = new DatabaseHelper(context, dbName, forMigration);
            // Table creation sometimes fails silently, which leads to a crash loop.
            // This way, we will try to create a table every time after crash, so the device
            // would eventually be able to recover.
@@ -643,9 +648,10 @@ public class LauncherProvider extends ContentProvider {
        /**
         * Constructor used in tests and for restore.
         */
        public DatabaseHelper(Context context, String dbName) {
        public DatabaseHelper(Context context, String dbName, boolean forMigration) {
            super(context, dbName, SCHEMA_VERSION);
            mContext = context;
            mForMigration = forMigration;
        }

        protected void initIds() {
@@ -670,8 +676,10 @@ public class LauncherProvider extends ContentProvider {

            // Fresh and clean launcher DB.
            mMaxItemId = initializeMaxItemId(db);
            if (!mForMigration) {
                onEmptyDbCreated();
            }
        }

        protected void onAddOrDeleteOp(SQLiteDatabase db) {
            if (!MULTI_DB_GRID_MIRATION_ALGO.get() && mBackupTableExists) {
+3 −5
Original line number Diff line number Diff line
package com.android.launcher3.model;

import static com.android.launcher3.InvariantDeviceProfile.KEY_MIGRATION_SRC_HOTSEAT_COUNT;
import static com.android.launcher3.InvariantDeviceProfile.KEY_MIGRATION_SRC_WORKSPACE_SIZE;
import static com.android.launcher3.LauncherSettings.Settings.EXTRA_VALUE;
import static com.android.launcher3.Utilities.getPointString;
import static com.android.launcher3.Utilities.parsePoint;
@@ -53,9 +55,6 @@ public class GridSizeMigrationTask {
    private static final String TAG = "GridSizeMigrationTask";
    private static final boolean DEBUG = true;

    private static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size";
    private static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count";

    // These are carefully selected weights for various item types (Math.random?), to allow for
    // the least absurd migration experience.
    private static final float WT_SHORTCUT = 1;
@@ -894,8 +893,7 @@ public class GridSizeMigrationTask {
        String gridSizeString = getPointString(idp.numColumns, idp.numRows);

        return !gridSizeString.equals(prefs.getString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, ""))
                || idp.numHotseatIcons != prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT,
                idp.numHotseatIcons);
                || idp.numHotseatIcons != prefs.getInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, -1);
    }

    /** See {@link #migrateGridIfNeeded(Context, InvariantDeviceProfile)} */
Loading