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 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'java/src') 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()); + } } } -- cgit v1.2.3-59-g8ed1b