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
diff --git a/service/src/com/android/server/connectivity/NetworkAgentInfo.java b/service/src/com/android/server/connectivity/NetworkAgentInfo.java
index c863165..353412c 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.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 @@
// 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 @@
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 @@
declaredUnderlyingNetworks = (nc.getUnderlyingNetworks() != null)
? nc.getUnderlyingNetworks().toArray(new Network[0])
: null;
+ mCreationTime = System.currentTimeMillis();
}
private class AgentDeathMonitor implements IBinder.DeathRecipient {
@@ -1330,6 +1334,7 @@
return "NetworkAgentInfo{"
+ "network{" + network + "} handle{" + network.getNetworkHandle() + "} ni{"
+ networkInfo.toShortString() + "} "
+ + "created=" + Instant.ofEpochMilli(mCreationTime) + " "
+ mScore + " "
+ (created ? " created" : "")
+ (destroyed ? " destroyed" : "")