From 702ed2788678ac744c768aad6a6302e7cf91a26b Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Wed, 14 Oct 2020 11:17:04 -0700 Subject: [PATCH] Fix the issue where shortcuts are removed in minimal device mode When loading the workspace, Launcher pins/unpins shortcuts in comply with the loaded workspace. Since minimal device mode creates a mostly empty workspace, existing shortcuts are getting unpinned as a result. To mitigate the issue this CL compares the db name and only invoke sanitizeData when it matches the one defined in InvariantDeviceProfile. Bug: 170611866 Test: manual 1. add some deep shortcut in workspace (e.g. long tap on chrome, drag "incognito tab" to workspace) 2. opt-in to sunshine fishfood (g/sunshine-teamfood) 3. enable bedtime mode with minimal device in Settings -> Digital Wellbeing -> Show Your Data -> Bedtime mode -> Customize -> minimal device 4. toggle bedtime mode, wait for apps in minimal device to show, then toggle off bedtime mode 5. verify the deep shortcut still exist Change-Id: Ie18216ecb288e7481aa2404c4cb3ea418aee85cb --- src/com/android/launcher3/LauncherProvider.java | 3 +++ src/com/android/launcher3/LauncherSettings.java | 2 ++ src/com/android/launcher3/model/LoaderTask.java | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 2973cf7278..aeed16aa28 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -188,6 +188,9 @@ public class LauncherProvider extends ContentProvider { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder); + final Bundle extra = new Bundle(); + extra.putString(LauncherSettings.Settings.EXTRA_DB_NAME, mOpenHelper.getDatabaseName()); + result.setExtras(extra); result.setNotificationUri(getContext().getContentResolver(), uri); return result; diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java index 58a418edec..d2758f53ad 100644 --- a/src/com/android/launcher3/LauncherSettings.java +++ b/src/com/android/launcher3/LauncherSettings.java @@ -358,6 +358,8 @@ public class LauncherSettings { public static final String EXTRA_VALUE = "value"; + public static final String EXTRA_DB_NAME = "db_name"; + public static Bundle call(ContentResolver cr, String method) { return call(cr, method, null /* arg */); } diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index c0d5882b46..d47fafd40b 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -41,6 +41,7 @@ import android.content.pm.PackageInstaller.SessionInfo; import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.net.Uri; +import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; import android.text.TextUtils; @@ -130,6 +131,7 @@ public class LoaderTask implements Runnable { private final Set mPendingPackages = new HashSet<>(); private boolean mItemsDeleted = false; + private String mDbName; public LoaderTask(LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel dataModel, ModelDelegate modelDelegate, LoaderResults results) { @@ -274,7 +276,14 @@ public class LoaderTask implements Runnable { if (FeatureFlags.FOLDER_NAME_SUGGEST.get()) { loadFolderNames(); } - sanitizeData(); + + // Sanitize data re-syncs widgets/shortcuts based on the workspace loaded from db. + // sanitizeData should not be invoked if the workspace is loaded from a db different + // from the main db as defined in the invariant device profile. + // (e.g. both grid preview and minimal device mode uses a different db) + if (mApp.getInvariantDeviceProfile().dbFile.equals(mDbName)) { + sanitizeData(); + } verifyNotStopped(); updateHandler.finish(); @@ -349,7 +358,9 @@ public class LoaderTask implements Runnable { final LoaderCursor c = new LoaderCursor( contentResolver.query(contentUri, null, selection, null, null), contentUri, mApp, mUserManagerState); - + final Bundle extras = c.getExtras(); + mDbName = extras == null + ? null : extras.getString(LauncherSettings.Settings.EXTRA_DB_NAME); try { final int appWidgetIdIndex = c.getColumnIndexOrThrow( LauncherSettings.Favorites.APPWIDGET_ID);