Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c8bd37a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Sharesheet - Fix app stacking" into rvc-dev am: 8714e7d1

Change-Id: I40adf83f6eff2185825310ab01ed858541240424
parents 45241220 8714e7d1
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -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());
+54 −0
Original line number Diff line number Diff line
@@ -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();