Add current user handle to tile intent in account detail page.

- the account detail settings page is launched with the correct user
handle when there is work profile to indicate which profile the account
belongs to. When we process the dynamic tile, for the page, we should
add this info to the tile intent, so that it can be launched with the
correct profile.
- when we launch the tile intent, check whether there's user handle
specified. If so, launch the intent directly without prompting for
profile selection.

Change-Id: I91f8c666a826909006b1f53907b3441825322c10
Fixes: 119657694
Test: make RunSettingsRoboTests
This commit is contained in:
Doris Ling
2019-01-28 13:37:31 -08:00
parent 1cf1d9b643
commit 3e586a5cf2
4 changed files with 81 additions and 5 deletions

View File

@@ -15,11 +15,14 @@
*/
package com.android.settings.accounts;
import static android.content.Intent.EXTRA_USER;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -56,6 +59,8 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
String mAccountType;
private AccountSyncPreferenceController mAccountSynController;
private RemoveAccountPreferenceController mRemoveAccountController;
@VisibleForTesting
UserHandle mUserHandle;
@Override
public void onCreate(Bundle icicle) {
@@ -63,7 +68,7 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
getPreferenceManager().setPreferenceComparisonCallback(null);
Bundle args = getArguments();
final Activity activity = getActivity();
UserHandle userHandle = Utils.getSecureTargetUser(activity.getActivityToken(),
mUserHandle = Utils.getSecureTargetUser(activity.getActivityToken(),
(UserManager) getSystemService(Context.USER_SERVICE), args,
activity.getIntent().getExtras());
if (args != null) {
@@ -77,8 +82,8 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
mAccountType = args.getString(KEY_ACCOUNT_TYPE);
}
}
mAccountSynController.init(mAccount, userHandle);
mRemoveAccountController.init(mAccount, userHandle);
mAccountSynController.init(mAccount, mUserHandle);
mRemoveAccountController.init(mAccount, mUserHandle);
}
@Override
@@ -154,7 +159,9 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
}
final boolean display = mAccountType.equals(metadata.getString(METADATA_IA_ACCOUNT));
if (display) {
tile.getIntent().putExtra(EXTRA_ACCOUNT_NAME, mAccount.name);
final Intent intent = tile.getIntent();
intent.putExtra(EXTRA_ACCOUNT_NAME, mAccount.name);
intent.putExtra(EXTRA_USER, mUserHandle);
}
return display;
}

View File

@@ -16,6 +16,8 @@
package com.android.settings.dashboard;
import static android.content.Intent.EXTRA_USER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_URI;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY_URI;
@@ -29,6 +31,7 @@ import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -238,10 +241,17 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
} else if (tile.userHandle.size() == 1) {
mMetricsFeatureProvider.logDashboardStartIntent(mContext, intent, sourceMetricCategory);
activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
} else {
final UserHandle userHandle = intent.getParcelableExtra(EXTRA_USER);
if (userHandle != null && tile.userHandle.contains(userHandle)) {
mMetricsFeatureProvider.logDashboardStartIntent(
mContext, intent, sourceMetricCategory);
activity.startActivityForResultAsUser(intent, 0, userHandle);
} else {
ProfileSelectDialog.show(activity.getSupportFragmentManager(), tile);
}
}
}
private boolean isIntentResolvable(Intent intent) {
return mPackageManager.resolveActivity(intent, 0) != null;

View File

@@ -15,6 +15,8 @@
*/
package com.android.settings.accounts;
import static android.content.Intent.EXTRA_USER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_TITLE;
@@ -160,6 +162,20 @@ public class AccountDetailDashboardFragmentTest {
assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
@Test
public void displayTile_shouldAddUserHandleToTileIntent() {
mFragment.mUserHandle = new UserHandle(1);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
mFragment.displayTile(tile);
final UserHandle userHandle = tile.getIntent().getParcelableExtra(EXTRA_USER);
assertThat(userHandle.getIdentifier()).isEqualTo(1);
}
@Test
public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager =

View File

@@ -16,6 +16,8 @@
package com.android.settings.dashboard;
import static android.content.Intent.EXTRA_USER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER;
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
@@ -67,6 +69,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
@@ -412,4 +415,44 @@ public class DashboardFeatureProviderImplTest {
.startActivityForResult(any(Intent.class), eq(0));
verify(mActivity, never()).getSupportFragmentManager();
}
@Test
public void openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow() {
final int userId = 10;
ShadowUserManager.getShadow().addUser(userId, "Someone", 0);
final UserHandle userHandle = new UserHandle(userId);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.getIntent().putExtra(EXTRA_USER, userHandle);
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(userHandle);
tile.userHandle = handles;
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(userId);
verify(mActivity, never()).getSupportFragmentManager();
}
@Test
public void openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow() {
ShadowUserManager.getShadow().addUser(10, "Someone", 0);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.getIntent().putExtra(EXTRA_USER, new UserHandle(30));
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(new UserHandle(10));
tile.userHandle = handles;
mImpl.openTileIntent(mActivity, tile);
verify(mActivity, never())
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
verify(mActivity).getSupportFragmentManager();
}
}