Loading src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java +11 −3 Original line number Diff line number Diff line Loading @@ -90,9 +90,17 @@ public class AutomaticStorageManagementSwitchPreferenceController extends 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); } Loading tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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)); } } Loading
src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceController.java +11 −3 Original line number Diff line number Diff line Loading @@ -90,9 +90,17 @@ public class AutomaticStorageManagementSwitchPreferenceController extends 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); } Loading
tests/robotests/src/com/android/settings/deviceinfo/storage/AutomaticStorageManagementSwitchPreferenceControllerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -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)); } }