From cc18ee380e8ec7b9039e7dcbbcc498fb235f75aa Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Mon, 9 Jun 2025 16:08:14 -0500 Subject: [PATCH] Do not modify the original item info when adding a new item in Worksapce Fix: 418114270 Test: NA Flag: EXEMPT bug fix (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:dbd6f0d18f69d5d33862aaad015c4c8c5907fb46) Merged-In: Ic0dd00da4f363868a1c2abeeb736b86f6f706631 Change-Id: Ic0dd00da4f363868a1c2abeeb736b86f6f706631 --- src/com/android/launcher3/Workspace.java | 3 +-- src/com/android/launcher3/util/ItemInflater.kt | 17 ++++++++++------- .../android/launcher3/model/AsyncBindingTest.kt | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index d589167fa5..ee3103c737 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2906,8 +2906,7 @@ public class Workspace extends PagedView mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); // TODO(b/414409465) We could just create a new info making a copy with all the new // needed values instead of choosing on each case what to modify. - info.container = container; - View view = mLauncher.getItemInflater().inflateItem(info, cellLayout); + View view = mLauncher.getItemInflater().inflateItem(info, cellLayout, container); d.dragInfo = info = (ItemInfo) view.getTag(); // First we find the cell nearest to point at which the item is diff --git a/src/com/android/launcher3/util/ItemInflater.kt b/src/com/android/launcher3/util/ItemInflater.kt index 0c73df525b..8bcc52a582 100644 --- a/src/com/android/launcher3/util/ItemInflater.kt +++ b/src/com/android/launcher3/util/ItemInflater.kt @@ -54,7 +54,11 @@ class ItemInflater( WidgetInflater(context, LauncherAppState.getInstance(context).isSafeModeEnabled) @JvmOverloads - fun inflateItem(item: ItemInfo, nullableParent: ViewGroup? = null): View? { + fun inflateItem( + item: ItemInfo, + nullableParent: ViewGroup? = null, + container: Int = item.container, + ): View? { val parent = nullableParent ?: defaultParent when (item.itemType) { Favorites.ITEM_TYPE_APPLICATION, @@ -66,11 +70,11 @@ class ItemInflater( is WorkspaceItemInfo -> item else -> return null } - if (info.container == Favorites.CONTAINER_ALL_APPS_PREDICTION) { + if (container == Favorites.CONTAINER_ALL_APPS_PREDICTION) { // Came from all apps prediction row -- make a copy info = WorkspaceItemInfo(info) } - return createShortcut(info, parent) + return createShortcut(info, parent, container) } Favorites.ITEM_TYPE_FOLDER -> return FolderIcon.inflateFolderAndIcon( @@ -103,10 +107,9 @@ class ItemInflater( * @param info The data structure describing the shortcut. * @return A View inflated from layoutResId. */ - private fun createShortcut(info: WorkspaceItemInfo, parent: ViewGroup): View { + private fun createShortcut(info: WorkspaceItemInfo, parent: ViewGroup, container: Int): View { val layout = - if (info.container == Favorites.CONTAINER_HOTSEAT_PREDICTION) - R.layout.predicted_app_icon + if (container == Favorites.CONTAINER_HOTSEAT_PREDICTION) R.layout.predicted_app_icon else R.layout.app_icon val favorite = LayoutInflater.from(parent.context).inflate(layout, parent, false) as BubbleTextView @@ -114,7 +117,7 @@ class ItemInflater( favorite.setOnClickListener(clickListener) favorite.onFocusChangeListener = focusListener - if (info.container == Favorites.CONTAINER_HOTSEAT_PREDICTION) favorite.verifyHighRes() + if (container == Favorites.CONTAINER_HOTSEAT_PREDICTION) favorite.verifyHighRes() return favorite } diff --git a/tests/multivalentTests/src/com/android/launcher3/model/AsyncBindingTest.kt b/tests/multivalentTests/src/com/android/launcher3/model/AsyncBindingTest.kt index 61d96bab00..2aeba6076a 100644 --- a/tests/multivalentTests/src/com/android/launcher3/model/AsyncBindingTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/model/AsyncBindingTest.kt @@ -98,7 +98,7 @@ class AsyncBindingTest { View(context) } .whenever(itemInflater) - .inflateItem(any(), isNull()) + .inflateItem(any(), isNull(), any()) doReturn(itemInflater).whenever(launcher).itemInflater doReturn(InvariantDeviceProfile.INSTANCE.get(context).getDeviceProfile(context))