From 7a1d7a8120f3410266a85f17531b6237e0ed2526 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Thu, 5 Aug 2021 21:02:22 +0900 Subject: [PATCH] Add a reevaluate command to ConnectivityService This is useful for debugging occasionally. Test: manual Change-Id: Ic29f81cb993d7e75916d3bacfaed7d0d6d07af07 --- .../android/server/ConnectivityService.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 8ec979a241..55369f94c6 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -9627,6 +9627,8 @@ public class ConnectivityService extends IConnectivityManager.Stub try { switch (cmd) { case "airplane-mode": + // Usage : adb shell cmd connectivity airplane-mode [enable|disable] + // If no argument, get and display the current status final String action = getNextArg(); if ("enable".equals(action)) { setAirplaneMode(true); @@ -9644,6 +9646,27 @@ public class ConnectivityService extends IConnectivityManager.Stub onHelp(); return -1; } + case "reevaluate": + // Usage : adb shell cmd connectivity reevaluate + // If netId is omitted, then reevaluate the default network + final String netId = getNextArg(); + final NetworkAgentInfo nai; + if (null == netId) { + // Note that the command is running on the wrong thread to call this, + // so this could in principle return stale data. But it can't crash. + nai = getDefaultNetwork(); + } else { + // If netId can't be parsed, this throws NumberFormatException, which + // is passed back to adb who prints it. + nai = getNetworkAgentInfoForNetId(Integer.parseInt(netId)); + } + if (null == nai) { + pw.println("Unknown network (net ID not found or no default network)"); + return 0; + } + Log.d(TAG, "Reevaluating network " + nai.network); + reportNetworkConnectivity(nai.network, !nai.isValidated()); + return 0; default: return handleDefaultCommands(cmd); }