From 671a439f5aa3656e2017d92687074576f3070096 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Sat, 26 Feb 2022 16:23:05 +0900 Subject: [PATCH] Log the creation time of network agents This is useful for debugging e.g. b/219083584 where the network agent is far older than the log start. Example log : NetworkAgentInfo{network{100} handle{432902426637} ni{WIFI CONNECTED extra: } created=2022-02-26T07:30:34.393Z Score(60 ; [...] Bug: 238139913 Test: manual Change-Id: I65f522c24e8b4084503765d29658bab78b45166c --- .../com/android/server/connectivity/NetworkAgentInfo.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/service/src/com/android/server/connectivity/NetworkAgentInfo.java b/service/src/com/android/server/connectivity/NetworkAgentInfo.java index c863165476..353412c00d 100644 --- a/service/src/com/android/server/connectivity/NetworkAgentInfo.java +++ b/service/src/com/android/server/connectivity/NetworkAgentInfo.java @@ -67,6 +67,7 @@ import com.android.modules.utils.build.SdkLevel; import com.android.server.ConnectivityService; import java.io.PrintWriter; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -105,7 +106,7 @@ import java.util.TreeSet; // for example: // a. a captive portal is present, or // b. a WiFi router whose Internet backhaul is down, or -// c. a wireless connection stops transfering packets temporarily (e.g. device is in elevator +// c. a wireless connection stops transferring packets temporarily (e.g. device is in elevator // or tunnel) but does not disconnect from the AP/cell tower, or // d. a stand-alone device offering a WiFi AP without an uplink for configuration purposes. // 5. registered, created, connected, validated @@ -417,6 +418,8 @@ public class NetworkAgentInfo implements Comparable, NetworkRa private final Handler mHandler; private final QosCallbackTracker mQosCallbackTracker; + private final long mCreationTime; + public NetworkAgentInfo(INetworkAgent na, Network net, NetworkInfo info, @NonNull LinkProperties lp, @NonNull NetworkCapabilities nc, @NonNull NetworkScore score, Context context, @@ -449,6 +452,7 @@ public class NetworkAgentInfo implements Comparable, NetworkRa declaredUnderlyingNetworks = (nc.getUnderlyingNetworks() != null) ? nc.getUnderlyingNetworks().toArray(new Network[0]) : null; + mCreationTime = System.currentTimeMillis(); } private class AgentDeathMonitor implements IBinder.DeathRecipient { @@ -1330,6 +1334,7 @@ public class NetworkAgentInfo implements Comparable, NetworkRa return "NetworkAgentInfo{" + "network{" + network + "} handle{" + network.getNetworkHandle() + "} ni{" + networkInfo.toShortString() + "} " + + "created=" + Instant.ofEpochMilli(mCreationTime) + " " + mScore + " " + (created ? " created" : "") + (destroyed ? " destroyed" : "")