Merge "Use intent resolver strings for sharesheet when picking intent" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
950aca5795
@@ -884,7 +884,8 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
/* context */ this,
|
/* context */ this,
|
||||||
adapter,
|
adapter,
|
||||||
getPersonalProfileUserHandle(),
|
getPersonalProfileUserHandle(),
|
||||||
/* workProfileUserHandle= */ null);
|
/* workProfileUserHandle= */ null,
|
||||||
|
isSendAction(getTargetIntent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChooserMultiProfilePagerAdapter createChooserMultiProfilePagerAdapterForTwoProfiles(
|
private ChooserMultiProfilePagerAdapter createChooserMultiProfilePagerAdapterForTwoProfiles(
|
||||||
@@ -914,7 +915,8 @@ public class ChooserActivity extends ResolverActivity implements
|
|||||||
workAdapter,
|
workAdapter,
|
||||||
selectedProfile,
|
selectedProfile,
|
||||||
getPersonalProfileUserHandle(),
|
getPersonalProfileUserHandle(),
|
||||||
getWorkProfileUserHandle());
|
getWorkProfileUserHandle(),
|
||||||
|
isSendAction(getTargetIntent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findSelectedProfile() {
|
private int findSelectedProfile() {
|
||||||
|
|||||||
@@ -37,15 +37,18 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
|
|||||||
private static final int SINGLE_CELL_SPAN_SIZE = 1;
|
private static final int SINGLE_CELL_SPAN_SIZE = 1;
|
||||||
|
|
||||||
private final ChooserProfileDescriptor[] mItems;
|
private final ChooserProfileDescriptor[] mItems;
|
||||||
|
private final boolean mIsSendAction;
|
||||||
|
|
||||||
ChooserMultiProfilePagerAdapter(Context context,
|
ChooserMultiProfilePagerAdapter(Context context,
|
||||||
ChooserActivity.ChooserGridAdapter adapter,
|
ChooserActivity.ChooserGridAdapter adapter,
|
||||||
UserHandle personalProfileUserHandle,
|
UserHandle personalProfileUserHandle,
|
||||||
UserHandle workProfileUserHandle) {
|
UserHandle workProfileUserHandle,
|
||||||
|
boolean isSendAction) {
|
||||||
super(context, /* currentPage */ 0, personalProfileUserHandle, workProfileUserHandle);
|
super(context, /* currentPage */ 0, personalProfileUserHandle, workProfileUserHandle);
|
||||||
mItems = new ChooserProfileDescriptor[] {
|
mItems = new ChooserProfileDescriptor[] {
|
||||||
createProfileDescriptor(adapter)
|
createProfileDescriptor(adapter)
|
||||||
};
|
};
|
||||||
|
mIsSendAction = isSendAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChooserMultiProfilePagerAdapter(Context context,
|
ChooserMultiProfilePagerAdapter(Context context,
|
||||||
@@ -53,13 +56,15 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
|
|||||||
ChooserActivity.ChooserGridAdapter workAdapter,
|
ChooserActivity.ChooserGridAdapter workAdapter,
|
||||||
@Profile int defaultProfile,
|
@Profile int defaultProfile,
|
||||||
UserHandle personalProfileUserHandle,
|
UserHandle personalProfileUserHandle,
|
||||||
UserHandle workProfileUserHandle) {
|
UserHandle workProfileUserHandle,
|
||||||
|
boolean isSendAction) {
|
||||||
super(context, /* currentPage */ defaultProfile, personalProfileUserHandle,
|
super(context, /* currentPage */ defaultProfile, personalProfileUserHandle,
|
||||||
workProfileUserHandle);
|
workProfileUserHandle);
|
||||||
mItems = new ChooserProfileDescriptor[] {
|
mItems = new ChooserProfileDescriptor[] {
|
||||||
createProfileDescriptor(personalAdapter),
|
createProfileDescriptor(personalAdapter),
|
||||||
createProfileDescriptor(workAdapter)
|
createProfileDescriptor(workAdapter)
|
||||||
};
|
};
|
||||||
|
mIsSendAction = isSendAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChooserProfileDescriptor createProfileDescriptor(
|
private ChooserProfileDescriptor createProfileDescriptor(
|
||||||
@@ -182,34 +187,62 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void showNoPersonalToWorkIntentsEmptyState(ResolverListAdapter activeListAdapter) {
|
protected void showNoPersonalToWorkIntentsEmptyState(ResolverListAdapter activeListAdapter) {
|
||||||
|
if (mIsSendAction) {
|
||||||
showEmptyState(activeListAdapter,
|
showEmptyState(activeListAdapter,
|
||||||
R.drawable.ic_sharing_disabled,
|
R.drawable.ic_sharing_disabled,
|
||||||
R.string.resolver_cant_share_with_work_apps,
|
R.string.resolver_cant_share_with_work_apps,
|
||||||
R.string.resolver_cant_share_with_work_apps_explanation);
|
R.string.resolver_cant_share_with_work_apps_explanation);
|
||||||
|
} else {
|
||||||
|
showEmptyState(activeListAdapter,
|
||||||
|
R.drawable.ic_sharing_disabled,
|
||||||
|
R.string.resolver_cant_access_work_apps,
|
||||||
|
R.string.resolver_cant_access_work_apps_explanation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void showNoWorkToPersonalIntentsEmptyState(ResolverListAdapter activeListAdapter) {
|
protected void showNoWorkToPersonalIntentsEmptyState(ResolverListAdapter activeListAdapter) {
|
||||||
|
if (mIsSendAction) {
|
||||||
showEmptyState(activeListAdapter,
|
showEmptyState(activeListAdapter,
|
||||||
R.drawable.ic_sharing_disabled,
|
R.drawable.ic_sharing_disabled,
|
||||||
R.string.resolver_cant_share_with_personal_apps,
|
R.string.resolver_cant_share_with_personal_apps,
|
||||||
R.string.resolver_cant_share_with_personal_apps_explanation);
|
R.string.resolver_cant_share_with_personal_apps_explanation);
|
||||||
|
} else {
|
||||||
|
showEmptyState(activeListAdapter,
|
||||||
|
R.drawable.ic_sharing_disabled,
|
||||||
|
R.string.resolver_cant_access_personal_apps,
|
||||||
|
R.string.resolver_cant_access_personal_apps_explanation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void showNoPersonalAppsAvailableEmptyState(ResolverListAdapter listAdapter) {
|
protected void showNoPersonalAppsAvailableEmptyState(ResolverListAdapter listAdapter) {
|
||||||
|
if (mIsSendAction) {
|
||||||
showEmptyState(listAdapter,
|
showEmptyState(listAdapter,
|
||||||
R.drawable.ic_no_apps,
|
R.drawable.ic_no_apps,
|
||||||
R.string.resolver_no_personal_apps_available_share,
|
R.string.resolver_no_personal_apps_available_share,
|
||||||
/* subtitleRes */ 0);
|
/* subtitleRes */ 0);
|
||||||
|
} else {
|
||||||
|
showEmptyState(listAdapter,
|
||||||
|
R.drawable.ic_no_apps,
|
||||||
|
R.string.resolver_no_personal_apps_available_resolve,
|
||||||
|
/* subtitleRes */ 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void showNoWorkAppsAvailableEmptyState(ResolverListAdapter listAdapter) {
|
protected void showNoWorkAppsAvailableEmptyState(ResolverListAdapter listAdapter) {
|
||||||
|
if (mIsSendAction) {
|
||||||
showEmptyState(listAdapter,
|
showEmptyState(listAdapter,
|
||||||
R.drawable.ic_no_apps,
|
R.drawable.ic_no_apps,
|
||||||
R.string.resolver_no_work_apps_available_share,
|
R.string.resolver_no_work_apps_available_share,
|
||||||
/* subtitleRes */ 0);
|
/* subtitleRes */ 0);
|
||||||
|
} else {
|
||||||
|
showEmptyState(listAdapter,
|
||||||
|
R.drawable.ic_no_apps,
|
||||||
|
R.string.resolver_no_work_apps_available_resolve,
|
||||||
|
/* subtitleRes */ 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChooserProfileDescriptor extends ProfileDescriptor {
|
class ChooserProfileDescriptor extends ProfileDescriptor {
|
||||||
|
|||||||
@@ -1763,7 +1763,8 @@ public class ChooserActivityTest {
|
|||||||
Mockito.anyBoolean(),
|
Mockito.anyBoolean(),
|
||||||
Mockito.isA(List.class)))
|
Mockito.isA(List.class)))
|
||||||
.thenReturn(new ArrayList<>(personalResolvedComponentInfos));
|
.thenReturn(new ArrayList<>(personalResolvedComponentInfos));
|
||||||
Intent chooserIntent = createChooserIntent(new Intent[] {new Intent("action.fake")});
|
Intent chooserIntent = createChooserIntent(createSendTextIntent(),
|
||||||
|
new Intent[] {new Intent("action.fake")});
|
||||||
ResolveInfo[] chosen = new ResolveInfo[1];
|
ResolveInfo[] chosen = new ResolveInfo[1];
|
||||||
sOverrides.onSafelyStartCallback = targetInfo -> {
|
sOverrides.onSafelyStartCallback = targetInfo -> {
|
||||||
chosen[0] = targetInfo.getResolveInfo();
|
chosen[0] = targetInfo.getResolveInfo();
|
||||||
@@ -1796,7 +1797,7 @@ public class ChooserActivityTest {
|
|||||||
new Intent("action.fake1"),
|
new Intent("action.fake1"),
|
||||||
new Intent("action.fake2")
|
new Intent("action.fake2")
|
||||||
};
|
};
|
||||||
Intent chooserIntent = createChooserIntent(initialIntents);
|
Intent chooserIntent = createChooserIntent(createSendTextIntent(), initialIntents);
|
||||||
sOverrides.packageManager = mock(PackageManager.class);
|
sOverrides.packageManager = mock(PackageManager.class);
|
||||||
when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt()))
|
when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt()))
|
||||||
.thenReturn(createFakeResolveInfo());
|
.thenReturn(createFakeResolveInfo());
|
||||||
@@ -1809,12 +1810,74 @@ public class ChooserActivityTest {
|
|||||||
assertThat(activity.getWorkListAdapter().getCallerTargetCount(), is(0));
|
assertThat(activity.getWorkListAdapter().getCallerTargetCount(), is(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent createChooserIntent(Intent[] initialIntents) {
|
@Test
|
||||||
|
public void testWorkTab_xProfileIntentsDisabled_personalToWork_nonSendIntent_emptyStateShown() {
|
||||||
|
// enable the work tab feature flag
|
||||||
|
ResolverActivity.ENABLE_TABBED_VIEW = true;
|
||||||
|
markWorkProfileUserAvailable();
|
||||||
|
int workProfileTargets = 4;
|
||||||
|
List<ResolvedComponentInfo> personalResolvedComponentInfos =
|
||||||
|
createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10);
|
||||||
|
List<ResolvedComponentInfo> workResolvedComponentInfos =
|
||||||
|
createResolvedComponentsForTest(workProfileTargets);
|
||||||
|
sOverrides.hasCrossProfileIntents = false;
|
||||||
|
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
|
||||||
|
Intent[] initialIntents = {
|
||||||
|
new Intent("action.fake1"),
|
||||||
|
new Intent("action.fake2")
|
||||||
|
};
|
||||||
|
Intent chooserIntent = createChooserIntent(new Intent(), initialIntents);
|
||||||
|
sOverrides.packageManager = mock(PackageManager.class);
|
||||||
|
when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt()))
|
||||||
|
.thenReturn(createFakeResolveInfo());
|
||||||
|
|
||||||
|
final ChooserWrapperActivity activity = mActivityRule.launchActivity(chooserIntent);
|
||||||
|
waitForIdle();
|
||||||
|
onView(withText(R.string.resolver_work_tab)).perform(click());
|
||||||
|
waitForIdle();
|
||||||
|
onView(withId(R.id.contentPanel))
|
||||||
|
.perform(swipeUp());
|
||||||
|
|
||||||
|
onView(withText(R.string.resolver_cant_access_work_apps))
|
||||||
|
.check(matches(isDisplayed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWorkTab_noWorkAppsAvailable_nonSendIntent_emptyStateShown() {
|
||||||
|
// enable the work tab feature flag
|
||||||
|
ResolverActivity.ENABLE_TABBED_VIEW = true;
|
||||||
|
markWorkProfileUserAvailable();
|
||||||
|
List<ResolvedComponentInfo> personalResolvedComponentInfos =
|
||||||
|
createResolvedComponentsForTest(3);
|
||||||
|
List<ResolvedComponentInfo> workResolvedComponentInfos =
|
||||||
|
createResolvedComponentsForTest(0);
|
||||||
|
setupResolverControllers(personalResolvedComponentInfos, workResolvedComponentInfos);
|
||||||
|
Intent[] initialIntents = {
|
||||||
|
new Intent("action.fake1"),
|
||||||
|
new Intent("action.fake2")
|
||||||
|
};
|
||||||
|
Intent chooserIntent = createChooserIntent(new Intent(), initialIntents);
|
||||||
|
sOverrides.packageManager = mock(PackageManager.class);
|
||||||
|
when(sOverrides.packageManager.resolveActivity(any(Intent.class), anyInt()))
|
||||||
|
.thenReturn(createFakeResolveInfo());
|
||||||
|
|
||||||
|
mActivityRule.launchActivity(chooserIntent);
|
||||||
|
waitForIdle();
|
||||||
|
onView(withId(R.id.contentPanel))
|
||||||
|
.perform(swipeUp());
|
||||||
|
onView(withText(R.string.resolver_work_tab)).perform(click());
|
||||||
|
waitForIdle();
|
||||||
|
|
||||||
|
onView(withText(R.string.resolver_no_work_apps_available_resolve))
|
||||||
|
.check(matches(isDisplayed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Intent createChooserIntent(Intent intent, Intent[] initialIntents) {
|
||||||
Intent chooserIntent = new Intent();
|
Intent chooserIntent = new Intent();
|
||||||
chooserIntent.setAction(Intent.ACTION_CHOOSER);
|
chooserIntent.setAction(Intent.ACTION_CHOOSER);
|
||||||
chooserIntent.putExtra(Intent.EXTRA_TEXT, "testing intent sending");
|
chooserIntent.putExtra(Intent.EXTRA_TEXT, "testing intent sending");
|
||||||
chooserIntent.putExtra(Intent.EXTRA_TITLE, "some title");
|
chooserIntent.putExtra(Intent.EXTRA_TITLE, "some title");
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INTENT, createSendTextIntent());
|
chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
|
||||||
chooserIntent.setType("text/plain");
|
chooserIntent.setType("text/plain");
|
||||||
if (initialIntents != null) {
|
if (initialIntents != null) {
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, initialIntents);
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, initialIntents);
|
||||||
|
|||||||
Reference in New Issue
Block a user