Merge "Added video calling data usage per-uid support"
diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java
index 060dd73..4152070 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.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.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 @@
// 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 @@
/**
* 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 @@
// 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;
}
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 5c718c7..e81c97e 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -32,6 +32,7 @@
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
+import android.net.NetworkStats;
import android.net.Uri;
import android.os.BatteryStats;
import android.os.Binder;
@@ -39,11 +40,6 @@
import android.provider.Settings.SettingNotFoundException;
import android.os.Bundle;
import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.Message;
-import android.os.Messenger;
-import android.os.Parcelable;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ResultReceiver;
@@ -6433,20 +6429,21 @@
/**
* Get aggregated video call data usage since boot.
* Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required.
- * @return total data usage in bytes
+ *
+ * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
+ * @return Snapshot of video call data usage
* @hide
*/
- public long getVtDataUsage() {
-
+ public NetworkStats getVtDataUsage(boolean perUidStats) {
try {
ITelephony service = getITelephony();
if (service != null) {
- return service.getVtDataUsage();
+ return service.getVtDataUsage(getSubId(), perUidStats);
}
} catch (RemoteException e) {
- Log.e(TAG, "Error calling getVtDataUsage", e);
+ Log.e(TAG, "Error calling ITelephony#getVtDataUsage", e);
}
- return 0;
+ return null;
}
/**
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index fb6782e..63e7abf 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -22,6 +22,7 @@
import android.os.IBinder;
import android.os.Messenger;
import android.os.ResultReceiver;
+import android.net.NetworkStats;
import android.net.Uri;
import android.service.carrier.CarrierIdentifier;
import android.telecom.PhoneAccount;
@@ -1268,10 +1269,12 @@
/**
* Get aggregated video call data usage since boot.
* Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required.
- * @return total data usage in bytes
+ *
+ * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
+ * @return Snapshot of video call data usage
* @hide
*/
- long getVtDataUsage();
+ NetworkStats getVtDataUsage(int subId, boolean perUidStats);
/**
* Policy control of data connection. Usually used when data limit is passed.