From d8789099806a169309071d68cea5f8b82380044e Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 29 May 2012 10:19:50 -0700 Subject: [PATCH] Surface metered networks as "Mobile hotspots." String changes to give clearer definition of metered networks, and remove metered control for mobile network. Also fix NPE when testing hasEthernet() before session is ready. Bug: 6494976 Change-Id: Ia55ca3362a05977b9f21ab41eb10bbc738e29620 --- res/values/strings.xml | 12 ++++++------ .../android/settings/DataUsageSummary.java | 19 +++++++++++-------- .../net/DataUsageMeteredSettings.java | 4 +++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 6f1bdad3a03..214d2f599a6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3749,7 +3749,7 @@ Show Ethernet usage - Metered networks + Mobile hotspots Change cycle\u2026 @@ -3804,13 +3804,13 @@ Restrict background data - Disable background data on metered networks. Unmetered networks will be used if available. + Disable background data on mobile networks. Non-mobile networks will be used if available. To restrict background data for this app, first set a mobile data limit. Restrict background data? - This feature may cause an app that depends on background data to stop working when only metered networks are available.\n\nYou can find more appropriate data usage controls in the settings available within the app. + This feature may cause an app that depends on background data to stop working when only mobile networks are available.\n\nYou can find more appropriate data usage controls in the settings available within the app. Restricting background data is possible only when you\'ve set a mobile data limit. @@ -3856,15 +3856,15 @@ %2$s: about %1$s used, as measured by your phone. Your carrier\'s data usage accounting may differ. - Metered networks + Mobile hotspots - Select the networks for which data usage is metered. Apps can be restricted from using these networks when in the background. Apps may also warn before using these networks for large downloads. + Select the Wi-Fi networks which are mobile hotspots. Apps can be restricted from using these networks when in the background. Apps may also warn before using these networks for large downloads. Mobile networks Wi-Fi networks - To select metered Wi-Fi networks, turn Wi-Fi on. + To select mobile hotspots, turn Wi-Fi on. Emergency call diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java index 94c8cda4a0b..c58e001c8b2 100644 --- a/src/com/android/settings/DataUsageSummary.java +++ b/src/com/android/settings/DataUsageSummary.java @@ -104,7 +104,6 @@ import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; @@ -2164,15 +2163,19 @@ public class DataUsageSummary extends Fragment { final boolean hasEthernet = conn.isNetworkSupported(TYPE_ETHERNET); final long ethernetBytes; - try { - ethernetBytes = mStatsSession.getSummaryForNetwork( - NetworkTemplate.buildTemplateEthernet(), Long.MIN_VALUE, Long.MAX_VALUE) - .getTotalBytes(); - } catch (RemoteException e) { - throw new RuntimeException(e); + if (mStatsSession != null) { + try { + ethernetBytes = mStatsSession.getSummaryForNetwork( + NetworkTemplate.buildTemplateEthernet(), Long.MIN_VALUE, Long.MAX_VALUE) + .getTotalBytes(); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } else { + ethernetBytes = 0; } - // suppress ethernet unless traffic has occurred + // only show ethernet when both hardware present and traffic has occurred return hasEthernet && ethernetBytes > 0; } diff --git a/src/com/android/settings/net/DataUsageMeteredSettings.java b/src/com/android/settings/net/DataUsageMeteredSettings.java index 69326bc85d0..ad12311c2b9 100644 --- a/src/com/android/settings/net/DataUsageMeteredSettings.java +++ b/src/com/android/settings/net/DataUsageMeteredSettings.java @@ -41,6 +41,8 @@ import com.android.settings.SettingsPreferenceFragment; */ public class DataUsageMeteredSettings extends SettingsPreferenceFragment { + private static final boolean SHOW_MOBILE_CATEGORY = false; + private NetworkPolicyManager mPolicyManager; private WifiManager mWifiManager; @@ -70,7 +72,7 @@ public class DataUsageMeteredSettings extends SettingsPreferenceFragment { } private void updateNetworks(Context context) { - if (hasReadyMobileRadio(context)) { + if (SHOW_MOBILE_CATEGORY && hasReadyMobileRadio(context)) { mMobileCategory.removeAll(); mMobileCategory.addPreference(buildMobilePref(context)); } else {