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

Commit a4e1f435 authored by Svetoslav's avatar Svetoslav Committed by Android Git Automerger
Browse files

am ac5d3827: Merge "Share pack historical sorting using wrong keys." into klp-dev

* commit 'ac5d3827':
  Share pack historical sorting using wrong keys.
parents 330c6be9 ac5d3827
Loading
Loading
Loading
Loading
+11 −9
Original line number Original line Diff line number Diff line
@@ -938,29 +938,31 @@ public class ActivityChooserModel extends DataSetObservable {
    private final class DefaultSorter implements ActivitySorter {
    private final class DefaultSorter implements ActivitySorter {
        private static final float WEIGHT_DECAY_COEFFICIENT = 0.95f;
        private static final float WEIGHT_DECAY_COEFFICIENT = 0.95f;


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


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


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


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