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

Commit f17f41d8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Allow enabling Adb logging dynamically" into main am: d1b89c0c

parents ede91dfc d1b89c0c
Loading
Loading
Loading
Loading
+19 −23
Original line number Diff line number Diff line
@@ -130,8 +130,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 */
public class AdbDebuggingManager {
    private static final String TAG = AdbDebuggingManager.class.getSimpleName();
    private static final boolean DEBUG = false;
    private static final boolean MDNS_DEBUG = false;

    private static final String ADBD_SOCKET = "adbd";
    private static final String ADB_DIRECTORY = "misc/adb";
@@ -261,13 +259,11 @@ public class AdbDebuggingManager {
            mHandler.sendMessage(msg);

            boolean paired = native_pairing_wait();
            if (DEBUG) {
            if (mPublicKey != null) {
                Slog.i(TAG, "Pairing succeeded key=" + mPublicKey);
            } else {
                Slog.i(TAG, "Pairing failed");
            }
            }

            mNsdManager.unregisterService(this);

@@ -307,7 +303,7 @@ public class AdbDebuggingManager {

        @Override
        public void onServiceRegistered(NsdServiceInfo serviceInfo) {
            if (MDNS_DEBUG) Slog.i(TAG, "Registered pairing service: " + serviceInfo);
            Slog.i(TAG, "Registered pairing service: " + serviceInfo);
        }

        @Override
@@ -319,7 +315,7 @@ public class AdbDebuggingManager {

        @Override
        public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
            if (MDNS_DEBUG) Slog.i(TAG, "Unregistered pairing service: " + serviceInfo);
            Slog.i(TAG, "Unregistered pairing service: " + serviceInfo);
        }

        @Override
@@ -354,7 +350,7 @@ public class AdbDebuggingManager {

        @Override
        public void run() {
            if (DEBUG) Slog.d(TAG, "Starting adb port property poller");
            Slog.d(TAG, "Starting adb port property poller");
            // Once adbwifi is enabled, we poll the service.adb.tls.port
            // system property until we get the port, or -1 on failure.
            // Let's also limit the polling to 10 seconds, just in case
@@ -390,7 +386,7 @@ public class AdbDebuggingManager {

    class PortListenerImpl implements AdbConnectionPortListener {
        public void onPortReceived(int port) {
            if (DEBUG) Slog.d(TAG, "Received tls port=" + port);
            Slog.d(TAG, "Received tls port=" + port);
            Message msg = mHandler.obtainMessage(port > 0
                     ? AdbDebuggingHandler.MSG_SERVER_CONNECTED
                     : AdbDebuggingHandler.MSG_SERVER_DISCONNECTED);
@@ -419,11 +415,11 @@ public class AdbDebuggingManager {

        @Override
        public void run() {
            if (DEBUG) Slog.d(TAG, "Entering thread");
            Slog.d(TAG, "Entering thread");
            while (true) {
                synchronized (this) {
                    if (mStopped) {
                        if (DEBUG) Slog.d(TAG, "Exiting thread");
                        Slog.d(TAG, "Exiting thread");
                        return;
                    }
                    try {
@@ -448,7 +444,7 @@ public class AdbDebuggingManager {
                        LocalSocketAddress.Namespace.RESERVED);
                mInputStream = null;

                if (DEBUG) Slog.d(TAG, "Creating socket");
                Slog.d(TAG, "Creating socket");
                mSocket = new LocalSocket(LocalSocket.SOCKET_SEQPACKET);
                mSocket.connect(address);

@@ -549,7 +545,7 @@ public class AdbDebuggingManager {
        }

        private void closeSocketLocked() {
            if (DEBUG) Slog.d(TAG, "Closing socket");
            Slog.d(TAG, "Closing socket");
            try {
                if (mOutputStream != null) {
                    mOutputStream.close();
@@ -859,7 +855,7 @@ public class AdbDebuggingManager {

        private void startAdbDebuggingThread() {
            ++mAdbEnabledRefCount;
            if (DEBUG) Slog.i(TAG, "startAdbDebuggingThread ref=" + mAdbEnabledRefCount);
            Slog.i(TAG, "startAdbDebuggingThread ref=" + mAdbEnabledRefCount);
            if (mAdbEnabledRefCount > 1) {
                return;
            }
@@ -875,7 +871,7 @@ public class AdbDebuggingManager {

        private void stopAdbDebuggingThread() {
            --mAdbEnabledRefCount;
            if (DEBUG) Slog.i(TAG, "stopAdbDebuggingThread ref=" + mAdbEnabledRefCount);
            Slog.i(TAG, "stopAdbDebuggingThread ref=" + mAdbEnabledRefCount);
            if (mAdbEnabledRefCount > 0) {
                return;
            }
@@ -1101,7 +1097,7 @@ public class AdbDebuggingManager {
                    startAdbDebuggingThread();
                    mAdbWifiEnabled = true;

                    if (DEBUG) Slog.i(TAG, "adb start wireless adb");
                    Slog.i(TAG, "adb start wireless adb");
                    break;
                }
                case MSG_ADBDWIFI_DISABLE:
@@ -1151,7 +1147,7 @@ public class AdbDebuggingManager {
                    startAdbDebuggingThread();
                    mAdbWifiEnabled = true;

                    if (DEBUG) Slog.i(TAG, "adb start wireless adb");
                    Slog.i(TAG, "adb start wireless adb");
                    break;
                case MSG_ADBWIFI_DENY:
                    Settings.Global.putInt(mContentResolver,
@@ -1259,7 +1255,7 @@ public class AdbDebuggingManager {
                    break;
                }
                case MSG_ADBD_SOCKET_CONNECTED: {
                    if (DEBUG) Slog.d(TAG, "adbd socket connected");
                    Slog.d(TAG, "adbd socket connected");
                    if (mAdbWifiEnabled) {
                        // In scenarios where adbd is restarted, the tls port may change.
                        mConnectionPortPoller =
@@ -1269,7 +1265,7 @@ public class AdbDebuggingManager {
                    break;
                }
                case MSG_ADBD_SOCKET_DISCONNECTED: {
                    if (DEBUG) Slog.d(TAG, "adbd socket disconnected");
                    Slog.d(TAG, "adbd socket disconnected");
                    if (mConnectionPortPoller != null) {
                        mConnectionPortPoller.cancelAndWait();
                        mConnectionPortPoller = null;
@@ -1477,7 +1473,7 @@ public class AdbDebuggingManager {
        }

        private void updateUIPairCode(String code) {
            if (DEBUG) Slog.i(TAG, "updateUIPairCode: " + code);
            Slog.i(TAG, "updateUIPairCode: " + code);

            Intent intent = new Intent(AdbManager.WIRELESS_DEBUG_PAIRING_RESULT_ACTION);
            intent.putExtra(AdbManager.WIRELESS_PAIRING_CODE_EXTRA, code);
+11 −25
Original line number Diff line number Diff line
@@ -222,8 +222,7 @@ public class AdbService extends IAdbManager.Stub {
        }
    }

    private static final String TAG = "AdbService";
    private static final boolean DEBUG = false;
    private static final String TAG = AdbService.class.getSimpleName();

    /**
     * The persistent property which stores whether adb is enabled or not.
@@ -256,7 +255,7 @@ public class AdbService extends IAdbManager.Stub {
     * SystemServer}.
     */
    public void systemReady() {
        if (DEBUG) Slog.d(TAG, "systemReady");
        Slog.d(TAG, "systemReady");

        /*
         * Use the normal bootmode persistent prop to maintain state of adb across
@@ -287,7 +286,7 @@ public class AdbService extends IAdbManager.Stub {
     * Called in response to {@code SystemService.PHASE_BOOT_COMPLETED} from {@code SystemServer}.
     */
    public void bootCompleted() {
        if (DEBUG) Slog.d(TAG, "boot completed");
        Slog.d(TAG, "boot completed");
        if (mDebuggingManager != null) {
            mDebuggingManager.setAdbEnabled(mIsAdbUsbEnabled, AdbTransportType.USB);
            mDebuggingManager.setAdbEnabled(mIsAdbWifiEnabled, AdbTransportType.WIFI);
@@ -429,17 +428,13 @@ public class AdbService extends IAdbManager.Stub {

    @Override
    public void registerCallback(IAdbCallback callback) throws RemoteException {
        if (DEBUG) {
        Slog.d(TAG, "Registering callback " + callback);
        }
        mCallbacks.register(callback);
    }

    @Override
    public void unregisterCallback(IAdbCallback callback) throws RemoteException {
        if (DEBUG) {
        Slog.d(TAG, "Unregistering callback " + callback);
        }
        mCallbacks.unregister(callback);
    }
    /**
@@ -500,11 +495,8 @@ public class AdbService extends IAdbManager.Stub {
    }

    private void setAdbEnabled(boolean enable, byte transportType) {
        if (DEBUG) {
        Slog.d(TAG, "setAdbEnabled(" + enable + "), mIsAdbUsbEnabled=" + mIsAdbUsbEnabled
                    + ", mIsAdbWifiEnabled=" + mIsAdbWifiEnabled + ", transportType="
                        + transportType);
        }
                 + ", mIsAdbWifiEnabled=" + mIsAdbWifiEnabled + ", transportType=" + transportType);

        if (transportType == AdbTransportType.USB && enable != mIsAdbUsbEnabled) {
            mIsAdbUsbEnabled = enable;
@@ -549,20 +541,14 @@ public class AdbService extends IAdbManager.Stub {
            mDebuggingManager.setAdbEnabled(enable, transportType);
        }

        if (DEBUG) {
        Slog.d(TAG, "Broadcasting enable = " + enable + ", type = " + transportType);
        }
        mCallbacks.broadcast((callback) -> {
            if (DEBUG) {
                Slog.d(TAG, "Sending enable = " + enable + ", type = " + transportType
                        + " to " + callback);
            }
            Slog.d(TAG, "Sending enable = " + enable + ", type = " + transportType + " to "
                    + callback);
            try {
                callback.onDebuggingChanged(enable, transportType);
            } catch (RemoteException ex) {
                if (DEBUG) {
                    Slog.d(TAG, "Unable to send onDebuggingChanged:", ex);
                }
                Slog.w(TAG, "Unable to send onDebuggingChanged:", ex);
            }
        });
    }