Loading core/java/com/android/internal/app/ChooserActivity.java +4 −2 Original line number Diff line number Diff line Loading @@ -1809,7 +1809,8 @@ public class ChooserActivity extends ResolverActivity implements } } void queryTargetServices(ChooserListAdapter adapter) { @VisibleForTesting protected void queryTargetServices(ChooserListAdapter adapter) { mQueriedTargetServicesTimeMs = System.currentTimeMillis(); Context selectedProfileContext = createContextAsUser( Loading Loading @@ -1962,7 +1963,8 @@ public class ChooserActivity extends ResolverActivity implements return driList; } private void queryDirectShareTargets( @VisibleForTesting protected void queryDirectShareTargets( ChooserListAdapter adapter, boolean skipAppPredictionService) { mQueriedSharingShortcutsTimeMs = System.currentTimeMillis(); UserHandle userHandle = adapter.getUserHandle(); Loading core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +45 −3 Original line number Diff line number Diff line Loading @@ -34,9 +34,11 @@ import static com.android.internal.app.ChooserListAdapter.SHORTCUT_TARGET_SCORE_ import static com.android.internal.app.ChooserWrapperActivity.sOverrides; import static com.android.internal.app.MatcherUtils.first; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; Loading Loading @@ -1327,7 +1329,6 @@ public class ChooserActivityTest { assertThat(activity.getWorkListAdapter().getCount(), is(workProfileTargets)); } @Ignore // b/148156663 @Test public void testWorkTab_selectingWorkTabAppOpensAppInWorkProfile() throws InterruptedException { // enable the work tab feature flag Loading @@ -1354,8 +1355,10 @@ public class ChooserActivityTest { // wait for the share sheet to expand Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); onView(first(withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name))) onView(first(allOf( withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name), isDisplayed()))) .perform(click()); waitForIdle(); assertThat(chosen[0], is(workResolvedComponentInfos.get(0).getResolveInfoAt(0))); Loading Loading @@ -1953,6 +1956,45 @@ public class ChooserActivityTest { assertThat(activity.getAdapter().getRankedTargetCount(), is(3)); } @Test public void testWorkTab_selectingWorkTabWithPausedWorkProfile_directShareTargetsNotQueried() { // enable the work tab feature flag ResolverActivity.ENABLE_TABBED_VIEW = true; markWorkProfileUserAvailable(); List<ResolvedComponentInfo> personalResolvedComponentInfos = createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10); List<ResolvedComponentInfo> workResolvedComponentInfos = createResolvedComponentsForTest(3); setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos); sOverrides.isQuietModeEnabled = true; boolean[] isQueryDirectShareCalledOnWorkProfile = new boolean[] { false }; sOverrides.onQueryDirectShareTargets = chooserListAdapter -> { isQueryDirectShareCalledOnWorkProfile[0] = (chooserListAdapter.getUserHandle().getIdentifier() == 10); return null; }; boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false }; sOverrides.onQueryTargetServices = chooserListAdapter -> { isQueryTargetServicesCalledOnWorkProfile[0] = (chooserListAdapter.getUserHandle().getIdentifier() == 10); return null; }; Intent sendIntent = createSendTextIntent(); sendIntent.setType("TestType"); mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test")); waitForIdle(); onView(withId(R.id.contentPanel)) .perform(swipeUp()); onView(withText(R.string.resolver_work_tab)).perform(click()); waitForIdle(); assertFalse("Direct share targets were queried on a paused work profile", isQueryDirectShareCalledOnWorkProfile[0]); assertFalse("Target services were queried on a paused work profile", isQueryTargetServicesCalledOnWorkProfile[0]); } private Intent createChooserIntent(Intent intent, Intent[] initialIntents) { Intent chooserIntent = new Intent(); chooserIntent.setAction(Intent.ACTION_CHOOSER); Loading core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +21 −0 Original line number Diff line number Diff line Loading @@ -205,6 +205,23 @@ public class ChooserWrapperActivity extends ChooserActivity { return getApplicationContext(); } @Override protected void queryDirectShareTargets(ChooserListAdapter adapter, boolean skipAppPredictionService) { if (sOverrides.onQueryDirectShareTargets != null) { sOverrides.onQueryDirectShareTargets.apply(adapter); } super.queryDirectShareTargets(adapter, skipAppPredictionService); } @Override protected void queryTargetServices(ChooserListAdapter adapter) { if (sOverrides.onQueryTargetServices != null) { sOverrides.onQueryTargetServices.apply(adapter); } super.queryTargetServices(adapter); } /** * We cannot directly mock the activity created since instrumentation creates it. * <p> Loading @@ -214,6 +231,8 @@ public class ChooserWrapperActivity extends ChooserActivity { @SuppressWarnings("Since15") public Function<PackageManager, PackageManager> createPackageManager; public Function<TargetInfo, Boolean> onSafelyStartCallback; public Function<ChooserListAdapter, Void> onQueryDirectShareTargets; public Function<ChooserListAdapter, Void> onQueryTargetServices; public ResolverListController resolverListController; public ResolverListController workResolverListController; public Boolean isVoiceInteraction; Loading @@ -233,6 +252,8 @@ public class ChooserWrapperActivity extends ChooserActivity { public void reset() { onSafelyStartCallback = null; onQueryDirectShareTargets = null; onQueryTargetServices = null; isVoiceInteraction = null; createPackageManager = null; previewThumbnail = null; Loading core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -592,7 +592,6 @@ public class ResolverActivityTest { TextUtils.equals(initialText, currentText)); } @Ignore // b/148156663 @Test public void testWorkTab_noPersonalApps_canStartWorkApps() throws InterruptedException { Loading @@ -617,8 +616,10 @@ public class ResolverActivityTest { waitForIdle(); // wait for the share sheet to expand Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); onView(first(allOf(withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name), isCompletelyDisplayed()))) onView(first(allOf( withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name), isDisplayed()))) .perform(click()); onView(withId(R.id.button_once)) .perform(click()); Loading Loading
core/java/com/android/internal/app/ChooserActivity.java +4 −2 Original line number Diff line number Diff line Loading @@ -1809,7 +1809,8 @@ public class ChooserActivity extends ResolverActivity implements } } void queryTargetServices(ChooserListAdapter adapter) { @VisibleForTesting protected void queryTargetServices(ChooserListAdapter adapter) { mQueriedTargetServicesTimeMs = System.currentTimeMillis(); Context selectedProfileContext = createContextAsUser( Loading Loading @@ -1962,7 +1963,8 @@ public class ChooserActivity extends ResolverActivity implements return driList; } private void queryDirectShareTargets( @VisibleForTesting protected void queryDirectShareTargets( ChooserListAdapter adapter, boolean skipAppPredictionService) { mQueriedSharingShortcutsTimeMs = System.currentTimeMillis(); UserHandle userHandle = adapter.getUserHandle(); Loading
core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +45 −3 Original line number Diff line number Diff line Loading @@ -34,9 +34,11 @@ import static com.android.internal.app.ChooserListAdapter.SHORTCUT_TARGET_SCORE_ import static com.android.internal.app.ChooserWrapperActivity.sOverrides; import static com.android.internal.app.MatcherUtils.first; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; Loading Loading @@ -1327,7 +1329,6 @@ public class ChooserActivityTest { assertThat(activity.getWorkListAdapter().getCount(), is(workProfileTargets)); } @Ignore // b/148156663 @Test public void testWorkTab_selectingWorkTabAppOpensAppInWorkProfile() throws InterruptedException { // enable the work tab feature flag Loading @@ -1354,8 +1355,10 @@ public class ChooserActivityTest { // wait for the share sheet to expand Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); onView(first(withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name))) onView(first(allOf( withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name), isDisplayed()))) .perform(click()); waitForIdle(); assertThat(chosen[0], is(workResolvedComponentInfos.get(0).getResolveInfoAt(0))); Loading Loading @@ -1953,6 +1956,45 @@ public class ChooserActivityTest { assertThat(activity.getAdapter().getRankedTargetCount(), is(3)); } @Test public void testWorkTab_selectingWorkTabWithPausedWorkProfile_directShareTargetsNotQueried() { // enable the work tab feature flag ResolverActivity.ENABLE_TABBED_VIEW = true; markWorkProfileUserAvailable(); List<ResolvedComponentInfo> personalResolvedComponentInfos = createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10); List<ResolvedComponentInfo> workResolvedComponentInfos = createResolvedComponentsForTest(3); setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos); sOverrides.isQuietModeEnabled = true; boolean[] isQueryDirectShareCalledOnWorkProfile = new boolean[] { false }; sOverrides.onQueryDirectShareTargets = chooserListAdapter -> { isQueryDirectShareCalledOnWorkProfile[0] = (chooserListAdapter.getUserHandle().getIdentifier() == 10); return null; }; boolean[] isQueryTargetServicesCalledOnWorkProfile = new boolean[] { false }; sOverrides.onQueryTargetServices = chooserListAdapter -> { isQueryTargetServicesCalledOnWorkProfile[0] = (chooserListAdapter.getUserHandle().getIdentifier() == 10); return null; }; Intent sendIntent = createSendTextIntent(); sendIntent.setType("TestType"); mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test")); waitForIdle(); onView(withId(R.id.contentPanel)) .perform(swipeUp()); onView(withText(R.string.resolver_work_tab)).perform(click()); waitForIdle(); assertFalse("Direct share targets were queried on a paused work profile", isQueryDirectShareCalledOnWorkProfile[0]); assertFalse("Target services were queried on a paused work profile", isQueryTargetServicesCalledOnWorkProfile[0]); } private Intent createChooserIntent(Intent intent, Intent[] initialIntents) { Intent chooserIntent = new Intent(); chooserIntent.setAction(Intent.ACTION_CHOOSER); Loading
core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +21 −0 Original line number Diff line number Diff line Loading @@ -205,6 +205,23 @@ public class ChooserWrapperActivity extends ChooserActivity { return getApplicationContext(); } @Override protected void queryDirectShareTargets(ChooserListAdapter adapter, boolean skipAppPredictionService) { if (sOverrides.onQueryDirectShareTargets != null) { sOverrides.onQueryDirectShareTargets.apply(adapter); } super.queryDirectShareTargets(adapter, skipAppPredictionService); } @Override protected void queryTargetServices(ChooserListAdapter adapter) { if (sOverrides.onQueryTargetServices != null) { sOverrides.onQueryTargetServices.apply(adapter); } super.queryTargetServices(adapter); } /** * We cannot directly mock the activity created since instrumentation creates it. * <p> Loading @@ -214,6 +231,8 @@ public class ChooserWrapperActivity extends ChooserActivity { @SuppressWarnings("Since15") public Function<PackageManager, PackageManager> createPackageManager; public Function<TargetInfo, Boolean> onSafelyStartCallback; public Function<ChooserListAdapter, Void> onQueryDirectShareTargets; public Function<ChooserListAdapter, Void> onQueryTargetServices; public ResolverListController resolverListController; public ResolverListController workResolverListController; public Boolean isVoiceInteraction; Loading @@ -233,6 +252,8 @@ public class ChooserWrapperActivity extends ChooserActivity { public void reset() { onSafelyStartCallback = null; onQueryDirectShareTargets = null; onQueryTargetServices = null; isVoiceInteraction = null; createPackageManager = null; previewThumbnail = null; Loading
core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -592,7 +592,6 @@ public class ResolverActivityTest { TextUtils.equals(initialText, currentText)); } @Ignore // b/148156663 @Test public void testWorkTab_noPersonalApps_canStartWorkApps() throws InterruptedException { Loading @@ -617,8 +616,10 @@ public class ResolverActivityTest { waitForIdle(); // wait for the share sheet to expand Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); onView(first(allOf(withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name), isCompletelyDisplayed()))) onView(first(allOf( withText(workResolvedComponentInfos.get(0) .getResolveInfoAt(0).activityInfo.applicationInfo.name), isDisplayed()))) .perform(click()); onView(withId(R.id.button_once)) .perform(click()); Loading