Allow Device Management Role Holder to update Settings strings.

Test: manual
Bug: 188414370
Change-Id: I6e1a06619799a9e99382d791e72e2e4518f93cac
This commit is contained in:
Jonathan Scott
2022-01-19 15:19:08 +00:00
parent 47d115c3ff
commit e0d439472f
55 changed files with 788 additions and 231 deletions

View File

@@ -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) {

View File

@@ -16,10 +16,14 @@
package com.android.settings.accounts;
import static android.app.admin.DevicePolicyResources.Strings.Settings.ACCESSIBILITY_PERSONAL_ACCOUNT_TITLE;
import static android.app.admin.DevicePolicyResources.Strings.Settings.ACCESSIBILITY_WORK_ACCOUNT_TITLE;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context;
@@ -154,10 +158,20 @@ public class AccountSyncSettings extends AccountPreferenceBase {
UserInfo user = um.getUserInfo(mUserHandle.getIdentifier());
boolean isWorkProfile = user != null ? user.isManagedProfile() : false;
CharSequence currentTitle = getActivity().getTitle();
DevicePolicyManager devicePolicyManager = getSystemService(DevicePolicyManager.class);
String accessibilityTitle =
getString(isWorkProfile
? R.string.accessibility_work_account_title
: R.string.accessibility_personal_account_title, currentTitle);
isWorkProfile
? devicePolicyManager.getString(ACCESSIBILITY_WORK_ACCOUNT_TITLE,
() -> getString(R.string.accessibility_work_account_title,
currentTitle), currentTitle)
: devicePolicyManager.getString(
ACCESSIBILITY_PERSONAL_ACCOUNT_TITLE,
() -> getString(
R.string.accessibility_personal_account_title,
currentTitle), currentTitle);
getActivity().setTitle(Utils.createAccessibleSequence(currentTitle, accessibilityTitle));
}

View File

@@ -15,12 +15,15 @@
*/
package com.android.settings.accounts;
import static android.app.admin.DevicePolicyResources.Strings.Settings.REMOVE_ACCOUNT_FAILED_ADMIN_RESTRICTION;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
@@ -213,7 +216,9 @@ public class RemoveAccountPreferenceController extends AbstractPreferenceControl
return new AlertDialog.Builder(context)
.setTitle(R.string.remove_account_label)
.setMessage(R.string.remove_account_failed)
.setMessage(getContext().getSystemService(DevicePolicyManager.class)
.getString(REMOVE_ACCOUNT_FAILED_ADMIN_RESTRICTION,
() -> getString(R.string.remove_account_failed)))
.setPositiveButton(android.R.string.ok, null)
.create();
}

View File

@@ -13,6 +13,10 @@
*/
package com.android.settings.accounts;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SETTING_OFF_SUMMARY;
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SETTING_ON_SUMMARY;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -40,6 +44,7 @@ public class WorkModePreferenceController extends BasePreferenceController imple
private UserManager mUserManager;
private UserHandle mManagedUser;
private DevicePolicyManager mDevicePolicyManager;
private Preference mPreference;
private IntentFilter mIntentFilter;
@@ -47,6 +52,7 @@ public class WorkModePreferenceController extends BasePreferenceController imple
public WorkModePreferenceController(Context context, String key) {
super(context, key);
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mDevicePolicyManager = mContext.getSystemService(DevicePolicyManager.class);
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
mIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
@@ -80,9 +86,15 @@ public class WorkModePreferenceController extends BasePreferenceController imple
@Override
public CharSequence getSummary() {
return mContext.getText(isChecked()
? R.string.work_mode_on_summary
: R.string.work_mode_off_summary);
if (isChecked()) {
return mDevicePolicyManager
.getString(WORK_PROFILE_SETTING_ON_SUMMARY,
() -> mContext.getString(R.string.work_mode_on_summary));
}
return mDevicePolicyManager
.getString(WORK_PROFILE_SETTING_OFF_SUMMARY,
() -> mContext.getString(R.string.work_mode_off_summary));
}
private boolean isChecked() {