summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2018-04-02 05:40:04 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-04-02 05:40:04 +0000
commit6f5a8db2e93bc358b211f576aa91cf9fdc7a88de (patch)
treed3afe8de91ec9ef5a79dc053acc543cb4e2c96c5 /core/java/android
parentdfa8f0dbcef180d3a9cdeb7311146cc1c0432962 (diff)
parentb6a920124f28422877f59bfb32719099a0067d76 (diff)
Merge "Add method to NetworkStatsService for UID stats." into pi-dev
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/net/INetworkStatsService.aidl10
-rw-r--r--core/java/android/net/NetworkStats.java64
-rw-r--r--core/java/android/os/INetworkManagementService.aidl6
3 files changed, 66 insertions, 14 deletions
diff --git a/core/java/android/net/INetworkStatsService.aidl b/core/java/android/net/INetworkStatsService.aidl
index 381cfb61de88..8e6f27238846 100644
--- a/core/java/android/net/INetworkStatsService.aidl
+++ b/core/java/android/net/INetworkStatsService.aidl
@@ -41,6 +41,16 @@ interface INetworkStatsService {
/** Return data layer snapshot of UID network usage. */
NetworkStats getDataLayerSnapshotForUid(int uid);
+
+ /** Get a detailed snapshot of stats since boot for all UIDs.
+ *
+ * <p>Results will not always be limited to stats on requiredIfaces when specified: stats for
+ * interfaces stacked on the specified interfaces, or for interfaces on which the specified
+ * interfaces are stacked on, will also be included.
+ * @param requiredIfaces Interface names to get data for, or {@link NetworkStats#INTERFACES_ALL}.
+ */
+ NetworkStats getDetailedUidStats(in String[] requiredIfaces);
+
/** Return set of any ifaces associated with mobile networks since boot. */
String[] getMobileIfaces();
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index 16fb858a58c2..292bf8e19664 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -64,6 +64,9 @@ public class NetworkStats implements Parcelable {
/** Debug {@link #set} value when the VPN stats are moved out of a vpn UID. */
public static final int SET_DBG_VPN_OUT = 1002;
+ /** Include all interfaces when filtering */
+ public static final String[] INTERFACES_ALL = null;
+
/** {@link #tag} value for total data across all tags. */
// TODO: Rename TAG_NONE to TAG_ALL.
public static final int TAG_NONE = 0;
@@ -366,23 +369,27 @@ public class NetworkStats implements Parcelable {
capacity = newLength;
}
- iface[size] = entry.iface;
- uid[size] = entry.uid;
- set[size] = entry.set;
- tag[size] = entry.tag;
- metered[size] = entry.metered;
- roaming[size] = entry.roaming;
- defaultNetwork[size] = entry.defaultNetwork;
- rxBytes[size] = entry.rxBytes;
- rxPackets[size] = entry.rxPackets;
- txBytes[size] = entry.txBytes;
- txPackets[size] = entry.txPackets;
- operations[size] = entry.operations;
+ setValues(size, entry);
size++;
return this;
}
+ private void setValues(int i, Entry entry) {
+ iface[i] = entry.iface;
+ uid[i] = entry.uid;
+ set[i] = entry.set;
+ tag[i] = entry.tag;
+ metered[i] = entry.metered;
+ roaming[i] = entry.roaming;
+ defaultNetwork[i] = entry.defaultNetwork;
+ rxBytes[i] = entry.rxBytes;
+ rxPackets[i] = entry.rxPackets;
+ txBytes[i] = entry.txBytes;
+ txPackets[i] = entry.txPackets;
+ operations[i] = entry.operations;
+ }
+
/**
* Return specific stats entry.
*/
@@ -831,6 +838,39 @@ public class NetworkStats implements Parcelable {
return stats;
}
+ /**
+ * Only keep entries that match all specified filters.
+ *
+ * <p>This mutates the original structure in place. After this method is called,
+ * size is the number of matching entries, and capacity is the previous capacity.
+ * @param limitUid UID to filter for, or {@link #UID_ALL}.
+ * @param limitIfaces Interfaces to filter for, or {@link #INTERFACES_ALL}.
+ * @param limitTag Tag to filter for, or {@link #TAG_ALL}.
+ */
+ public void filter(int limitUid, String[] limitIfaces, int limitTag) {
+ if (limitUid == UID_ALL && limitTag == TAG_ALL && limitIfaces == INTERFACES_ALL) {
+ return;
+ }
+
+ Entry entry = new Entry();
+ int nextOutputEntry = 0;
+ for (int i = 0; i < size; i++) {
+ entry = getValues(i, entry);
+ final boolean matches =
+ (limitUid == UID_ALL || limitUid == entry.uid)
+ && (limitTag == TAG_ALL || limitTag == entry.tag)
+ && (limitIfaces == INTERFACES_ALL
+ || ArrayUtils.contains(limitIfaces, entry.iface));
+
+ if (matches) {
+ setValues(nextOutputEntry, entry);
+ nextOutputEntry++;
+ }
+ }
+
+ size = nextOutputEntry;
+ }
+
public void dump(String prefix, PrintWriter pw) {
pw.print(prefix);
pw.print("NetworkStats: elapsedRealtime="); pw.println(elapsedRealtime);
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl
index 2437ed1b6d61..31dbafad62e3 100644
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -268,10 +268,12 @@ interface INetworkManagementService
NetworkStats getNetworkStatsDetail();
/**
- * Return detailed network statistics for the requested UID,
+ * Return detailed network statistics for the requested UID and interfaces,
* including interface and tag details.
+ * @param uid UID to obtain statistics for, or {@link NetworkStats#UID_ALL}.
+ * @param ifaces Interfaces to obtain statistics for, or {@link NetworkStats#INTERFACES_ALL}.
*/
- NetworkStats getNetworkStatsUidDetail(int uid);
+ NetworkStats getNetworkStatsUidDetail(int uid, in String[] ifaces);
/**
* Return summary of network statistics all tethering interfaces.