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

Commit ac29885a authored by Joshua Duong's avatar Joshua Duong Committed by Nikita Ioffe
Browse files

Allow UsbDeviceManager to start adbd again.

There's some weird state where if persist.sys.usb.config=none,adb, then
adbd won't get started. Give back adbd start permissions to
UsbDeviceManager to see if that fixes the issue.

Bug: 150130503
Bug: 150116813

Test: adb shell su 0 setprop persist.sys.usb.config none,adb; adb reboot
adb should be online after.

Change-Id: I36c6ef4b20d58570a2d51ed70088ae5c54d6687d
Exempt-From-Owner-Approval: Fix adbd offline failure
(cherry picked from commit 7a380099)
parent 6f01c62d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -53,4 +53,14 @@ public abstract class AdbManagerInternal {
     * Returns the file that contains all of the ADB keys and their last used time.
     */
    public abstract File getAdbTempKeysFile();

    /**
     * Starts adbd for a transport.
     */
    public abstract void startAdbdForTransport(byte transportType);

    /**
     * Stops adbd for a transport.
     */
    public abstract void stopAdbdForTransport(byte transportType);
}
+25 −0
Original line number Diff line number Diff line
@@ -144,6 +144,18 @@ public class AdbService extends IAdbManager.Stub {
        public File getAdbTempKeysFile() {
            return mDebuggingManager.getAdbTempKeysFile();
        }

        @Override
        public void startAdbdForTransport(byte transportType) {
            FgThread.getHandler().sendMessage(obtainMessage(
                    AdbService::setAdbdEnabledForTransport, AdbService.this, true, transportType));
        }

        @Override
        public void stopAdbdForTransport(byte transportType) {
            FgThread.getHandler().sendMessage(obtainMessage(
                    AdbService::setAdbdEnabledForTransport, AdbService.this, false, transportType));
        }
    }

    private void initAdbState() {
@@ -437,6 +449,19 @@ public class AdbService extends IAdbManager.Stub {
        }
    }

    private void setAdbdEnabledForTransport(boolean enable, byte transportType) {
        if (transportType == AdbTransportType.USB) {
            mIsAdbUsbEnabled = enable;
        } else if (transportType == AdbTransportType.WIFI) {
            mIsAdbWifiEnabled = enable;
        }
        if (enable) {
            startAdbd();
        } else {
            stopAdbd();
        }
    }

    private void setAdbEnabled(boolean enable, byte transportType) {
        if (DEBUG) {
            Slog.d(TAG, "setAdbEnabled(" + enable + "), mIsAdbUsbEnabled=" + mIsAdbUsbEnabled
+13 −1
Original line number Diff line number Diff line
@@ -1917,7 +1917,19 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                    return;
                }
                try {
                    // Adbd will be started by AdbService once Global.ADB_ENABLED is set.
                    if ((config & UsbManager.FUNCTION_ADB) != 0) {
                        /**
                         * Start adbd if ADB function is included in the configuration.
                         */
                        LocalServices.getService(AdbManagerInternal.class)
                                .startAdbdForTransport(AdbTransportType.USB);
                    } else {
                        /**
                         * Stop adbd otherwise
                         */
                        LocalServices.getService(AdbManagerInternal.class)
                                .stopAdbdForTransport(AdbTransportType.USB);
                    }
                    UsbGadgetCallback usbGadgetCallback = new UsbGadgetCallback(mCurrentRequest,
                            config, chargingFunctions);
                    mGadgetProxy.setCurrentUsbFunctions(config, usbGadgetCallback,