Add work profile items of Account page to dynamic index.

- Add "Work profile settings" & "Remove work profile"
to dynamic index

Test: manual & robotests AccountPreferenceControllerTest
Change-Id: I122269927fd466bc8fbce1dd68faa372a6a7477b
Bugs: 69907442
This commit is contained in:
Stanley Wang
2019-11-27 10:39:59 +08:00
parent 1a359b5b22
commit 8015cbab9e
4 changed files with 38 additions and 34 deletions

View File

@@ -7202,7 +7202,7 @@
<string name="keywords_sounds_and_notifications_interruptions">dont don\u2019t disturb, interrupt, interruption, break</string>
<string name="keywords_app">RAM</string>
<string name="keywords_location">nearby, location, history, reporting, GPS</string>
<string name="keywords_accounts">account, add an account, work profile</string>
<string name="keywords_accounts">account, add an account, work profile, add account</string>
<string name="keywords_users">restriction, restrict, restricted</string>
<string name="keywords_keyboard_and_ime">text correction, correct, sound, vibrate, auto, language, gesture, suggest, suggestion, theme, offensive, word, type, emoji, international</string>
<string name="keywords_reset_apps">reset, preferences, default</string>

View File

@@ -30,6 +30,7 @@ import com.android.settings.users.AutoSyncPersonalDataPreferenceController;
import com.android.settings.users.AutoSyncWorkDataPreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.search.SearchIndexableRaw;
import java.util.ArrayList;
import java.util.List;
@@ -92,5 +93,11 @@ public class AccountDashboardFragment extends DashboardFragment {
return buildPreferenceControllers(
context, null /* parent */, null /* authorities*/);
}
@Override
public List<SearchIndexableRaw> getDynamicRawDataToIndex(Context context,
boolean enabled) {
return null;
}
};
}

View File

@@ -80,6 +80,9 @@ public class AccountPreferenceController extends AbstractPreferenceController
private static final int ORDER_NEXT_TO_LAST = 1001;
private static final int ORDER_NEXT_TO_NEXT_TO_LAST = 1000;
private static final String PREF_KEY_REMOVE_PROFILE = "remove_profile";
private static final String PREF_KEY_WORK_PROFILE_SETTING = "work_profile_setting";
private UserManager mUm;
private SparseArray<ProfileData> mProfiles = new SparseArray<ProfileData>();
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver =
@@ -170,7 +173,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
}
@Override
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
if (!isAvailable()) {
return;
}
@@ -178,32 +181,24 @@ public class AccountPreferenceController extends AbstractPreferenceController
final String screenTitle = res.getString(R.string.account_settings_title);
List<UserInfo> profiles = mUm.getProfiles(UserHandle.myUserId());
final int profilesCount = profiles.size();
for (int i = 0; i < profilesCount; i++) {
UserInfo userInfo = profiles.get(i);
if (userInfo.isEnabled()) {
if (!mHelper.hasBaseUserRestriction(DISALLOW_MODIFY_ACCOUNTS, userInfo.id)) {
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
data.title = res.getString(R.string.add_account_label);
data.screenTitle = screenTitle;
rawData.add(data);
}
if (userInfo.isManagedProfile()) {
for (final UserInfo userInfo : profiles) {
if (userInfo.isEnabled() && userInfo.isManagedProfile()) {
if (!mHelper.hasBaseUserRestriction(DISALLOW_REMOVE_MANAGED_PROFILE,
UserHandle.myUserId())) {
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
final SearchIndexableRaw data = new SearchIndexableRaw(mContext);
data.key = PREF_KEY_REMOVE_PROFILE;
data.title = res.getString(R.string.remove_managed_profile_label);
data.screenTitle = screenTitle;
rawData.add(data);
}
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
final SearchIndexableRaw data = new SearchIndexableRaw(mContext);
data.key = PREF_KEY_WORK_PROFILE_SETTING;
data.title = res.getString(R.string.managed_profile_settings_title);
data.screenTitle = screenTitle;
rawData.add(data);
}
}
}
}
@Override
public void onResume() {
@@ -375,6 +370,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
private RestrictedPreference newRemoveWorkProfilePreference() {
RestrictedPreference preference = new RestrictedPreference(
mParent.getPreferenceManager().getContext());
preference.setKey(PREF_KEY_REMOVE_PROFILE);
preference.setTitle(R.string.remove_managed_profile_label);
preference.setIcon(R.drawable.ic_delete);
preference.setOnPreferenceClickListener(this);
@@ -385,6 +381,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
private Preference newManagedProfileSettings() {
Preference preference = new Preference(mParent.getPreferenceManager().getContext());
preference.setKey(PREF_KEY_WORK_PROFILE_SETTING);
preference.setTitle(R.string.managed_profile_settings_title);
preference.setIcon(R.drawable.ic_settings_24dp);
preference.setOnPreferenceClickListener(this);

View File

@@ -274,33 +274,33 @@ public class AccountPreferenceControllerTest {
}
@Test
public void updateRawDataToIndex_EnabledUser_shouldAddOne() {
public void updateDynamicRawDataToIndex_enabledUser_notManagedUser_shouldNotUpdate() {
final List<SearchIndexableRaw> data = new ArrayList<>();
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
mController.updateRawDataToIndex(data);
mController.updateDynamicRawDataToIndex(data);
assertThat(data.size()).isEqualTo(1);
assertThat(data.size()).isEqualTo(0);
}
@Test
public void updateRawDataToIndex_ManagedUser_shouldAddThree() {
public void updateDynamicRawDataToIndex_managedUser_shouldAddTwo() {
final List<SearchIndexableRaw> data = new ArrayList<>();
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_MANAGED_PROFILE));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
mController.updateRawDataToIndex(data);
mController.updateDynamicRawDataToIndex(data);
assertThat(data.size()).isEqualTo(3);
assertThat(data.size()).isEqualTo(2);
}
@Test
public void updateRawDataToIndex_DisallowRemove_shouldAddTwo() {
public void updateDynamicRawDataToIndex_disallowRemove_shouldAddOne() {
final List<SearchIndexableRaw> data = new ArrayList<>();
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_MANAGED_PROFILE));
@@ -310,13 +310,13 @@ public class AccountPreferenceControllerTest {
eq(UserManager.DISALLOW_REMOVE_MANAGED_PROFILE), anyInt()))
.thenReturn(true);
mController.updateRawDataToIndex(data);
mController.updateDynamicRawDataToIndex(data);
assertThat(data.size()).isEqualTo(2);
assertThat(data.size()).isEqualTo(1);
}
@Test
public void updateRawDataToIndex_DisallowModify_shouldAddTwo() {
public void updateDynamicRawDataToIndex_disallowModify_shouldAddTwo() {
final List<SearchIndexableRaw> data = new ArrayList<>();
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_MANAGED_PROFILE));
@@ -325,7 +325,7 @@ public class AccountPreferenceControllerTest {
when(mAccountHelper.hasBaseUserRestriction(
eq(UserManager.DISALLOW_MODIFY_ACCOUNTS), anyInt())).thenReturn(true);
mController.updateRawDataToIndex(data);
mController.updateDynamicRawDataToIndex(data);
assertThat(data.size()).isEqualTo(2);
}