From bdbeea28d256600095dc158be71baa545e8edb95 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Mon, 1 Jul 2019 13:06:21 -0400 Subject: Sharesheet - Fix regression in direct share sorting When mutiple apps share shortcuts and are given to the UI to display, the ranked order from both the App Prediction Service and the legacy ranker is inadvertently being discarded. This means that targets the user almost never uses will now be shown as high priority, causing confusion and pretty horrible user experience. Address the issue by adding in a score for shortcuts, based on the index in the ordered list. Bug: 136201796 Test: atest ChooserActivityTest and manually compare results from AppPredictionService to verify order is consistent Change-Id: I1fe2c2d2e13195f6f6c3a5818fade4844c15488e --- core/java/com/android/internal/app/ChooserActivity.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index f9d27bb46592..00206fc38d1d 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -1534,7 +1534,11 @@ public class ChooserActivity extends ResolverActivity { if (driList.get(i).getResolvedComponentName().equals( resultList.get(j).getTargetComponent())) { ShortcutManager.ShareShortcutInfo shareShortcutInfo = resultList.get(j); - ChooserTarget chooserTarget = convertToChooserTarget(shareShortcutInfo); + // Incoming results are ordered but without a score. Create a score + // based on the index in order to be sorted appropriately when joined + // with legacy direct share api results. + float score = Math.max(1.0f - (0.05f * j), 0.0f); + ChooserTarget chooserTarget = convertToChooserTarget(shareShortcutInfo, score); chooserTargets.add(chooserTarget); if (mDirectShareAppTargetCache != null && appTargets != null) { mDirectShareAppTargetCache.put(chooserTarget, appTargets.get(j)); @@ -1580,7 +1584,8 @@ public class ChooserActivity extends ResolverActivity { return false; } - private ChooserTarget convertToChooserTarget(ShortcutManager.ShareShortcutInfo shareShortcut) { + private ChooserTarget convertToChooserTarget(ShortcutManager.ShareShortcutInfo shareShortcut, + float score) { ShortcutInfo shortcutInfo = shareShortcut.getShortcutInfo(); Bundle extras = new Bundle(); extras.putString(Intent.EXTRA_SHORTCUT_ID, shortcutInfo.getId()); @@ -1591,7 +1596,7 @@ public class ChooserActivity extends ResolverActivity { null, // The ranking score for this target (0.0-1.0); the system will omit items with low // scores when there are too many Direct Share items. - 1.0f, + score, // The name of the component to be launched if this target is chosen. shareShortcut.getTargetComponent().clone(), // The extra values here will be merged into the Intent when this target is chosen. -- cgit v1.2.3-59-g8ed1b