Merge "Display network name in status bar"
diff --git a/res/values/config.xml b/res/values/config.xml
index 8c59999..4ba73cc 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -73,6 +73,9 @@
     <!-- If the support features are enabled. -->
     <bool name="config_support_enabled">false</bool>
 
+    <!-- Whether to enable "show operator name in the status bar" setting -->
+    <bool name="config_showOperatorNameInStatusBar">false</bool>
+
     <!-- List containing the component names of pre-installed screen reader services. -->
     <string-array name="config_preinstalled_screen_reader_services" translatable="false">
         <!--
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6acd127..f0721fc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9016,6 +9016,11 @@
     <!-- Temporary reboot string, will be removed -->
     <string name="change_theme_reboot" translatable="false">Changing the theme requires a restart.</string>
 
+    <!-- Switch label to show operator name in the status bar [CHAR LIMIT=60] -->
+    <string name="show_operator_name_title">Network name</string>
+    <!-- Switch summary to show operator name in the status bar [CHAR LIMIT=NONE] -->
+    <string name="show_operator_name_summary">Display network name in status bar</string>
+
     <!-- Indicates if the automatic storage manager is enabled or not. [CHAR_LIMIT=40] -->
     <string name="storage_manager_indicator">Storage Manager: <xliff:g id="status" example="on">^1</xliff:g></string>
 
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 18bfe57..a6efb5c 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -84,6 +84,11 @@
         android:fragment="com.android.settings.display.ScreenZoomSettings"
         settings:keywords="@string/screen_zoom_keywords" />
 
+    <SwitchPreference
+        android:key="show_operator_name"
+        android:title="@string/show_operator_name_title"
+        android:summary="@string/show_operator_name_summary" />
+
     <Preference
         android:key="screensaver"
         android:title="@string/screensaver_settings_title"
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 9a3f047..d67758a 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -33,6 +33,7 @@
 import com.android.settings.display.NightDisplayPreferenceController;
 import com.android.settings.display.NightModePreferenceController;
 import com.android.settings.display.ScreenSaverPreferenceController;
+import com.android.settings.display.ShowOperatorNamePreferenceController;
 import com.android.settings.display.TapToWakePreferenceController;
 import com.android.settings.display.ThemePreferenceController;
 import com.android.settings.display.TimeoutPreferenceController;
@@ -98,6 +99,7 @@
         controllers.add(new TapToWakePreferenceController(context));
         controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
         controllers.add(new VrDisplayPreferenceController(context));
+        controllers.add(new ShowOperatorNamePreferenceController(context));
         controllers.add(new WallpaperPreferenceController(context));
         controllers.add(new ThemePreferenceController(context));
         controllers.add(new BrightnessLevelPreferenceController(context, lifecycle));
diff --git a/src/com/android/settings/display/ShowOperatorNamePreferenceController.java b/src/com/android/settings/display/ShowOperatorNamePreferenceController.java
new file mode 100644
index 0000000..8341519
--- /dev/null
+++ b/src/com/android/settings/display/ShowOperatorNamePreferenceController.java
@@ -0,0 +1,57 @@
+/*
+ * 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. 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.display;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class ShowOperatorNamePreferenceController extends AbstractPreferenceController
+        implements Preference.OnPreferenceChangeListener {
+
+    private static final String KEY_SHOW_OPERATOR_NAME = "show_operator_name";
+
+    public ShowOperatorNamePreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return mContext.getResources().getBoolean(R.bool.config_showOperatorNameInStatusBar);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_SHOW_OPERATOR_NAME;
+    }
+
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        boolean value = (Boolean) newValue;
+        Settings.Secure.putInt(mContext.getContentResolver(),
+                KEY_SHOW_OPERATOR_NAME, value ? 1 : 0);
+        return true;
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        int value = Settings.Secure.getInt(mContext.getContentResolver(),
+                KEY_SHOW_OPERATOR_NAME, 1);
+        ((SwitchPreference) preference).setChecked(value != 0);
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/display/ShowOperatorNamePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/ShowOperatorNamePreferenceControllerTest.java
new file mode 100644
index 0000000..23b43d6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/ShowOperatorNamePreferenceControllerTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ * 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.display;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ShowOperatorNamePreferenceControllerTest {
+
+    private static final String KEY_SHOW_OPERATOR_NAME = "show_operator_name";
+
+    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+    private Context mContext;
+    @Mock
+    private SwitchPreference mPreference;
+
+    private ShowOperatorNamePreferenceController mController;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mController = new ShowOperatorNamePreferenceController(mContext);
+    }
+
+    @Test
+    public void testIsAvailable_configIsTrue_ReturnTrue() {
+        when(mContext.getResources().getBoolean(R.bool.config_showOperatorNameInStatusBar))
+                .thenReturn(true);
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void testIsAvailable_configIsFalse_ReturnFalse() {
+        when(mContext.getResources().getBoolean(R.bool.config_showOperatorNameInStatusBar))
+                .thenReturn(false);
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void testOnPreferenceChange_TurnOn_ReturnOn() {
+        mController.onPreferenceChange(mPreference, true);
+
+        final int mode = Settings.Secure.getInt(mContext.getContentResolver(),
+                KEY_SHOW_OPERATOR_NAME, 0);
+        assertThat(mode).isEqualTo(1);
+    }
+
+    @Test
+    public void testOnPreferenceChange_TurnOff_ReturnOff() {
+        mController.onPreferenceChange(mPreference, false);
+
+        final int mode = Settings.Secure.getInt(mContext.getContentResolver(),
+                KEY_SHOW_OPERATOR_NAME, 1);
+        assertThat(mode).isEqualTo(0);
+    }
+}