diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-04-10 19:48:07 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-04-12 14:53:32 -0700 |
commit | 234766a36af6214644fa8205202287084ca9cf93 (patch) | |
tree | 81484fc9d4b9da4821544b2bebb44ff4f02aa637 /services | |
parent | 9492947a5970325c494872324078b898868b9403 (diff) | |
download | frameworks_base-234766a36af6214644fa8205202287084ca9cf93.zip frameworks_base-234766a36af6214644fa8205202287084ca9cf93.tar.gz frameworks_base-234766a36af6214644fa8205202287084ca9cf93.tar.bz2 |
Move TrafficStats iface counters to xt_qtaguid.
Use xt_qtaguid iface_stat_all counters, which are monotonic during
a single boot.
Track all ifaces associated with mobile networks since boot, and
move TrafficStats to using these ifaces. This will include usage of
networks omitted from config_data_usage_network_types, specifically
on devices that recycle network interfaces across APNs.
Split wildcard template matching, and move NetworkStatsService to
use mobile wildcard when logging stats.
Bug: 5324515
Change-Id: I2211c374c05d1b598cc647f2f873630538955ffe
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/net/NetworkStatsService.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index 4382a03..2a67e02 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -26,6 +26,7 @@ import static android.content.Intent.ACTION_UID_REMOVED; import static android.content.Intent.EXTRA_UID; import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE; +import static android.net.ConnectivityManager.isNetworkTypeMobile; import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED; import static android.net.NetworkStats.IFACE_ALL; import static android.net.NetworkStats.SET_ALL; @@ -33,7 +34,7 @@ import static android.net.NetworkStats.SET_DEFAULT; import static android.net.NetworkStats.SET_FOREGROUND; import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; -import static android.net.NetworkTemplate.buildTemplateMobileAll; +import static android.net.NetworkTemplate.buildTemplateMobileWildcard; import static android.net.NetworkTemplate.buildTemplateWifiWildcard; import static android.net.TrafficStats.MB_IN_BYTES; import static android.provider.Settings.Secure.NETSTATS_DEV_BUCKET_DURATION; @@ -54,6 +55,8 @@ import static android.text.format.DateUtils.DAY_IN_MILLIS; import static android.text.format.DateUtils.HOUR_IN_MILLIS; import static android.text.format.DateUtils.MINUTE_IN_MILLIS; import static android.text.format.DateUtils.SECOND_IN_MILLIS; +import static com.android.internal.util.ArrayUtils.appendElement; +import static com.android.internal.util.ArrayUtils.contains; import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT; import static com.android.server.NetworkManagementSocketTagger.resetKernelUidStats; @@ -194,6 +197,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { private HashMap<String, NetworkIdentitySet> mActiveIfaces = Maps.newHashMap(); /** Current default active iface. */ private String mActiveIface; + /** Set of any ifaces associated with mobile networks since boot. */ + private String[] mMobileIfaces = new String[0]; private final DropBoxNonMonotonicObserver mNonMonotonicObserver = new DropBoxNonMonotonicObserver(); @@ -517,6 +522,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } @Override + public String[] getMobileIfaces() { + return mMobileIfaces; + } + + @Override public void incrementOperationCount(int uid, int tag, int operationCount) { if (Binder.getCallingUid() != uid) { mContext.enforceCallingOrSelfPermission(MODIFY_NETWORK_ACCOUNTING, TAG); @@ -735,6 +745,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } ident.add(NetworkIdentity.buildNetworkIdentity(mContext, state)); + + // remember any ifaces associated with mobile networks + if (isNetworkTypeMobile(state.networkInfo.getType())) { + if (!contains(mMobileIfaces, iface)) { + mMobileIfaces = appendElement(String.class, mMobileIfaces, iface); + } + } } } } @@ -861,7 +878,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { NetworkStats.Entry uidTotal; // collect mobile sample - template = buildTemplateMobileAll(getActiveSubscriberId(mContext)); + template = buildTemplateMobileWildcard(); devTotal = mDevRecorder.getTotalSinceBootLocked(template); xtTotal = new NetworkStats.Entry(); uidTotal = mUidRecorder.getTotalSinceBootLocked(template); @@ -1022,12 +1039,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } }; - private static String getActiveSubscriberId(Context context) { - final TelephonyManager telephony = (TelephonyManager) context.getSystemService( - Context.TELEPHONY_SERVICE); - return telephony.getSubscriberId(); - } - private boolean isBandwidthControlEnabled() { try { return mNetworkManager.isBandwidthControlEnabled(); |