diff options
| -rw-r--r-- | core/java/com/android/internal/app/ChooserListAdapter.java | 15 | ||||
| -rw-r--r-- | core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java | 54 |
2 files changed, 63 insertions, 6 deletions
diff --git a/core/java/com/android/internal/app/ChooserListAdapter.java b/core/java/com/android/internal/app/ChooserListAdapter.java index f426bc0ecbb5..14a2d379ced6 100644 --- a/core/java/com/android/internal/app/ChooserListAdapter.java +++ b/core/java/com/android/internal/app/ChooserListAdapter.java @@ -262,14 +262,17 @@ public class ChooserListAdapter extends ResolverListAdapter { Map<String, DisplayResolveInfo> consolidated = new HashMap<>(); for (DisplayResolveInfo info : mDisplayList) { String packageName = info.getResolvedComponentName().getPackageName(); - if (consolidated.get(packageName) != null) { - // create consolidated target + DisplayResolveInfo multiDri = consolidated.get(packageName); + if (multiDri == null) { + consolidated.put(packageName, info); + } else if (multiDri instanceof MultiDisplayResolveInfo) { + ((MultiDisplayResolveInfo) multiDri).addTarget(info); + } else { + // create consolidated target from the single DisplayResolveInfo MultiDisplayResolveInfo multiDisplayResolveInfo = - new MultiDisplayResolveInfo(packageName, info); - multiDisplayResolveInfo.addTarget(consolidated.get(packageName)); + new MultiDisplayResolveInfo(packageName, multiDri); + multiDisplayResolveInfo.addTarget(info); consolidated.put(packageName, multiDisplayResolveInfo); - } else { - consolidated.put(packageName, info); } } mSortedList.addAll(consolidated.values()); 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 e23a3cad914b..cb84ff907069 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -294,6 +294,60 @@ public class ChooserActivityTest { } @Test + 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); + + // next create 4 targets in a single app that should be stacked into a single target + String packageName = "xxx.yyy"; + String appName = "aaa"; + ComponentName cn = new ComponentName(packageName, appName); + Intent intent = new Intent("fakeIntent"); + List<ResolvedComponentInfo> infosToStack = new ArrayList<>(); + for (int i = 0; i < 4; i++) { + ResolveInfo resolveInfo = ResolverDataProvider.createResolveInfo(i, + UserHandle.USER_CURRENT); + resolveInfo.activityInfo.applicationInfo.name = appName; + resolveInfo.activityInfo.applicationInfo.packageName = packageName; + resolveInfo.activityInfo.packageName = packageName; + resolveInfo.activityInfo.name = "ccc" + i; + infosToStack.add(new ResolvedComponentInfo(cn, intent, resolveInfo)); + } + resolvedComponentInfos.addAll(infosToStack); + + when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(), + Mockito.anyBoolean(), + Mockito.isA(List.class))).thenReturn(resolvedComponentInfos); + + final ChooserWrapperActivity activity = mActivityRule + .launchActivity(Intent.createChooser(sendIntent, null)); + waitForIdle(); + + // expect 12 unique targets + 1 group + 4 ranked app targets + assertThat(activity.getAdapter().getCount(), is(17)); + + ResolveInfo[] chosen = new ResolveInfo[1]; + sOverrides.onSafelyStartCallback = targetInfo -> { + chosen[0] = targetInfo.getResolveInfo(); + return true; + }; + + onView(withText(appName)).perform(click()); + waitForIdle(); + + // clicking will launch a dialog to choose the activity within the app + onView(withText(appName)).check(matches(isDisplayed())); + int i = 0; + for (ResolvedComponentInfo rci: infosToStack) { + onView(withText("ccc" + i)).check(matches(isDisplayed())); + ++i; + } + } + + @Test public void updateChooserCountsAndModelAfterUserSelection() throws InterruptedException { Intent sendIntent = createSendTextIntent(); List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2); |