Allow user to change scan always available setting

Bug: 8141918
Change-Id: I3595812eccf5f7760f7521b9cbe6dece6fd658f1
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c15d315..921b9e5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1270,6 +1270,10 @@
     <string name="wifi_poor_network_detection">Avoid poor connections</string>
     <!-- Checkbox summary for option to toggle poor network detection -->
     <string name="wifi_poor_network_detection_summary">Don\'t use a Wi\u2011Fi network unless it has a good Internet connection</string>
+    <!-- Checkbox title for option to scan always available setting -->
+    <string name="wifi_scan_always_available">Scanning always available</string>
+    <!-- Checkbox summary for option to toggle scan always available setting -->
+    <string name="wifi_scan_always_available_summary">Let Google\'s location service and other apps scan for networks, even when Wi-Fi is off</string>
     <!-- Setting title for setting the wifi sleep policy. Do we keep Wi-Fi active when the screen turns off? -->
     <string name="wifi_setting_sleep_policy_title">Keep Wi\u2011Fi on during sleep</string>
     <!-- Generic error message when the sleep policy could not be set. -->
diff --git a/res/xml/wifi_advanced_settings.xml b/res/xml/wifi_advanced_settings.xml
index 10eab29..4319ec6 100644
--- a/res/xml/wifi_advanced_settings.xml
+++ b/res/xml/wifi_advanced_settings.xml
@@ -31,6 +31,11 @@
             android:entries="@array/wifi_sleep_policy_entries"
             android:entryValues="@array/wifi_sleep_policy_values"
             />
+    <CheckBoxPreference
+            android:key="wifi_scan_always_available"
+            android:title="@string/wifi_scan_always_available"
+            android:summary="@string/wifi_scan_always_available_summary"
+            android:persistent="false" />
 
     <!-- android:dependency="enable_wifi" -->
     <CheckBoxPreference
diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java
index dddb353..abe153f 100644
--- a/src/com/android/settings/wifi/AdvancedWifiSettings.java
+++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java
@@ -45,6 +45,7 @@
     private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
     private static final String KEY_SLEEP_POLICY = "sleep_policy";
     private static final String KEY_POOR_NETWORK_DETECTION = "wifi_poor_network_detection";
+    private static final String KEY_SCAN_ALWAYS_AVAILABLE = "wifi_scan_always_available";
     private static final String KEY_SUSPEND_OPTIMIZATIONS = "suspend_optimizations";
 
     private WifiManager mWifiManager;
@@ -88,6 +89,11 @@
             }
         }
 
+        CheckBoxPreference scanAlwaysAvailable =
+            (CheckBoxPreference) findPreference(KEY_SCAN_ALWAYS_AVAILABLE);
+        scanAlwaysAvailable.setChecked(Global.getInt(getContentResolver(),
+                    Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1);
+
         CheckBoxPreference suspendOptimizations =
             (CheckBoxPreference) findPreference(KEY_SUSPEND_OPTIMIZATIONS);
         suspendOptimizations.setChecked(Global.getInt(getContentResolver(),
@@ -167,6 +173,10 @@
             Global.putInt(getContentResolver(),
                     Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED,
                     ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
+        } else if (KEY_SCAN_ALWAYS_AVAILABLE.equals(key)) {
+            Global.putInt(getContentResolver(),
+                    Global.WIFI_SCAN_ALWAYS_AVAILABLE,
+                    ((CheckBoxPreference) preference).isChecked() ? 1 : 0);
         } else {
             return super.onPreferenceTreeClick(screen, preference);
         }