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

Commit 6fbfa148 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "adb: fix the initial adbd state in AdbService"" into main

parents a095f402 c7eb647a
Loading
Loading
Loading
Loading
+12 −18
Original line number Diff line number Diff line
@@ -217,13 +217,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 ContentObserver mObserver;
@@ -248,24 +243,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.");
@@ -277,6 +269,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