diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index e336e96d577e1..fd5eac8071bdc 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -1603,6 +1603,11 @@ public class ResolverActivity extends Activity implements List otherProfileList = mMultiProfilePagerAdapter.getInactiveListAdapter().mDisplayList; + if (sameProfileList.isEmpty()) { + Log.d(TAG, "No targets in the current profile"); + return false; + } + if (otherProfileList.size() != 1) { Log.d(TAG, "Found " + otherProfileList.size() + " resolvers in the other profile"); return false; 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 2817728fd9eab..e7a23f2627532 100644 --- a/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java @@ -39,6 +39,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.fail; import android.content.Intent; import android.content.pm.ResolveInfo; @@ -52,6 +53,7 @@ import android.widget.TextView; import androidx.test.InstrumentationRegistry; import androidx.test.espresso.Espresso; +import androidx.test.espresso.NoMatchingViewException; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; @@ -749,6 +751,34 @@ public class ResolverActivityTest { onView(withId(R.id.open_cross_profile)).check(matches(isDisplayed())); } + @Test + public void testMiniResolver_noCurrentProfileTarget() { + ResolverActivity.ENABLE_TABBED_VIEW = true; + markWorkProfileUserAvailable(); + List personalResolvedComponentInfos = + createResolvedComponentsForTest(0); + List workResolvedComponentInfos = + createResolvedComponentsForTest(1); + setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos); + Intent sendIntent = createSendImageIntent(); + sendIntent.setType("TestType"); + + mActivityRule.launchActivity(sendIntent); + waitForIdle(); + + // Need to ensure mini resolver doesn't trigger here. + assertNotMiniResolver(); + } + + private void assertNotMiniResolver() { + try { + onView(withId(R.id.open_cross_profile)).check(matches(isDisplayed())); + } catch (NoMatchingViewException e) { + return; + } + fail("Mini resolver present but shouldn't be"); + } + @Test public void testWorkTab_noAppsAvailable_workOff_noAppsAvailableEmptyStateShown() { // enable the work tab feature flag