summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zhuning3 <zhuning3@xiaomi.com> 2024-01-23 16:07:26 +0800
committer ning zhu <zhuning3@xiaomi.com> 2024-02-07 01:54:55 +0000
commita21ab8dda6b5b5eba1e3aec59e63fe0e249ebdab (patch)
tree718782c1a06b31aa42b65d38bc0d95f55303a9b2
parentc40bde3f8e0b3fd98f3ae0579770b9947322c229 (diff)
Fix the concurrency issue in AdbDebuggingManager that leads to Watchdog
Avoid destruction of the pairing server while it is being initialized by ensuring that both native_pairing_start and native_pairing_cancel run on the same FgThread. Test: MTBF Bug: 321884100 Change-Id: I7b3614f3922b265930d95a30d37174ba60dbd806 Signed-off-by: zhuning3 <zhuning3@xiaomi.corp-partner.google.com>
-rw-r--r--services/core/java/com/android/server/adb/AdbDebuggingManager.java32
1 files changed, 22 insertions, 10 deletions
diff --git a/services/core/java/com/android/server/adb/AdbDebuggingManager.java b/services/core/java/com/android/server/adb/AdbDebuggingManager.java
index 627a62ee0496..34c3d7ec8433 100644
--- a/services/core/java/com/android/server/adb/AdbDebuggingManager.java
+++ b/services/core/java/com/android/server/adb/AdbDebuggingManager.java
@@ -246,16 +246,6 @@ public class AdbDebuggingManager {
@Override
public void run() {
- if (mGuid.isEmpty()) {
- Slog.e(TAG, "adbwifi guid was not set");
- return;
- }
- mPort = native_pairing_start(mGuid, mPairingCode);
- if (mPort <= 0 || mPort > 65535) {
- Slog.e(TAG, "Unable to start pairing server");
- return;
- }
-
// Register the mdns service
NsdServiceInfo serviceInfo = new NsdServiceInfo();
serviceInfo.setServiceName(mServiceName);
@@ -288,6 +278,28 @@ public class AdbDebuggingManager {
mHandler.sendMessage(message);
}
+ @Override
+ public void start() {
+ /*
+ * If a user is fast enough to click cancel, native_pairing_cancel can be invoked
+ * while native_pairing_start is running which run the destruction of the object
+ * while it is being constructed. Here we start the pairing server on foreground
+ * Thread so native_pairing_cancel can never be called concurrently. Then we let
+ * the pairing server run on a background Thread.
+ */
+ if (mGuid.isEmpty()) {
+ Slog.e(TAG, "adbwifi guid was not set");
+ return;
+ }
+ mPort = native_pairing_start(mGuid, mPairingCode);
+ if (mPort <= 0) {
+ Slog.e(TAG, "Unable to start pairing server");
+ return;
+ }
+
+ super.start();
+ }
+
public void cancelPairing() {
native_pairing_cancel();
}