Loading core/java/com/android/internal/app/ChooserActivity.java +3 −3 Original line number Diff line number Diff line Loading @@ -855,10 +855,11 @@ public class ChooserActivity extends ResolverActivity implements Intent[] initialIntents, List<ResolveInfo> rList, boolean filterLastUsed) { int selectedProfile = findSelectedProfile(); ChooserGridAdapter personalAdapter = createChooserGridAdapter( /* context */ this, /* payloadIntents */ mIntents, initialIntents, selectedProfile == PROFILE_PERSONAL ? initialIntents : null, rList, filterLastUsed, mUseLayoutForBrowsables, Loading @@ -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, Loading core/java/com/android/internal/app/ResolverActivity.java +14 −14 Original line number Diff line number Diff line Loading @@ -459,13 +459,25 @@ public class ResolverActivity extends Activity implements Intent[] initialIntents, List<ResolveInfo> rList, boolean filterLastUsed) { // 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. int selectedProfile = getCurrentProfile(); UserHandle intentUser = UserHandle.of(getLaunchingUserId()); if (!getUser().equals(intentUser)) { if (getPersonalProfileUserHandle().equals(intentUser)) { selectedProfile = PROFILE_PERSONAL; } else if (getWorkProfileUserHandle().equals(intentUser)) { 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, initialIntents, selectedProfile == PROFILE_PERSONAL ? initialIntents : null, rList, (filterLastUsed && UserHandle.myUserId() == getPersonalProfileUserHandle().getIdentifier()), Loading @@ -475,24 +487,12 @@ public class ResolverActivity extends Activity implements ResolverListAdapter workAdapter = createResolverListAdapter( /* context */ this, /* payloadIntents */ mIntents, initialIntents, selectedProfile == PROFILE_WORK ? initialIntents : null, 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. int selectedProfile = getCurrentProfile(); UserHandle intentUser = UserHandle.of(getLaunchingUserId()); if (!getUser().equals(intentUser)) { if (getPersonalProfileUserHandle().equals(intentUser)) { selectedProfile = PROFILE_PERSONAL; } else if (getWorkProfileUserHandle().equals(intentUser)) { selectedProfile = PROFILE_WORK; } } return new ResolverMultiProfilePagerAdapter( /* context */ this, personalAdapter, Loading core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +30 −1 Original line number Diff line number Diff line Loading @@ -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<ResolvedComponentInfo> personalResolvedComponentInfos = createResolvedComponentsForTestWithOtherProfile(2, /* userId */ 10); List<ResolvedComponentInfo> 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) { Loading Loading
core/java/com/android/internal/app/ChooserActivity.java +3 −3 Original line number Diff line number Diff line Loading @@ -855,10 +855,11 @@ public class ChooserActivity extends ResolverActivity implements Intent[] initialIntents, List<ResolveInfo> rList, boolean filterLastUsed) { int selectedProfile = findSelectedProfile(); ChooserGridAdapter personalAdapter = createChooserGridAdapter( /* context */ this, /* payloadIntents */ mIntents, initialIntents, selectedProfile == PROFILE_PERSONAL ? initialIntents : null, rList, filterLastUsed, mUseLayoutForBrowsables, Loading @@ -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, Loading
core/java/com/android/internal/app/ResolverActivity.java +14 −14 Original line number Diff line number Diff line Loading @@ -459,13 +459,25 @@ public class ResolverActivity extends Activity implements Intent[] initialIntents, List<ResolveInfo> rList, boolean filterLastUsed) { // 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. int selectedProfile = getCurrentProfile(); UserHandle intentUser = UserHandle.of(getLaunchingUserId()); if (!getUser().equals(intentUser)) { if (getPersonalProfileUserHandle().equals(intentUser)) { selectedProfile = PROFILE_PERSONAL; } else if (getWorkProfileUserHandle().equals(intentUser)) { 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, initialIntents, selectedProfile == PROFILE_PERSONAL ? initialIntents : null, rList, (filterLastUsed && UserHandle.myUserId() == getPersonalProfileUserHandle().getIdentifier()), Loading @@ -475,24 +487,12 @@ public class ResolverActivity extends Activity implements ResolverListAdapter workAdapter = createResolverListAdapter( /* context */ this, /* payloadIntents */ mIntents, initialIntents, selectedProfile == PROFILE_WORK ? initialIntents : null, 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. int selectedProfile = getCurrentProfile(); UserHandle intentUser = UserHandle.of(getLaunchingUserId()); if (!getUser().equals(intentUser)) { if (getPersonalProfileUserHandle().equals(intentUser)) { selectedProfile = PROFILE_PERSONAL; } else if (getWorkProfileUserHandle().equals(intentUser)) { selectedProfile = PROFILE_WORK; } } return new ResolverMultiProfilePagerAdapter( /* context */ this, personalAdapter, Loading
core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +30 −1 Original line number Diff line number Diff line Loading @@ -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<ResolvedComponentInfo> personalResolvedComponentInfos = createResolvedComponentsForTestWithOtherProfile(2, /* userId */ 10); List<ResolvedComponentInfo> 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) { Loading