diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 0395fbbcc7..e714a0bf8d 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -110,7 +110,6 @@ import com.android.launcher3.util.ActivityResultInfo; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.ItemInfoMatcher; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.MultiValueAlpha; import com.android.launcher3.util.MultiValueAlpha.AlphaProperty; import com.android.launcher3.util.PackageManagerHelper; @@ -137,6 +136,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -2163,11 +2163,11 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } /** - * Copies LauncherModel's map of activities to shortcut ids to Launcher's. This is necessary + * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary * because LauncherModel's map is updated in the background, while Launcher runs on the UI. */ @Override - public void bindDeepShortcutMap(MultiHashMap deepShortcutMapCopy) { + public void bindDeepShortcutMap(HashMap deepShortcutMapCopy) { mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy); } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 8e9021f58b..b3dabae538 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -57,7 +57,6 @@ import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.ItemInfoMatcher; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.Preconditions; import com.android.launcher3.util.Provider; @@ -69,6 +68,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -161,7 +161,7 @@ public class LauncherModel extends BroadcastReceiver public void bindAllWidgets(ArrayList widgets); public void onPageBoundSynchronously(int page); public void executeOnNextDraw(ViewOnDrawExecutor executor); - public void bindDeepShortcutMap(MultiHashMap deepShortcutMap); + public void bindDeepShortcutMap(HashMap deepShortcutMap); } LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) { diff --git a/src/com/android/launcher3/model/BaseModelUpdateTask.java b/src/com/android/launcher3/model/BaseModelUpdateTask.java index fcdc088a70..c9d8e3eb48 100644 --- a/src/com/android/launcher3/model/BaseModelUpdateTask.java +++ b/src/com/android/launcher3/model/BaseModelUpdateTask.java @@ -27,10 +27,10 @@ import com.android.launcher3.LauncherModel.Callbacks; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.ItemInfoMatcher; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.widget.WidgetListRowEntry; import java.util.ArrayList; +import java.util.HashMap; import java.util.concurrent.Executor; /** @@ -107,13 +107,9 @@ public abstract class BaseModelUpdateTask implements ModelUpdateTask { } public void bindDeepShortcuts(BgDataModel dataModel) { - final MultiHashMap shortcutMapCopy = dataModel.deepShortcutMap.clone(); - scheduleCallbackTask(new CallbackTask() { - @Override - public void execute(Callbacks callbacks) { - callbacks.bindDeepShortcutMap(shortcutMapCopy); - } - }); + final HashMap shortcutMapCopy = + new HashMap<>(dataModel.deepShortcutMap); + scheduleCallbackTask(callbacks -> callbacks.bindDeepShortcutMap(shortcutMapCopy)); } public void bindUpdatedWidgets(BgDataModel dataModel) { diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java index 81eefc4d8b..151d6f4b6f 100644 --- a/src/com/android/launcher3/model/BgDataModel.java +++ b/src/com/android/launcher3/model/BgDataModel.java @@ -38,7 +38,6 @@ import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSparseArrayMap; -import com.android.launcher3.util.MultiHashMap; import com.google.protobuf.nano.MessageNano; import java.io.FileDescriptor; @@ -97,9 +96,9 @@ public class BgDataModel { public boolean hasShortcutHostPermission; /** - * Maps all launcher activities to the id's of their shortcuts (if they have any). + * Maps all launcher activities to counts of their shortcuts. */ - public final MultiHashMap deepShortcutMap = new MultiHashMap<>(); + public final HashMap deepShortcutMap = new HashMap<>(); /** * Entire list of widgets. @@ -154,14 +153,11 @@ public class BgDataModel { } if (args.length > 0 && TextUtils.equals(args[0], "--all")) { - writer.println(prefix + "shortcuts"); - for (ArrayList map : deepShortcutMap.values()) { - writer.print(prefix + " "); - for (String str : map) { - writer.print(str + ", "); - } - writer.println(); + writer.println(prefix + "shortcut counts "); + for (Integer count : deepShortcutMap.values()) { + writer.print(count + ", "); } + writer.println(); } } @@ -359,9 +355,9 @@ public class BgDataModel { } /** - * Clear all the deep shortcuts for the given package, and re-add the new shortcuts. + * Clear all the deep shortcut counts for the given package, and re-add the new shortcut counts. */ - public synchronized void updateDeepShortcutMap( + public synchronized void updateDeepShortcutCounts( String packageName, UserHandle user, List shortcuts) { if (packageName != null) { Iterator keysIter = deepShortcutMap.keySet().iterator(); @@ -381,7 +377,9 @@ public class BgDataModel { if (shouldShowInContainer) { ComponentKey targetComponent = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle()); - deepShortcutMap.addToList(targetComponent, shortcut.getId()); + + Integer previousCount = deepShortcutMap.get(targetComponent); + deepShortcutMap.put(targetComponent, previousCount == null ? 1 : previousCount + 1); } } } diff --git a/src/com/android/launcher3/model/LoaderResults.java b/src/com/android/launcher3/model/LoaderResults.java index 2c15df1925..1d18e7667b 100644 --- a/src/com/android/launcher3/model/LoaderResults.java +++ b/src/com/android/launcher3/model/LoaderResults.java @@ -34,7 +34,6 @@ import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; import com.android.launcher3.util.LooperIdleLock; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.ViewOnDrawExecutor; import com.android.launcher3.widget.WidgetListRowEntry; @@ -42,9 +41,8 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; +import java.util.HashMap; import java.util.Iterator; -import java.util.Set; import java.util.concurrent.Executor; /** @@ -333,20 +331,16 @@ public class LoaderResults { } public void bindDeepShortcuts() { - final MultiHashMap shortcutMapCopy; + final HashMap shortcutMapCopy; synchronized (mBgDataModel) { - shortcutMapCopy = mBgDataModel.deepShortcutMap.clone(); + shortcutMapCopy = new HashMap<>(mBgDataModel.deepShortcutMap); } - Runnable r = new Runnable() { - @Override - public void run() { - Callbacks callbacks = mCallbacks.get(); - if (callbacks != null) { - callbacks.bindDeepShortcutMap(shortcutMapCopy); - } + mUiExecutor.execute(() -> { + Callbacks callbacks = mCallbacks.get(); + if (callbacks != null) { + callbacks.bindDeepShortcutMap(shortcutMapCopy); } - }; - mUiExecutor.execute(r); + }); } public void bindAllApps() { diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 405125e12d..8b3e2c9a86 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -861,7 +861,7 @@ public class LoaderTask implements Runnable { if (mUserManager.isUserUnlocked(user)) { List shortcuts = mShortcutManager.queryForAllShortcuts(user); - mBgDataModel.updateDeepShortcutMap(null, user, shortcuts); + mBgDataModel.updateDeepShortcutCounts(null, user, shortcuts); } } } diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java index 47fcd9e13b..e99fed9294 100644 --- a/src/com/android/launcher3/model/ShortcutsChangedTask.java +++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java @@ -116,7 +116,7 @@ public class ShortcutsChangedTask extends BaseModelUpdateTask { if (mUpdateIdMap) { // Update the deep shortcut map if the list of ids has changed for an activity. - dataModel.updateDeepShortcutMap(mPackageName, mUser, mShortcuts); + dataModel.updateDeepShortcutCounts(mPackageName, mUser, mShortcuts); bindDeepShortcuts(dataModel); } } diff --git a/src/com/android/launcher3/model/UserLockStateChangedTask.java b/src/com/android/launcher3/model/UserLockStateChangedTask.java index 40c1912252..8e7557a2ee 100644 --- a/src/com/android/launcher3/model/UserLockStateChangedTask.java +++ b/src/com/android/launcher3/model/UserLockStateChangedTask.java @@ -117,7 +117,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask { } if (isUserUnlocked) { - dataModel.updateDeepShortcutMap( + dataModel.updateDeepShortcutCounts( null, mUser, deepShortcutManager.queryForAllShortcuts(mUser)); } bindDeepShortcuts(dataModel); diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index b9e6a98b45..4f1fcda122 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -216,13 +216,13 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, BubbleTextView icon, ItemInfo item, SystemShortcutFactory factory) { PopupDataProvider popupDataProvider = mLauncher.getPopupDataProvider(); populateAndShow(icon, - popupDataProvider.getShortcutIdsForItem(item), + popupDataProvider.getShortcutCountForItem(item), popupDataProvider.getNotificationKeysForItem(item), factory.getEnabledShortcuts(mLauncher, item)); } @TargetApi(Build.VERSION_CODES.P) - protected void populateAndShow(final BubbleTextView originalIcon, final List shortcutIds, + protected void populateAndShow(final BubbleTextView originalIcon, int shortcutCount, final List notificationKeys, List systemShortcuts) { mNumNotifications = notificationKeys.size(); mOriginalIcon = originalIcon; @@ -240,12 +240,12 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, int viewsToFlip = getChildCount(); mSystemShortcutContainer = this; - if (!shortcutIds.isEmpty()) { + if (shortcutCount > 0) { if (mNotificationItemView != null) { mNotificationItemView.addGutter(); } - for (int i = shortcutIds.size(); i > 0; i--) { + for (int i = shortcutCount; i > 0; i--) { mShortcuts.add(inflateAndAdd(R.layout.deep_shortcut, this)); } updateHiddenShortcuts(); @@ -284,7 +284,7 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, final Looper workerLooper = LauncherModel.getWorkerLooper(); new Handler(workerLooper).postAtFrontOfQueue(PopupPopulator.createUpdateRunnable( mLauncher, originalItemInfo, new Handler(Looper.getMainLooper()), - this, shortcutIds, mShortcuts, notificationKeys)); + this, mShortcuts, notificationKeys)); } private String getTitleForAccessibility() { diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index 4d5a9c6e93..320650397f 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -29,7 +29,6 @@ import com.android.launcher3.notification.NotificationKeyData; import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.util.ComponentKey; -import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.widget.WidgetListRowEntry; @@ -52,8 +51,8 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan private final Launcher mLauncher; - /** Maps launcher activity components to their list of shortcut ids. */ - private MultiHashMap mDeepShortcutMap = new MultiHashMap<>(); + /** Maps launcher activity components to a count of how many shortcuts they have. */ + private HashMap mDeepShortcutMap = new HashMap<>(); /** Maps packages to their BadgeInfo's . */ private Map mPackageUserToBadgeInfos = new HashMap<>(); /** Maps packages to their Widgets */ @@ -146,22 +145,22 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } } - public void setDeepShortcutMap(MultiHashMap deepShortcutMapCopy) { + public void setDeepShortcutMap(HashMap deepShortcutMapCopy) { mDeepShortcutMap = deepShortcutMapCopy; if (LOGD) Log.d(TAG, "bindDeepShortcutMap: " + mDeepShortcutMap); } - public List getShortcutIdsForItem(ItemInfo info) { + public int getShortcutCountForItem(ItemInfo info) { if (!DeepShortcutManager.supportsShortcuts(info)) { - return Collections.EMPTY_LIST; + return 0; } ComponentName component = info.getTargetComponent(); if (component == null) { - return Collections.EMPTY_LIST; + return 0; } - List ids = mDeepShortcutMap.get(new ComponentKey(component, info.user)); - return ids == null ? Collections.EMPTY_LIST : ids; + Integer count = mDeepShortcutMap.get(new ComponentKey(component, info.user)); + return count == null ? 0 : count; } public BadgeInfo getBadgeInfoForItem(ItemInfo info) { diff --git a/src/com/android/launcher3/popup/PopupPopulator.java b/src/com/android/launcher3/popup/PopupPopulator.java index 61113b80fd..2c59202e9b 100644 --- a/src/com/android/launcher3/popup/PopupPopulator.java +++ b/src/com/android/launcher3/popup/PopupPopulator.java @@ -124,7 +124,7 @@ public class PopupPopulator { public static Runnable createUpdateRunnable(final Launcher launcher, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, - final List shortcutIds, final List shortcutViews, + final List shortcutViews, final List notificationKeys) { final ComponentName activity = originalInfo.getTargetComponent(); final UserHandle user = originalInfo.user; @@ -141,7 +141,7 @@ public class PopupPopulator { } List shortcuts = DeepShortcutManager.getInstance(launcher) - .queryForShortcutsContainer(activity, shortcutIds, user); + .queryForShortcutsContainer(activity, user); String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId; shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe); diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java index 24e2e2f81f..e70aac68f6 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java @@ -94,10 +94,11 @@ public class DeepShortcutManager { * Gets all the manifest and dynamic shortcuts associated with the given package and user, * to be displayed in the shortcuts container on long press. */ + @TargetApi(25) public List queryForShortcutsContainer(ComponentName activity, - List ids, UserHandle user) { + UserHandle user) { return query(ShortcutQuery.FLAG_MATCH_MANIFEST | ShortcutQuery.FLAG_MATCH_DYNAMIC, - activity.getPackageName(), activity, ids, user); + activity.getPackageName(), activity, null, user); } /**