From 79ca9efe77bf5324bcf6c6ca17f519e2eedbff86 Mon Sep 17 00:00:00 2001 From: 1 Date: Mon, 8 May 2023 15:23:54 +0000 Subject: Make app-provided chooser targets only show in the default profile Previously if, say, a work-profile app injected a chooser target, that target would show in *both* profiles, but showing it in the opposite (personal) profile doesn't really make sense since and uses up direct share space. The placement of this code is highly-suspect but I'm avoiding changing that in this CL given the proximity to release. Bug: 280517912 Test: atest UnbundledChooserActivity Change-Id: Ia73699cde6347cd300eae388a42a2433b3840d63 --- .../com/android/intentresolver/ChooserActivity.java | 21 ++++++++++++++------- .../UnbundledChooserActivityTest.java | 14 +++++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'java') diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 7f55f78f..95c93696 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -807,13 +807,20 @@ public class ChooserActivity extends ResolverActivity implements @Override public void addUseDifferentAppLabelIfNecessary(ResolverListAdapter adapter) { - if (mChooserRequest.getCallerChooserTargets().size() > 0) { - mChooserMultiProfilePagerAdapter.getActiveListAdapter().addServiceResults( - /* origTarget */ null, - new ArrayList<>(mChooserRequest.getCallerChooserTargets()), - TARGET_TYPE_DEFAULT, - /* directShareShortcutInfoCache */ Collections.emptyMap(), - /* directShareAppTargetCache */ Collections.emptyMap()); + if (!mChooserRequest.getCallerChooserTargets().isEmpty()) { + // Send the caller's chooser targets only to the default profile. + UserHandle defaultUser = (findSelectedProfile() == PROFILE_WORK) + ? getAnnotatedUserHandles().workProfileUserHandle + : getAnnotatedUserHandles().personalProfileUserHandle; + ChooserListAdapter chooserAdapter = (ChooserListAdapter) adapter; + if (chooserAdapter.getUserHandle() == defaultUser) { + chooserAdapter.addServiceResults( + /* origTarget */ null, + new ArrayList<>(mChooserRequest.getCallerChooserTargets()), + TARGET_TYPE_DEFAULT, + /* directShareShortcutInfoCache */ Collections.emptyMap(), + /* directShareAppTargetCache */ Collections.emptyMap()); + } } } diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index 7c4838a2..7b925bce 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -1651,7 +1651,8 @@ public class UnbundledChooserActivityTest { // We need app targets for direct targets to get displayed List resolvedComponentInfos = createResolvedComponentsForTest(2); - setupResolverControllers(resolvedComponentInfos); + setupResolverControllers(resolvedComponentInfos, resolvedComponentInfos); + markWorkProfileUserAvailable(); // set caller-provided target Intent chooserIntent = Intent.createChooser(createSendTextIntent(), null); @@ -1707,6 +1708,17 @@ public class UnbundledChooserActivityTest { "The display label must match", activeAdapter.getItem(0).getDisplayLabel(), is(callerTargetLabel)); + + // Switch to work profile and ensure that the target *doesn't* show up there. + onView(withText(R.string.resolver_work_tab)).perform(click()); + waitForIdle(); + + for (int i = 0; i < activity.getWorkListAdapter().getCount(); i++) { + assertThat( + "Chooser target should not show up in opposite profile", + activity.getWorkListAdapter().getItem(i).getDisplayLabel(), + not(callerTargetLabel)); + } } @Test -- cgit v1.2.3-59-g8ed1b