OSDN Git Service

Only show ethernet when traffic has occurred.
authorJeff Sharkey <jsharkey@android.com>
Thu, 24 May 2012 18:01:29 +0000 (11:01 -0700)
committerJeff Sharkey <jsharkey@android.com>
Thu, 24 May 2012 18:01:29 +0000 (11:01 -0700)
Bug: 6231172
Change-Id: I24dfd5f998b4e96681813c9fd7ce1ed74cf30eb5

src/com/android/settings/DataUsageSummary.java

index 1bdc1d1..94c8cda 100644 (file)
@@ -2155,13 +2155,25 @@ public class DataUsageSummary extends Fragment {
     /**
      * Test if device has an ethernet network connection.
      */
-    public static boolean hasEthernet(Context context) {
+    public boolean hasEthernet(Context context) {
         if (TEST_RADIOS) {
             return SystemProperties.get(TEST_RADIOS_PROP).contains("ethernet");
         }
 
         final ConnectivityManager conn = ConnectivityManager.from(context);
-        return conn.isNetworkSupported(TYPE_ETHERNET);
+        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);
+        }
+
+        // suppress ethernet unless traffic has occurred
+        return hasEthernet && ethernetBytes > 0;
     }
 
     /**