Allow Device Management Role Holder to update Settings strings.
Test: manual Bug: 188414370 Change-Id: I6e1a06619799a9e99382d791e72e2e4518f93cac
This commit is contained in:
@@ -16,6 +16,14 @@
|
||||
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.ACCESSIBILITY_CATEGORY_PERSONAL;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.ACCESSIBILITY_CATEGORY_WORK;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.MANAGED_BY;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.MANAGED_PROFILE_SETTINGS_TITLE;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_CATEGORY_HEADER;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.REMOVE_WORK_PROFILE;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_NOT_AVAILABLE;
|
||||
import static android.content.Intent.EXTRA_USER;
|
||||
import static android.os.UserManager.DISALLOW_MODIFY_ACCOUNTS;
|
||||
import static android.os.UserManager.DISALLOW_REMOVE_MANAGED_PROFILE;
|
||||
@@ -24,6 +32,7 @@ import static android.provider.Settings.EXTRA_AUTHORITIES;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -85,6 +94,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
private static final String PREF_KEY_WORK_PROFILE_SETTING = "work_profile_setting";
|
||||
|
||||
private UserManager mUm;
|
||||
private DevicePolicyManager mDpm;
|
||||
private SparseArray<ProfileData> mProfiles = new SparseArray<ProfileData>();
|
||||
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver =
|
||||
new ManagedProfileBroadcastReceiver();
|
||||
@@ -146,6 +156,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
@ProfileSelectFragment.ProfileType int type) {
|
||||
super(context);
|
||||
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mDpm = context.getSystemService(DevicePolicyManager.class);
|
||||
mAuthorities = authorities;
|
||||
mFragment = parent;
|
||||
if (mAuthorities != null) {
|
||||
@@ -188,13 +199,16 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
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.title = mDpm.getString(
|
||||
REMOVE_WORK_PROFILE,
|
||||
() -> 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.title = mDpm.getString(MANAGED_PROFILE_SETTINGS_TITLE,
|
||||
() -> res.getString(R.string.managed_profile_settings_title));
|
||||
data.screenTitle = screenTitle;
|
||||
rawData.add(data);
|
||||
}
|
||||
@@ -253,7 +267,8 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
new SubSettingLauncher(mContext)
|
||||
.setSourceMetricsCategory(metricsCategory)
|
||||
.setDestination(ManagedProfileSettings.class.getName())
|
||||
.setTitleRes(R.string.managed_profile_settings_title)
|
||||
.setTitleText(mDpm.getString(MANAGED_PROFILE_SETTINGS_TITLE,
|
||||
() -> mContext.getString(R.string.managed_profile_settings_title)))
|
||||
.setArguments(arguments)
|
||||
.launch();
|
||||
|
||||
@@ -331,11 +346,15 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
preferenceGroup.setContentDescription(title);
|
||||
} else if (userInfo.isManagedProfile()) {
|
||||
if (mType == ProfileSelectFragment.ProfileType.ALL) {
|
||||
preferenceGroup.setTitle(R.string.category_work);
|
||||
preferenceGroup.setTitle(
|
||||
mDpm.getString(WORK_CATEGORY_HEADER,
|
||||
() -> mContext.getString(R.string.category_work)));
|
||||
final String workGroupSummary = getWorkGroupSummary(context, userInfo);
|
||||
preferenceGroup.setSummary(workGroupSummary);
|
||||
preferenceGroup.setContentDescription(
|
||||
mContext.getString(R.string.accessibility_category_work, workGroupSummary));
|
||||
mDpm.getString(ACCESSIBILITY_CATEGORY_WORK, () ->
|
||||
mContext.getString(
|
||||
R.string.accessibility_category_work, workGroupSummary)));
|
||||
}
|
||||
profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference();
|
||||
mHelper.enforceRestrictionOnPreference(profileData.removeWorkProfilePreference,
|
||||
@@ -343,9 +362,12 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
profileData.managedProfilePreference = newManagedProfileSettings();
|
||||
} else {
|
||||
if (mType == ProfileSelectFragment.ProfileType.ALL) {
|
||||
preferenceGroup.setTitle(R.string.category_personal);
|
||||
preferenceGroup.setTitle(
|
||||
mDpm.getString(PERSONAL_CATEGORY_HEADER,
|
||||
() -> mContext.getString(R.string.category_personal)));
|
||||
preferenceGroup.setContentDescription(
|
||||
mContext.getString(R.string.accessibility_category_personal));
|
||||
mDpm.getString(ACCESSIBILITY_CATEGORY_PERSONAL, () ->
|
||||
mContext.getString(R.string.accessibility_category_personal)));
|
||||
}
|
||||
}
|
||||
final PreferenceScreen screen = mFragment.getPreferenceScreen();
|
||||
@@ -378,7 +400,9 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
RestrictedPreference preference = new RestrictedPreference(
|
||||
mFragment.getPreferenceManager().getContext());
|
||||
preference.setKey(PREF_KEY_REMOVE_PROFILE);
|
||||
preference.setTitle(R.string.remove_managed_profile_label);
|
||||
preference.setTitle(
|
||||
mDpm.getString(REMOVE_WORK_PROFILE,
|
||||
() -> mContext.getString(R.string.remove_managed_profile_label)));
|
||||
preference.setIcon(R.drawable.ic_delete);
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
preference.setOrder(ORDER_LAST);
|
||||
@@ -389,7 +413,8 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
private Preference newManagedProfileSettings() {
|
||||
Preference preference = new Preference(mFragment.getPreferenceManager().getContext());
|
||||
preference.setKey(PREF_KEY_WORK_PROFILE_SETTING);
|
||||
preference.setTitle(R.string.managed_profile_settings_title);
|
||||
preference.setTitle(mDpm.getString(MANAGED_PROFILE_SETTINGS_TITLE,
|
||||
() -> mContext.getString(R.string.managed_profile_settings_title)));
|
||||
preference.setIcon(R.drawable.ic_settings_24dp);
|
||||
preference.setOnPreferenceClickListener(this);
|
||||
preference.setOrder(ORDER_NEXT_TO_LAST);
|
||||
@@ -403,7 +428,8 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
return null;
|
||||
}
|
||||
CharSequence appLabel = packageManager.getApplicationLabel(adminApplicationInfo);
|
||||
return mContext.getString(R.string.managing_admin, appLabel);
|
||||
return mDpm.getString(MANAGED_BY,
|
||||
() -> mContext.getString(R.string.managing_admin, appLabel), appLabel);
|
||||
}
|
||||
|
||||
void cleanUpPreferences() {
|
||||
@@ -482,7 +508,9 @@ public class AccountPreferenceController extends AbstractPreferenceController
|
||||
mProfileNotAvailablePreference.setIcon(R.drawable.empty_icon);
|
||||
mProfileNotAvailablePreference.setTitle(null);
|
||||
mProfileNotAvailablePreference.setSummary(
|
||||
R.string.managed_profile_not_available_label);
|
||||
mDpm.getString(
|
||||
WORK_PROFILE_NOT_AVAILABLE, () -> mContext.getString(
|
||||
R.string.managed_profile_not_available_label)));
|
||||
profileData.preferenceGroup.addPreference(mProfileNotAvailablePreference);
|
||||
}
|
||||
if (profileData.removeWorkProfilePreference != null) {
|
||||
|
Reference in New Issue
Block a user