diff options
author | 2021-12-21 17:17:08 +0000 | |
---|---|---|
committer | 2022-01-26 18:43:14 +0000 | |
commit | 9130147d8f31348d7f6d440f43b961166f55b2d0 (patch) | |
tree | 4f3f298460610d0e0197b5ce2668128d869466f4 | |
parent | 375bab6f013042fe52f0f6aedaece9bc1849030c (diff) |
allow updating enterprise strings in sysUI
Bug: 188414133
Bug: 211422509
Bug: 188410712
Test: manual
Change-Id: Ia595f95456064156f48b7f2a6b1b774a47e9f0af
7 files changed, 348 insertions, 103 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java index 0fb12953bd54..57ca0f4826e9 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java @@ -16,6 +16,12 @@ package com.android.systemui.biometrics; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.BIOMETRIC_DIALOG_WORK_LOCK_FAILED_ATTEMPTS; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.BIOMETRIC_DIALOG_WORK_PASSWORD_LAST_ATTEMPT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.BIOMETRIC_DIALOG_WORK_PATTERN_LAST_ATTEMPT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.BIOMETRIC_DIALOG_WORK_PIN_LAST_ATTEMPT; +import static android.app.admin.DevicePolicyResources.Strings.UNDEFINED; + import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; @@ -374,7 +380,7 @@ public abstract class AuthCredentialView extends LinearLayout { final AlertDialog alertDialog = new AlertDialog.Builder(mContext) .setTitle(R.string.biometric_dialog_last_attempt_before_wipe_dialog_title) .setMessage( - getLastAttemptBeforeWipeMessageRes(getUserTypeForWipe(), mCredentialType)) + getLastAttemptBeforeWipeMessage(getUserTypeForWipe(), mCredentialType)) .setPositiveButton(android.R.string.ok, null) .create(); alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL); @@ -383,7 +389,7 @@ public abstract class AuthCredentialView extends LinearLayout { private void showNowWipingDialog() { final AlertDialog alertDialog = new AlertDialog.Builder(mContext) - .setMessage(getNowWipingMessageRes(getUserTypeForWipe())) + .setMessage(getNowWipingMessage(getUserTypeForWipe())) .setPositiveButton(R.string.biometric_dialog_now_wiping_dialog_dismiss, null) .setOnDismissListener( dialog -> mContainerView.animateAway(AuthDialogCallback.DISMISSED_ERROR)) @@ -404,70 +410,121 @@ public abstract class AuthCredentialView extends LinearLayout { } } - private static @StringRes int getLastAttemptBeforeWipeMessageRes( + private String getLastAttemptBeforeWipeMessage( @UserType int userType, @Utils.CredentialType int credentialType) { switch (userType) { case USER_TYPE_PRIMARY: - return getLastAttemptBeforeWipeDeviceMessageRes(credentialType); + return getLastAttemptBeforeWipeDeviceMessage(credentialType); case USER_TYPE_MANAGED_PROFILE: - return getLastAttemptBeforeWipeProfileMessageRes(credentialType); + return getLastAttemptBeforeWipeProfileMessage(credentialType); case USER_TYPE_SECONDARY: - return getLastAttemptBeforeWipeUserMessageRes(credentialType); + return getLastAttemptBeforeWipeUserMessage(credentialType); default: throw new IllegalArgumentException("Unrecognized user type:" + userType); } } - private static @StringRes int getLastAttemptBeforeWipeDeviceMessageRes( + private String getLastAttemptBeforeWipeDeviceMessage( @Utils.CredentialType int credentialType) { switch (credentialType) { case Utils.CREDENTIAL_PIN: - return R.string.biometric_dialog_last_pin_attempt_before_wipe_device; + return mContext.getString( + R.string.biometric_dialog_last_pin_attempt_before_wipe_device); case Utils.CREDENTIAL_PATTERN: - return R.string.biometric_dialog_last_pattern_attempt_before_wipe_device; + return mContext.getString( + R.string.biometric_dialog_last_pattern_attempt_before_wipe_device); case Utils.CREDENTIAL_PASSWORD: default: - return R.string.biometric_dialog_last_password_attempt_before_wipe_device; + return mContext.getString( + R.string.biometric_dialog_last_password_attempt_before_wipe_device); } } - private static @StringRes int getLastAttemptBeforeWipeProfileMessageRes( + private String getLastAttemptBeforeWipeProfileMessage( + @Utils.CredentialType int credentialType) { + return mDevicePolicyManager.getString( + getLastAttemptBeforeWipeProfileUpdatableStringId(credentialType), + () -> getLastAttemptBeforeWipeProfileDefaultMessage(credentialType)); + } + + private static String getLastAttemptBeforeWipeProfileUpdatableStringId( @Utils.CredentialType int credentialType) { switch (credentialType) { case Utils.CREDENTIAL_PIN: - return R.string.biometric_dialog_last_pin_attempt_before_wipe_profile; + return BIOMETRIC_DIALOG_WORK_PIN_LAST_ATTEMPT; case Utils.CREDENTIAL_PATTERN: - return R.string.biometric_dialog_last_pattern_attempt_before_wipe_profile; + return BIOMETRIC_DIALOG_WORK_PATTERN_LAST_ATTEMPT; case Utils.CREDENTIAL_PASSWORD: default: - return R.string.biometric_dialog_last_password_attempt_before_wipe_profile; + return BIOMETRIC_DIALOG_WORK_PASSWORD_LAST_ATTEMPT; } } - private static @StringRes int getLastAttemptBeforeWipeUserMessageRes( + private String getLastAttemptBeforeWipeProfileDefaultMessage( @Utils.CredentialType int credentialType) { + int resId; switch (credentialType) { case Utils.CREDENTIAL_PIN: - return R.string.biometric_dialog_last_pin_attempt_before_wipe_user; + resId = R.string.biometric_dialog_last_pin_attempt_before_wipe_profile; + break; case Utils.CREDENTIAL_PATTERN: - return R.string.biometric_dialog_last_pattern_attempt_before_wipe_user; + resId = R.string.biometric_dialog_last_pattern_attempt_before_wipe_profile; + break; case Utils.CREDENTIAL_PASSWORD: default: - return R.string.biometric_dialog_last_password_attempt_before_wipe_user; + resId = R.string.biometric_dialog_last_password_attempt_before_wipe_profile; + } + return mContext.getString(resId); + } + + private String getLastAttemptBeforeWipeUserMessage( + @Utils.CredentialType int credentialType) { + int resId; + switch (credentialType) { + case Utils.CREDENTIAL_PIN: + resId = R.string.biometric_dialog_last_pin_attempt_before_wipe_user; + break; + case Utils.CREDENTIAL_PATTERN: + resId = R.string.biometric_dialog_last_pattern_attempt_before_wipe_user; + break; + case Utils.CREDENTIAL_PASSWORD: + default: + resId = R.string.biometric_dialog_last_password_attempt_before_wipe_user; + } + return mContext.getString(resId); + } + + private String getNowWipingMessage(@UserType int userType) { + return mDevicePolicyManager.getString( + getNowWipingUpdatableStringId(userType), + () -> getNowWipingDefaultMessage(userType)); + } + + private String getNowWipingUpdatableStringId(@UserType int userType) { + switch (userType) { + case USER_TYPE_MANAGED_PROFILE: + return BIOMETRIC_DIALOG_WORK_LOCK_FAILED_ATTEMPTS; + default: + return UNDEFINED; } } - private static @StringRes int getNowWipingMessageRes(@UserType int userType) { + private String getNowWipingDefaultMessage(@UserType int userType) { + int resId; switch (userType) { case USER_TYPE_PRIMARY: - return R.string.biometric_dialog_failed_attempts_now_wiping_device; + resId = R.string.biometric_dialog_failed_attempts_now_wiping_device; + break; case USER_TYPE_MANAGED_PROFILE: - return R.string.biometric_dialog_failed_attempts_now_wiping_profile; + resId = R.string.biometric_dialog_failed_attempts_now_wiping_profile; + break; case USER_TYPE_SECONDARY: - return R.string.biometric_dialog_failed_attempts_now_wiping_user; + resId = R.string.biometric_dialog_failed_attempts_now_wiping_user; + break; default: throw new IllegalArgumentException("Unrecognized user type:" + userType); } + return mContext.getString(resId); } @Nullable diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivity.java b/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivity.java index 24ad75d7dcc0..b3371831454b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivity.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivity.java @@ -17,6 +17,7 @@ package com.android.systemui.keyguard; import static android.app.ActivityManager.TaskDescription; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.WORK_LOCK_ACCESSIBILITY; import android.annotation.ColorInt; import android.annotation.UserIdInt; @@ -92,8 +93,11 @@ public class WorkLockActivity extends Activity { // Blank out the activity. When it is on-screen it will look like a Recents thumbnail with // redaction switched on. + final DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class); + String contentDescription = dpm.getString( + WORK_LOCK_ACCESSIBILITY, () -> getString(R.string.accessibility_desc_work_lock)); final View blankView = new View(this); - blankView.setContentDescription(getString(R.string.accessibility_desc_work_lock)); + blankView.setContentDescription(contentDescription); blankView.setBackgroundColor(getPrimaryColor()); setContentView(blankView); } diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java index 878f7530fa8b..9e17c121a79f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java @@ -16,6 +16,31 @@ package com.android.systemui.qs; import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_MANAGEMENT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_MANAGEMENT_CA_CERT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_MANAGEMENT_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_MANAGEMENT_NETWORK; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_MANAGEMENT_TITLE; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_MANAGEMENT_TWO_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_NAMED_MANAGEMENT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_PERSONAL_PROFILE_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_VIEW_POLICIES; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_WORK_PROFILE_CA_CERT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_WORK_PROFILE_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_DIALOG_WORK_PROFILE_NETWORK; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_MANAGEMENT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_MANAGEMENT_MONITORING; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_MANAGEMENT_MULTIPLE_VPNS; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_MANAGEMENT_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_NAMED_MANAGEMENT; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_NAMED_MANAGEMENT_MONITORING; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_NAMED_MANAGEMENT_MULTIPLE_VPNS; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_NAMED_MANAGEMENT_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_NAMED_WORK_PROFILE_MONITORING; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_PERSONAL_PROFILE_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_WORK_PROFILE_MONITORING; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_WORK_PROFILE_NAMED_VPN; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_MSG_WORK_PROFILE_NETWORK; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; @@ -24,6 +49,7 @@ import static com.android.systemui.qs.dagger.QSFragmentModule.QS_SECURITY_FOOTER import android.app.AlertDialog; import android.app.admin.DeviceAdminInfo; import android.app.admin.DevicePolicyEventLogger; +import android.app.admin.DevicePolicyManager; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -75,6 +101,7 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen private final TextView mFooterText; private final ImageView mPrimaryFooterIcon; private final Context mContext; + private final DevicePolicyManager mDpm; private final Callback mCallback = new Callback(); private final SecurityController mSecurityController; private final ActivityStarter mActivityStarter; @@ -102,6 +129,7 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen mPrimaryFooterIcon = mRootView.findViewById(R.id.primary_footer_icon); mFooterIconId = R.drawable.ic_info_outline; mContext = rootView.getContext(); + mDpm = rootView.getContext().getSystemService(DevicePolicyManager.class); mMainHandler = mainHandler; mActivityStarter = activityStarter; mSecurityController = securityController; @@ -254,87 +282,175 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen return mContext.getString(R.string.quick_settings_disclosure_parental_controls); } if (isDeviceManaged || DEBUG_FORCE_VISIBLE) { - if (hasCACerts || hasCACertsInWorkProfile || isNetworkLoggingEnabled) { - if (organizationName == null) { - return mContext.getString( - R.string.quick_settings_disclosure_management_monitoring); - } - return mContext.getString( + return getManagedDeviceFooterText(hasCACerts, hasCACertsInWorkProfile, + isNetworkLoggingEnabled, vpnName, vpnNameWorkProfile, organizationName); + } + return getManagedAndPersonalProfileFooterText(hasWorkProfile, hasCACerts, + hasCACertsInWorkProfile, isNetworkLoggingEnabled, vpnName, vpnNameWorkProfile, + workProfileOrganizationName, isProfileOwnerOfOrganizationOwnedDevice, + isWorkProfileOn); + } + + private String getManagedDeviceFooterText( + boolean hasCACerts, boolean hasCACertsInWorkProfile, boolean isNetworkLoggingEnabled, + String vpnName, String vpnNameWorkProfile, CharSequence organizationName) { + if (hasCACerts || hasCACertsInWorkProfile || isNetworkLoggingEnabled) { + return getManagedDeviceMonitoringText(organizationName); + } + if (vpnName != null || vpnNameWorkProfile != null) { + return getManagedDeviceVpnText(vpnName, vpnNameWorkProfile, organizationName); + } + return getMangedDeviceGeneralText(organizationName); + } + + private String getManagedDeviceMonitoringText(CharSequence organizationName) { + if (organizationName == null) { + return mDpm.getString( + QS_MSG_MANAGEMENT_MONITORING, + () -> mContext.getString( + R.string.quick_settings_disclosure_management_monitoring)); + } + return mDpm.getString( + QS_MSG_NAMED_MANAGEMENT_MONITORING, + () -> mContext.getString( R.string.quick_settings_disclosure_named_management_monitoring, - organizationName); - } - if (vpnName != null && vpnNameWorkProfile != null) { - if (organizationName == null) { - return mContext.getString(R.string.quick_settings_disclosure_management_vpns); - } - return mContext.getString(R.string.quick_settings_disclosure_named_management_vpns, - organizationName); + organizationName), + organizationName); + } + + private String getManagedDeviceVpnText( + String vpnName, String vpnNameWorkProfile, CharSequence organizationName) { + if (vpnName != null && vpnNameWorkProfile != null) { + if (organizationName == null) { + return mDpm.getString( + QS_MSG_MANAGEMENT_MULTIPLE_VPNS, + () -> mContext.getString( + R.string.quick_settings_disclosure_management_vpns)); } - if (vpnName != null || vpnNameWorkProfile != null) { - if (organizationName == null) { - return mContext.getString( + return mDpm.getString( + QS_MSG_NAMED_MANAGEMENT_MULTIPLE_VPNS, + () -> mContext.getString( + R.string.quick_settings_disclosure_named_management_vpns, + organizationName), + organizationName); + } + String name = vpnName != null ? vpnName : vpnNameWorkProfile; + if (organizationName == null) { + return mDpm.getString( + QS_MSG_MANAGEMENT_NAMED_VPN, + () -> mContext.getString( R.string.quick_settings_disclosure_management_named_vpn, - vpnName != null ? vpnName : vpnNameWorkProfile); - } - return mContext.getString( + name), + name); + } + return mDpm.getString( + QS_MSG_NAMED_MANAGEMENT_NAMED_VPN, + () -> mContext.getString( R.string.quick_settings_disclosure_named_management_named_vpn, organizationName, - vpnName != null ? vpnName : vpnNameWorkProfile); - } - if (organizationName == null) { - return mContext.getString(R.string.quick_settings_disclosure_management); - } - if (isFinancedDevice()) { - return mContext.getString( - R.string.quick_settings_financed_disclosure_named_management, - organizationName); - } else { - return mContext.getString(R.string.quick_settings_disclosure_named_management, - organizationName); - } - } // end if(isDeviceManaged) + name), + organizationName, + name); + } + + private String getMangedDeviceGeneralText(CharSequence organizationName) { + if (organizationName == null) { + return mDpm.getString( + QS_MSG_MANAGEMENT, + () -> mContext.getString( + R.string.quick_settings_disclosure_management)); + } + if (isFinancedDevice()) { + return mContext.getString( + R.string.quick_settings_financed_disclosure_named_management, + organizationName); + } else { + return mDpm.getString( + QS_MSG_NAMED_MANAGEMENT, + () -> mContext.getString( + R.string.quick_settings_disclosure_named_management, + organizationName), + organizationName); + } + } + + private String getManagedAndPersonalProfileFooterText(boolean hasWorkProfile, + boolean hasCACerts, boolean hasCACertsInWorkProfile, boolean isNetworkLoggingEnabled, + String vpnName, String vpnNameWorkProfile, CharSequence workProfileOrganizationName, + boolean isProfileOwnerOfOrganizationOwnedDevice, boolean isWorkProfileOn) { + if (hasCACerts || (hasCACertsInWorkProfile && isWorkProfileOn)) { + return getMonitoringText( + hasCACerts, hasCACertsInWorkProfile, workProfileOrganizationName, + isWorkProfileOn); + } + if (vpnName != null || (vpnNameWorkProfile != null && isWorkProfileOn)) { + return getVpnText(hasWorkProfile, vpnName, vpnNameWorkProfile, isWorkProfileOn); + } + if (hasWorkProfile && isNetworkLoggingEnabled && isWorkProfileOn) { + return getManagedProfileNetworkActivityText(); + } + if (isProfileOwnerOfOrganizationOwnedDevice) { + return getMangedDeviceGeneralText(workProfileOrganizationName); + } + return null; + } + + private String getMonitoringText(boolean hasCACerts, boolean hasCACertsInWorkProfile, + CharSequence workProfileOrganizationName, boolean isWorkProfileOn) { if (hasCACertsInWorkProfile && isWorkProfileOn) { if (workProfileOrganizationName == null) { - return mContext.getString( - R.string.quick_settings_disclosure_managed_profile_monitoring); + return mDpm.getString( + QS_MSG_WORK_PROFILE_MONITORING, + () -> mContext.getString( + R.string.quick_settings_disclosure_managed_profile_monitoring)); } - return mContext.getString( - R.string.quick_settings_disclosure_named_managed_profile_monitoring, + return mDpm.getString( + QS_MSG_NAMED_WORK_PROFILE_MONITORING, + () -> mContext.getString( + R.string.quick_settings_disclosure_named_managed_profile_monitoring, + workProfileOrganizationName), workProfileOrganizationName); } if (hasCACerts) { return mContext.getString(R.string.quick_settings_disclosure_monitoring); } + return null; + } + + private String getVpnText(boolean hasWorkProfile, String vpnName, String vpnNameWorkProfile, + boolean isWorkProfileOn) { if (vpnName != null && vpnNameWorkProfile != null) { return mContext.getString(R.string.quick_settings_disclosure_vpns); } if (vpnNameWorkProfile != null && isWorkProfileOn) { - return mContext.getString(R.string.quick_settings_disclosure_managed_profile_named_vpn, + return mDpm.getString( + QS_MSG_WORK_PROFILE_NAMED_VPN, + () -> mContext.getString( + R.string.quick_settings_disclosure_managed_profile_named_vpn, + vpnNameWorkProfile), vpnNameWorkProfile); } if (vpnName != null) { if (hasWorkProfile) { - return mContext.getString( - R.string.quick_settings_disclosure_personal_profile_named_vpn, + return mDpm.getString( + QS_MSG_PERSONAL_PROFILE_NAMED_VPN, + () -> mContext.getString( + R.string.quick_settings_disclosure_personal_profile_named_vpn, + vpnName), vpnName); } return mContext.getString(R.string.quick_settings_disclosure_named_vpn, vpnName); } - if (hasWorkProfile && isNetworkLoggingEnabled && isWorkProfileOn) { - return mContext.getString( - R.string.quick_settings_disclosure_managed_profile_network_activity); - } - if (isProfileOwnerOfOrganizationOwnedDevice) { - if (workProfileOrganizationName == null) { - return mContext.getString(R.string.quick_settings_disclosure_management); - } - return mContext.getString(R.string.quick_settings_disclosure_named_management, - workProfileOrganizationName); - } return null; } + private String getManagedProfileNetworkActivityText() { + return mDpm.getString( + QS_MSG_WORK_PROFILE_NETWORK, + () -> mContext.getString( + R.string.quick_settings_disclosure_managed_profile_network_activity)); + } @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_NEGATIVE) { @@ -494,7 +610,9 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen @VisibleForTesting String getSettingsButton() { - return mContext.getString(R.string.monitoring_button_view_policies); + return mDpm.getString( + QS_DIALOG_VIEW_POLICIES, + () -> mContext.getString(R.string.monitoring_button_view_policies)); } private String getPositiveButton() { @@ -520,11 +638,17 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen return mContext.getString(R.string.monitoring_financed_description_named_management, organizationName, organizationName); } else { - return mContext.getString( - R.string.monitoring_description_named_management, organizationName); + return mDpm.getString( + QS_DIALOG_NAMED_MANAGEMENT, + () -> mContext.getString( + R.string.monitoring_description_named_management, + organizationName), + organizationName); } } - return mContext.getString(R.string.monitoring_description_management); + return mDpm.getString( + QS_DIALOG_MANAGEMENT, + () -> mContext.getString(R.string.monitoring_description_management)); } @Nullable @@ -532,11 +656,16 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen boolean hasCACertsInWorkProfile) { if (!(hasCACerts || hasCACertsInWorkProfile)) return null; if (isDeviceManaged) { - return mContext.getString(R.string.monitoring_description_management_ca_certificate); + return mDpm.getString( + QS_DIALOG_MANAGEMENT_CA_CERT, + () -> mContext.getString( + R.string.monitoring_description_management_ca_certificate)); } if (hasCACertsInWorkProfile) { - return mContext.getString( - R.string.monitoring_description_managed_profile_ca_certificate); + return mDpm.getString( + QS_DIALOG_WORK_PROFILE_CA_CERT, + () -> mContext.getString( + R.string.monitoring_description_managed_profile_ca_certificate)); } return mContext.getString(R.string.monitoring_description_ca_certificate); } @@ -546,10 +675,15 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen boolean isNetworkLoggingEnabled) { if (!isNetworkLoggingEnabled) return null; if (isDeviceManaged) { - return mContext.getString(R.string.monitoring_description_management_network_logging); + return mDpm.getString( + QS_DIALOG_MANAGEMENT_NETWORK, + () -> mContext.getString( + R.string.monitoring_description_management_network_logging)); } else { - return mContext.getString( - R.string.monitoring_description_managed_profile_network_logging); + return mDpm.getString( + QS_DIALOG_WORK_PROFILE_NETWORK, + () -> mContext.getString( + R.string.monitoring_description_managed_profile_network_logging)); } } @@ -560,23 +694,46 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen final SpannableStringBuilder message = new SpannableStringBuilder(); if (isDeviceManaged) { if (vpnName != null && vpnNameWorkProfile != null) { - message.append(mContext.getString(R.string.monitoring_description_two_named_vpns, - vpnName, vpnNameWorkProfile)); + String namedVpns = mDpm.getString( + QS_DIALOG_MANAGEMENT_TWO_NAMED_VPN, + () -> mContext.getString( + R.string.monitoring_description_two_named_vpns, + vpnName, vpnNameWorkProfile), + vpnName, vpnNameWorkProfile); + message.append(namedVpns); } else { - message.append(mContext.getString(R.string.monitoring_description_named_vpn, - vpnName != null ? vpnName : vpnNameWorkProfile)); + String name = vpnName != null ? vpnName : vpnNameWorkProfile; + String namedVp = mDpm.getString( + QS_DIALOG_MANAGEMENT_NAMED_VPN, + () -> mContext.getString(R.string.monitoring_description_named_vpn, name), + name); + message.append(namedVp); } } else { if (vpnName != null && vpnNameWorkProfile != null) { - message.append(mContext.getString(R.string.monitoring_description_two_named_vpns, - vpnName, vpnNameWorkProfile)); + String namedVpns = mDpm.getString( + QS_DIALOG_MANAGEMENT_TWO_NAMED_VPN, + () -> mContext.getString( + R.string.monitoring_description_two_named_vpns, + vpnName, vpnNameWorkProfile), + vpnName, vpnNameWorkProfile); + message.append(namedVpns); } else if (vpnNameWorkProfile != null) { - message.append(mContext.getString( - R.string.monitoring_description_managed_profile_named_vpn, - vpnNameWorkProfile)); + String namedVpn = mDpm.getString( + QS_DIALOG_WORK_PROFILE_NAMED_VPN, + () -> mContext.getString( + R.string.monitoring_description_managed_profile_named_vpn, + vpnNameWorkProfile), + vpnNameWorkProfile); + message.append(namedVpn); } else if (hasWorkProfile) { - message.append(mContext.getString( - R.string.monitoring_description_personal_profile_named_vpn, vpnName)); + String namedVpn = mDpm.getString( + QS_DIALOG_PERSONAL_PROFILE_NAMED_VPN, + () -> mContext.getString( + R.string.monitoring_description_personal_profile_named_vpn, + vpnName), + vpnName); + message.append(namedVpn); } else { message.append(mContext.getString(R.string.monitoring_description_named_vpn, vpnName)); @@ -594,7 +751,9 @@ class QSSecurityFooter implements OnClickListener, DialogInterface.OnClickListen return mContext.getString(R.string.monitoring_title_financed_device, deviceOwnerOrganization); } else { - return mContext.getString(R.string.monitoring_title_device_owned); + return mDpm.getString( + QS_DIALOG_MANAGEMENT_TITLE, + () -> mContext.getString(R.string.monitoring_title_device_owned)); } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java index 8df8c63702c3..4279b62d54ab 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/WorkModeTile.java @@ -16,6 +16,9 @@ package com.android.systemui.qs.tiles; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.QS_WORK_PROFILE_LABEL; + +import android.app.admin.DevicePolicyManager; import android.content.Intent; import android.os.Handler; import android.os.Looper; @@ -100,7 +103,9 @@ public class WorkModeTile extends QSTileImpl<BooleanState> implements @Override public CharSequence getTileLabel() { - return mContext.getString(R.string.quick_settings_work_mode_label); + DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); + return dpm.getString(QS_WORK_PROFILE_LABEL, + () -> mContext.getString(R.string.quick_settings_work_mode_label)); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 6335f88152c8..a3f0a6dbf1da 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -17,6 +17,7 @@ package com.android.systemui.statusbar; import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.KEYGUARD_MANAGEMENT_DISCLOSURE; import static android.view.View.GONE; import static android.view.View.VISIBLE; @@ -343,7 +344,9 @@ public class KeyguardIndicationController { private CharSequence getDisclosureText(@Nullable CharSequence organizationName) { final Resources packageResources = mContext.getResources(); if (organizationName == null) { - return packageResources.getText(R.string.do_disclosure_generic); + return mDevicePolicyManager.getString( + KEYGUARD_MANAGEMENT_DISCLOSURE, + () -> packageResources.getString(R.string.do_disclosure_generic)); } else if (mDevicePolicyManager.isDeviceManaged() && mDevicePolicyManager.getDeviceOwnerType( mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()) @@ -351,7 +354,10 @@ public class KeyguardIndicationController { return packageResources.getString(R.string.do_financed_disclosure_with_name, organizationName); } else { - return packageResources.getString(R.string.do_disclosure_with_name, + return mDevicePolicyManager.getString( + KEYGUARD_MANAGEMENT_DISCLOSURE, + () -> packageResources.getString( + R.string.do_disclosure_with_name, organizationName), organizationName); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java index d19ed28bd823..0059c1b3642c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java @@ -16,12 +16,15 @@ package com.android.systemui.statusbar.phone; +import static android.app.admin.DevicePolicyResources.Strings.SystemUi.STATUS_BAR_WORK_ICON_ACCESSIBILITY; + import android.annotation.Nullable; import android.app.ActivityTaskManager; import android.app.AlarmManager; import android.app.AlarmManager.AlarmClockInfo; import android.app.IActivityManager; import android.app.SynchronousUserSwitchObserver; +import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -132,6 +135,7 @@ public class PhoneStatusBarPolicy private final UserInfoController mUserInfoController; private final IActivityManager mIActivityManager; private final UserManager mUserManager; + private final DevicePolicyManager mDevicePolicyManager; private final StatusBarIconController mIconController; private final CommandQueue mCommandQueue; private final BroadcastDispatcher mBroadcastDispatcher; @@ -172,7 +176,7 @@ public class PhoneStatusBarPolicy LocationController locationController, SensorPrivacyController sensorPrivacyController, IActivityManager iActivityManager, AlarmManager alarmManager, UserManager userManager, - RecordingController recordingController, + DevicePolicyManager devicePolicyManager, RecordingController recordingController, @Nullable TelecomManager telecomManager, @DisplayId int displayId, @Main SharedPreferences sharedPreferences, DateFormatUtil dateFormatUtil, RingerModeTracker ringerModeTracker, @@ -190,6 +194,7 @@ public class PhoneStatusBarPolicy mUserInfoController = userInfoController; mIActivityManager = iActivityManager; mUserManager = userManager; + mDevicePolicyManager = devicePolicyManager; mRotationLockController = rotationLockController; mDataSaver = dataSaverController; mZenController = zenModeController; @@ -288,7 +293,7 @@ public class PhoneStatusBarPolicy // managed profile mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status, - mResources.getString(R.string.accessibility_managed_profile)); + getManagedProfileAccessibilityString()); mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible); // data saver @@ -343,6 +348,12 @@ public class PhoneStatusBarPolicy mCommandQueue.addCallback(this); } + private String getManagedProfileAccessibilityString() { + return mDevicePolicyManager.getString( + STATUS_BAR_WORK_ICON_ACCESSIBILITY, + () -> mResources.getString(R.string.accessibility_managed_profile)); + } + @Override public void onZenChanged(int zen) { updateVolumeZen(); @@ -525,7 +536,7 @@ public class PhoneStatusBarPolicy showIcon = true; mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status, - mResources.getString(R.string.accessibility_managed_profile)); + getManagedProfileAccessibilityString()); } else { showIcon = false; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java index cf1a36af24ba..529f6b47cf9e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java @@ -207,6 +207,9 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { .thenReturn(DEVICE_OWNER_COMPONENT); when(mDevicePolicyManager.getDeviceOwnerType(DEVICE_OWNER_COMPONENT)) .thenReturn(DEVICE_OWNER_TYPE_DEFAULT); + when(mDevicePolicyManager.getString(anyString(), any())).thenReturn(mDisclosureGeneric); + when(mDevicePolicyManager.getString(anyString(), any(), anyString())) + .thenReturn(mDisclosureWithOrganization); mWakeLock = new WakeLockFake(); mWakeLockBuilder = new WakeLockFake.Builder(mContext); |