diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 8f3edb8f1787b..d5e9e50be547e 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -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( @@ -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(); 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 dcecb5f32096b..547176855f327 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -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; @@ -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 @@ -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))); @@ -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 personalResolvedComponentInfos = + createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10); + List 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); diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java index 749b0e54b8807..44a52639bd35c 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserWrapperActivity.java @@ -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. *

@@ -214,6 +231,8 @@ public class ChooserWrapperActivity extends ChooserActivity { @SuppressWarnings("Since15") public Function createPackageManager; public Function onSafelyStartCallback; + public Function onQueryDirectShareTargets; + public Function onQueryTargetServices; public ResolverListController resolverListController; public ResolverListController workResolverListController; public Boolean isVoiceInteraction; @@ -233,6 +252,8 @@ public class ChooserWrapperActivity extends ChooserActivity { public void reset() { onSafelyStartCallback = null; + onQueryDirectShareTargets = null; + onQueryTargetServices = null; isVoiceInteraction = null; createPackageManager = null; previewThumbnail = null; diff --git a/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java index 8bee1e5cab3ba..7dc5a8b58f914 100644 --- a/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java @@ -592,7 +592,6 @@ public class ResolverActivityTest { TextUtils.equals(initialText, currentText)); } - @Ignore // b/148156663 @Test public void testWorkTab_noPersonalApps_canStartWorkApps() throws InterruptedException { @@ -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());