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

Commit 2ce67257 authored by Roman Kiryanov's avatar Roman Kiryanov
Browse files

adb: replace `if(transportType==` with `switch(transportType)`



Use switch on transportType to provision
adding more enum cases. No behavior change.

Bug: 402444824
Test: adb still works
Flag: EXEMPT cleanup
Change-Id: I06dfa5162ca8697a9bdc24547495067df2b58087
Signed-off-by: default avatarRoman Kiryanov <rkir@google.com>
parent 33965ac0
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -53,13 +53,19 @@ public final class AdbNotifications {
        int titleId;
        int messageId;

        if (transportType == AdbTransportType.USB) {
        switch (transportType) {
            case AdbTransportType.USB:
                titleId = com.android.internal.R.string.adb_active_notification_title;
                messageId = com.android.internal.R.string.adb_active_notification_message;
        } else if (transportType == AdbTransportType.WIFI) {
                break;
            case AdbTransportType.WIFI:
                titleId = com.android.internal.R.string.adbwifi_active_notification_title;
                messageId = com.android.internal.R.string.adbwifi_active_notification_message;
        } else {
                break;
            case AdbTransportType.VSOCK:
                throw new IllegalArgumentException(
                        "AdbTransportType.VSOCK is not yet supported here");
            default:
                throw new IllegalArgumentException(
                        "createNotification called with unknown transport type=" + transportType);
        }
+63 −39
Original line number Diff line number Diff line
@@ -432,40 +432,58 @@ public class AdbDebuggingManager {
                    } else if (buffer[0] == 'W' && buffer[1] == 'E') {
                        byte transportType = buffer[2];
                        String key = new String(Arrays.copyOfRange(buffer, 3, count));
                        if (transportType == AdbTransportType.USB) {
                        switch (transportType) {
                            case AdbTransportType.USB: {
                                Slog.d(TAG, "Received USB TLS connected key message: " + key);
                                Message msg = mHandler.obtainMessage(
                                        AdbDebuggingHandler.MESSAGE_ADB_CONNECTED_KEY);
                                msg.obj = key;
                                mHandler.sendMessage(msg);
                        } else if (transportType == AdbTransportType.WIFI) {
                                break;
                            }
                            case AdbTransportType.WIFI: {
                                Slog.d(TAG, "Received WIFI TLS connected key message: " + key);
                                Message msg = mHandler.obtainMessage(
                                        AdbDebuggingHandler.MSG_WIFI_DEVICE_CONNECTED);
                                msg.obj = key;
                                mHandler.sendMessage(msg);
                        } else {
                            Slog.e(TAG, "Got unknown transport type from adbd (" + transportType
                                    + ")");
                                break;
                            }
                            case AdbTransportType.VSOCK:
                                Slog.e(TAG, "AdbTransportType.VSOCK is not yet supported here");
                                break;
                            default:
                                Slog.e(TAG, "Got unknown transport type from adbd ("
                                        + transportType + ")");
                                break;
                        }
                    } else if (buffer[0] == 'W' && buffer[1] == 'F') {
                        byte transportType = buffer[2];
                        String key = new String(Arrays.copyOfRange(buffer, 3, count));
                        if (transportType == AdbTransportType.USB) {
                        switch (transportType) {
                            case AdbTransportType.USB: {
                                Slog.d(TAG, "Received USB TLS disconnect message: " + key);
                                Message msg = mHandler.obtainMessage(
                                        AdbDebuggingHandler.MESSAGE_ADB_DISCONNECT);
                                msg.obj = key;
                                mHandler.sendMessage(msg);
                        } else if (transportType == AdbTransportType.WIFI) {
                                break;
                            }
                            case AdbTransportType.WIFI: {
                                Slog.d(TAG, "Received WIFI TLS disconnect key message: " + key);
                                Message msg = mHandler.obtainMessage(
                                        AdbDebuggingHandler.MSG_WIFI_DEVICE_DISCONNECTED);
                                msg.obj = key;
                                mHandler.sendMessage(msg);
                        } else {
                                break;
                            }
                            case AdbTransportType.VSOCK:
                                Slog.e(TAG, "AdbTransportType.VSOCK is not yet supported here");
                                break;
                            default:
                                Slog.e(TAG, "Got unknown transport type from adbd (" + transportType
                                        + ")");
                                break;
                        }
                    } else if (buffer[0] == 'T' && buffer[1] == 'P') {
                        if (count < 4) {
@@ -1595,13 +1613,19 @@ public class AdbDebuggingManager {
     * If all transport types are disabled, the ADB handler thread will shut down.
     */
    public void setAdbEnabled(boolean enabled, byte transportType) {
        if (transportType == AdbTransportType.USB) {
        switch (transportType) {
            case AdbTransportType.USB:
                mHandler.sendEmptyMessage(enabled ? AdbDebuggingHandler.MESSAGE_ADB_ENABLED
                                                  : AdbDebuggingHandler.MESSAGE_ADB_DISABLED);
        } else if (transportType == AdbTransportType.WIFI) {
                break;
            case AdbTransportType.WIFI:
                mHandler.sendEmptyMessage(enabled ? AdbDebuggingHandler.MSG_ADBDWIFI_ENABLE
                                                  : AdbDebuggingHandler.MSG_ADBDWIFI_DISABLE);
        } else {
                break;
            case AdbTransportType.VSOCK:
                throw new IllegalArgumentException(
                        "AdbTransportType.VSOCK is not yet supported here");
            default:
                throw new IllegalArgumentException(
                        "setAdbEnabled called with unimplemented transport type=" + transportType);
        }
+39 −22
Original line number Diff line number Diff line
@@ -122,14 +122,19 @@ public class AdbService extends IAdbManager.Stub {

        @Override
        public boolean isAdbEnabled(byte transportType) {
            if (transportType == AdbTransportType.USB) {
            switch (transportType) {
                case AdbTransportType.USB:
                    return mIsAdbUsbEnabled;
            } else if (transportType == AdbTransportType.WIFI) {
                case AdbTransportType.WIFI:
                    return mIsAdbWifiEnabled;
            }
                case AdbTransportType.VSOCK:
                    throw new IllegalArgumentException(
                            "AdbTransportType.VSOCK is not yet supported here");
                default:
                    throw new IllegalArgumentException(
                        "isAdbEnabled called with unimplemented transport type=" + transportType);
            }
        }

        @Override
        public File getAdbKeysFile() {
@@ -420,9 +425,17 @@ public class AdbService extends IAdbManager.Stub {
        Slog.d(TAG, "setAdbEnabled(" + enable + "), mIsAdbUsbEnabled=" + mIsAdbUsbEnabled
                 + ", mIsAdbWifiEnabled=" + mIsAdbWifiEnabled + ", transportType=" + transportType);

        if (transportType == AdbTransportType.USB && enable != mIsAdbUsbEnabled) {
        switch (transportType) {
            case AdbTransportType.USB:
                if (enable == mIsAdbUsbEnabled) {
                    return;
                }
                mIsAdbUsbEnabled = enable;
        } else if (transportType == AdbTransportType.WIFI && enable != mIsAdbWifiEnabled) {
                break;
            case AdbTransportType.WIFI:
                if (enable == mIsAdbWifiEnabled) {
                    return;
                }
                mIsAdbWifiEnabled = enable;
                if (mIsAdbWifiEnabled) {
                    // Start adb over WiFi.
@@ -433,8 +446,12 @@ public class AdbService extends IAdbManager.Stub {
                    SystemProperties.set(WIFI_PERSISTENT_CONFIG_PROPERTY, "0");
                    releaseMulticastLock();
                }
        } else {
            // No change
                break;
            case AdbTransportType.VSOCK:
                Slog.e(TAG, "AdbTransportType.VSOCK is not yet supported here");
                return;
            default:
                Slog.e(TAG, "Unknown transport type=" + transportType);
                return;
        }