Refactor bindPreferenceToTile to properly handle multi-user

Change-Id: I751eb645663b3546c212925e2ba4a0a94714013b
Fixes: 32470791
Test: RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2016-11-01 11:56:22 -07:00
parent aa12b4d269
commit 5482637f8b
2 changed files with 11 additions and 8 deletions

View File

@@ -98,16 +98,17 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
}
if (!TextUtils.isEmpty(clsName)) {
pref.setFragment(clsName);
} else if (tile.userHandle != null && tile.userHandle.size() > 1) {
pref.setOnPreferenceClickListener(preference -> {
ProfileSelectDialog.updateUserHandlesIfNeeded(activity, tile);
ProfileSelectDialog.show(activity.getFragmentManager(), tile);
return true;
});
} else if (tile.intent != null) {
final Intent intent = new Intent(tile.intent);
pref.setOnPreferenceClickListener(preference -> {
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
if (tile.userHandle == null) {
activity.startActivityForResult(intent, 0);
} else if (tile.userHandle.size() == 1) {
activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
} else {
ProfileSelectDialog.show(activity.getFragmentManager(), tile);
}
return true;
});
}

View File

@@ -112,7 +112,9 @@ public class DashboardFeatureProviderImplTest {
tile.userHandle.add(mock(UserHandle.class));
tile.userHandle.add(mock(UserHandle.class));
tile.intent = new Intent();
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123");
preference.getOnPreferenceClickListener().onPreferenceClick(null);