Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a21ab8dd authored by zhuning3's avatar zhuning3 Committed by ning zhu
Browse files

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: default avatarzhuning3 <zhuning3@xiaomi.corp-partner.google.com>
parent c40bde3f
Loading
Loading
Loading
Loading
+22 −10
Original line number Original line Diff line number Diff line
@@ -246,16 +246,6 @@ public class AdbDebuggingManager {


        @Override
        @Override
        public void run() {
        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
            // Register the mdns service
            NsdServiceInfo serviceInfo = new NsdServiceInfo();
            NsdServiceInfo serviceInfo = new NsdServiceInfo();
            serviceInfo.setServiceName(mServiceName);
            serviceInfo.setServiceName(mServiceName);
@@ -288,6 +278,28 @@ public class AdbDebuggingManager {
            mHandler.sendMessage(message);
            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() {
        public void cancelPairing() {
            native_pairing_cancel();
            native_pairing_cancel();
        }
        }