From bfc5d563aa19912e2ab103d04329419e8cec6fb2 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Mon, 17 Oct 2016 17:37:13 -0700 Subject: [PATCH] Clean up persistent usb state on boot. b/31814300 was fixed, but mtp can still stick around in the persistent config even after flashing. This block of code will only run once, but will ensure that mtp is not in the config after the update. Bug: 31814300 Test: Manual Change-Id: Icf02be38c9e1f769412ac963ed6afc14e6092bfb (cherry-picked from commit a45dac0e83f4f907b6b42f453181a7d5c01f65f3) --- .../usb/java/com/android/server/usb/UsbDeviceManager.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java index 2132cd317b43..3bfc47a05c1c 100644 --- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java @@ -342,6 +342,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)); + } + setEnabledFunctions(null, false); String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); @@ -457,10 +467,6 @@ 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) { -- 2.11.0