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

Commit 51ad097a authored by Fabien Sanglard's avatar Fabien Sanglard
Browse files

Use libadb_auth to start/stop adbd wifi

Problem: There is a race condition between AdbService and adbd.
AdbService starts adbd wifi using a system property. Depending how fast
adbd responds, the TLS server can be up before AdbDebuggingManager had
a chance to toggle off ADB Wifi (if user has no granted access to the
current Wifi network.

Solution: Leverage libadb_auth to send message from AdbService to adbd.
This allows AdbService to start adbd wifi only after user has granted
access.

Test: Manual
Bug: 414682912
Flag: EXEMPT (Bug fix)
Change-Id: I0228f9e3480a0a229a51ff72f08f44ad7bb9ed87
parent 9d868b25
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -543,6 +543,8 @@ public class AdbDebuggingManager {
            }
        }

        // TODO: Change the name of this method. This is not always a response. It should be called
        // sendMessage.
        void sendResponse(String msg) {
            synchronized (this) {
                Slog.d(TAG, "Send packet " + msg);
@@ -772,6 +774,8 @@ public class AdbDebuggingManager {

        // === Messages we can send to adbd ===========
        static final String MSG_DISCONNECT_DEVICE = "DD";
        static final String MSG_START_ADB_WIFI = "W1";
        static final String MSG_STOP_ADB_WIFI = "W0";

        @Nullable @VisibleForTesting AdbKeyStore mAdbKeyStore;

@@ -822,6 +826,18 @@ public class AdbDebuggingManager {
            }
        }

        private void startAdbdWifi() {
            if (mThread != null) {
                mThread.sendResponse(MSG_START_ADB_WIFI);
            }
        }

        private void stopAdbdWifi() {
            if (mThread != null) {
                mThread.sendResponse(MSG_STOP_ADB_WIFI);
            }
        }

        private void startAdbDebuggingThread() {
            ++mAdbEnabledRefCount;
            Slog.i(TAG, "startAdbDebuggingThread ref=" + mAdbEnabledRefCount);
@@ -1058,9 +1074,9 @@ public class AdbDebuggingManager {
                    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
                    mContext.registerReceiver(mBroadcastReceiver, intentFilter);

                    SystemProperties.set(AdbService.WIFI_PERSISTENT_CONFIG_PROPERTY, "1");

                    startAdbDebuggingThread();
                    startAdbdWifi();
                    mAdbWifiEnabled = true;

                    Slog.i(TAG, "adb start wireless adb");
@@ -1074,6 +1090,8 @@ public class AdbDebuggingManager {
                    setAdbConnectionInfo(null);
                    mContext.unregisterReceiver(mBroadcastReceiver);

                    stopAdbdWifi();

                    onAdbdWifiServerDisconnected(-1);
                    stopAdbDebuggingThread();
                    break;
@@ -1102,9 +1120,8 @@ public class AdbDebuggingManager {
                    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
                    mContext.registerReceiver(mBroadcastReceiver, intentFilter);

                    SystemProperties.set(AdbService.WIFI_PERSISTENT_CONFIG_PROPERTY, "1");

                    startAdbDebuggingThread();
                    startAdbdWifi();
                    mAdbWifiEnabled = true;

                    Slog.i(TAG, "adb start wireless adb");
+6 −1
Original line number Diff line number Diff line
@@ -210,7 +210,12 @@ public class AdbService extends IAdbManager.Stub {
     * May also contain vendor-specific default functions for testing purposes.
     */
    private static final String USB_PERSISTENT_CONFIG_PROPERTY = "persist.sys.usb.config";
    static final String WIFI_PERSISTENT_CONFIG_PROPERTY = "persist.adb.tls_server.enable";

    /**
     * The system property used by both framework and adbd to set if ADB Wifi should be enabled
     * when either system starts up.
     */
    private static final String WIFI_PERSISTENT_CONFIG_PROPERTY = "persist.adb.tls_server.enable";

    private final Context mContext;
    private final ContentResolver mContentResolver;