Merge "Add ability to show/hide Wi-Fi settings, and all related sub-settings."
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 4c1c9c2..c28b968 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -49,6 +49,11 @@
     <!--Whether help links are defined. -->
     <bool name="config_has_help">false</bool>
 
+    <!-- Whether Wi-Fi settings should be shown or not.
+    This also controls whether Wi-fi related sub-settings (e.g. Wi-Fi preferences) will
+    surface in search results or not.-->
+    <bool name="config_show_wifi_settings">true</bool>
+
     <!-- Whether location mode is available or not. -->
     <bool name="config_location_mode_available">true</bool>
 
diff --git a/src/com/android/settings/wifi/ConfigureWifiSettings.java b/src/com/android/settings/wifi/ConfigureWifiSettings.java
index 4cb87e5..3cd925e 100644
--- a/src/com/android/settings/wifi/ConfigureWifiSettings.java
+++ b/src/com/android/settings/wifi/ConfigureWifiSettings.java
@@ -44,6 +44,7 @@
 
     private static final String TAG = "ConfigureWifiSettings";
 
+    public static final String KEY_WIFI_CONFIGURE = "wifi_configure_settings_screen";
     public static final String KEY_IP_ADDRESS = "current_ip_address";
 
     private WifiWakeupPreferenceController mWifiWakeupPreferenceController;
@@ -134,5 +135,10 @@
 
                     return keys;
                 }
+
+                protected boolean isPageSearchEnabled(Context context) {
+                    return context.getResources()
+                            .getBoolean(R.bool.config_show_wifi_settings);
+                }
             };
 }
diff --git a/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java b/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java
index 2fadede..de1b030 100644
--- a/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java
@@ -20,6 +20,7 @@
 
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.R;
 import com.android.settings.widget.SummaryUpdater;
 import com.android.settings.widget.MasterSwitchPreference;
 import com.android.settings.widget.MasterSwitchController;
@@ -56,7 +57,7 @@
 
     @Override
     public boolean isAvailable() {
-        return true;
+        return mContext.getResources().getBoolean(R.bool.config_show_wifi_settings);
     }
 
     @Override
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 863bf6b..73f17f7 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -167,7 +167,7 @@
     private LinkablePreference mStatusMessagePreference;
 
     // For Search
-    private static final String DATA_KEY_REFERENCE = "main_toggle_wifi";
+    public static final String DATA_KEY_REFERENCE = "main_toggle_wifi";
 
     /**
      * Tracks whether the user initiated a connection via clicking in order to autoscroll to the
@@ -1104,13 +1104,15 @@
                 final List<SearchIndexableRaw> result = new ArrayList<>();
                 final Resources res = context.getResources();
 
-                // Add fragment title
-                SearchIndexableRaw data = new SearchIndexableRaw(context);
-                data.title = res.getString(R.string.wifi_settings);
-                data.screenTitle = res.getString(R.string.wifi_settings);
-                data.keywords = res.getString(R.string.keywords_wifi);
-                data.key = DATA_KEY_REFERENCE;
-                result.add(data);
+                // Add fragment title if we are showing this fragment
+                if (res.getBoolean(R.bool.config_show_wifi_settings)) {
+                    SearchIndexableRaw data = new SearchIndexableRaw(context);
+                    data.title = res.getString(R.string.wifi_settings);
+                    data.screenTitle = res.getString(R.string.wifi_settings);
+                    data.keywords = res.getString(R.string.keywords_wifi);
+                    data.key = DATA_KEY_REFERENCE;
+                    result.add(data);
+                }
 
                 return result;
             }
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index f8f59f1..d2e146b 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_show_wifi_settings">false</bool>
     <bool name="config_location_mode_available">false</bool>
     <bool name="config_show_wallpaper_attribution">false</bool>
     <bool name="config_show_default_home">false</bool>
diff --git a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
index 687287b..f32177c 100644
--- a/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/ConfigureWifiSettingsTest.java
@@ -45,6 +45,17 @@
     }
 
     @Test
+    @Config(qualifiers = "mcc999")
+    public void testNonIndexableKeys_ifPageDisabled_shouldNotIndexResource() {
+        final List<String> niks = ConfigureWifiSettings.SEARCH_INDEX_DATA_PROVIDER
+                .getNonIndexableKeys(mContext);
+        final int xmlId = new ConfigureWifiSettings().getPreferenceScreenResId();
+
+        final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(mContext, xmlId);
+        assertThat(niks).containsAllIn(keys);
+    }
+
+    @Test
     public void testNonIndexableKeys_noConnection_blocksIP() {
         ConnectivityManager manager = mock(ConnectivityManager.class);
         when(manager.getActiveNetworkInfo()).thenReturn(null);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
index f1bca6f..1708e36 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiMasterSwitchPreferenceControllerTest.java
@@ -72,11 +72,18 @@
     }
 
     @Test
-    public void isAvailable_shouldAlwaysReturnTrue() {
+    public void testWifiMasterSwitch_byDefault_shouldBeShown() {
         assertThat(mController.isAvailable()).isTrue();
     }
 
     @Test
+    @Config(qualifiers = "mcc999")
+    public void testWifiMasterSwitch_ifDisabled_shouldNotBeShown() {
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+
+    @Test
     public void onResume_shouldRegisterCallback() {
         mController.onResume();
 
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
new file mode 100644
index 0000000..5f34800
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.wifi;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+
+import com.android.settings.TestConfig;
+import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WifiSettingsTest {
+
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+    }
+
+    @Test
+    public void testSearchIndexProvider_shouldIndexFragmentTitle() {
+        final List<SearchIndexableRaw> indexRes =
+                WifiSettings.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext,
+                        true /* enabled */);
+
+        assertThat(indexRes).isNotNull();
+        assertThat(indexRes.get(0).key).isEqualTo(WifiSettings.DATA_KEY_REFERENCE);
+    }
+
+    @Test
+    @Config(qualifiers = "mcc999")
+    public void testSearchIndexProvider_ifWifiSettingsNotVisible_shouldNotIndexFragmentTitle() {
+        final List<SearchIndexableRaw> indexRes =
+                WifiSettings.SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext,
+                        true /* enabled */);
+
+        assertThat(indexRes).isEmpty();
+    }
+}
\ No newline at end of file