Return offloaded traffic when querying from TrafficStats API

TrafficStats API are being used for querying realtime network
statistics for years. However, on certain devices, some network
traffic are produced by hardware components and not be
able to seen by kernel counters.

Thus, include statistics for those missing network traffic is
necessary. Note that the included statistics might be stale
since polling newest stats from hardware might impact system
health and not suitable for TrafficStats API use cases.

Test: atest FrameworksNetTests TetheringTests
Bug: 16229221

Change-Id: I6741c41cb5145ca8748f9b083b9c15e7e2735681
This commit is contained in:
junyulai
2020-10-06 11:59:56 +08:00
parent 1694538a20
commit 3841fbeeca
2 changed files with 73 additions and 34 deletions

View File

@@ -976,11 +976,17 @@ public class TrafficStats {
}
}
// NOTE: keep these in sync with android_net_TrafficStats.cpp
private static final int TYPE_RX_BYTES = 0;
private static final int TYPE_RX_PACKETS = 1;
private static final int TYPE_TX_BYTES = 2;
private static final int TYPE_TX_PACKETS = 3;
private static final int TYPE_TCP_RX_PACKETS = 4;
private static final int TYPE_TCP_TX_PACKETS = 5;
// NOTE: keep these in sync with {@code com_android_server_net_NetworkStatsService.cpp}.
/** {@hide} */
public static final int TYPE_RX_BYTES = 0;
/** {@hide} */
public static final int TYPE_RX_PACKETS = 1;
/** {@hide} */
public static final int TYPE_TX_BYTES = 2;
/** {@hide} */
public static final int TYPE_TX_PACKETS = 3;
/** {@hide} */
public static final int TYPE_TCP_RX_PACKETS = 4;
/** {@hide} */
public static final int TYPE_TCP_TX_PACKETS = 5;
}