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

Commit c7eb647a authored by Khoa Hong's avatar Khoa Hong Committed by Android (Google) Code Review
Browse files

Revert "adb: fix the initial adbd state in AdbService"

This reverts commit f9a05b68.

Reason for revert: Changing USB function (MTP/USB tethering/etc.) will make ADB stop working until reboot.

Bug: 402444824
Bug: 421811449
Bug: 422319426
Bug: 422348332
Change-Id: Ia8c97a59cc6b9dde75ad7ecd2b581e683dffe2d6
parent f9a05b68
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -235,13 +235,8 @@ public class AdbService extends IAdbManager.Stub {
    private final ContentResolver mContentResolver;
    private final ArrayMap<IBinder, IAdbTransport> mTransports = new ArrayMap<>();

    /*
     * mIsAdb*Enabled variables are owned by setAdbEnabled, do not write to them
     * directly: they track the adbd state from the AdbService perspective.
     */
    private boolean mIsAdbUsbEnabled;
    private boolean mIsAdbWifiEnabled;

    private final AdbDebuggingManager mDebuggingManager;

    private AdbSettingsObserver mObserver;
@@ -266,24 +261,21 @@ public class AdbService extends IAdbManager.Stub {
         * Use the normal bootmode persistent prop to maintain state of adb across
         * all boot modes.
         */
        final boolean shouldEnableAdbUsb =
                containsFunction(SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, ""),
                                 UsbManager.USB_FUNCTION_ADB)
        mIsAdbUsbEnabled = containsFunction(
                SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, ""),
                UsbManager.USB_FUNCTION_ADB);
        boolean shouldEnableAdbUsb = mIsAdbUsbEnabled
                || SystemProperties.getBoolean(
                        TestHarnessModeService.TEST_HARNESS_MODE_PROPERTY, false);

        final boolean shouldEnableAdbWifi = "1".equals(
        mIsAdbWifiEnabled = "1".equals(
                SystemProperties.get(WIFI_PERSISTENT_CONFIG_PROPERTY, "0"));

        // These writes will trigger AdbSettingsObserver which will call setAdbEnabled.
        // make sure the ADB_ENABLED setting value matches the current state
        try {
            if (shouldEnableAdbUsb) {
                Settings.Global.putInt(mContentResolver, Settings.Global.ADB_ENABLED, 1);
            }

            if (shouldEnableAdbWifi) {
                Settings.Global.putInt(mContentResolver, Settings.Global.ADB_WIFI_ENABLED, 1);
            }
            Settings.Global.putInt(mContentResolver,
                    Settings.Global.ADB_ENABLED, shouldEnableAdbUsb ? 1 : 0);
            Settings.Global.putInt(mContentResolver,
                    Settings.Global.ADB_WIFI_ENABLED, mIsAdbWifiEnabled ? 1 : 0);
        } catch (SecurityException e) {
            // If UserManager.DISALLOW_DEBUGGING_FEATURES is on, that this setting can't be changed.
            Slog.d(TAG, "ADB_ENABLED is restricted.");
@@ -295,6 +287,8 @@ public class AdbService extends IAdbManager.Stub {
     */
    public void bootCompleted() {
        Slog.d(TAG, "boot completed");
        mDebuggingManager.setAdbEnabled(mIsAdbUsbEnabled, AdbTransportType.USB);
        mDebuggingManager.setAdbEnabled(mIsAdbWifiEnabled, AdbTransportType.WIFI);
    }

    @Override