From 8f345d7fd6e96ed5ac7ee52a643b093e0d846c78 Mon Sep 17 00:00:00 2001 From: Daniel Nishi Date: Tue, 27 Jun 2017 15:09:20 -0700 Subject: [PATCH] Expand ASM activation warning. If the device had ASM enabled by default but still opted to disable ASM for policy reasons, we need to start warning the user. Change-Id: I6a296e95d00413308de3ddc565b42c5f605087e9 Fixes: 62105682 Test: Settings robotest --- ...eManagementSwitchPreferenceController.java | 14 +++++++++++--- ...agementSwitchPreferenceControllerTest.java | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java index acd34f0fb2d..3e81fc7c34f 100644 --- a/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java @@ -88,9 +88,17 @@ public class AutomaticStorageManagementSwitchPreferenceController extends Prefer Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, isChecked ? 1 : 0); - boolean storageManagerEnabledByDefault = SystemProperties.getBoolean( - STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, false); - if (isChecked && !storageManagerEnabledByDefault) { + final boolean storageManagerEnabledByDefault = + SystemProperties.getBoolean(STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, false); + final boolean storageManagerDisabledByPolicy = + Settings.Secure.getInt( + mContext.getContentResolver(), + Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY, + 0) + != 0; + // Show warning if it is disabled by default and turning it on or if it was disabled by + // policy and we're turning it on. + if ((isChecked && (!storageManagerEnabledByDefault || storageManagerDisabledByPolicy))) { ActivationWarningFragment fragment = ActivationWarningFragment.newInstance(); fragment.show(mFragmentManager, ActivationWarningFragment.TAG); } diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java index 9bc1a3a521b..faf8b394da3 100644 --- a/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java @@ -168,4 +168,23 @@ public class AutomaticStorageManagementSwitchPreferenceControllerTest { verify(transaction, never()).add(any(), eq(ActivationWarningFragment.TAG)); } + + @Config(shadows = {SettingsShadowSystemProperties.class}) + @Test + public void togglingOnShouldTriggerWarningFragmentIfEnabledByDefaultAndDisabledByPolicy() { + FragmentTransaction transaction = mock(FragmentTransaction.class); + when(mFragmentManager.beginTransaction()).thenReturn(transaction); + SettingsShadowSystemProperties.set( + AutomaticStorageManagementSwitchPreferenceController + .STORAGE_MANAGER_ENABLED_BY_DEFAULT_PROPERTY, + "true"); + Settings.Secure.putInt( + mContext.getContentResolver(), + Settings.Secure.AUTOMATIC_STORAGE_MANAGER_TURNED_OFF_BY_POLICY, + 1); + + mController.onSwitchToggled(true); + + verify(transaction).add(any(), eq(ActivationWarningFragment.TAG)); + } }