diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index a84d9640c7f87..a144ffb57a15e 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -855,10 +855,11 @@ public class ChooserActivity extends ResolverActivity implements Intent[] initialIntents, List rList, boolean filterLastUsed) { + int selectedProfile = findSelectedProfile(); ChooserGridAdapter personalAdapter = createChooserGridAdapter( /* context */ this, /* payloadIntents */ mIntents, - initialIntents, + selectedProfile == PROFILE_PERSONAL ? initialIntents : null, rList, filterLastUsed, mUseLayoutForBrowsables, @@ -866,12 +867,11 @@ public class ChooserActivity extends ResolverActivity implements ChooserGridAdapter workAdapter = createChooserGridAdapter( /* context */ this, /* payloadIntents */ mIntents, - initialIntents, + selectedProfile == PROFILE_WORK ? initialIntents : null, rList, filterLastUsed, mUseLayoutForBrowsables, /* userHandle */ getWorkProfileUserHandle()); - int selectedProfile = findSelectedProfile(); return new ChooserMultiProfilePagerAdapter( /* context */ this, personalAdapter, diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index cf9b955333300..2f62f8e7a0c97 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -459,28 +459,6 @@ public class ResolverActivity extends Activity implements Intent[] initialIntents, List rList, boolean filterLastUsed) { - // We only show the default app for the profile of the current user. The filterLastUsed - // flag determines whether to show a default app and that app is not shown in the - // resolver list. So filterLastUsed should be false for the other profile. - ResolverListAdapter personalAdapter = createResolverListAdapter( - /* context */ this, - /* payloadIntents */ mIntents, - initialIntents, - rList, - (filterLastUsed && UserHandle.myUserId() - == getPersonalProfileUserHandle().getIdentifier()), - mUseLayoutForBrowsables, - /* userHandle */ getPersonalProfileUserHandle()); - UserHandle workProfileUserHandle = getWorkProfileUserHandle(); - ResolverListAdapter workAdapter = createResolverListAdapter( - /* context */ this, - /* payloadIntents */ mIntents, - initialIntents, - rList, - (filterLastUsed && UserHandle.myUserId() - == workProfileUserHandle.getIdentifier()), - mUseLayoutForBrowsables, - /* userHandle */ workProfileUserHandle); // In the edge case when we have 0 apps in the current profile and >1 apps in the other, // the intent resolver is started in the other profile. Since this is the only case when // this happens, we check for it here and set the current profile's tab. @@ -493,6 +471,28 @@ public class ResolverActivity extends Activity implements selectedProfile = PROFILE_WORK; } } + // We only show the default app for the profile of the current user. The filterLastUsed + // flag determines whether to show a default app and that app is not shown in the + // resolver list. So filterLastUsed should be false for the other profile. + ResolverListAdapter personalAdapter = createResolverListAdapter( + /* context */ this, + /* payloadIntents */ mIntents, + selectedProfile == PROFILE_PERSONAL ? initialIntents : null, + rList, + (filterLastUsed && UserHandle.myUserId() + == getPersonalProfileUserHandle().getIdentifier()), + mUseLayoutForBrowsables, + /* userHandle */ getPersonalProfileUserHandle()); + UserHandle workProfileUserHandle = getWorkProfileUserHandle(); + ResolverListAdapter workAdapter = createResolverListAdapter( + /* context */ this, + /* payloadIntents */ mIntents, + selectedProfile == PROFILE_WORK ? initialIntents : null, + rList, + (filterLastUsed && UserHandle.myUserId() + == workProfileUserHandle.getIdentifier()), + mUseLayoutForBrowsables, + /* userHandle */ workProfileUserHandle); return new ResolverMultiProfilePagerAdapter( /* context */ this, personalAdapter, diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java index edad5c40fccd8..80fb358130091 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -1774,10 +1774,39 @@ public class ChooserActivityTest { when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(ri); waitForIdle(); - mActivityRule.launchActivity(chooserIntent); + ChooserWrapperActivity activity = mActivityRule.launchActivity(chooserIntent); waitForIdle(); assertNull(chosen[0]); + assertThat(activity.getPersonalListAdapter().getCallerTargetCount(), is(1)); + } + + @Test + public void testWorkTab_withInitialIntents_workTabDoesNotIncludePersonalInitialIntents() { + // enable the work tab feature flag + ResolverActivity.ENABLE_TABBED_VIEW = true; + markWorkProfileUserAvailable(); + int workProfileTargets = 1; + List personalResolvedComponentInfos = + createResolvedComponentsForTestWithOtherProfile(2, /* userId */ 10); + List workResolvedComponentInfos = + createResolvedComponentsForTest(workProfileTargets); + setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos); + Intent[] initialIntents = { + new Intent("action.fake1"), + new Intent("action.fake2") + }; + Intent chooserIntent = createChooserIntent(initialIntents); + sOverrides.packageManager = mock(PackageManager.class); + when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt())) + .thenReturn(createFakeResolveInfo()); + waitForIdle(); + + ChooserWrapperActivity activity = mActivityRule.launchActivity(chooserIntent); + waitForIdle(); + + assertThat(activity.getPersonalListAdapter().getCallerTargetCount(), is(2)); + assertThat(activity.getWorkListAdapter().getCallerTargetCount(), is(0)); } private Intent createChooserIntent(Intent[] initialIntents) {