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

Commit 4ace1668 authored by Roman Kiryanov's avatar Roman Kiryanov
Browse files

adb: fix the initial adbd state in AdbService



AdbService::systemReady used to set mIsAdbUsbEnabled
and mIsAdbWifiEnabled without starting adbd
explicitly. In the rest of the file these variables
means that adbd is already started and writing
to these variables without starting adbd breaks
the invariant.

mIsAdbUsbEnabled and mIsAdbWifiEnabled will be set
through AdbSettingsObserver in setAdbEnabled.
mDebuggingManager.setAdbEnabled will also be
called there.

Bug: 402444824
Test: * flashed a user build into Pixel 9a
      * enabled USB debugging
      * ran `adb shell getprop ro.build.fingerprint`
      * rebooted Pixel 9a
      * ran `adb shell getprop ro.build.fingerprint`
Flag: EXEMPT cleanup
Change-Id: I449c3c5f364860c3d6bae86f973f59eba5920139
Signed-off-by: default avatarRoman Kiryanov <rkir@google.com>
parent 437af864
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -242,21 +242,19 @@ public class AdbService extends IAdbManager.Stub {
         * Use the normal bootmode persistent prop to maintain state of adb across
         * all boot modes.
         */
        mIsAdbUsbEnabled = containsFunction(
                SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, ""),
                UsbManager.USB_FUNCTION_ADB);
        boolean shouldEnableAdbUsb = mIsAdbUsbEnabled
                || SystemProperties.getBoolean(
                        TestHarnessModeService.TEST_HARNESS_MODE_PROPERTY, false);
        mIsAdbWifiEnabled = "1".equals(
        final boolean shouldEnableAdbUsb =
                containsFunction(SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, ""),
                                 UsbManager.USB_FUNCTION_ADB)
                || SystemProperties.getBoolean(TestHarnessModeService.TEST_HARNESS_MODE_PROPERTY,
                                               false);
        final boolean shouldEnableAdbWifi = "1".equals(
                SystemProperties.get(WIFI_PERSISTENT_CONFIG_PROPERTY, "0"));

        // make sure the ADB_ENABLED setting value matches the current state
        try {
            Settings.Global.putInt(mContentResolver,
                    Settings.Global.ADB_ENABLED, shouldEnableAdbUsb ? 1 : 0);
            Settings.Global.putInt(mContentResolver,
                    Settings.Global.ADB_WIFI_ENABLED, mIsAdbWifiEnabled ? 1 : 0);
                    Settings.Global.ADB_WIFI_ENABLED, shouldEnableAdbWifi ? 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.");
@@ -268,8 +266,6 @@ 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