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:
@@ -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>
|
||||
|
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -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,29 +181,21 @@ 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()) {
|
||||
if (!mHelper.hasBaseUserRestriction(DISALLOW_REMOVE_MANAGED_PROFILE,
|
||||
UserHandle.myUserId())) {
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
|
||||
data.title = res.getString(R.string.remove_managed_profile_label);
|
||||
data.screenTitle = screenTitle;
|
||||
rawData.add(data);
|
||||
}
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(mContext);
|
||||
data.title = res.getString(R.string.managed_profile_settings_title);
|
||||
for (final UserInfo userInfo : profiles) {
|
||||
if (userInfo.isEnabled() && userInfo.isManagedProfile()) {
|
||||
if (!mHelper.hasBaseUserRestriction(DISALLOW_REMOVE_MANAGED_PROFILE,
|
||||
UserHandle.myUserId())) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user