From 0b4a66a1c2298c0a2131da9ab89d67db51aff29a Mon Sep 17 00:00:00 2001 From: junyulai Date: Mon, 25 Jun 2018 21:51:14 +0800 Subject: [PATCH 1/2] DO NOT MERGE: use legacy way to get tcp packet count The current networkStats getIfaceStats implementation check if bpf is enabled, and use bpf to get all traffic stats. However, the bpf implementation did not contain tcp packet counts. So data stall detection in DcTracker could not get the packet count to trigger data stall. Hence the data stall never triggers for device that enables bpf. This solution is for short term solution that rollback the design to use xt_qtaguid for bpf enabled device. Bug: 110443385 Test: 1. fake data stall to trigger data stall recovery 2. enable debug log to make sure tcp packet count is correct 3. runtest frameworks-net 4. run cts -m CtsUsageStatsTestCases Change-Id: I1ce9e92fe194da2ea0a3eec014fd50bb50cdd44a --- .../java/com/android/server/net/NetworkStatsService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index addc479404..fec510f28a 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -941,7 +941,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub { @Override public long getIfaceStats(String iface, int type) { - return nativeGetIfaceStat(iface, type, checkBpfStatsEnable()); + // eBPF code doesn't provide per-interface TCP counters. Use xt_qtaguid for now. + // TODO: delete getMobileTcp(Rx|Tx)Packets entirely. See b/110443385 . + if (type == TYPE_TCP_TX_PACKETS || type == TYPE_TCP_RX_PACKETS) { + return nativeGetIfaceStat(iface, type, false); + } else { + return nativeGetIfaceStat(iface, type, checkBpfStatsEnable()); + } } @Override From c134e24a77609e81c69c444e6d112fd010801728 Mon Sep 17 00:00:00 2001 From: kopriva Date: Mon, 23 Jul 2018 18:19:39 -0700 Subject: [PATCH 2/2] docs: added Android P behavior change note to untagSocket reference staged here: https://android-dot-devsite.googleplex.com/reference/android/net/TrafficStats#untagSocket(java.net.Socket) Test: make ds-docs Exempt-From-Owner-Approval: Docs-only change Bug: 110484513 Change-Id: I24575e6f4451a019b60c5bf60e17e14a928c6cc3 --- core/java/android/net/TrafficStats.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java index 40d53b741d..f033268698 100644 --- a/core/java/android/net/TrafficStats.java +++ b/core/java/android/net/TrafficStats.java @@ -329,6 +329,14 @@ public class TrafficStats { /** * Remove any statistics parameters from the given {@link Socket}. + *

+ * In Android 8.1 (API level 27) and lower, a socket is automatically + * untagged when it's sent to another process using binder IPC with a + * {@code ParcelFileDescriptor} container. In Android 9.0 (API level 28) + * and higher, the socket tag is kept when the socket is sent to another + * process using binder IPC. You can mimic the previous behavior by + * calling {@code untagSocket()} before sending the socket to another + * process. */ public static void untagSocket(Socket socket) throws SocketException { SocketTagger.get().untag(socket);