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

Commit 7790e3ea authored by Fabien Sanglard's avatar Fabien Sanglard
Browse files

Wifi lifecycle message ADBd/Framework over adbdauth

Start/Stop and send TLS port using libadbdauth instead of system
properties/listener (which are prompt to race conditions).

Test: CI covered
Bug: 414682912
Flag: com.android.adbdauth.flags.use_tls_lifecycle

Change-Id: I9e498c80e277bfc01142459395e1d16dc83a3101
parent 4a2b1bfc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -249,6 +249,7 @@ java_library_static {
        "uprobestats_flags_java_lib",
        "clipboard_flags_lib",
        "signal_collector_flags_lib",
        "aconfig_adbdauth_flags_java_lib",
    ],
    javac_shard_size: 50,
    javacflags: [
+38 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
@@ -63,6 +64,7 @@ import android.text.TextUtils;
import android.util.Base64;
import android.util.Slog;

import com.android.adbdauth.flags.Flags;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
@@ -190,6 +192,12 @@ public class AdbDebuggingManager {
    }

    private void startTLSPortPoller() {
        if (wifiLifeCycleOverAdbdauthSupported()) {
            Slog.d(TAG, "Expecting tls port from adbdauth");
            return;
        }

        Slog.d(TAG, "Expecting tls port from ADB Wifi connection poller");
        mConnectionPortPoller =
                new AdbConnectionPortPoller(
                        port -> {
@@ -448,6 +456,26 @@ public class AdbDebuggingManager {
        }
    }

    // We need to know if ADBd will have access to the version of adbdauth which allows
    // to send ADB Wifi TSL port and ADBWifi lifecycle management over methods.
    private static boolean wifiLifeCycleOverAdbdauthSupported() {
        return Flags.useTlsLifecycle()
                && (Build.VERSION.SDK_INT >= 37
                        || (Build.VERSION.SDK_INT == 36 && isAtLeastPreReleaseCodename("Baklava")));
    }

    // This should only be used with NDK APIs because the NDK lacks flagging support.
    private static boolean isAtLeastPreReleaseCodename(@NonNull String codename) {
        // Special case "REL", which means the build is not a pre-release build.
        if ("REL".equals(Build.VERSION.CODENAME)) {
            return false;
        }

        // Otherwise lexically compare them. Return true if the build codename is equal to or
        // greater than the requested codename.
        return Build.VERSION.CODENAME.compareTo(codename) >= 0;
    }

    class AdbDebuggingHandler extends Handler {
        private NotificationManager mNotificationManager;
        private boolean mAdbNotificationShown;
@@ -605,12 +633,20 @@ public class AdbDebuggingManager {
        }

        private void startAdbdWifi() {
            if (wifiLifeCycleOverAdbdauthSupported()) {
                mThread.sendResponse(MSG_START_ADB_WIFI);
            } else {
                AdbService.enableADBdWifi();
            }
        }

        private void stopAdbdWifi() {
            if (wifiLifeCycleOverAdbdauthSupported()) {
                mThread.sendResponse(MSG_STOP_ADB_WIFI);
            } else {
                AdbService.disableADBdWifi();
            }
        }

        // AdbService/AdbDebuggingManager are always created but we only start the connection
        // with adbd thread when it is actually needed.