Add a Developer option of "Disable automatic update".

For devices using A/B update or update-on-boot feature, we need a
Developer option to prevent the system updates from being installed
automatically.

We store the "disabled" status internally to turn on the automatic
update by default. But we show the opposite "enabled" status on screen
based on UX comments.

Bug: 27193001
Change-Id: I36a08a2a08fd1ba0f8f3c4b3ae5a08dc50829cd2
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0e7ca62..b777bb2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7001,6 +7001,9 @@
     <!-- Toast message letting the user know the color temperature setting is not immediate -->
     <string name="color_temperature_toast">To apply color change, turn off screen</string>
 
+    <!-- Name of the setting to disable the automatic update -->
+    <string name="ota_disable_automatic_update">Automatic system updates</string>
+
     <!-- Label for category for data usage [CHAR LIMIT=30] -->
     <string name="usage">Usage</string>
 
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 3b3dafe..3556843 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -89,6 +89,10 @@
         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" />
+
     <PreferenceCategory android:key="debug_debugging_category"
             android:title="@string/debug_debugging_category">
 
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index af38ad0..f5801ad 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -205,6 +205,8 @@
     private static final String KEY_NIGHT_MODE = "night_mode";
     private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";
 
+    private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update";
+
     private static final int RESULT_DEBUG_APP = 1000;
     private static final int RESULT_MOCK_LOCATION_APP = 1001;
 
@@ -252,6 +254,7 @@
     private SwitchPreference mLegacyDhcpClient;
     private SwitchPreference mMobileDataAlwaysOn;
     private SwitchPreference mBluetoothDisableAbsVolume;
+    private SwitchPreference mOtaDisableAutomaticUpdate;
 
     private SwitchPreference mWifiAllowScansWithTraffic;
     private SwitchPreference mStrictMode;
@@ -465,6 +468,8 @@
             removePreference(KEY_CONVERT_FBE);
         }
 
+        mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY);
+
         mNightModePreference = (DropDownPreference) findPreference(KEY_NIGHT_MODE);
         final UiModeManager uiManager = (UiModeManager) getSystemService(
                 Context.UI_MODE_SERVICE);
@@ -698,6 +703,7 @@
         updateAppProcessLimitOptions();
         updateShowAllANRsOptions();
         updateVerifyAppsOverUsbOptions();
+        updateOtaDisableAutomaticUpdateOptions();
         updateBugreportOptions();
         updateForceRtlOptions();
         updateLogdSizeValues();
@@ -949,6 +955,24 @@
                 mVerifyAppsOverUsb.isChecked() ? 1 : 0);
     }
 
+    private void updateOtaDisableAutomaticUpdateOptions() {
+        // 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.
+        updateSwitchPreference(mOtaDisableAutomaticUpdate, Settings.Global.getInt(
+                getActivity().getContentResolver(),
+                Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0) != 1);
+    }
+
+    private void writeOtaDisableAutomaticUpdateOptions() {
+        // 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.
+        Settings.Global.putInt(getActivity().getContentResolver(),
+                Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE,
+                mOtaDisableAutomaticUpdate.isChecked() ? 0 : 1);
+    }
+
     private boolean enableVerifierSetting() {
         final ContentResolver cr = getActivity().getContentResolver();
         if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
@@ -1850,6 +1874,8 @@
             writeDebuggerOptions();
         } else if (preference == mVerifyAppsOverUsb) {
             writeVerifyAppsOverUsbOptions();
+        } else if (preference == mOtaDisableAutomaticUpdate) {
+            writeOtaDisableAutomaticUpdateOptions();
         } else if (preference == mStrictMode) {
             writeStrictModeVisualOptions();
         } else if (preference == mPointerLocation) {