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

Commit 27f592df authored by Svetoslav's avatar Svetoslav
Browse files

Share pack historical sorting using wrong keys.

The ActivityChooserModel keeps a history of the last fifty
share targets and based on past usage orders the targets in
the UI. The soring implementation is using a map for improving
performance. However, the activities in this map were keyed
on the package name but there maybe more that one share
target per package. Thus, the sorting was generating bad
results. Now the unique component name is used.

bug:11195578

Change-Id: I8c7018fea168b7253ddbe57b477028368726e75e
parent baeabb65
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -938,29 +938,31 @@ public class ActivityChooserModel extends DataSetObservable {
    private final class DefaultSorter implements ActivitySorter {
        private static final float WEIGHT_DECAY_COEFFICIENT = 0.95f;

        private final Map<String, ActivityResolveInfo> mPackageNameToActivityMap =
            new HashMap<String, ActivityResolveInfo>();
        private final Map<ComponentName, ActivityResolveInfo> mPackageNameToActivityMap =
                new HashMap<ComponentName, ActivityResolveInfo>();

        public void sort(Intent intent, List<ActivityResolveInfo> activities,
                List<HistoricalRecord> historicalRecords) {
            Map<String, ActivityResolveInfo> packageNameToActivityMap =
            Map<ComponentName, ActivityResolveInfo> componentNameToActivityMap =
                    mPackageNameToActivityMap;
            packageNameToActivityMap.clear();
            componentNameToActivityMap.clear();

            final int activityCount = activities.size();
            for (int i = 0; i < activityCount; i++) {
                ActivityResolveInfo activity = activities.get(i);
                activity.weight = 0.0f;
                String packageName = activity.resolveInfo.activityInfo.packageName;
                packageNameToActivityMap.put(packageName, activity);
                ComponentName componentName = new ComponentName(
                        activity.resolveInfo.activityInfo.packageName,
                        activity.resolveInfo.activityInfo.name);
                componentNameToActivityMap.put(componentName, activity);
            }

            final int lastShareIndex = historicalRecords.size() - 1;
            float nextRecordWeight = 1;
            for (int i = lastShareIndex; i >= 0; i--) {
                HistoricalRecord historicalRecord = historicalRecords.get(i);
                String packageName = historicalRecord.activity.getPackageName();
                ActivityResolveInfo activity = packageNameToActivityMap.get(packageName);
                ComponentName componentName = historicalRecord.activity;
                ActivityResolveInfo activity = componentNameToActivityMap.get(componentName);
                if (activity != null) {
                    activity.weight += historicalRecord.weight * nextRecordWeight;
                    nextRecordWeight = nextRecordWeight * WEIGHT_DECAY_COEFFICIENT;