Merge changes Ibd1291ff,I5224900b

* changes:
  Add ability to show/hide System Update.
  Clean up SystemUpdatePreferences tests.
diff --git a/res/values/bools.xml b/res/values/bools.xml
index e4a57ab..ab8a6fd 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -155,4 +155,7 @@
 
     <!-- Whether assist_and_voice_input should be shown or not. -->
     <bool name="config_show_assist_and_voice_input">true</bool>
+
+    <!-- Whether system_update_settings should be shown or not. -->
+    <bool name="config_show_system_update_settings">true</bool>
 </resources>
diff --git a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
index a061f82..2806275 100644
--- a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
@@ -47,7 +47,8 @@
 
     @Override
     public int getAvailabilityStatus() {
-        return mUm.isAdminUser()
+        return mContext.getResources().getBoolean(R.bool.config_show_system_update_settings)
+                && mUm.isAdminUser()
                 ? AVAILABLE
                 : DISABLED_UNSUPPORTED;
     }
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index f437f96..e755f27 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -20,6 +20,7 @@
     <bool name="config_show_camera_laser_sensor">false</bool>
     <bool name="config_show_connectivity_monitor">false</bool>
     <bool name="config_display_recent_apps">false</bool>
+    <bool name="config_additional_system_update_setting_enable">true</bool>
     <bool name="config_show_wifi_settings">false</bool>
     <bool name="config_show_toggle_airplane">false</bool>
     <bool name="config_show_high_power_apps">false</bool>
@@ -54,5 +55,6 @@
     <bool name="config_show_vibrate_input_devices">false</bool>
     <bool name="config_show_color_correction_preference">false</bool>
     <bool name="config_show_color_inversion_preference">false</bool>
+    <bool name="config_show_system_update_settings">false</bool>
     <bool name="config_wifi_support_connected_mac_randomization">false</bool>
 </resources>
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceControllerTest.java
new file mode 100644
index 0000000..e5708ba
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/AdditionalSystemUpdatePreferenceControllerTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2018 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AdditionalSystemUpdatePreferenceControllerTest {
+
+    private Context mContext;
+    private AdditionalSystemUpdatePreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mContext = RuntimeEnvironment.application;
+        mController = new AdditionalSystemUpdatePreferenceController(mContext);
+    }
+
+    @Test
+    public void displayPrefs_ifNotAvailable_shouldNotDisplay() {
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    @Config(qualifiers = "mcc999")
+    public void displayPrefs_ifAvailable_shouldDisplay() {
+        assertThat(mController.isAvailable()).isTrue();
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java
index 1fd5430..b5b84da 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/SystemUpdatePreferenceControllerTest.java
@@ -16,7 +16,9 @@
 package com.android.settings.deviceinfo;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
@@ -28,6 +30,7 @@
 import com.android.settings.R;
 import com.android.settings.TestConfig;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowUserManager;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -36,29 +39,32 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
 
 import java.util.ArrayList;
 import java.util.List;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+@Config(
+        manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION,
+        shadows = {
+                ShadowUserManager.class
+        })
 public class SystemUpdatePreferenceControllerTest {
 
-    @Mock(answer = RETURNS_DEEP_STUBS)
-    private Context mContext;
-    @Mock
-    private UserManager mUserManager;
     @Mock
     private PreferenceScreen mScreen;
 
+    private Context mContext;
     private SystemUpdatePreferenceController mController;
     private Preference mPreference;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
 
-        when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
         mController = new SystemUpdatePreferenceController(mContext);
         mPreference = new Preference(RuntimeEnvironment.application);
         mPreference.setKey(mController.getPreferenceKey());
@@ -66,12 +72,9 @@
     }
 
     @Test
-    public void updateNonIndexable_bothAvailable_shouldNotUpdate() {
+    public void updateNonIndexable_ifAvailable_shouldNotUpdate() {
         final List<String> keys = new ArrayList<>();
-        when(mUserManager.isAdminUser()).thenReturn(true);
-        when(mContext.getResources().getBoolean(
-                R.bool.config_additional_system_update_setting_enable))
-                .thenReturn(true);
+        ShadowUserManager.getShadow().setIsAdminUser(true);
 
         mController.updateNonIndexableKeys(keys);
 
@@ -79,7 +82,8 @@
     }
 
     @Test
-    public void updateNonIndexable_nothingAvailable_shouldUpdateWith2Prefs() {
+    public void updateNonIndexable_ifNotAvailable_shouldUpdate() {
+        ShadowUserManager.getShadow().setIsAdminUser(false);
         final List<String> keys = new ArrayList<>();
 
         mController.updateNonIndexableKeys(keys);
@@ -88,31 +92,37 @@
     }
 
     @Test
-    public void displayPrefs_nothingAvailable_shouldNotDisplay() {
+    public void displayPrefs_ifVisible_butNotAdminUser_shouldNotDisplay() {
+        ShadowUserManager.getShadow().setIsAdminUser(false);
         mController.displayPreference(mScreen);
 
         assertThat(mPreference.isVisible()).isFalse();
     }
 
     @Test
-    public void updateState_shouldSetToAndroidVersion() {
-        mController = new SystemUpdatePreferenceController(RuntimeEnvironment.application);
+    @Config(qualifiers = "mcc999")
+    public void displayPrefs_ifAdminUser_butNotVisible_shouldNotDisplay() {
+        ShadowUserManager.getShadow().setIsAdminUser(true);
+        mController.displayPreference(mScreen);
 
+        assertThat(mPreference.isVisible()).isFalse();
+    }
+
+    @Test
+    public void displayPrefs_ifAvailable_shouldDisplay() {
+        ShadowUserManager.getShadow().setIsAdminUser(true);
+
+        mController.displayPreference(mScreen);
+
+        assertThat(mPreference.isVisible()).isTrue();
+    }
+
+    @Test
+    public void updateState_shouldSetToAndroidVersion() {
         mController.updateState(mPreference);
 
         assertThat(mPreference.getSummary())
                 .isEqualTo(RuntimeEnvironment.application.getString(R.string.about_summary,
                         Build.VERSION.RELEASE));
     }
-
-    @Test
-    public void displayPrefs_oneAvailable_shouldDisplayOne() {
-        when(mContext.getResources().getBoolean(
-                R.bool.config_additional_system_update_setting_enable))
-                .thenReturn(true);
-
-        mController.displayPreference(mScreen);
-
-        assertThat(mPreference.isVisible()).isFalse();
-    }
-}
+}
\ No newline at end of file