Merge "Deepshortcuts - only keep the per package shortcut count in memory." into ub-launcher3-master
This commit is contained in:
@@ -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<ComponentKey, String> deepShortcutMapCopy) {
|
||||
public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) {
|
||||
mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<WidgetListRowEntry> widgets);
|
||||
public void onPageBoundSynchronously(int page);
|
||||
public void executeOnNextDraw(ViewOnDrawExecutor executor);
|
||||
public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMap);
|
||||
public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMap);
|
||||
}
|
||||
|
||||
LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) {
|
||||
|
||||
@@ -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<ComponentKey, String> shortcutMapCopy = dataModel.deepShortcutMap.clone();
|
||||
scheduleCallbackTask(new CallbackTask() {
|
||||
@Override
|
||||
public void execute(Callbacks callbacks) {
|
||||
callbacks.bindDeepShortcutMap(shortcutMapCopy);
|
||||
}
|
||||
});
|
||||
final HashMap<ComponentKey, Integer> shortcutMapCopy =
|
||||
new HashMap<>(dataModel.deepShortcutMap);
|
||||
scheduleCallbackTask(callbacks -> callbacks.bindDeepShortcutMap(shortcutMapCopy));
|
||||
}
|
||||
|
||||
public void bindUpdatedWidgets(BgDataModel dataModel) {
|
||||
|
||||
@@ -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<ComponentKey, String> deepShortcutMap = new MultiHashMap<>();
|
||||
public final HashMap<ComponentKey, Integer> 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<String> 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<ShortcutInfoCompat> shortcuts) {
|
||||
if (packageName != null) {
|
||||
Iterator<ComponentKey> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ComponentKey, String> shortcutMapCopy;
|
||||
final HashMap<ComponentKey, Integer> 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() {
|
||||
|
||||
@@ -861,7 +861,7 @@ public class LoaderTask implements Runnable {
|
||||
if (mUserManager.isUserUnlocked(user)) {
|
||||
List<ShortcutInfoCompat> shortcuts =
|
||||
mShortcutManager.queryForAllShortcuts(user);
|
||||
mBgDataModel.updateDeepShortcutMap(null, user, shortcuts);
|
||||
mBgDataModel.updateDeepShortcutCounts(null, user, shortcuts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask {
|
||||
}
|
||||
|
||||
if (isUserUnlocked) {
|
||||
dataModel.updateDeepShortcutMap(
|
||||
dataModel.updateDeepShortcutCounts(
|
||||
null, mUser, deepShortcutManager.queryForAllShortcuts(mUser));
|
||||
}
|
||||
bindDeepShortcuts(dataModel);
|
||||
|
||||
@@ -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<String> shortcutIds,
|
||||
protected void populateAndShow(final BubbleTextView originalIcon, int shortcutCount,
|
||||
final List<NotificationKeyData> notificationKeys, List<SystemShortcut> 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() {
|
||||
|
||||
@@ -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<ComponentKey, String> mDeepShortcutMap = new MultiHashMap<>();
|
||||
/** Maps launcher activity components to a count of how many shortcuts they have. */
|
||||
private HashMap<ComponentKey, Integer> mDeepShortcutMap = new HashMap<>();
|
||||
/** Maps packages to their BadgeInfo's . */
|
||||
private Map<PackageUserKey, BadgeInfo> mPackageUserToBadgeInfos = new HashMap<>();
|
||||
/** Maps packages to their Widgets */
|
||||
@@ -146,22 +145,22 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
|
||||
}
|
||||
}
|
||||
|
||||
public void setDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMapCopy) {
|
||||
public void setDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMapCopy) {
|
||||
mDeepShortcutMap = deepShortcutMapCopy;
|
||||
if (LOGD) Log.d(TAG, "bindDeepShortcutMap: " + mDeepShortcutMap);
|
||||
}
|
||||
|
||||
public List<String> 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<String> 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) {
|
||||
|
||||
@@ -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<String> shortcutIds, final List<DeepShortcutView> shortcutViews,
|
||||
final List<DeepShortcutView> shortcutViews,
|
||||
final List<NotificationKeyData> notificationKeys) {
|
||||
final ComponentName activity = originalInfo.getTargetComponent();
|
||||
final UserHandle user = originalInfo.user;
|
||||
@@ -141,7 +141,7 @@ public class PopupPopulator {
|
||||
}
|
||||
|
||||
List<ShortcutInfoCompat> 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);
|
||||
|
||||
@@ -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<ShortcutInfoCompat> queryForShortcutsContainer(ComponentName activity,
|
||||
List<String> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user