Loading res/xml/development_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -109,6 +109,11 @@ android:title="@string/color_temperature" android:summary="@string/color_temperature_desc" /> <SwitchPreference android:key="ota_disable_automatic_update" android:title="@string/ota_disable_automatic_update" android:summary="@string/ota_disable_automatic_update_summary" /> <Preference android:key="dsu_loader" android:title="@string/dsu_loader_title" /> Loading res/xml/system_dashboard_fragment.xml +0 −8 Original line number Diff line number Diff line Loading @@ -65,14 +65,6 @@ <intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS"/> </Preference> <SwitchPreference android:key="ota_disable_automatic_update" android:title="@string/ota_disable_automatic_update" android:summary="@string/ota_disable_automatic_update_summary" android:icon="@drawable/ic_system_update" android:order="-57" settings:controller="com.android.settings.system.DisableAutomaticUpdatesPreferenceController"/> <Preference android:key="reset_dashboard" android:title="@string/reset_dashboard_title" Loading src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -481,6 +481,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new PictureColorModePreferenceController(context, lifecycle)); controllers.add(new WebViewAppPreferenceController(context)); controllers.add(new CoolColorTemperaturePreferenceController(context)); controllers.add(new DisableAutomaticUpdatesPreferenceController(context)); controllers.add(new SelectDSUPreferenceController(context)); controllers.add(new AdbPreferenceController(context, fragment)); controllers.add(new ClearAdbKeysPreferenceController(context, fragment)); Loading src/com/android/settings/system/DisableAutomaticUpdatesPreferenceController.java→src/com/android/settings/development/DisableAutomaticUpdatesPreferenceController.java +76 −0 Original line number Diff line number Diff line Loading @@ -14,46 +14,63 @@ * limitations under the License. */ package com.android.settings.system; package com.android.settings.development; import android.content.Context; import android.provider.Settings; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.SwitchPreference; import com.android.settings.core.TogglePreferenceController; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; /** A controller maintains the state of Automatic System Update feature. */ public class DisableAutomaticUpdatesPreferenceController extends TogglePreferenceController { public class DisableAutomaticUpdatesPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update"; // We use the "disabled status" in code, but show the opposite text // "Automatic system updates" on screen. So a value 0 indicates the // automatic update is enabled. @VisibleForTesting static final int DISABLE_UPDATES_SETTING = 1; final static int DISABLE_UPDATES_SETTING = 1; @VisibleForTesting static final int ENABLE_UPDATES_SETTING = 0; final static int ENABLE_UPDATES_SETTING = 0; public DisableAutomaticUpdatesPreferenceController(Context context, String key) { super(context, key); public DisableAutomaticUpdatesPreferenceController(Context context) { super(context); } @Override public int getAvailabilityStatus() { return AVAILABLE; public String getPreferenceKey() { return OTA_DISABLE_AUTOMATIC_UPDATE_KEY; } @Override public boolean isChecked() { return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, ENABLE_UPDATES_SETTING /* default */) == ENABLE_UPDATES_SETTING; public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean updatesEnabled = (Boolean) newValue; Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, updatesEnabled ? ENABLE_UPDATES_SETTING : DISABLE_UPDATES_SETTING); return true; } @Override public boolean setChecked(boolean isChecked) { return Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, isChecked ? ENABLE_UPDATES_SETTING : DISABLE_UPDATES_SETTING); public void updateState(Preference preference) { final int updatesEnabled = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0 /* default */); ((SwitchPreference) mPreference).setChecked(updatesEnabled != DISABLE_UPDATES_SETTING); } @Override protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DISABLE_UPDATES_SETTING); ((SwitchPreference) mPreference).setChecked(false); } } tests/robotests/src/com/android/settings/system/DisableAutomaticUpdatesPreferenceControllerTest.java→tests/robotests/src/com/android/settings/development/DisableAutomaticUpdatesPreferenceControllerTest.java +108 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -14,18 +14,19 @@ * limitations under the License. */ package com.android.settings.system; package com.android.settings.development; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; import com.android.settings.core.BasePreferenceController; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -49,54 +50,59 @@ public class DisableAutomaticUpdatesPreferenceControllerTest { public void setup() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mController = new DisableAutomaticUpdatesPreferenceController(mContext, "test"); mController = new DisableAutomaticUpdatesPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn( mPreference); mController.displayPreference(mPreferenceScreen); } @Test public void getAvailabilityStatus_shouldReturnAVAILABLE() { assertThat(mController.getAvailabilityStatus()).isEqualTo( BasePreferenceController.AVAILABLE); public void onPreferenceChanged_turnOnAutomaticUpdates() { mController.onPreferenceChange(null, true); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, -1); assertThat(mode).isEqualTo( DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); } @Test public void isChecked_valueIsZeroInProvider_shouldReturnTrue() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); public void onPreferenceChanged_turnOffAutomaticUpdates() { mController.onPreferenceChange(null, false); assertThat(mController.isChecked()).isTrue(); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, -1); assertThat(mode).isEqualTo( DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); } @Test public void isChecked_valueIsOneInProvider_shouldReturnFalse() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); public void updateState_preferenceShouldBeChecked() { Settings.Global .putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); mController.updateState(mPreference); assertThat(mController.isChecked()).isFalse(); verify(mPreference).setChecked(true); } @Test public void setChecked_true_providerValueIsZero() { mController.setChecked(true); int value = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING /* default */); public void updateState_preferenceShouldNotBeChecked() { Settings.Global .putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); mController.updateState(mPreference); assertThat(value).isEqualTo( DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); verify(mPreference).setChecked(false); } @Test public void setChecked_false_providerValueIsOne() { mController.setChecked(false); int value = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING /* default */); public void onDeveloperOptionsDisabled_shouldDisablePreference() { mController.onDeveloperOptionsDisabled(); assertThat(value).isEqualTo( DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); verify(mPreference).setEnabled(false); verify(mPreference).setChecked(false); } } Loading
res/xml/development_settings.xml +5 −0 Original line number Diff line number Diff line Loading @@ -109,6 +109,11 @@ android:title="@string/color_temperature" android:summary="@string/color_temperature_desc" /> <SwitchPreference android:key="ota_disable_automatic_update" android:title="@string/ota_disable_automatic_update" android:summary="@string/ota_disable_automatic_update_summary" /> <Preference android:key="dsu_loader" android:title="@string/dsu_loader_title" /> Loading
res/xml/system_dashboard_fragment.xml +0 −8 Original line number Diff line number Diff line Loading @@ -65,14 +65,6 @@ <intent android:action="android.settings.SYSTEM_UPDATE_SETTINGS"/> </Preference> <SwitchPreference android:key="ota_disable_automatic_update" android:title="@string/ota_disable_automatic_update" android:summary="@string/ota_disable_automatic_update_summary" android:icon="@drawable/ic_system_update" android:order="-57" settings:controller="com.android.settings.system.DisableAutomaticUpdatesPreferenceController"/> <Preference android:key="reset_dashboard" android:title="@string/reset_dashboard_title" Loading
src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +1 −0 Original line number Diff line number Diff line Loading @@ -481,6 +481,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new PictureColorModePreferenceController(context, lifecycle)); controllers.add(new WebViewAppPreferenceController(context)); controllers.add(new CoolColorTemperaturePreferenceController(context)); controllers.add(new DisableAutomaticUpdatesPreferenceController(context)); controllers.add(new SelectDSUPreferenceController(context)); controllers.add(new AdbPreferenceController(context, fragment)); controllers.add(new ClearAdbKeysPreferenceController(context, fragment)); Loading
src/com/android/settings/system/DisableAutomaticUpdatesPreferenceController.java→src/com/android/settings/development/DisableAutomaticUpdatesPreferenceController.java +76 −0 Original line number Diff line number Diff line Loading @@ -14,46 +14,63 @@ * limitations under the License. */ package com.android.settings.system; package com.android.settings.development; import android.content.Context; import android.provider.Settings; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.SwitchPreference; import com.android.settings.core.TogglePreferenceController; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; /** A controller maintains the state of Automatic System Update feature. */ public class DisableAutomaticUpdatesPreferenceController extends TogglePreferenceController { public class DisableAutomaticUpdatesPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update"; // We use the "disabled status" in code, but show the opposite text // "Automatic system updates" on screen. So a value 0 indicates the // automatic update is enabled. @VisibleForTesting static final int DISABLE_UPDATES_SETTING = 1; final static int DISABLE_UPDATES_SETTING = 1; @VisibleForTesting static final int ENABLE_UPDATES_SETTING = 0; final static int ENABLE_UPDATES_SETTING = 0; public DisableAutomaticUpdatesPreferenceController(Context context, String key) { super(context, key); public DisableAutomaticUpdatesPreferenceController(Context context) { super(context); } @Override public int getAvailabilityStatus() { return AVAILABLE; public String getPreferenceKey() { return OTA_DISABLE_AUTOMATIC_UPDATE_KEY; } @Override public boolean isChecked() { return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, ENABLE_UPDATES_SETTING /* default */) == ENABLE_UPDATES_SETTING; public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean updatesEnabled = (Boolean) newValue; Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, updatesEnabled ? ENABLE_UPDATES_SETTING : DISABLE_UPDATES_SETTING); return true; } @Override public boolean setChecked(boolean isChecked) { return Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, isChecked ? ENABLE_UPDATES_SETTING : DISABLE_UPDATES_SETTING); public void updateState(Preference preference) { final int updatesEnabled = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0 /* default */); ((SwitchPreference) mPreference).setChecked(updatesEnabled != DISABLE_UPDATES_SETTING); } @Override protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DISABLE_UPDATES_SETTING); ((SwitchPreference) mPreference).setChecked(false); } }
tests/robotests/src/com/android/settings/system/DisableAutomaticUpdatesPreferenceControllerTest.java→tests/robotests/src/com/android/settings/development/DisableAutomaticUpdatesPreferenceControllerTest.java +108 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 The Android Open Source Project * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -14,18 +14,19 @@ * limitations under the License. */ package com.android.settings.system; package com.android.settings.development; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; import com.android.settings.core.BasePreferenceController; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -49,54 +50,59 @@ public class DisableAutomaticUpdatesPreferenceControllerTest { public void setup() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mController = new DisableAutomaticUpdatesPreferenceController(mContext, "test"); mController = new DisableAutomaticUpdatesPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn( mPreference); mController.displayPreference(mPreferenceScreen); } @Test public void getAvailabilityStatus_shouldReturnAVAILABLE() { assertThat(mController.getAvailabilityStatus()).isEqualTo( BasePreferenceController.AVAILABLE); public void onPreferenceChanged_turnOnAutomaticUpdates() { mController.onPreferenceChange(null, true); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, -1); assertThat(mode).isEqualTo( DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); } @Test public void isChecked_valueIsZeroInProvider_shouldReturnTrue() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); public void onPreferenceChanged_turnOffAutomaticUpdates() { mController.onPreferenceChange(null, false); assertThat(mController.isChecked()).isTrue(); final int mode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, -1); assertThat(mode).isEqualTo( DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); } @Test public void isChecked_valueIsOneInProvider_shouldReturnFalse() { Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); public void updateState_preferenceShouldBeChecked() { Settings.Global .putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); mController.updateState(mPreference); assertThat(mController.isChecked()).isFalse(); verify(mPreference).setChecked(true); } @Test public void setChecked_true_providerValueIsZero() { mController.setChecked(true); int value = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING /* default */); public void updateState_preferenceShouldNotBeChecked() { Settings.Global .putInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); mController.updateState(mPreference); assertThat(value).isEqualTo( DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING); verify(mPreference).setChecked(false); } @Test public void setChecked_false_providerValueIsOne() { mController.setChecked(false); int value = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, DisableAutomaticUpdatesPreferenceController.ENABLE_UPDATES_SETTING /* default */); public void onDeveloperOptionsDisabled_shouldDisablePreference() { mController.onDeveloperOptionsDisabled(); assertThat(value).isEqualTo( DisableAutomaticUpdatesPreferenceController.DISABLE_UPDATES_SETTING); verify(mPreference).setEnabled(false); verify(mPreference).setChecked(false); } }