Merge "Better messaging when Wi-Fi disabled." into jb-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8ee96e4..b119f2a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3784,6 +3784,8 @@
     <string name="data_usage_metered_mobile">Mobile networks</string>
     <!-- Header for list of Wi-Fi networks. [CHAR LIMIT=32] -->
     <string name="data_usage_metered_wifi">Wi-Fi networks</string>
+    <!-- Body text prompting user to enable Wi-Fi to configure metered networks. [CHAR LIMIT=64] -->
+    <string name="data_usage_metered_wifi_disabled">To select metered Wi-Fi networks, turn Wi-Fi on.</string>
 
     <!-- Button at the bottom of the CryptKeeper screen to make an emergency call. -->
     <string name="cryptkeeper_emergency_call">Emergency call</string>
diff --git a/res/xml/data_usage_metered_prefs.xml b/res/xml/data_usage_metered_prefs.xml
index 7ec3059..a0c6df4 100644
--- a/res/xml/data_usage_metered_prefs.xml
+++ b/res/xml/data_usage_metered_prefs.xml
@@ -29,6 +29,14 @@
     <PreferenceCategory
         android:key="wifi"
         android:title="@string/data_usage_metered_wifi"
-        android:persistent="false" />
+        android:persistent="false">
+
+        <Preference
+            android:key="wifi_disabled"
+            android:summary="@string/data_usage_metered_wifi_disabled"
+            android:persistent="false"
+            android:selectable="false" />
+
+    </PreferenceCategory>
 
 </PreferenceScreen>
diff --git a/src/com/android/settings/net/DataUsageMeteredSettings.java b/src/com/android/settings/net/DataUsageMeteredSettings.java
index fea8a12..69326bc 100644
--- a/src/com/android/settings/net/DataUsageMeteredSettings.java
+++ b/src/com/android/settings/net/DataUsageMeteredSettings.java
@@ -48,6 +48,7 @@
 
     private PreferenceCategory mMobileCategory;
     private PreferenceCategory mWifiCategory;
+    private Preference mWifiDisabled;
 
     @Override
     public void onCreate(Bundle icicle) {
@@ -63,9 +64,9 @@
         addPreferencesFromResource(R.xml.data_usage_metered_prefs);
         mMobileCategory = (PreferenceCategory) findPreference("mobile");
         mWifiCategory = (PreferenceCategory) findPreference("wifi");
+        mWifiDisabled = findPreference("wifi_disabled");
 
         updateNetworks(context);
-
     }
 
     private void updateNetworks(Context context) {
@@ -76,15 +77,15 @@
             getPreferenceScreen().removePreference(mMobileCategory);
         }
 
-        if (hasWifiRadio(context)) {
-            mWifiCategory.removeAll();
+        mWifiCategory.removeAll();
+        if (hasWifiRadio(context) && mWifiManager.isWifiEnabled()) {
             for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
                 if (config.SSID != null) {
                     mWifiCategory.addPreference(buildWifiPref(context, config));
                 }
             }
         } else {
-            getPreferenceScreen().removePreference(mWifiCategory);
+            mWifiCategory.addPreference(mWifiDisabled);
         }
     }