From 29667d2942de3bebacad29638288811e3f7792b1 Mon Sep 17 00:00:00 2001 From: Aaron Huang Date: Fri, 27 Sep 2019 22:31:22 +0800 Subject: Add TrafficStats methods to public APIs Add methods to public APIs for mainline support. Bug: 139268426 Bug: 135998869 Test: atest FrameworksNetTests ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh atest android.net.cts atest android.net.wifi.cts Change-Id: I21a9c0dbdc79b1f1041fc9e23c6a4e1e97ecde92 --- api/current.txt | 2 ++ core/java/android/net/TrafficStats.java | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/api/current.txt b/api/current.txt index c71855cab92b..1f2d4e83f535 100644 --- a/api/current.txt +++ b/api/current.txt @@ -29024,12 +29024,14 @@ package android.net { method public static long getMobileRxPackets(); method public static long getMobileTxBytes(); method public static long getMobileTxPackets(); + method public static long getRxPackets(@NonNull String); method public static int getThreadStatsTag(); method public static int getThreadStatsUid(); method public static long getTotalRxBytes(); method public static long getTotalRxPackets(); method public static long getTotalTxBytes(); method public static long getTotalTxPackets(); + method public static long getTxPackets(@NonNull String); method public static long getUidRxBytes(int); method public static long getUidRxPackets(int); method @Deprecated public static long getUidTcpRxBytes(int); diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java index 1c6a48434adc..bf4884aa96a7 100644 --- a/core/java/android/net/TrafficStats.java +++ b/core/java/android/net/TrafficStats.java @@ -16,6 +16,7 @@ package android.net; +import android.annotation.NonNull; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.TestApi; @@ -595,8 +596,15 @@ public class TrafficStats { return total; } - /** {@hide} */ - public static long getTxPackets(String iface) { + /** + * Return the number of packets transmitted on the specified interface since + * device boot. Statistics are measured at the network layer, so both TCP and + * UDP usage are included. + * + * @param iface The name of the interface. + * @return The number of transmitted packets. + */ + public static long getTxPackets(@NonNull String iface) { try { return getStatsService().getIfaceStats(iface, TYPE_TX_PACKETS); } catch (RemoteException e) { @@ -604,8 +612,15 @@ public class TrafficStats { } } - /** {@hide} */ - public static long getRxPackets(String iface) { + /** + * Return the number of packets received on the specified interface since + * device boot. Statistics are measured at the network layer, so both TCP + * and UDP usage are included. + * + * @param iface The name of the interface. + * @return The number of received packets. + */ + public static long getRxPackets(@NonNull String iface) { try { return getStatsService().getIfaceStats(iface, TYPE_RX_PACKETS); } catch (RemoteException e) { -- cgit v1.2.3-59-g8ed1b