diff options
| author | 2020-06-10 09:56:38 -0400 | |
|---|---|---|
| committer | 2020-06-10 11:16:55 -0400 | |
| commit | 1245b38b600e415a3b3cbad90d2948c34c4bafad (patch) | |
| tree | f2fdb2ddf5b51913774060f77e895c78f62185a7 | |
| parent | a4614b0f1fa2b1aed944a659355a5a91c2a91c5d (diff) | |
Sharesheet - Fix logic for a-z count
Prior logic only counted the number of grouped items. This could
result in the a-z list not being shown even though there were
additional targets. For instance, if 1 group had 9 targets, a-z
would've been hidden even though only 4 targets were present in the
ranked app row, resulting in 5 targets being inaccessible.
Fixes: 158017940
Test: atest ChooserActivityTest#fourOptionsStackedIntoOneTarget
Change-Id: I58e262e40f3064ce8a091e44d6b00163c8f4e4f3
3 files changed, 13 insertions, 10 deletions
diff --git a/core/java/com/android/internal/app/ChooserListAdapter.java b/core/java/com/android/internal/app/ChooserListAdapter.java index f4fb993fbb93..d6ff7b13c934 100644 --- a/core/java/com/android/internal/app/ChooserListAdapter.java +++ b/core/java/com/android/internal/app/ChooserListAdapter.java @@ -181,6 +181,7 @@ public class ChooserListAdapter extends ResolverListAdapter { ri.icon = 0; } mCallerTargets.add(new DisplayResolveInfo(ii, ri, ii, makePresentationGetter(ri))); + if (mCallerTargets.size() == MAX_SUGGESTED_APP_TARGETS) break; } } } @@ -320,7 +321,7 @@ public class ChooserListAdapter extends ResolverListAdapter { public int getCallerTargetCount() { - return Math.min(mCallerTargets.size(), MAX_SUGGESTED_APP_TARGETS); + return mCallerTargets.size(); } /** @@ -346,8 +347,9 @@ public class ChooserListAdapter extends ResolverListAdapter { } int getAlphaTargetCount() { - int standardCount = mSortedList.size(); - return standardCount > mChooserListCommunicator.getMaxRankedTargets() ? standardCount : 0; + int groupedCount = mSortedList.size(); + int ungroupedCount = mCallerTargets.size() + mDisplayList.size(); + return ungroupedCount > mChooserListCommunicator.getMaxRankedTargets() ? groupedCount : 0; } /** diff --git a/core/java/com/android/internal/app/ResolverListAdapter.java b/core/java/com/android/internal/app/ResolverListAdapter.java index b1e8ed1f943e..d63ebda5117e 100644 --- a/core/java/com/android/internal/app/ResolverListAdapter.java +++ b/core/java/com/android/internal/app/ResolverListAdapter.java @@ -617,7 +617,8 @@ public class ResolverListAdapter extends BaseAdapter { } } - UserHandle getUserHandle() { + @VisibleForTesting + public UserHandle getUserHandle() { return mResolverListController.getUserHandle(); } diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java index 547176855f32..49de7c80057f 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -21,6 +21,7 @@ import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.swipeUp; import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist; import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.hasSibling; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; @@ -299,9 +300,8 @@ public class ChooserActivityTest { public void fourOptionsStackedIntoOneTarget() throws InterruptedException { Intent sendIntent = createSendTextIntent(); - // create 12 unique app targets to ensure the app ranking row can be filled, otherwise - // targets will not stack - List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(12); + // create just enough targets to ensure the a-z list should be shown + List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(1); // next create 4 targets in a single app that should be stacked into a single target String packageName = "xxx.yyy"; @@ -328,8 +328,8 @@ public class ChooserActivityTest { .launchActivity(Intent.createChooser(sendIntent, null)); waitForIdle(); - // expect 12 unique targets + 1 group + 4 ranked app targets - assertThat(activity.getAdapter().getCount(), is(17)); + // expect 1 unique targets + 1 group + 4 ranked app targets + assertThat(activity.getAdapter().getCount(), is(6)); ResolveInfo[] chosen = new ResolveInfo[1]; sOverrides.onSafelyStartCallback = targetInfo -> { @@ -337,7 +337,7 @@ public class ChooserActivityTest { return true; }; - onView(withText(appName)).perform(click()); + onView(allOf(withText(appName), hasSibling(withText("")))).perform(click()); waitForIdle(); // clicking will launch a dialog to choose the activity within the app |