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

Commit ee18f669 authored by Jerry Zhang's avatar Jerry Zhang Committed by Android (Google) Code Review
Browse files

Merge changes from topics 'usb_bugfixes', 'usb_bugfixes2'

* changes:
  Revert: Remove the kick from config switches in UsbDeviceManager
  Clean up persistent usb state on boot.
parents 860297b9 2d2346e0
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -352,6 +352,16 @@ public class UsbDeviceManager {
                mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(),
                        UsbManager.USB_FUNCTION_ADB);

                /**
                 * Remove MTP from persistent config, to bring usb to a good state
                 * after fixes to b/31814300. This block can be removed after the update
                 */
                String persisted = SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY);
                if (UsbManager.containsFunction(persisted, UsbManager.USB_FUNCTION_MTP)) {
                    SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY,
                            UsbManager.removeFunction(persisted, UsbManager.USB_FUNCTION_MTP));
                }

                String buildType = SystemProperties.get(BUILD_TYPE_PROPERTY);
                if (buildType.equals(BUILD_TYPE_USERDEBUG) || buildType.equals(BUILD_TYPE_ENG)) {
                    setAdbEnabled(true);
@@ -472,17 +482,13 @@ public class UsbDeviceManager {
                            USB_PERSISTENT_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE));
                SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY, newFunction);

                // Changing the persistent config also changes the normal
                // config. Wait for this to happen before changing again.
                waitForState(newFunction);

                // Remove mtp from the config if file transfer is not enabled
                if (oldFunctions.equals(UsbManager.USB_FUNCTION_MTP) && 
                        !mUsbDataUnlocked && enable) {
                    oldFunctions = UsbManager.USB_FUNCTION_NONE;
                }

                setEnabledFunctions(oldFunctions, false, mUsbDataUnlocked);
                setEnabledFunctions(oldFunctions, true, mUsbDataUnlocked);
                updateAdbNotification();
            }

@@ -554,6 +560,9 @@ public class UsbDeviceManager {
                mCurrentFunctions = functions;
                mCurrentFunctionsApplied = false;

                // Kick the USB stack to close existing connections.
                setUsbConfig(UsbManager.USB_FUNCTION_NONE);

                // Set the new USB configuration.
                if (!setUsbConfig(functions)) {
                    Slog.e(TAG, "Failed to switch USB config to " + functions);