Merge "Ensure that inactive archived icons in the folder preview are not shown as grey pending icons" into main
diff --git a/src/com/android/launcher3/folder/PreviewItemManager.java b/src/com/android/launcher3/folder/PreviewItemManager.java
index 6311638..2276ac7 100644
--- a/src/com/android/launcher3/folder/PreviewItemManager.java
+++ b/src/com/android/launcher3/folder/PreviewItemManager.java
@@ -23,6 +23,7 @@
import static com.android.launcher3.folder.FolderIcon.DROP_IN_ANIMATION_DURATION;
import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED;
+import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -41,14 +42,13 @@
import androidx.annotation.VisibleForTesting;
import com.android.launcher3.BubbleTextView;
+import com.android.launcher3.Flags;
import com.android.launcher3.Utilities;
import com.android.launcher3.apppairs.AppPairIcon;
import com.android.launcher3.apppairs.AppPairIconDrawingParams;
import com.android.launcher3.apppairs.AppPairIconGraphic;
-import com.android.launcher3.graphics.PreloadIconDrawable;
import com.android.launcher3.model.data.AppPairInfo;
import com.android.launcher3.model.data.ItemInfo;
-import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ActivityContext;
@@ -442,10 +442,8 @@
@VisibleForTesting
public void setDrawable(PreviewItemDrawingParams p, ItemInfo item) {
if (item instanceof WorkspaceItemInfo wii) {
- if (wii.hasPromiseIconUi() || (wii.runtimeStatusFlags
- & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
- PreloadIconDrawable drawable = newPendingIcon(mContext, wii);
- p.drawable = drawable;
+ if (isActivePendingIcon(wii)) {
+ p.drawable = newPendingIcon(mContext, wii);
} else {
p.drawable = wii.newIcon(mContext,
Themes.isThemedIconEnabled(mContext) ? FLAG_THEMED : 0);
@@ -463,4 +461,14 @@
// callback will be released when the folder is opened.
p.drawable.setCallback(mIcon);
}
+
+ /**
+ * Returns true if item is a Promise Icon or actively downloading, and the item is not an
+ * inactive archived app.
+ */
+ private boolean isActivePendingIcon(WorkspaceItemInfo item) {
+ return (item.hasPromiseIconUi()
+ || (item.runtimeStatusFlags & FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0)
+ && !(Flags.useNewIconForArchivedApps() && item.isInactiveArchive());
+ }
}
diff --git a/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt b/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt
index 5516f45..7c9f99a 100644
--- a/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt
+++ b/tests/src/com/android/launcher3/folder/PreviewItemManagerTest.kt
@@ -25,16 +25,23 @@
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.android.launcher3.LauncherPrefs.Companion.THEMED_ICONS
import com.android.launcher3.LauncherPrefs.Companion.get
+import com.android.launcher3.graphics.PreloadIconDrawable
import com.android.launcher3.icons.BaseIconFactory
import com.android.launcher3.icons.FastBitmapDrawable
import com.android.launcher3.icons.UserBadgeDrawable
import com.android.launcher3.model.data.FolderInfo
import com.android.launcher3.model.data.ItemInfo
+import com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED
+import com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE
+import com.android.launcher3.model.data.WorkspaceItemInfo
import com.android.launcher3.util.ActivityContextWrapper
+import com.android.launcher3.util.Executors
import com.android.launcher3.util.FlagOp
import com.android.launcher3.util.LauncherLayoutBuilder
import com.android.launcher3.util.LauncherModelHelper
+import com.android.launcher3.util.TestUtil
import com.android.launcher3.util.UserIconInfo
+import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Test
@@ -219,6 +226,39 @@
)
}
+ @Test
+ fun `Inactive archived app previews are not drawn as preload icon`() {
+ // Given
+ val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
+ val archivedApp =
+ WorkspaceItemInfo().apply {
+ runtimeStatusFlags = runtimeStatusFlags or FLAG_ARCHIVED
+ runtimeStatusFlags = runtimeStatusFlags and FLAG_INSTALL_SESSION_ACTIVE.inv()
+ }
+ // When
+ previewItemManager.setDrawable(drawingParams, archivedApp)
+ // Then
+ assertThat(drawingParams.drawable).isNotInstanceOf(PreloadIconDrawable::class.java)
+ }
+
+ @Test
+ fun `Actively installing archived app previews are drawn as preload icon`() {
+ // Given
+ val drawingParams = PreviewItemDrawingParams(0f, 0f, 0f)
+ val archivedApp =
+ WorkspaceItemInfo().apply {
+ runtimeStatusFlags = runtimeStatusFlags or FLAG_ARCHIVED
+ runtimeStatusFlags = runtimeStatusFlags or FLAG_INSTALL_SESSION_ACTIVE
+ }
+ // When
+ TestUtil.runOnExecutorSync(Executors.MAIN_EXECUTOR) {
+ // Run on main thread because preload drawable triggers animator
+ previewItemManager.setDrawable(drawingParams, archivedApp)
+ }
+ // Then
+ assertThat(drawingParams.drawable).isInstanceOf(PreloadIconDrawable::class.java)
+ }
+
private fun profileFlagOp(type: Int) =
UserIconInfo(Process.myUserHandle(), type).applyBitmapInfoFlags(FlagOp.NO_OP)
}