Move dumpsys to handler thread

I0afdda023208c3f8620cb5b89add66448af596d7 added some assertions
to ensure NetworkAgentInfo can only be accessed from the handler
thread. This is good to eliminate any potential concurrent
accessing problem. Howver, dumpsys runs on binder thread, this
change breaks dumpsys functionality.

Thus, this change:
  1. Copy Handler#runWithScissors() and related class
     locally since they are @hide methods.
  2. Run doDump on the handler thread and waits for return.

Test: adb shell dumpsys connectivity
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.HandlerUtilsTest
Fix: 303348620
Change-Id: Ic3a22f5d370bbf8c18b1972e86d695b6ad61bd0d
This commit is contained in:
Junyu Lai 2023-10-12 17:01:03 +08:00
commit f8dba342f1

View file

@ -303,6 +303,7 @@ import com.android.server.connectivity.DnsManager;
import com.android.server.connectivity.DnsManager.PrivateDnsValidationUpdate;
import com.android.server.connectivity.DscpPolicyTracker;
import com.android.server.connectivity.FullScore;
import com.android.server.connectivity.HandlerUtils;
import com.android.server.connectivity.InvalidTagException;
import com.android.server.connectivity.KeepaliveResourceUtil;
import com.android.server.connectivity.KeepaliveTracker;
@ -1255,16 +1256,24 @@ public class ConnectivityService extends IConnectivityManager.Stub
private static final String PRIORITY_ARG = "--dump-priority";
private static final String PRIORITY_ARG_HIGH = "HIGH";
private static final String PRIORITY_ARG_NORMAL = "NORMAL";
private static final int DUMPSYS_DEFAULT_TIMEOUT_MS = 10_000;
LocalPriorityDump() {}
private void dumpHigh(FileDescriptor fd, PrintWriter pw) {
doDump(fd, pw, new String[] {DIAG_ARG});
doDump(fd, pw, new String[] {SHORT_ARG});
if (!HandlerUtils.runWithScissors(mHandler, () -> {
doDump(fd, pw, new String[]{DIAG_ARG});
doDump(fd, pw, new String[]{SHORT_ARG});
}, DUMPSYS_DEFAULT_TIMEOUT_MS)) {
pw.println("dumpHigh timeout");
}
}
private void dumpNormal(FileDescriptor fd, PrintWriter pw, String[] args) {
doDump(fd, pw, args);
if (!HandlerUtils.runWithScissors(mHandler, () -> doDump(fd, pw, args),
DUMPSYS_DEFAULT_TIMEOUT_MS)) {
pw.println("dumpNormal timeout");
}
}
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {