Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Improve TrafficStats UID APIs.
Browse files Browse the repository at this point in the history
Deprecate transport layer statistics, leaving only the summarized
network layer statistics.

Improve documentation to be clear about layers where measurements
occur, and their behavior since boot.  Under the hood, move to using
xt_qtaguid UID statistics.

Bug: 6818637, 7013662
Change-Id: I9f26992e5fcdebd88c671e5765bd91229e7b0016
  • Loading branch information
jsharkey committed Feb 7, 2013
1 parent fde19b1 commit 92be93a
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 305 deletions.
16 changes: 8 additions & 8 deletions api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12805,16 +12805,16 @@ package android.net {
method public static long getTotalTxPackets();
method public static long getUidRxBytes(int);
method public static long getUidRxPackets(int);
method public static long getUidTcpRxBytes(int);
method public static long getUidTcpRxSegments(int);
method public static long getUidTcpTxBytes(int);
method public static long getUidTcpTxSegments(int);
method public static deprecated long getUidTcpRxBytes(int);
method public static deprecated long getUidTcpRxSegments(int);
method public static deprecated long getUidTcpTxBytes(int);
method public static deprecated long getUidTcpTxSegments(int);
method public static long getUidTxBytes(int);
method public static long getUidTxPackets(int);
method public static long getUidUdpRxBytes(int);
method public static long getUidUdpRxPackets(int);
method public static long getUidUdpTxBytes(int);
method public static long getUidUdpTxPackets(int);
method public static deprecated long getUidUdpRxBytes(int);
method public static deprecated long getUidUdpRxPackets(int);
method public static deprecated long getUidUdpTxBytes(int);
method public static deprecated long getUidUdpTxPackets(int);
method public static void incrementOperationCount(int);
method public static void incrementOperationCount(int, int);
method public static void setThreadStatsTag(int);
Expand Down
230 changes: 113 additions & 117 deletions core/java/android/net/TrafficStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,161 +424,156 @@ public static long getTotalRxBytes() {
}

/**
* Get the number of bytes sent through the network for this UID.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
* Return number of bytes transmitted by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
* <p>
* Before {@link android.os.Build.VERSION_CODES#K}, this may return
* {@link #UNSUPPORTED} on devices where statistics aren't available.
*
* @param uid The UID of the process to examine.
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @see android.os.Process#myUid()
* @see android.content.pm.ApplicationInfo#uid
*/
public static native long getUidTxBytes(int uid);
public static long getUidTxBytes(int uid) {
return nativeGetUidStat(uid, TYPE_TX_BYTES);
}

/**
* Get the number of bytes received through the network for this UID.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
* Return number of bytes received by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
* <p>
* Before {@link android.os.Build.VERSION_CODES#K}, this may return
* {@link #UNSUPPORTED} on devices where statistics aren't available.
*
* @param uid The UID of the process to examine.
* @return number of bytes
* @see android.os.Process#myUid()
* @see android.content.pm.ApplicationInfo#uid
*/
public static native long getUidRxBytes(int uid);
public static long getUidRxBytes(int uid) {
return nativeGetUidStat(uid, TYPE_RX_BYTES);
}

/**
* Get the number of packets (TCP segments + UDP) sent through
* the network for this UID.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
* Return number of packets transmitted by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
* <p>
* Before {@link android.os.Build.VERSION_CODES#K}, this may return
* {@link #UNSUPPORTED} on devices where statistics aren't available.
*
* @param uid The UID of the process to examine.
* @return number of packets.
* If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @see android.os.Process#myUid()
* @see android.content.pm.ApplicationInfo#uid
*/
public static native long getUidTxPackets(int uid);
public static long getUidTxPackets(int uid) {
return nativeGetUidStat(uid, TYPE_TX_PACKETS);
}

/**
* Get the number of packets (TCP segments + UDP) received through
* the network for this UID.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
* Return number of packets received by the given UID since device boot.
* Counts packets across all network interfaces, and always increases
* monotonically since device boot. Statistics are measured at the network
* layer, so they include both TCP and UDP usage.
* <p>
* Before {@link android.os.Build.VERSION_CODES#K}, this may return
* {@link #UNSUPPORTED} on devices where statistics aren't available.
*
* @param uid The UID of the process to examine.
* @return number of packets
* @see android.os.Process#myUid()
* @see android.content.pm.ApplicationInfo#uid
*/
public static native long getUidRxPackets(int uid);
public static long getUidRxPackets(int uid) {
return nativeGetUidStat(uid, TYPE_RX_PACKETS);
}

/**
* Get the number of TCP payload bytes sent for this UID.
* This total does not include protocol and control overheads at
* the transport and the lower layers of the networking stack.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidTxBytes(int)
*/
public static native long getUidTcpTxBytes(int uid);
@Deprecated
public static long getUidTcpTxBytes(int uid) {
return UNSUPPORTED;
}

/**
* Get the number of TCP payload bytes received for this UID.
* This total does not include protocol and control overheads at
* the transport and the lower layers of the networking stack.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidRxBytes(int)
*/
public static native long getUidTcpRxBytes(int uid);
@Deprecated
public static long getUidTcpRxBytes(int uid) {
return UNSUPPORTED;
}

/**
* Get the number of UDP payload bytes sent for this UID.
* This total does not include protocol and control overheads at
* the transport and the lower layers of the networking stack.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidTxBytes(int)
*/
public static native long getUidUdpTxBytes(int uid);
@Deprecated
public static long getUidUdpTxBytes(int uid) {
return UNSUPPORTED;
}

/**
* Get the number of UDP payload bytes received for this UID.
* This total does not include protocol and control overheads at
* the transport and the lower layers of the networking stack.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of bytes. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidRxBytes(int)
*/
public static native long getUidUdpRxBytes(int uid);
@Deprecated
public static long getUidUdpRxBytes(int uid) {
return UNSUPPORTED;
}

/**
* Get the number of TCP segments sent for this UID.
* Does not include TCP control packets (SYN/ACKs/FIN/..).
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of TCP segments. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidTxPackets(int)
*/
public static native long getUidTcpTxSegments(int uid);
@Deprecated
public static long getUidTcpTxSegments(int uid) {
return UNSUPPORTED;
}

/**
* Get the number of TCP segments received for this UID.
* Does not include TCP control packets (SYN/ACKs/FIN/..).
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of TCP segments. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidRxPackets(int)
*/
public static native long getUidTcpRxSegments(int uid);
@Deprecated
public static long getUidTcpRxSegments(int uid) {
return UNSUPPORTED;
}

/**
* Get the number of UDP packets sent for this UID.
* Includes DNS requests.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of packets. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidTxPackets(int)
*/
public static native long getUidUdpTxPackets(int uid);
@Deprecated
public static long getUidUdpTxPackets(int uid) {
return UNSUPPORTED;
}

/**
* Get the number of UDP packets received for this UID.
* Includes DNS responses.
* The statistics are across all interfaces.
*
* {@see android.os.Process#myUid()}.
*
* @param uid The UID of the process to examine.
* @return number of packets. If the statistics are not supported by this device,
* {@link #UNSUPPORTED} will be returned.
* @deprecated Starting in {@link android.os.Build.VERSION_CODES#K},
* transport layer statistics are no longer available, and will
* always return {@link #UNSUPPORTED}.
* @see #getUidRxPackets(int)
*/
public static native long getUidUdpRxPackets(int uid);
@Deprecated
public static long getUidUdpRxPackets(int uid) {
return UNSUPPORTED;
}

/**
* Return detailed {@link NetworkStats} for the current UID. Requires no
Expand Down Expand Up @@ -616,4 +611,5 @@ private static String[] getMobileIfaces() {

private static native long nativeGetTotalStat(int type);
private static native long nativeGetIfaceStat(String iface, int type);
private static native long nativeGetUidStat(int uid, int type);
}
Loading

0 comments on commit 92be93a

Please sign in to comment.