Merge "Resolve tiles intent before prompting a dialog for profile selection" am: 7b8b881f8a

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/12401652

Change-Id: I06a28acdb2f757d6fee843f43c8a9c6bbff458e3
This commit is contained in:
Yanting Yang
2020-09-09 15:04:17 +00:00
committed by Automerger Merge Worker
2 changed files with 45 additions and 6 deletions

View File

@@ -398,26 +398,41 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
return;
}
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
if (tile.userHandle == null || tile.isPrimaryProfileOnly()) {
mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
activity.startActivityForResult(intent, 0);
} else if (tile.userHandle.size() == 1) {
mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
} else {
mMetricsFeatureProvider.logStartedIntent(intent, sourceMetricCategory);
final UserHandle userHandle = intent.getParcelableExtra(EXTRA_USER);
if (userHandle != null && tile.userHandle.contains(userHandle)) {
activity.startActivityForResultAsUser(intent, 0, userHandle);
} else {
ProfileSelectDialog.show(activity.getSupportFragmentManager(), tile,
sourceMetricCategory);
return;
}
final List<UserHandle> resolvableUsers = getResolvableUsers(intent, tile);
if (resolvableUsers.size() == 1) {
activity.startActivityForResultAsUser(intent, 0, resolvableUsers.get(0));
return;
}
ProfileSelectDialog.show(activity.getSupportFragmentManager(), tile,
sourceMetricCategory);
}
}
private boolean isIntentResolvable(Intent intent) {
return mPackageManager.resolveActivity(intent, 0) != null;
}
private List<UserHandle> getResolvableUsers(Intent intent, Tile tile) {
final ArrayList<UserHandle> eligibleUsers = new ArrayList<>();
for (UserHandle user : tile.userHandle) {
if (mPackageManager.resolveActivityAsUser(intent, 0, user.getIdentifier()) != null) {
eligibleUsers.add(user);
}
}
return eligibleUsers;
}
}

View File

@@ -583,4 +583,28 @@ public class DashboardFeatureProviderImplTest {
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
verify(mActivity).getSupportFragmentManager();
}
@Test
public void openTileIntent_profileSelectionDialog_unresolvableWorkProfileIntentShouldNotShow() {
final int userId = 10;
ShadowUserManager.getShadow().addUser(userId, "Someone", 0);
final UserHandle userHandle = new UserHandle(userId);
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(userHandle);
tile.userHandle = handles;
when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), eq(0)))
.thenReturn(new ResolveInfo());
when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), eq(userId)))
.thenReturn(null);
mImpl.openTileIntent(mActivity, tile);
final ArgumentCaptor<UserHandle> argument = ArgumentCaptor.forClass(UserHandle.class);
verify(mActivity)
.startActivityForResultAsUser(any(Intent.class), anyInt(), argument.capture());
assertThat(argument.getValue().getIdentifier()).isEqualTo(0);
verify(mActivity, never()).getSupportFragmentManager();
}
}