summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Charlie Anderson <charlander@google.com> 2025-03-21 10:05:24 -0400
committer Charlie Anderson <charlander@google.com> 2025-03-21 13:29:14 -0700
commitca9a920fa95803e91239d1b2afe08dd537292f2a (patch)
tree8ab8b7d8388b73e9b37b815470582cc2d083d798
parent500698152c20e4765585e83f7ff21fb23751d7d4 (diff)
Make sure loading icons from db for archived apps only happens once after restore.
- This is to enable users to theme and shape archived apps Bug: 402303619 Flag: com.android.launcher3.restore_archived_app_icons_from_db Test: performing restore and toggling themed icons on/off Change-Id: I5883f703c3b0c8df5ee303ea4d99b0c02743faa4
-rw-r--r--src/com/android/launcher3/model/LoaderCursor.java4
-rw-r--r--tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java26
2 files changed, 28 insertions, 2 deletions
diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java
index 8f116bbd6b..fd8e2f7838 100644
--- a/src/com/android/launcher3/model/LoaderCursor.java
+++ b/src/com/android/launcher3/model/LoaderCursor.java
@@ -45,6 +45,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.launcher3.Flags;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherModel;
+import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
@@ -421,7 +422,8 @@ public class LoaderCursor extends CursorWrapper {
) {
boolean isPreArchived = Flags.enableSupportForArchiving()
&& Flags.restoreArchivedAppIconsFromDb()
- && info.isInactiveArchive();
+ && info.isInactiveArchive()
+ && LauncherPrefs.get(mContext).get(LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE);
boolean preArchivedIconNotFound = isPreArchived && !loadIconFromDb(info);
if (preArchivedIconNotFound) {
Log.d(TAG, "loadIconFromDb failed for pre-archived icon, loading from cache."
diff --git a/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java b/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java
index b848d27cd9..d1292cf0aa 100644
--- a/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java
+++ b/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java
@@ -21,6 +21,7 @@ import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType
import static androidx.test.InstrumentationRegistry.getContext;
+import static com.android.launcher3.LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE;
import static com.android.launcher3.LauncherSettings.Favorites.APPWIDGET_ID;
import static com.android.launcher3.LauncherSettings.Favorites.APPWIDGET_PROVIDER;
import static com.android.launcher3.LauncherSettings.Favorites.APPWIDGET_SOURCE;
@@ -69,6 +70,7 @@ import androidx.test.filters.SmallTest;
import com.android.launcher3.Flags;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.model.data.ItemInfo;
@@ -96,6 +98,7 @@ public class LoaderCursorTest {
private LauncherModelHelper mModelHelper;
private LauncherAppState mApp;
+ private LauncherPrefs mPrefs;
private MatrixCursor mCursor;
private InvariantDeviceProfile mIDP;
@@ -113,6 +116,7 @@ public class LoaderCursorTest {
public void setup() {
mModelHelper = new LauncherModelHelper();
mContext = mModelHelper.sandboxContext;
+ mPrefs = LauncherPrefs.get(mContext);
mIDP = InvariantDeviceProfile.INSTANCE.get(mContext);
mApp = LauncherAppState.getInstance(mContext);
@@ -131,6 +135,7 @@ public class LoaderCursorTest {
@After
public void tearDown() {
+ mPrefs.putSync(IS_FIRST_LOAD_AFTER_RESTORE.to(false));
mCursor.close();
mModelHelper.destroy();
}
@@ -253,8 +258,9 @@ public class LoaderCursorTest {
@Test
@EnableFlags(Flags.FLAG_RESTORE_ARCHIVED_APP_ICONS_FROM_DB)
- public void ifArchivedWithFlag_whenloadWorkspaceTitleAndIcon_thenLoadIconFromDb() {
+ public void ifArchivedWithFlagAndRestore_whenloadWorkspaceTitleAndIcon_thenLoadIconFromDb() {
// Given
+ mPrefs.putSync(IS_FIRST_LOAD_AFTER_RESTORE.to(true));
initCursor(ITEM_TYPE_APPLICATION, "title");
assertTrue(mLoaderCursor.moveToNext());
WorkspaceItemInfo itemInfo = new WorkspaceItemInfo();
@@ -262,6 +268,7 @@ public class LoaderCursorTest {
Bitmap expectedBitmap = LauncherIcons.obtain(mContext)
.createIconBitmap(decodeByteArray(sTestBlob, 0, sTestBlob.length))
.icon;
+
// When
mLoaderCursor.loadWorkspaceTitleAndIcon(false, true, itemInfo);
// Then
@@ -271,6 +278,23 @@ public class LoaderCursorTest {
@Test
@EnableFlags(Flags.FLAG_RESTORE_ARCHIVED_APP_ICONS_FROM_DB)
+ public void ifArchivedWithFlagAndNotRestore_whenloadWorkspaceTitleAndIcon_thenLoadIconFromDb() {
+ // Given
+ mPrefs.putSync(IS_FIRST_LOAD_AFTER_RESTORE.to(false));
+ initCursor(ITEM_TYPE_APPLICATION, "title");
+ assertTrue(mLoaderCursor.moveToNext());
+ WorkspaceItemInfo itemInfo = new WorkspaceItemInfo();
+ BitmapInfo original = itemInfo.bitmap;
+ itemInfo.runtimeStatusFlags |= FLAG_ARCHIVED;
+
+ // When
+ mLoaderCursor.loadWorkspaceTitleAndIcon(false, true, itemInfo);
+ // Then
+ assertThat(itemInfo.bitmap).isEqualTo(original);
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_RESTORE_ARCHIVED_APP_ICONS_FROM_DB)
public void ifArchivedWithFlag_whenLoadIconFromDb_thenLoadIconFromBlob() {
// Given
initCursor(ITEM_TYPE_APPLICATION, "title");