From 955599c5477dbe85aade5275dbab4081c54cb934 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 26 May 2017 16:08:22 -0700 Subject: [PATCH] Added video calling data usage per-uid support Now the VT call data usage will be counted under current dialer's data usage as well as the total device data usage. Test: Manual bug: 37671326 Merged-In: I8351e9ae17c84210f7ca6c319d3bddcbb0043341 Change-Id: I8351e9ae17c84210f7ca6c319d3bddcbb0043341 --- .../server/net/NetworkStatsService.java | 52 ++++++++----------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index 060dd73d11..4152070dc6 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -31,7 +31,6 @@ import static android.net.NetworkStats.IFACE_ALL; import static android.net.NetworkStats.SET_ALL; import static android.net.NetworkStats.SET_DEFAULT; import static android.net.NetworkStats.SET_FOREGROUND; -import static android.net.NetworkStats.TAG_ALL; import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; import static android.net.NetworkTemplate.buildTemplateMobileWildcard; @@ -58,14 +57,13 @@ 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.Preconditions.checkArgument; + import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT; import static com.android.server.NetworkManagementSocketTagger.resetKernelUidStats; import static com.android.server.NetworkManagementSocketTagger.setKernelCounterSet; import android.app.AlarmManager; -import android.app.IAlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.ContentResolver; @@ -1031,7 +1029,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // snapshot and record current counters; read UID stats first to // avoid over counting dev stats. final NetworkStats uidSnapshot = getNetworkStatsUidDetail(); - final NetworkStats xtSnapshot = getNetworkStatsXtAndVt(); + final NetworkStats xtSnapshot = getNetworkStatsXt(); final NetworkStats devSnapshot = mNetworkManager.getNetworkStatsSummaryDev(); @@ -1323,7 +1321,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { /** * Return snapshot of current UID statistics, including any - * {@link TrafficStats#UID_TETHERING} and {@link #mUidOperations} values. + * {@link TrafficStats#UID_TETHERING}, video calling data usage, and {@link #mUidOperations} + * values. */ private NetworkStats getNetworkStatsUidDetail() throws RemoteException { final NetworkStats uidSnapshot = mNetworkManager.getNetworkStatsUidDetail(UID_ALL); @@ -1331,43 +1330,34 @@ public class NetworkStatsService extends INetworkStatsService.Stub { // fold tethering stats and operations into uid snapshot final NetworkStats tetherSnapshot = getNetworkStatsTethering(); uidSnapshot.combineAllValues(tetherSnapshot); + + final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService( + Context.TELEPHONY_SERVICE); + + // fold video calling data usage stats into uid snapshot + final NetworkStats vtStats = telephonyManager.getVtDataUsage(true); + if (vtStats != null) { + uidSnapshot.combineAllValues(vtStats); + } uidSnapshot.combineAllValues(mUidOperations); return uidSnapshot; } /** - * Return snapshot of current XT plus VT statistics. + * Return snapshot of current XT statistics with video calling data usage statistics. */ - private NetworkStats getNetworkStatsXtAndVt() throws RemoteException { + private NetworkStats getNetworkStatsXt() throws RemoteException { final NetworkStats xtSnapshot = mNetworkManager.getNetworkStatsSummaryXt(); - TelephonyManager tm = (TelephonyManager) mContext.getSystemService( + final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService( Context.TELEPHONY_SERVICE); - long usage = tm.getVtDataUsage(); - - if (LOGV) Slog.d(TAG, "VT call data usage = " + usage); - - final NetworkStats vtSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), 1); - - final NetworkStats.Entry entry = new NetworkStats.Entry(); - entry.iface = VT_INTERFACE; - entry.uid = -1; - entry.set = TAG_ALL; - entry.tag = TAG_NONE; - - // Since modem only tell us the total usage instead of each usage for RX and TX, - // we need to split it up (though it might not quite accurate). At - // least we can make sure the data usage report to the user will still be accurate. - entry.rxBytes = usage / 2; - entry.rxPackets = 0; - entry.txBytes = usage - entry.rxBytes; - entry.txPackets = 0; - vtSnapshot.combineValues(entry); - - // Merge VT int XT - xtSnapshot.combineAllValues(vtSnapshot); + // Merge video calling data usage into XT + final NetworkStats vtSnapshot = telephonyManager.getVtDataUsage(false); + if (vtSnapshot != null) { + xtSnapshot.combineAllValues(vtSnapshot); + } return xtSnapshot; }