Loading core/java/com/android/internal/app/ChooserListAdapter.java +9 −6 Original line number Diff line number Diff line Loading @@ -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()); Loading core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +54 −0 Original line number Diff line number Diff line Loading @@ -293,6 +293,60 @@ public class ChooserActivityTest { assertThat(chosen[0], is(toChoose)); } @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(); Loading Loading
core/java/com/android/internal/app/ChooserListAdapter.java +9 −6 Original line number Diff line number Diff line Loading @@ -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()); Loading
core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +54 −0 Original line number Diff line number Diff line Loading @@ -293,6 +293,60 @@ public class ChooserActivityTest { assertThat(chosen[0], is(toChoose)); } @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(); Loading