Add logs and prevent collissions when adding items

-AddWorkspaceItemsTask can add multiple items to the same position, we
avoid that here by adding each item to the database before processing
the next item.
-We add more logs to InstallSessionHelper to be able to check who the
installer is

Bug: 432237485, 425754534
Test: AddWorkspaceItemsTaskTest
Flag: EXEMPT bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4b439e999734852a017ce662543b4789b36e0e3b)
Merged-In: I2d238f3eb27734ab9cb723e2fe9d6752c5921dd1
Change-Id: I2d238f3eb27734ab9cb723e2fe9d6752c5921dd1
This commit is contained in:
Federico Baron authored and Android Build Coastguard Worker committed 2025-07-27 22:00:10 -07:00
1 parent 02aa11510d
commit df328e5dfa
6 files changed
+71 -15

No files matched your search

@@ -125,8 +125,8 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask {
ModelWriter writer = taskController.getModelWriter();
for (ItemInfo item : filteredItems) {
// Find appropriate space for the item.
int[] coords = mItemSpaceFinder.findSpaceForItem(
workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
int[] coords = mItemSpaceFinder.findSpaceForItem(workspaceScreens,
addedWorkspaceScreensFinal, addedItemsFinal, item.spanX, item.spanY);
int screenId = coords[0];
ItemInfo itemInfo;
@@ -54,8 +54,8 @@ public class WorkspaceItemSpaceFinder {
*
* @return screenId and the coordinates for the item in an int array of size 3.
*/
public int[] findSpaceForItem(
IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY) {
public int[] findSpaceForItem(IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal,
ArrayList<ItemInfo> addItemsFinal, int spanX, int spanY) {
LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
// Use sBgItemsIdMap as all the items are already loaded.
@@ -72,6 +72,18 @@ public class WorkspaceItemSpaceFinder {
}
}
// Add items that are due to be added to the database from AddWorkspaceItemsTask#execute.
for (ItemInfo info : addItemsFinal) {
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
ArrayList<ItemInfo> items = screenItems.get(info.screenId);
if (items == null) {
items = new ArrayList<>();
screenItems.put(info.screenId, items);
}
items.add(info);
}
}
// Find appropriate space for the item.
int screenId = 0;
int[] coordinates = new int[2];
@@ -225,8 +225,11 @@ public class InstallSessionHelper {
// not already present. For general app installations however, we do support it.
if (!Flags.enableSupportForArchiving() || !sessionInfo.isUnarchival()) {
FileLog.d(LOG, "Adding package name to install queue: "
+ sessionInfo.getAppPackageName());
+ sessionInfo.getAppPackageName()
+ "Package installer: "
+ sessionInfo.getInstallerPackageName()
+ "Session id: "
+ sessionInfo.getSessionId());
ItemInstallQueue.INSTANCE.get(mAppContext)
.queueItem(sessionInfo.getAppPackageName(), getUserHandle(sessionInfo));
}