OSDN Git Service

Surface metered networks as "Mobile hotspots."
authorJeff Sharkey <jsharkey@android.com>
Tue, 29 May 2012 17:19:50 +0000 (10:19 -0700)
committerJeff Sharkey <jsharkey@android.com>
Tue, 29 May 2012 18:03:55 +0000 (11:03 -0700)
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
src/com/android/settings/DataUsageSummary.java
src/com/android/settings/net/DataUsageMeteredSettings.java

index 6f1bdad..214d2f5 100644 (file)
     <!-- Title for checkbox menu option to show Ethernet data usage. [CHAR LIMIT=26] -->
     <string name="data_usage_menu_show_ethernet">Show Ethernet usage</string>
     <!-- Title for menu option to configure metered networks. [CHAR LIMIT=26] -->
-    <string name="data_usage_menu_metered">Metered networks</string>
+    <string name="data_usage_menu_metered">Mobile hotspots</string>
 
     <!-- Title for option to change data usage cycle day. [CHAR LIMIT=32] -->
     <string name="data_usage_change_cycle">Change cycle\u2026</string>
     <!-- Checkbox label that restricts background data usage of a specific application. [CHAR LIMIT=32] -->
     <string name="data_usage_app_restrict_background">Restrict background data</string>
     <!-- Summary message for checkbox that restricts background data usage of a specific application. [CHAR LIMIT=64] -->
-    <string name="data_usage_app_restrict_background_summary">Disable background data on metered networks. Unmetered networks will be used if available.</string>
+    <string name="data_usage_app_restrict_background_summary">Disable background data on mobile networks. Non-mobile networks will be used if available.</string>
     <!-- Summary message for checkbox that restricts background data usage of a specific application when no networks have been limited. [CHAR LIMIT=64] -->
     <string name="data_usage_app_restrict_background_summary_disabled">To restrict background data for this app, first set a mobile data limit.</string>
     <!-- Title of dialog shown when user restricts background data usage of a specific application. [CHAR LIMIT=48] -->
     <string name="data_usage_app_restrict_dialog_title">Restrict background data?</string>
     <!-- Body of dialog shown when user restricts background data usage of a specific application. [CHAR LIMIT=NONE] -->
-    <string name="data_usage_app_restrict_dialog">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.</string>
+    <string name="data_usage_app_restrict_dialog">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.</string>
     <!-- Body of dialog shown when user attempts to restrict background data before a network data limit has been set. [CHAR LIMIT=NONE] -->
     <string name="data_usage_restrict_denied_dialog">Restricting background data is possible only when you\'ve set a mobile data limit.</string>
 
     <string name="data_usage_total_during_range_mobile" product="default"><xliff:g id="range" example="Jul 1 - Jul 31">%2$s</xliff:g>: about <xliff:g id="total" example="128KB">%1$s</xliff:g> used, as measured by your phone. Your carrier\'s data usage accounting may differ.</string>
 
     <!-- Dialog title for selecting metered networks. [CHAR LIMIT=25] -->
-    <string name="data_usage_metered_title">Metered networks</string>
+    <string name="data_usage_metered_title">Mobile hotspots</string>
     <!-- Dialog body for selecting paid networks. [CHAR LIMIT=NONE] -->
-    <string name="data_usage_metered_body">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.</string>
+    <string name="data_usage_metered_body">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.</string>
     <!-- Header for list of mobile networks. [CHAR LIMIT=32] -->
     <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>
+    <string name="data_usage_metered_wifi_disabled">To select mobile hotspots, 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>
index 94c8cda..c58e001 100644 (file)
@@ -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;
     }
 
index 69326bc..ad12311 100644 (file)
@@ -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 {