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

Commit be13d109 authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Render user's actual workspace in ThemePicker preview (Part 3)

go/grid-migration-preview

With this change, we can see actual grid migration in wallpaper preview.

The approach here: we use a tmp table (favorites_preview) here specifically for this preview (to write off the migration results), and load from this tmp table workspace items if migration is necessary and successful. Otherwise, we load from the current workspace.

UPDATED: this change should be completely compatible with the new multi-db grid migration algorithm. Here is why
1. In LauncherPreviewRender#renderScreenShot, I added a check to decide which grid migration preview method we should call. Once v2 preview method is implemented, it should be integrated with other parts of this change perfectly (the reason will be mentioned below).
2. While we have multiple DBs, mOpenHelper in LauncherProvider always points to the current db we are using. Queries using CONTENT_URI is routed to whatever DB mOpenHelper points to, so it works perfectly to directly operate on CONTENT_URI even when we use multi-db underneath the hood.
3. With 1 and 2 mentioned, I believe in order for this preview change to support multi-db, we only need to implement the V2 grid migration algorithm. Because most of what we are doing in this change is wrapped in GridSizeMigrationTask, it's perfectly safeguarded.

Bug: 144052839
Change-Id: Ie6d6048d77326f96546c8a180a7cd8f15b47e4c4
parent 1562d104
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class GridSizeMigrationTaskTest {
        };

        mIdp.numHotseatIcons = 3;
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, 5, 3)
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false, 5, 3)
                .migrateHotseat();
        // First item is dropped as it has the least weight.
        verifyHotseat(hotseatItems[1], hotseatItems[3], hotseatItems[4]);
@@ -82,7 +82,7 @@ public class GridSizeMigrationTaskTest {
        };

        mIdp.numHotseatIcons = 3;
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, 5, 3)
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false, 5, 3)
                .migrateHotseat();
        // First item is dropped as it has the least weight.
        verifyHotseat(hotseatItems[1], hotseatItems[3], hotseatItems[4]);
@@ -127,7 +127,7 @@ public class GridSizeMigrationTaskTest {
                {  5,  2, -1,  6},
        }});

        new GridSizeMigrationTask(mContext, mDb, mValidPackages,
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false,
                new Point(4, 4), new Point(3, 3)).migrateWorkspace();

        // Column 2 and row 2 got removed.
@@ -147,7 +147,7 @@ public class GridSizeMigrationTaskTest {
                {  5,  2, -1,  6},
        }});

        new GridSizeMigrationTask(mContext, mDb, mValidPackages,
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false,
                new Point(4, 4), new Point(3, 3)).migrateWorkspace();

        // Items in the second column get moved to new screen
@@ -172,7 +172,7 @@ public class GridSizeMigrationTaskTest {
                {  3,  1, -1,  4},
        }});

        new GridSizeMigrationTask(mContext, mDb, mValidPackages,
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false,
                new Point(4, 4), new Point(3, 3)).migrateWorkspace();

        // Items in the second column of the first screen should get placed on the 3rd
@@ -204,7 +204,7 @@ public class GridSizeMigrationTaskTest {
                {  5,  2, -1,  6},
        }});

        new GridSizeMigrationTask(mContext, mDb, mValidPackages,
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false,
                new Point(4, 4), new Point(3, 3)).migrateWorkspace();

        // Items in the second column of the first screen should get placed on a new screen.
@@ -235,7 +235,7 @@ public class GridSizeMigrationTaskTest {
                {  5,  2,  7, -1},
        }}, 0);

        new GridSizeMigrationTask(mContext, mDb, mValidPackages,
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false,
                new Point(4, 4), new Point(3, 4)).migrateWorkspace();

        // Items in the second column of the first screen should get placed on a new screen.
@@ -262,7 +262,7 @@ public class GridSizeMigrationTaskTest {
                {  5,  6,  7, -1},
        }}, 0);

        new GridSizeMigrationTask(mContext, mDb, mValidPackages,
        new GridSizeMigrationTask(mContext, mDb, mValidPackages, false,
                new Point(4, 4), new Point(3, 3)).migrateWorkspace();

        // Items in the second column of the first screen should get placed on a new screen.
@@ -282,7 +282,7 @@ public class GridSizeMigrationTaskTest {
     *            represent the workspace grid.
     */
    private void verifyWorkspace(int[][][] ids) {
        IntArray allScreens = getWorkspaceScreenIds(mDb);
        IntArray allScreens = getWorkspaceScreenIds(mDb, LauncherSettings.Favorites.TABLE_NAME);
        assertEquals(ids.length, allScreens.size());
        int total = 0;

@@ -351,7 +351,7 @@ public class GridSizeMigrationTaskTest {
        private final LinkedList<Point> mPoints;

        public MultiStepMigrationTaskVerifier(int... points) {
            super(null, null, null);
            super(null, null, null, false);

            mPoints = new LinkedList<>();
            for (int i = 0; i < points.length; i += 2) {
+2 −1
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.os.Process;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.LauncherRoboTestRunner;
@@ -91,7 +92,7 @@ public class LoaderCursorTest {
                SCREEN, CELLX, CELLY, RESTORED, INTENT
        });

        mLoaderCursor = new LoaderCursor(mCursor, mApp);
        mLoaderCursor = new LoaderCursor(mCursor, LauncherSettings.Favorites.CONTENT_URI, mApp);
        mLoaderCursor.allUsers.put(0, Process.myUserHandle());
    }

+6 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.launcher3.graphics.IconShape;
import com.android.launcher3.graphics.LauncherPreviewRenderer;
import com.android.launcher3.util.ConfigMonitor;
import com.android.launcher3.util.DefaultDisplay;
import com.android.launcher3.util.DefaultDisplay.Info;
@@ -156,6 +157,11 @@ public class InvariantDeviceProfile {

    @TargetApi(23)
    private InvariantDeviceProfile(Context context) {
        if (context instanceof LauncherPreviewRenderer.PreviewContext) {
            throw new IllegalArgumentException(
                    "PreviewContext is passed into this IDP constructor");
        }

        String gridName = Utilities.getPrefs(context).getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)
                ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null)
                : null;
+32 −18
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import android.content.pm.LauncherApps;
import android.os.Handler;
import android.util.Log;

import androidx.annotation.Nullable;

import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.IconProvider;
@@ -55,12 +57,12 @@ public class LauncherAppState {
    private final IconCache mIconCache;
    private final WidgetPreviewLoader mWidgetCache;
    private final InvariantDeviceProfile mInvariantDeviceProfile;
    private final SecureSettingsObserver mNotificationDotsObserver;

    private final InstallSessionTracker mInstallSessionTracker;
    private final SimpleBroadcastReceiver mModelChangeReceiver;
    private final SafeCloseable mCalendarChangeTracker;
    private final SafeCloseable mUserChangeListener;
    private SecureSettingsObserver mNotificationDotsObserver;
    private InstallSessionTracker mInstallSessionTracker;
    private SimpleBroadcastReceiver mModelChangeReceiver;
    private SafeCloseable mCalendarChangeTracker;
    private SafeCloseable mUserChangeListener;

    public static LauncherAppState getInstance(final Context context) {
        return INSTANCE.get(context);
@@ -74,15 +76,8 @@ public class LauncherAppState {
        return mContext;
    }

    private LauncherAppState(Context context) {
        Log.v(Launcher.TAG, "LauncherAppState initiated");
        Preconditions.assertUIThread();
        mContext = context;

        mInvariantDeviceProfile = InvariantDeviceProfile.INSTANCE.get(mContext);
        mIconCache = new IconCache(mContext, mInvariantDeviceProfile);
        mWidgetCache = new WidgetPreviewLoader(mContext, mIconCache);
        mModel = new LauncherModel(this, mIconCache, AppFilter.newInstance(mContext));
    public LauncherAppState(Context context) {
        this(context, LauncherFiles.APP_ICONS_DB);

        mModelChangeReceiver = new SimpleBroadcastReceiver(mModel::onBroadcastIntent);

@@ -123,6 +118,17 @@ public class LauncherAppState {
        }
    }

    public LauncherAppState(Context context, @Nullable String iconCacheFileName) {
        Log.v(Launcher.TAG, "LauncherAppState initiated");
        Preconditions.assertUIThread();
        mContext = context;

        mInvariantDeviceProfile = InvariantDeviceProfile.INSTANCE.get(context);
        mIconCache = new IconCache(mContext, mInvariantDeviceProfile, iconCacheFileName);
        mWidgetCache = new WidgetPreviewLoader(mContext, mIconCache);
        mModel = new LauncherModel(this, mIconCache, AppFilter.newInstance(mContext));
    }

    protected void onNotificationSettingsChanged(boolean areNotificationDotsEnabled) {
        if (areNotificationDotsEnabled) {
            NotificationListener.requestRebind(new ComponentName(
@@ -148,11 +154,19 @@ public class LauncherAppState {
     * Call from Application.onTerminate(), which is not guaranteed to ever be called.
     */
    public void onTerminate() {
        if (mModelChangeReceiver != null) {
            mContext.unregisterReceiver(mModelChangeReceiver);
        }
        mContext.getSystemService(LauncherApps.class).unregisterCallback(mModel);
        if (mInstallSessionTracker != null) {
            mInstallSessionTracker.unregister();
        }
        if (mCalendarChangeTracker != null) {
            mCalendarChangeTracker.close();
        }
        if (mUserChangeListener != null) {
            mUserChangeListener.close();
        }
        CustomWidgetManager.INSTANCE.get(mContext).setWidgetRefreshCallback(null);

        if (mNotificationDotsObserver != null) {
+17 −6
Original line number Diff line number Diff line
@@ -93,15 +93,26 @@ public class LauncherSettings {
        public static final String TABLE_NAME = "favorites";

        /**
         * Backup table created when when the favorites table is modified during grid migration
         * Backup table created when the favorites table is modified during grid migration
         */
        public static final String BACKUP_TABLE_NAME = "favorites_bakup";

        /**
         * The content:// style URL for this table
         * Temporary table used specifically for grid migrations during wallpaper preview
         */
        public static final Uri CONTENT_URI = Uri.parse("content://" +
                LauncherProvider.AUTHORITY + "/" + TABLE_NAME);
        public static final String PREVIEW_TABLE_NAME = "favorites_preview";

        /**
         * The content:// style URL for "favorites" table
         */
        public static final Uri CONTENT_URI = Uri.parse("content://"
                + 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 a given row, identified by its id.
@@ -111,8 +122,8 @@ public class LauncherSettings {
         * @return The unique content URL for the specified row.
         */
        public static Uri getContentUri(int id) {
            return Uri.parse("content://" + LauncherProvider.AUTHORITY +
                    "/" + TABLE_NAME + "/" + id);
            return Uri.parse("content://" + LauncherProvider.AUTHORITY
                    + "/" + TABLE_NAME + "/" + id);
        }

        /**
Loading