Loading services/usb/java/com/android/server/usb/UsbDeviceManager.java +21 −18 Original line number Original line Diff line number Diff line Loading @@ -337,14 +337,12 @@ public class UsbDeviceManager { // Restore default functions. // Restore default functions. mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY, mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE); UsbManager.USB_FUNCTION_NONE); if (UsbManager.USB_FUNCTION_NONE.equals(mCurrentFunctions)) { mCurrentFunctions = UsbManager.USB_FUNCTION_MTP; } mCurrentFunctionsApplied = mCurrentFunctions.equals( mCurrentFunctionsApplied = mCurrentFunctions.equals( SystemProperties.get(USB_STATE_PROPERTY)); SystemProperties.get(USB_STATE_PROPERTY)); mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(), mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(), UsbManager.USB_FUNCTION_ADB); UsbManager.USB_FUNCTION_ADB); setEnabledFunctions(null, false); setEnabledFunctions(null, false, false); String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); updateState(state); updateState(state); Loading Loading @@ -452,17 +450,24 @@ public class UsbDeviceManager { if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (enable != mAdbEnabled) { if (enable != mAdbEnabled) { mAdbEnabled = enable; mAdbEnabled = enable; String oldFunctions = mCurrentFunctions; // Persist the adb setting String newFunction = applyAdbFunction(SystemProperties.get( USB_PERSISTENT_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE)); SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY, newFunction); // Due to the persist.sys.usb.config property trigger, changing adb state requires // Changing the persistent config also changes the normal // persisting default function // config. Wait for this to happen before changing again. String oldFunctions = getDefaultFunctions(); waitForState(newFunction); String newFunctions = applyAdbFunction(oldFunctions); if (!oldFunctions.equals(newFunctions)) { // Remove mtp from the config if file transfer is not enabled SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY, newFunctions); if (oldFunctions.equals(UsbManager.USB_FUNCTION_MTP) && !mUsbDataUnlocked && enable) { oldFunctions = UsbManager.USB_FUNCTION_NONE; } } // After persisting them use the lock-down aware function set setEnabledFunctions(oldFunctions, false, mUsbDataUnlocked); setEnabledFunctions(mCurrentFunctions, false); updateAdbNotification(); updateAdbNotification(); } } Loading @@ -474,7 +479,8 @@ public class UsbDeviceManager { /** /** * Evaluates USB function policies and applies the change accordingly. * Evaluates USB function policies and applies the change accordingly. */ */ private void setEnabledFunctions(String functions, boolean forceRestart) { private void setEnabledFunctions(String functions, boolean forceRestart, boolean usbDataUnlocked) { if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " + "forceRestart=" + forceRestart); + "forceRestart=" + forceRestart); Loading Loading @@ -514,7 +520,8 @@ public class UsbDeviceManager { } } private boolean trySetEnabledFunctions(String functions, boolean forceRestart) { private boolean trySetEnabledFunctions(String functions, boolean forceRestart) { if (functions == null) { if (functions == null || applyAdbFunction(functions) .equals(UsbManager.USB_FUNCTION_NONE)) { functions = getDefaultFunctions(); functions = getDefaultFunctions(); } } functions = applyAdbFunction(functions); functions = applyAdbFunction(functions); Loading Loading @@ -596,10 +603,6 @@ public class UsbDeviceManager { if (mBroadcastedIntent == null) { if (mBroadcastedIntent == null) { for (String key : keySet) { for (String key : keySet) { if (intent.getBooleanExtra(key, false)) { if (intent.getBooleanExtra(key, false)) { // MTP function is enabled by default. if (UsbManager.USB_FUNCTION_MTP.equals(key)) { continue; } return true; return true; } } } } Loading Loading
services/usb/java/com/android/server/usb/UsbDeviceManager.java +21 −18 Original line number Original line Diff line number Diff line Loading @@ -337,14 +337,12 @@ public class UsbDeviceManager { // Restore default functions. // Restore default functions. mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY, mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE); UsbManager.USB_FUNCTION_NONE); if (UsbManager.USB_FUNCTION_NONE.equals(mCurrentFunctions)) { mCurrentFunctions = UsbManager.USB_FUNCTION_MTP; } mCurrentFunctionsApplied = mCurrentFunctions.equals( mCurrentFunctionsApplied = mCurrentFunctions.equals( SystemProperties.get(USB_STATE_PROPERTY)); SystemProperties.get(USB_STATE_PROPERTY)); mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(), mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(), UsbManager.USB_FUNCTION_ADB); UsbManager.USB_FUNCTION_ADB); setEnabledFunctions(null, false); setEnabledFunctions(null, false, false); String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim(); updateState(state); updateState(state); Loading Loading @@ -452,17 +450,24 @@ public class UsbDeviceManager { if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (enable != mAdbEnabled) { if (enable != mAdbEnabled) { mAdbEnabled = enable; mAdbEnabled = enable; String oldFunctions = mCurrentFunctions; // Persist the adb setting String newFunction = applyAdbFunction(SystemProperties.get( USB_PERSISTENT_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE)); SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY, newFunction); // Due to the persist.sys.usb.config property trigger, changing adb state requires // Changing the persistent config also changes the normal // persisting default function // config. Wait for this to happen before changing again. String oldFunctions = getDefaultFunctions(); waitForState(newFunction); String newFunctions = applyAdbFunction(oldFunctions); if (!oldFunctions.equals(newFunctions)) { // Remove mtp from the config if file transfer is not enabled SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY, newFunctions); if (oldFunctions.equals(UsbManager.USB_FUNCTION_MTP) && !mUsbDataUnlocked && enable) { oldFunctions = UsbManager.USB_FUNCTION_NONE; } } // After persisting them use the lock-down aware function set setEnabledFunctions(oldFunctions, false, mUsbDataUnlocked); setEnabledFunctions(mCurrentFunctions, false); updateAdbNotification(); updateAdbNotification(); } } Loading @@ -474,7 +479,8 @@ public class UsbDeviceManager { /** /** * Evaluates USB function policies and applies the change accordingly. * Evaluates USB function policies and applies the change accordingly. */ */ private void setEnabledFunctions(String functions, boolean forceRestart) { private void setEnabledFunctions(String functions, boolean forceRestart, boolean usbDataUnlocked) { if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " + "forceRestart=" + forceRestart); + "forceRestart=" + forceRestart); Loading Loading @@ -514,7 +520,8 @@ public class UsbDeviceManager { } } private boolean trySetEnabledFunctions(String functions, boolean forceRestart) { private boolean trySetEnabledFunctions(String functions, boolean forceRestart) { if (functions == null) { if (functions == null || applyAdbFunction(functions) .equals(UsbManager.USB_FUNCTION_NONE)) { functions = getDefaultFunctions(); functions = getDefaultFunctions(); } } functions = applyAdbFunction(functions); functions = applyAdbFunction(functions); Loading Loading @@ -596,10 +603,6 @@ public class UsbDeviceManager { if (mBroadcastedIntent == null) { if (mBroadcastedIntent == null) { for (String key : keySet) { for (String key : keySet) { if (intent.getBooleanExtra(key, false)) { if (intent.getBooleanExtra(key, false)) { // MTP function is enabled by default. if (UsbManager.USB_FUNCTION_MTP.equals(key)) { continue; } return true; return true; } } } } Loading