diff options
author | 2025-02-24 16:38:18 +0000 | |
---|---|---|
committer | 2025-03-04 21:55:56 +0000 | |
commit | 5f2ee05fbe7029e6074e0f4f6971abc61551b7a7 (patch) | |
tree | 829a55787f5fd18389fff2287845633c92e6ce72 | |
parent | 1c72035d02f77e57043dd8585d4bc2c3bebd298e (diff) |
Update summaries of preferences controlled by Advanced Protection
Previously, all preferences controlled by Advanced Protection had a
detailed summary "Disabled by Advanced Protection". This change updates
the summary to:
- "Disabled" if a preference is in a list view in SPA.
- The existing summary if a preference is on its own.
Bug: 398167869
Test: RestrictedLockUtilsTest
Test: RestrictedPreferenceHelperTest
Test: RestrictedModeTest
Test: TogglePermissionAppListPageTest
Flag: EXEMPT bug fix
Change-Id: I05b98edeb30871e55cb27ee1ff4fc56d660f1f65
8 files changed, 30 insertions, 39 deletions
diff --git a/packages/SettingsLib/RestrictedLockUtils/res/values/strings.xml b/packages/SettingsLib/RestrictedLockUtils/res/values/strings.xml index 75809730a514..2ffdc930ccea 100644 --- a/packages/SettingsLib/RestrictedLockUtils/res/values/strings.xml +++ b/packages/SettingsLib/RestrictedLockUtils/res/values/strings.xml @@ -21,8 +21,4 @@ <string name="enabled_by_admin">Enabled by admin</string> <!-- Summary for switch preference to denote it is switched off by an admin [CHAR LIMIT=50] --> <string name="disabled_by_admin">Disabled by admin</string> - <!-- Summary for switch preference to denote it is switched on by Advanced protection [CHAR LIMIT=50] --> - <string name="enabled_by_advanced_protection">Enabled by Advanced Protection</string> - <!-- Summary for switch preference to denote it is switched off by Advanced protection [CHAR LIMIT=50] --> - <string name="disabled_by_advanced_protection">Disabled by Advanced Protection</string> </resources> diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedMode.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedMode.kt index a8483308556d..6f37f0cc5799 100644 --- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedMode.kt +++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedMode.kt @@ -46,7 +46,7 @@ internal data class BlockedByAdminImpl( ) : BlockedByAdmin { override fun getSummary(checked: Boolean?) = when (checked) { true -> enterpriseRepository.getAdminSummaryString( - advancedProtectionStringId = R.string.enabled_by_advanced_protection, + advancedProtectionStringId = com.android.settingslib.R.string.enabled, updatableStringId = Settings.ENABLED_BY_ADMIN_SWITCH_SUMMARY, resId = R.string.enabled_by_admin, enforcedAdmin = enforcedAdmin, @@ -54,7 +54,7 @@ internal data class BlockedByAdminImpl( ) false -> enterpriseRepository.getAdminSummaryString( - advancedProtectionStringId = R.string.disabled_by_advanced_protection, + advancedProtectionStringId = com.android.settingslib.R.string.disabled, updatableStringId = Settings.DISABLED_BY_ADMIN_SWITCH_SUMMARY, resId = R.string.disabled_by_admin, enforcedAdmin = enforcedAdmin, diff --git a/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedModeTest.kt b/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedModeTest.kt index f3245c9085e7..189bf363420c 100644 --- a/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedModeTest.kt +++ b/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/model/enterprise/RestrictedModeTest.kt @@ -77,8 +77,8 @@ class RestrictedModeTest { if (RestrictedLockUtilsInternal.isPolicyEnforcedByAdvancedProtection(context, RESTRICTION, userId)) { return when (advancedProtectionStringId) { - R.string.enabled_by_advanced_protection -> ENABLED_BY_ADVANCED_PROTECTION - R.string.disabled_by_advanced_protection -> DISABLED_BY_ADVANCED_PROTECTION + com.android.settingslib.R.string.enabled -> ENABLED + com.android.settingslib.R.string.disabled -> DISABLED else -> "" } } @@ -129,7 +129,7 @@ class RestrictedModeTest { val summary = blockedByAdmin.getSummary(true) - assertThat(summary).isEqualTo(ENABLED_BY_ADVANCED_PROTECTION) + assertThat(summary).isEqualTo(ENABLED) } @RequiresFlagsEnabled(Flags.FLAG_AAPM_API) @@ -148,7 +148,7 @@ class RestrictedModeTest { val summary = blockedByAdmin.getSummary(false) - assertThat(summary).isEqualTo(DISABLED_BY_ADVANCED_PROTECTION) + assertThat(summary).isEqualTo(DISABLED) } @RequiresFlagsEnabled(Flags.FLAG_AAPM_API) @@ -202,7 +202,7 @@ class RestrictedModeTest { const val ENABLED_BY_ADMIN = "Enabled by admin" const val DISABLED_BY_ADMIN = "Disabled by admin" - const val ENABLED_BY_ADVANCED_PROTECTION = "Enabled by advanced protection" - const val DISABLED_BY_ADVANCED_PROTECTION = "Disabled by advanced protection" + const val ENABLED = "Enabled" + const val DISABLED = "Disabled" } } diff --git a/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt b/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt index 79085af63c6d..308b285e0cfc 100644 --- a/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt +++ b/packages/SettingsLib/SpaPrivileged/tests/unit/src/com/android/settingslib/spaprivileged/template/app/TogglePermissionAppListPageTest.kt @@ -175,13 +175,7 @@ class TogglePermissionAppListPageTest { val summary = getSummary(listModel) - assertThat(summary) - .isEqualTo( - context.getString( - com.android.settingslib.widget.restricted.R.string - .disabled_by_advanced_protection - ) - ) + assertThat(summary).isEqualTo(context.getString(com.android.settingslib.R.string.disabled)) } @RequiresFlagsEnabled(Flags.FLAG_AAPM_API) diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml index 91ec83690722..03cb1ffbdef1 100644 --- a/packages/SettingsLib/res/values/strings.xml +++ b/packages/SettingsLib/res/values/strings.xml @@ -1263,6 +1263,8 @@ <!-- [CHAR LIMIT=25] Manage applications, text telling using an application is disabled. --> <string name="disabled">Disabled</string> + <!-- Summary for a settings preference indicating it is enabled [CHAR LIMIT = 30] --> + <string name="enabled">Enabled</string> <!-- Summary of app trusted to install apps [CHAR LIMIT=45] --> <string name="external_source_trusted">Allowed</string> <!-- Summary of app not trusted to install apps [CHAR LIMIT=45] --> diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java index 1044750bae25..9d979019be58 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreferenceHelper.java @@ -120,7 +120,7 @@ public class RestrictedPreferenceHelper { final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); if (summaryView != null) { final CharSequence disabledText = getDisabledByAdminSummaryString(); - if (mDisabledByAdmin) { + if (mDisabledByAdmin && disabledText != null) { summaryView.setText(disabledText); } else if (mDisabledByEcm) { summaryView.setText(getEcmTextResId()); @@ -132,10 +132,10 @@ public class RestrictedPreferenceHelper { } } - private String getDisabledByAdminSummaryString() { + private @Nullable String getDisabledByAdminSummaryString() { if (isRestrictionEnforcedByAdvancedProtection()) { - return mContext.getString(com.android.settingslib.widget.restricted - .R.string.disabled_by_advanced_protection); + // Advanced Protection doesn't set the summary string, it keeps the current summary. + return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { return mContext.getSystemService(DevicePolicyManager.class).getResources().getString( @@ -321,7 +321,10 @@ public class RestrictedPreferenceHelper { } if (android.security.Flags.aapmApi() && !isEnabled && mDisabledByAdmin) { - mPreference.setSummary(getDisabledByAdminSummaryString()); + String summary = getDisabledByAdminSummaryString(); + if (summary != null) { + mPreference.setSummary(summary); + } } if (!isEnabled && mDisabledByEcm) { diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java index a5fa6a854e97..67c4207cb8be 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedSwitchPreference.java @@ -36,6 +36,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceViewHolder; @@ -141,7 +142,7 @@ public class RestrictedSwitchPreference extends SwitchPreferenceCompat implement final TextView additionalSummaryView = (TextView) holder.findViewById( R.id.additional_summary); if (additionalSummaryView != null) { - if (isDisabledByAdmin()) { + if (isDisabledByAdmin() && switchSummary != null) { additionalSummaryView.setText(switchSummary); additionalSummaryView.setVisibility(View.VISIBLE); } else { @@ -151,7 +152,7 @@ public class RestrictedSwitchPreference extends SwitchPreferenceCompat implement } else { final TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); if (summaryView != null) { - if (isDisabledByAdmin()) { + if (isDisabledByAdmin() && switchSummary != null) { summaryView.setText(switchSummary); summaryView.setVisibility(View.VISIBLE); } @@ -171,14 +172,10 @@ public class RestrictedSwitchPreference extends SwitchPreferenceCompat implement () -> context.getString(resId)); } - private String getRestrictedSwitchSummary() { + private @Nullable String getRestrictedSwitchSummary() { if (mHelper.isRestrictionEnforcedByAdvancedProtection()) { - final int apmResId = isChecked() - ? com.android.settingslib.widget.restricted.R.string - .enabled_by_advanced_protection - : com.android.settingslib.widget.restricted.R.string - .disabled_by_advanced_protection; - return getContext().getString(apmResId); + // Advanced Protection doesn't set the summary string, it keeps the current summary. + return null; } return isChecked() diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/RestrictedPreferenceHelperTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/RestrictedPreferenceHelperTest.java index dbbbd5bf8089..f9769fa61e0d 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/RestrictedPreferenceHelperTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/RestrictedPreferenceHelperTest.java @@ -23,6 +23,7 @@ import static com.google.common.truth.Truth.assertWithMessage; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.atMostOnce; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -130,7 +131,7 @@ public class RestrictedPreferenceHelperTest { @RequiresFlagsEnabled(android.security.Flags.FLAG_AAPM_API) @Test - public void bindPreference_disabled_byAdvancedProtection_shouldDisplayDisabledSummary() { + public void bindPreference_disabled_byAdvancedProtection_shouldKeepExistingSummary() { final TextView summaryView = mock(TextView.class, RETURNS_DEEP_STUBS); final String userRestriction = UserManager.DISALLOW_UNINSTALL_APPS; final RestrictedLockUtils.EnforcedAdmin enforcedAdmin = new RestrictedLockUtils @@ -143,16 +144,14 @@ public class RestrictedPreferenceHelperTest { .thenReturn(summaryView); when(mDevicePolicyManager.getEnforcingAdmin(UserHandle.myUserId(), userRestriction)) .thenReturn(advancedProtectionEnforcingAdmin); - when(mContext.getString( - com.android.settingslib.widget.restricted.R.string.disabled_by_advanced_protection)) - .thenReturn("advanced_protection"); + summaryView.setText("existing summary"); mHelper.useAdminDisabledSummary(true); mHelper.setDisabledByAdmin(enforcedAdmin); mHelper.onBindViewHolder(mViewHolder); - verify(summaryView).setText("advanced_protection"); - verify(summaryView, never()).setVisibility(View.GONE); + verify(summaryView, atMostOnce()).setText(any()); // To set it to existing summary + verify(summaryView, never()).setVisibility(View.VISIBLE); } @RequiresFlagsEnabled(android.security.Flags.FLAG_AAPM_API) |