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
diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java
index 00a92ca..61df922 100644
--- a/core/java/android/widget/ActivityChooserModel.java
+++ b/core/java/android/widget/ActivityChooserModel.java
@@ -938,29 +938,31 @@
     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 =
-                mPackageNameToActivityMap;
-            packageNameToActivityMap.clear();
+            Map<ComponentName, ActivityResolveInfo> 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;