Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d21fd69 authored by Zak Cohen's avatar Zak Cohen Committed by Android (Google) Code Review
Browse files

Merge "Deepshortcuts - only keep the per package shortcut count in memory."...

Merge "Deepshortcuts - only keep the per package shortcut count in memory." into ub-launcher3-master
parents 76fea5fd 658c67a6
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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);
    }

+2 −2
Original line number Diff line number Diff line
@@ -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) {
+4 −8
Original line number Diff line number Diff line
@@ -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) {
+11 −13
Original line number Diff line number Diff line
@@ -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,16 +153,13 @@ 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(prefix + "shortcut counts ");
            for (Integer count : deepShortcutMap.values()) {
                writer.print(count + ", ");
            }
            writer.println();
        }
    }
    }

    private synchronized void dumpProto(String prefix, FileDescriptor fd, PrintWriter writer,
            String[] args) {
@@ -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);
            }
        }
    }
+8 −14
Original line number Diff line number Diff line
@@ -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() {
        mUiExecutor.execute(() -> {
            Callbacks callbacks = mCallbacks.get();
            if (callbacks != null) {
                callbacks.bindDeepShortcutMap(shortcutMapCopy);
            }
            }
        };
        mUiExecutor.execute(r);
        });
    }

    public void bindAllApps() {
Loading