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

Commit 9e847f03 authored by Antoan Angelov's avatar Antoan Angelov Committed by Automerger Merge Worker
Browse files

Merge "Use intent resolver strings for sharesheet when picking intent" into...

Merge "Use intent resolver strings for sharesheet when picking intent" into rvc-dev am: 950aca57 am: 0675309d

Change-Id: Ic73193682155c2c652b91f48083a2a32bf888578
parents 7be12959 0675309d
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -884,7 +884,8 @@ public class ChooserActivity extends ResolverActivity implements
                /* context */ this,
                adapter,
                getPersonalProfileUserHandle(),
                /* workProfileUserHandle= */ null);
                /* workProfileUserHandle= */ null,
                isSendAction(getTargetIntent()));
    }

    private ChooserMultiProfilePagerAdapter createChooserMultiProfilePagerAdapterForTwoProfiles(
@@ -914,7 +915,8 @@ public class ChooserActivity extends ResolverActivity implements
                workAdapter,
                selectedProfile,
                getPersonalProfileUserHandle(),
                getWorkProfileUserHandle());
                getWorkProfileUserHandle(),
                isSendAction(getTargetIntent()));
    }

    private int findSelectedProfile() {
+51 −18
Original line number Diff line number Diff line
@@ -37,15 +37,18 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
    private static final int SINGLE_CELL_SPAN_SIZE = 1;

    private final ChooserProfileDescriptor[] mItems;
    private final boolean mIsSendAction;

    ChooserMultiProfilePagerAdapter(Context context,
            ChooserActivity.ChooserGridAdapter adapter,
            UserHandle personalProfileUserHandle,
            UserHandle workProfileUserHandle) {
            UserHandle workProfileUserHandle,
            boolean isSendAction) {
        super(context, /* currentPage */ 0, personalProfileUserHandle, workProfileUserHandle);
        mItems = new ChooserProfileDescriptor[] {
                createProfileDescriptor(adapter)
        };
        mIsSendAction = isSendAction;
    }

    ChooserMultiProfilePagerAdapter(Context context,
@@ -53,13 +56,15 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
            ChooserActivity.ChooserGridAdapter workAdapter,
            @Profile int defaultProfile,
            UserHandle personalProfileUserHandle,
            UserHandle workProfileUserHandle) {
            UserHandle workProfileUserHandle,
            boolean isSendAction) {
        super(context, /* currentPage */ defaultProfile, personalProfileUserHandle,
                workProfileUserHandle);
        mItems = new ChooserProfileDescriptor[] {
                createProfileDescriptor(personalAdapter),
                createProfileDescriptor(workAdapter)
        };
        mIsSendAction = isSendAction;
    }

    private ChooserProfileDescriptor createProfileDescriptor(
@@ -182,34 +187,62 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd

    @Override
    protected void showNoPersonalToWorkIntentsEmptyState(ResolverListAdapter activeListAdapter) {
        if (mIsSendAction) {
            showEmptyState(activeListAdapter,
                    R.drawable.ic_sharing_disabled,
                    R.string.resolver_cant_share_with_work_apps,
                    R.string.resolver_cant_share_with_work_apps_explanation);
        } else {
            showEmptyState(activeListAdapter,
                    R.drawable.ic_sharing_disabled,
                    R.string.resolver_cant_access_work_apps,
                    R.string.resolver_cant_access_work_apps_explanation);
        }
    }

    @Override
    protected void showNoWorkToPersonalIntentsEmptyState(ResolverListAdapter activeListAdapter) {
        if (mIsSendAction) {
            showEmptyState(activeListAdapter,
                    R.drawable.ic_sharing_disabled,
                    R.string.resolver_cant_share_with_personal_apps,
                    R.string.resolver_cant_share_with_personal_apps_explanation);
        } else {
            showEmptyState(activeListAdapter,
                    R.drawable.ic_sharing_disabled,
                    R.string.resolver_cant_access_personal_apps,
                    R.string.resolver_cant_access_personal_apps_explanation);
        }
    }

    @Override
    protected void showNoPersonalAppsAvailableEmptyState(ResolverListAdapter listAdapter) {
        if (mIsSendAction) {
            showEmptyState(listAdapter,
                    R.drawable.ic_no_apps,
                    R.string.resolver_no_personal_apps_available_share,
                    /* subtitleRes */ 0);
        } else {
            showEmptyState(listAdapter,
                    R.drawable.ic_no_apps,
                    R.string.resolver_no_personal_apps_available_resolve,
                    /* subtitleRes */ 0);
        }
    }

    @Override
    protected void showNoWorkAppsAvailableEmptyState(ResolverListAdapter listAdapter) {
        if (mIsSendAction) {
            showEmptyState(listAdapter,
                    R.drawable.ic_no_apps,
                    R.string.resolver_no_work_apps_available_share,
                    /* subtitleRes */ 0);
        } else {
            showEmptyState(listAdapter,
                    R.drawable.ic_no_apps,
                    R.string.resolver_no_work_apps_available_resolve,
                    /* subtitleRes */ 0);
        }
    }

    class ChooserProfileDescriptor extends ProfileDescriptor {
+67 −4
Original line number Diff line number Diff line
@@ -1763,7 +1763,8 @@ public class ChooserActivityTest {
                Mockito.anyBoolean(),
                Mockito.isA(List.class)))
                .thenReturn(new ArrayList<>(personalResolvedComponentInfos));
        Intent chooserIntent = createChooserIntent(new Intent[] {new Intent("action.fake")});
        Intent chooserIntent = createChooserIntent(createSendTextIntent(),
                new Intent[] {new Intent("action.fake")});
        ResolveInfo[] chosen = new ResolveInfo[1];
        sOverrides.onSafelyStartCallback = targetInfo -> {
            chosen[0] = targetInfo.getResolveInfo();
@@ -1796,7 +1797,7 @@ public class ChooserActivityTest {
                new Intent("action.fake1"),
                new Intent("action.fake2")
        };
        Intent chooserIntent = createChooserIntent(initialIntents);
        Intent chooserIntent = createChooserIntent(createSendTextIntent(), initialIntents);
        sOverrides.packageManager = mock(PackageManager.class);
        when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt()))
                .thenReturn(createFakeResolveInfo());
@@ -1809,12 +1810,74 @@ public class ChooserActivityTest {
        assertThat(activity.getWorkListAdapter().getCallerTargetCount(), is(0));
    }

    private Intent createChooserIntent(Intent[] initialIntents) {
    @Test
    public void testWorkTab_xProfileIntentsDisabled_personalToWork_nonSendIntent_emptyStateShown() {
        // enable the work tab feature flag
        ResolverActivity.ENABLE_TABBED_VIEW = true;
        markWorkProfileUserAvailable();
        int workProfileTargets = 4;
        List<ResolvedComponentInfo> personalResolvedComponentInfos =
                createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10);
        List<ResolvedComponentInfo> workResolvedComponentInfos =
                createResolvedComponentsForTest(workProfileTargets);
        sOverrides.hasCrossProfileIntents = false;
        setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
        Intent[] initialIntents = {
                new Intent("action.fake1"),
                new Intent("action.fake2")
        };
        Intent chooserIntent = createChooserIntent(new Intent(), initialIntents);
        sOverrides.packageManager = mock(PackageManager.class);
        when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt()))
                .thenReturn(createFakeResolveInfo());

        final ChooserWrapperActivity activity = mActivityRule.launchActivity(chooserIntent);
        waitForIdle();
        onView(withText(R.string.resolver_work_tab)).perform(click());
        waitForIdle();
        onView(withId(R.id.contentPanel))
                .perform(swipeUp());

        onView(withText(R.string.resolver_cant_access_work_apps))
                .check(matches(isDisplayed()));
    }

    @Test
    public void testWorkTab_noWorkAppsAvailable_nonSendIntent_emptyStateShown() {
        // enable the work tab feature flag
        ResolverActivity.ENABLE_TABBED_VIEW = true;
        markWorkProfileUserAvailable();
        List<ResolvedComponentInfo> personalResolvedComponentInfos =
                createResolvedComponentsForTest(3);
        List<ResolvedComponentInfo> workResolvedComponentInfos =
                createResolvedComponentsForTest(0);
        setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
        Intent[] initialIntents = {
                new Intent("action.fake1"),
                new Intent("action.fake2")
        };
        Intent chooserIntent = createChooserIntent(new Intent(), initialIntents);
        sOverrides.packageManager = mock(PackageManager.class);
        when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt()))
                .thenReturn(createFakeResolveInfo());

        mActivityRule.launchActivity(chooserIntent);
        waitForIdle();
        onView(withId(R.id.contentPanel))
                .perform(swipeUp());
        onView(withText(R.string.resolver_work_tab)).perform(click());
        waitForIdle();

        onView(withText(R.string.resolver_no_work_apps_available_resolve))
                .check(matches(isDisplayed()));
    }

    private Intent createChooserIntent(Intent intent, Intent[] initialIntents) {
        Intent chooserIntent = new Intent();
        chooserIntent.setAction(Intent.ACTION_CHOOSER);
        chooserIntent.putExtra(Intent.EXTRA_TEXT, "testing intent sending");
        chooserIntent.putExtra(Intent.EXTRA_TITLE, "some title");
        chooserIntent.putExtra(Intent.EXTRA_INTENT, createSendTextIntent());
        chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
        chooserIntent.setType("text/plain");
        if (initialIntents != null) {
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, initialIntents);