From 27f592df8ce604c62327cc93ee5adac3152a0bd2 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Mon, 28 Oct 2013 18:38:14 -0700 Subject: [PATCH] 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 --- .../android/widget/ActivityChooserModel.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java index 00a92ca4cb2c9..61df92265518d 100644 --- a/core/java/android/widget/ActivityChooserModel.java +++ b/core/java/android/widget/ActivityChooserModel.java @@ -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 mPackageNameToActivityMap = - new HashMap(); + private final Map mPackageNameToActivityMap = + new HashMap(); public void sort(Intent intent, List activities, List historicalRecords) { - Map packageNameToActivityMap = - mPackageNameToActivityMap; - packageNameToActivityMap.clear(); + Map componentNameToActivityMap = + mPackageNameToActivityMap; + 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;