From e824438570b2ef69c555de101ad3d078e6634e95 Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Wed, 20 Jan 2021 10:10:46 -0800 Subject: [PATCH] Add check to prevent adding duplicate pending install icons onto the worksapce. Test: manual Change-Id: Ifa1bbe39278a7a4f7a385204efcbb815c2a59ca3 --- .../launcher3/model/ItemInstallQueue.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/model/ItemInstallQueue.java b/src/com/android/launcher3/model/ItemInstallQueue.java index 5e48a0ff2e..d09bf81e17 100644 --- a/src/com/android/launcher3/model/ItemInstallQueue.java +++ b/src/com/android/launcher3/model/ItemInstallQueue.java @@ -104,8 +104,10 @@ public class ItemInstallQueue { @WorkerThread private void addToQueue(PendingInstallShortcutInfo info) { ensureQueueLoaded(); - mItems.add(info); - mStorage.write(mContext, mItems); + if (!mItems.contains(info)) { + mItems.add(info); + mStorage.write(mContext, mItems); + } } @WorkerThread @@ -303,6 +305,33 @@ public class ItemInstallQueue { } return null; } + + @Override + public boolean equals(Object obj) { + if (obj instanceof PendingInstallShortcutInfo) { + PendingInstallShortcutInfo other = (PendingInstallShortcutInfo) obj; + + boolean userMatches = user.equals(other.user); + boolean itemTypeMatches = itemType == other.itemType; + boolean intentMatches = intent.toUri(0).equals(other.intent.toUri(0)); + boolean shortcutInfoMatches = shortcutInfo == null + ? other.shortcutInfo == null + : other.shortcutInfo != null + && shortcutInfo.getId().equals(other.shortcutInfo.getId()) + && shortcutInfo.getPackage().equals(other.shortcutInfo.getPackage()); + boolean providerInfoMatches = providerInfo == null + ? other.providerInfo == null + : other.providerInfo != null + && providerInfo.provider.equals(other.providerInfo.provider); + + return userMatches + && itemTypeMatches + && intentMatches + && shortcutInfoMatches + && providerInfoMatches; + } + return false; + } } private static String getIntentPackage(Intent intent) {