Expose getTx/RxBytes in TrafficStats
Test: atest FrameworksNetTests TrafficStatsTest
atest android.net.cts android.net.wifi.cts
Bug: 164965653
Change-Id: I17b9d0bc2404c5727d4c4530ad941439b7b71a54
This commit is contained in:
@@ -597,10 +597,17 @@ public class TrafficStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of packets transmitted on the specified interface since
|
* Return the number of packets transmitted on the specified interface since the interface
|
||||||
* device boot. Statistics are measured at the network layer, so both TCP and
|
* was created. Statistics are measured at the network layer, so both TCP and
|
||||||
* UDP usage are included.
|
* UDP usage are included.
|
||||||
*
|
*
|
||||||
|
* Note that the returned values are partial statistics that do not count data from several
|
||||||
|
* sources and do not apply several adjustments that are necessary for correctness, such
|
||||||
|
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
|
||||||
|
* determine whether traffic is being transferred on the specific interface but are not a
|
||||||
|
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
|
||||||
|
* APIs.
|
||||||
|
*
|
||||||
* @param iface The name of the interface.
|
* @param iface The name of the interface.
|
||||||
* @return The number of transmitted packets.
|
* @return The number of transmitted packets.
|
||||||
*/
|
*/
|
||||||
@@ -613,10 +620,17 @@ public class TrafficStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of packets received on the specified interface since
|
* Return the number of packets received on the specified interface since the interface was
|
||||||
* device boot. Statistics are measured at the network layer, so both TCP
|
* created. Statistics are measured at the network layer, so both TCP
|
||||||
* and UDP usage are included.
|
* and UDP usage are included.
|
||||||
*
|
*
|
||||||
|
* Note that the returned values are partial statistics that do not count data from several
|
||||||
|
* sources and do not apply several adjustments that are necessary for correctness, such
|
||||||
|
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
|
||||||
|
* determine whether traffic is being transferred on the specific interface but are not a
|
||||||
|
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
|
||||||
|
* APIs.
|
||||||
|
*
|
||||||
* @param iface The name of the interface.
|
* @param iface The name of the interface.
|
||||||
* @return The number of received packets.
|
* @return The number of received packets.
|
||||||
*/
|
*/
|
||||||
@@ -628,9 +642,22 @@ public class TrafficStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@hide} */
|
/**
|
||||||
@UnsupportedAppUsage
|
* Return the number of bytes transmitted on the specified interface since the interface
|
||||||
public static long getTxBytes(String iface) {
|
* was created. Statistics are measured at the network layer, so both TCP and
|
||||||
|
* UDP usage are included.
|
||||||
|
*
|
||||||
|
* Note that the returned values are partial statistics that do not count data from several
|
||||||
|
* sources and do not apply several adjustments that are necessary for correctness, such
|
||||||
|
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
|
||||||
|
* determine whether traffic is being transferred on the specific interface but are not a
|
||||||
|
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
|
||||||
|
* APIs.
|
||||||
|
*
|
||||||
|
* @param iface The name of the interface.
|
||||||
|
* @return The number of transmitted bytes.
|
||||||
|
*/
|
||||||
|
public static long getTxBytes(@NonNull String iface) {
|
||||||
try {
|
try {
|
||||||
return getStatsService().getIfaceStats(iface, TYPE_TX_BYTES);
|
return getStatsService().getIfaceStats(iface, TYPE_TX_BYTES);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -638,9 +665,22 @@ public class TrafficStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@hide} */
|
/**
|
||||||
@UnsupportedAppUsage
|
* Return the number of bytes received on the specified interface since the interface
|
||||||
public static long getRxBytes(String iface) {
|
* was created. Statistics are measured at the network layer, so both TCP
|
||||||
|
* and UDP usage are included.
|
||||||
|
*
|
||||||
|
* Note that the returned values are partial statistics that do not count data from several
|
||||||
|
* sources and do not apply several adjustments that are necessary for correctness, such
|
||||||
|
* as adjusting for VPN apps, IPv6-in-IPv4 translation, etc. These values can be used to
|
||||||
|
* determine whether traffic is being transferred on the specific interface but are not a
|
||||||
|
* substitute for the more accurate statistics provided by the {@link NetworkStatsManager}
|
||||||
|
* APIs.
|
||||||
|
*
|
||||||
|
* @param iface The name of the interface.
|
||||||
|
* @return The number of received bytes.
|
||||||
|
*/
|
||||||
|
public static long getRxBytes(@NonNull String iface) {
|
||||||
try {
|
try {
|
||||||
return getStatsService().getIfaceStats(iface, TYPE_RX_BYTES);
|
return getStatsService().getIfaceStats(iface, TYPE_RX_BYTES);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user