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

Commit 30bb3a24 authored by Charlie Anderson's avatar Charlie Anderson
Browse files

Revert "Changing GridMigrationTask to use ModelDbController directly"

This reverts commit 9ef41413.

Reason for revert: This was the only launcher CL during the time  b/280669657 and 280680602 occurred

Change-Id: Id7107f0935f84908ca87e1ae4c62ab05efe41a24
parent 9ef41413
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -16,8 +16,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
import androidx.annotation.WorkerThread;


import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.DatabaseHelper;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.pm.UserCache;
@@ -52,7 +52,7 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
     * Updates the app widgets whose id has changed during the restore process.
     * Updates the app widgets whose id has changed during the restore process.
     */
     */
    @WorkerThread
    @WorkerThread
    public static void restoreAppWidgetIds(Context context, ModelDbController controller,
    public static void restoreAppWidgetIds(Context context, DatabaseHelper helper,
            int[] oldWidgetIds, int[] newWidgetIds, @NonNull AppWidgetHost host) {
            int[] oldWidgetIds, int[] newWidgetIds, @NonNull AppWidgetHost host) {
        if (WidgetsModel.GO_DISABLE_WIDGETS) {
        if (WidgetsModel.GO_DISABLE_WIDGETS) {
            Log.e(TAG, "Skipping widget ID remap as widgets not supported");
            Log.e(TAG, "Skipping widget ID remap as widgets not supported");
@@ -92,12 +92,12 @@ public class AppWidgetsRestoredReceiver extends BroadcastReceiver {
            final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?";
            final String where = "appWidgetId=? and (restored & 1) = 1 and profileId=?";
            final String[] args = new String[] { oldWidgetId, Long.toString(mainProfileId) };
            final String[] args = new String[] { oldWidgetId, Long.toString(mainProfileId) };
            int result = new ContentWriter(context,
            int result = new ContentWriter(context,
                            new ContentWriter.CommitParams(controller, where, args))
                            new ContentWriter.CommitParams(helper, where, args))
                    .put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i])
                    .put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i])
                    .put(LauncherSettings.Favorites.RESTORED, state)
                    .put(LauncherSettings.Favorites.RESTORED, state)
                    .commit();
                    .commit();
            if (result == 0) {
            if (result == 0) {
                Cursor cursor = controller.getDb().query(
                Cursor cursor = helper.getWritableDatabase().query(
                        Favorites.TABLE_NAME,
                        Favorites.TABLE_NAME,
                        new String[] {Favorites.APPWIDGET_ID},
                        new String[] {Favorites.APPWIDGET_ID},
                        "appWidgetId=?", new String[] { oldWidgetId }, null, null, null);
                        "appWidgetId=?", new String[] { oldWidgetId }, null, null, null);
+12 −0
Original line number Original line Diff line number Diff line
@@ -263,6 +263,18 @@ public class LauncherProvider extends ContentProvider {
                getModelDbController().refreshHotseatRestoreTable();
                getModelDbController().refreshHotseatRestoreTable();
                return null;
                return null;
            }
            }
            case LauncherSettings.Settings.METHOD_UPDATE_CURRENT_OPEN_HELPER: {
                Bundle result = new Bundle();
                result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
                        getModelDbController().updateCurrentOpenHelper(arg /* dbFile */));
                return result;
            }
            case LauncherSettings.Settings.METHOD_PREP_FOR_PREVIEW: {
                Bundle result = new Bundle();
                result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE,
                        getModelDbController().prepareForPreview(arg /* dbFile */));
                return result;
            }
        }
        }
        return null;
        return null;
    }
    }
+25 −1
Original line number Original line Diff line number Diff line
@@ -147,6 +147,11 @@ public class LauncherSettings {
         */
         */
        public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";
        public static final String HYBRID_HOTSEAT_BACKUP_TABLE = "hotseat_restore_backup";


        /**
         * Temporary table used specifically for grid migrations during wallpaper preview
         */
        public static final String PREVIEW_TABLE_NAME = "favorites_preview";

        /**
        /**
         * Temporary table used specifically for multi-db grid migrations
         * Temporary table used specifically for multi-db grid migrations
         */
         */
@@ -158,6 +163,18 @@ public class LauncherSettings {
        public static final Uri CONTENT_URI = Uri.parse("content://"
        public static final Uri CONTENT_URI = Uri.parse("content://"
                + LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
                + LauncherProvider.AUTHORITY + "/" + TABLE_NAME);


        /**
         * The content:// style URL for "favorites_preview" table
         */
        public static final Uri PREVIEW_CONTENT_URI = Uri.parse("content://"
                + LauncherProvider.AUTHORITY + "/" + PREVIEW_TABLE_NAME);

        /**
         * The content:// style URL for "favorites_tmp" table
         */
        public static final Uri TMP_CONTENT_URI = Uri.parse("content://"
                + LauncherProvider.AUTHORITY + "/" + TMP_TABLE);

        /**
        /**
         * The content:// style URL for a given row, identified by its id.
         * The content:// style URL for a given row, identified by its id.
         *
         *
@@ -359,6 +376,10 @@ public class LauncherSettings {


        public static final String METHOD_REFRESH_HOTSEAT_RESTORE_TABLE = "restore_hotseat_table";
        public static final String METHOD_REFRESH_HOTSEAT_RESTORE_TABLE = "restore_hotseat_table";


        public static final String METHOD_UPDATE_CURRENT_OPEN_HELPER = "update_current_open_helper";

        public static final String METHOD_PREP_FOR_PREVIEW = "prep_for_preview";

        public static final String EXTRA_VALUE = "value";
        public static final String EXTRA_VALUE = "value";


        public static final String EXTRA_DB_NAME = "db_name";
        public static final String EXTRA_DB_NAME = "db_name";
@@ -372,8 +393,11 @@ public class LauncherSettings {
        }
        }


        public static Bundle call(ContentResolver cr, String method, String arg) {
        public static Bundle call(ContentResolver cr, String method, String arg) {
            return cr.call(CONTENT_URI, method, arg, null);
            return call(cr, method, arg, null /* extras */);
        }
        }


        public static Bundle call(ContentResolver cr, String method, String arg, Bundle extras) {
            return cr.call(CONTENT_URI, method, arg, extras);
        }
    }
    }
}
}
+14 −20
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


package com.android.launcher3.graphics;
package com.android.launcher3.graphics;


import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;


@@ -53,8 +52,6 @@ import com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.GridSizeMigrationUtil;
import com.android.launcher3.model.GridSizeMigrationUtil;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.provider.LauncherDbUtils;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.Themes;
@@ -148,9 +145,7 @@ public class PreviewSurfaceRenderer {
        final String query = LauncherSettings.Favorites.ITEM_TYPE + " = "
        final String query = LauncherSettings.Favorites.ITEM_TYPE + " = "
                + LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
                + LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;


        ModelDbController mainController =
        try (Cursor c = context.getContentResolver().query(LauncherSettings.Favorites.CONTENT_URI,
                LauncherAppState.getInstance(mContext).getModel().getModelDbController();
        try (Cursor c = mainController.query(TABLE_NAME,
                new String[] {
                new String[] {
                        LauncherSettings.Favorites.APPWIDGET_ID,
                        LauncherSettings.Favorites.APPWIDGET_ID,
                        LauncherSettings.Favorites.SPANX,
                        LauncherSettings.Favorites.SPANX,
@@ -195,6 +190,8 @@ public class PreviewSurfaceRenderer {


    @WorkerThread
    @WorkerThread
    private void loadModelData() {
    private void loadModelData() {
        final boolean migrated = doGridMigrationIfNecessary();

        final Context inflationContext;
        final Context inflationContext;
        if (mWallpaperColors != null) {
        if (mWallpaperColors != null) {
            // Create a themed context, without affecting the main application context
            // Create a themed context, without affecting the main application context
@@ -212,20 +209,8 @@ public class PreviewSurfaceRenderer {
                    Themes.getActivityThemeRes(mContext));
                    Themes.getActivityThemeRes(mContext));
        }
        }


        if (GridSizeMigrationUtil.needsToMigrate(inflationContext, mIdp)) {
        if (migrated) {
            // Start the migration
            PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
            PreviewContext previewContext = new PreviewContext(inflationContext, mIdp);
            // Copy existing data to preview DB
            LauncherDbUtils.copyTable(LauncherAppState.getInstance(mContext)
                    .getModel().getModelDbController().getDb(),
                    TABLE_NAME,
                    LauncherAppState.getInstance(previewContext)
                            .getModel().getModelDbController().getDb(),
                    TABLE_NAME,
                    mContext);
            LauncherAppState.getInstance(previewContext)
                    .getModel().getModelDbController().clearEmptyDbFlag();

            new LoaderTask(
            new LoaderTask(
                    LauncherAppState.getInstance(previewContext),
                    LauncherAppState.getInstance(previewContext),
                    /* bgAllAppsList= */ null,
                    /* bgAllAppsList= */ null,
@@ -244,7 +229,8 @@ public class PreviewSurfaceRenderer {
                        query += " or " + LauncherSettings.Favorites.SCREEN + " = "
                        query += " or " + LauncherSettings.Favorites.SCREEN + " = "
                                + Workspace.SECOND_SCREEN_ID;
                                + Workspace.SECOND_SCREEN_ID;
                    }
                    }
                    loadWorkspace(new ArrayList<>(), query, null);
                    loadWorkspaceForPreviewSurfaceRenderer(new ArrayList<>(),
                            LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);


                    final SparseArray<Size> spanInfo =
                    final SparseArray<Size> spanInfo =
                            getLoadedLauncherWidgetInfo(previewContext.getBaseContext());
                            getLoadedLauncherWidgetInfo(previewContext.getBaseContext());
@@ -267,6 +253,14 @@ public class PreviewSurfaceRenderer {
        }
        }
    }
    }


    @WorkerThread
    private boolean doGridMigrationIfNecessary() {
        if (!GridSizeMigrationUtil.needsToMigrate(mContext, mIdp)) {
            return false;
        }
        return GridSizeMigrationUtil.migrateGridIfNeeded(mContext, mIdp);
    }

    @UiThread
    @UiThread
    private void renderView(Context inflationContext, BgDataModel dataModel,
    private void renderView(Context inflationContext, BgDataModel dataModel,
            Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap,
            Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap,
+69 −13
Original line number Original line Diff line number Diff line
@@ -15,8 +15,8 @@
 */
 */
package com.android.launcher3.model;
package com.android.launcher3.model;


import static com.android.launcher3.LauncherSettings.Favorites.addTableToDb;
import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
import static com.android.launcher3.provider.LauncherDbUtils.dropTable;
import static com.android.launcher3.provider.LauncherDbUtils.tableExists;


import android.content.ContentValues;
import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
@@ -36,6 +36,9 @@ import androidx.annotation.NonNull;


import com.android.launcher3.AutoInstallsLayout;
import com.android.launcher3.AutoInstallsLayout;
import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherFiles;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
@@ -55,7 +58,6 @@ import java.io.File;
import java.net.URISyntaxException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Locale;
import java.util.Locale;
import java.util.function.ToLongFunction;
import java.util.stream.Collectors;
import java.util.stream.Collectors;


/**
/**
@@ -74,23 +76,45 @@ public class DatabaseHelper extends NoLocaleSQLiteHelper implements
    private static final boolean LOGD = false;
    private static final boolean LOGD = false;


    private static final String DOWNGRADE_SCHEMA_FILE = "downgrade_schema.json";
    private static final String DOWNGRADE_SCHEMA_FILE = "downgrade_schema.json";
    public static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";


    private final Context mContext;
    private final Context mContext;
    private final ToLongFunction<UserHandle> mUserSerialProvider;
    private final boolean mForMigration;
    private final Runnable mOnEmptyDbCreateCallback;

    private int mMaxItemId = -1;
    private int mMaxItemId = -1;
    public boolean mHotseatRestoreTableExists;
    public boolean mHotseatRestoreTableExists;


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

    public static DatabaseHelper createDatabaseHelper(Context context, String dbName,
            boolean forMigration) {
        if (dbName == null) {
            dbName = InvariantDeviceProfile.INSTANCE.get(context).dbFile;
        }
        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.
        if (!tableExists(databaseHelper.getReadableDatabase(), Favorites.TABLE_NAME)) {
            Log.e(TAG, "Tables are missing after onCreate has been called. Trying to recreate");
            // This operation is a no-op if the table already exists.
            databaseHelper.addFavoritesTable(databaseHelper.getWritableDatabase(), true);
        }
        databaseHelper.mHotseatRestoreTableExists = tableExists(
                databaseHelper.getReadableDatabase(), Favorites.HYBRID_HOTSEAT_BACKUP_TABLE);

        databaseHelper.initIds();
        return databaseHelper;
    }

    /**
    /**
     * Constructor used in tests and for restore.
     * Constructor used in tests and for restore.
     */
     */
    public DatabaseHelper(Context context, String dbName,
    public DatabaseHelper(Context context, String dbName, boolean forMigration) {
            ToLongFunction<UserHandle> userSerialProvider, Runnable onEmptyDbCreateCallback) {
        super(context, dbName, SCHEMA_VERSION);
        super(context, dbName, SCHEMA_VERSION);
        mContext = context;
        mContext = context;
        mUserSerialProvider = userSerialProvider;
        mForMigration = forMigration;
        mOnEmptyDbCreateCallback = onEmptyDbCreateCallback;
    }
    }


    protected void initIds() {
    protected void initIds() {
@@ -107,11 +131,13 @@ public class DatabaseHelper extends NoLocaleSQLiteHelper implements


        mMaxItemId = 1;
        mMaxItemId = 1;


        addTableToDb(db, getDefaultUserSerial(), false /* optional */);
        addFavoritesTable(db, false);


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


    public void onAddOrDeleteOp(SQLiteDatabase db) {
    public void onAddOrDeleteOp(SQLiteDatabase db) {
@@ -121,8 +147,38 @@ public class DatabaseHelper extends NoLocaleSQLiteHelper implements
        }
        }
    }
    }


    private long getDefaultUserSerial() {
    /**
        return mUserSerialProvider.applyAsLong(Process.myUserHandle());
     * Re-composite given key in respect to database. If the current db is
     * {@link LauncherFiles#LAUNCHER_DB}, return the key as-is. Otherwise append the db name to
     * given key. e.g. consider key="EMPTY_DATABASE_CREATED", dbName="minimal.db", the returning
     * string will be "EMPTY_DATABASE_CREATED@minimal.db".
     */
    public String getKey(final String key) {
        if (TextUtils.equals(getDatabaseName(), LauncherFiles.LAUNCHER_DB)) {
            return key;
        }
        return key + "@" + getDatabaseName();
    }

    /**
     * Overridden in tests.
     */
    protected void onEmptyDbCreated() {
        // Set the flag for empty DB
        LauncherPrefs.getPrefs(mContext).edit().putBoolean(getKey(EMPTY_DATABASE_CREATED), true)
                .commit();
    }

    public long getSerialNumberForUser(UserHandle user) {
        return UserCache.INSTANCE.get(mContext).getSerialNumberForUser(user);
    }

    public long getDefaultUserSerial() {
        return getSerialNumberForUser(Process.myUserHandle());
    }

    private void addFavoritesTable(SQLiteDatabase db, boolean optional) {
        Favorites.addTableToDb(db, getDefaultUserSerial(), optional);
    }
    }


    @Override
    @Override
Loading