From 3ce93600fd8213e439082fbf104db877cab5f3ec Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 14 Jun 2011 17:27:29 -0700 Subject: [PATCH] Data usage warning and limit notifications. Watch for network statistics to cross NetworkPolicy warning or limit, and show notifications to user as needed. Currently checks during any statistics update, but will eventually move to event registration through netd when kernel supports. Fixed accounting bug in getSummaryForNetwork(). Only apply UID policy to applications; applying to system processes could break critical services like RIL. Change-Id: Iac0f20e910e205f3cbc54ec96395ff268b1aa379 --- .../com/android/server/net/NetworkStatsService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index de69849b7d..f762123a87 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -106,6 +106,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // @VisibleForTesting public static final String ACTION_NETWORK_STATS_POLL = "com.android.server.action.NETWORK_STATS_POLL"; + public static final String ACTION_NETWORK_STATS_UPDATED = + "com.android.server.action.NETWORK_STATS_UPDATED"; private PendingIntent mPollIntent; @@ -203,7 +205,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mContext.registerReceiver(mIfaceReceiver, ifaceFilter, CONNECTIVITY_INTERNAL, mHandler); // listen for periodic polling events - // TODO: switch to stronger internal permission final IntentFilter pollFilter = new IntentFilter(ACTION_NETWORK_STATS_POLL); mContext.registerReceiver(mPollReceiver, pollFilter, READ_NETWORK_USAGE_HISTORY, mHandler); @@ -298,7 +299,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } final NetworkStats stats = new NetworkStats(end - start, 1); - stats.addEntry(IFACE_ALL, UID_ALL, tx, tx); + stats.addEntry(IFACE_ALL, UID_ALL, rx, tx); return stats; } } @@ -446,6 +447,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub { break; } } + + // finally, dispatch updated event to any listeners + final Intent updatedIntent = new Intent(ACTION_NETWORK_STATS_UPDATED); + updatedIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + mContext.sendBroadcast(updatedIntent, READ_NETWORK_USAGE_HISTORY); } /**