在frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java类中的finishBoot()函数中修改setEnabledFunctions(UsbManager.FUNCTION_NONE, false);改为setEnabledFunctions(UsbManager.FUNCTION_MTP, false);即可
18、Android9.0修改默认usb为MTP模式,方法如下:
diff --git a/frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 78e91ef..923509c 100644
--- a/frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -824,7 +824,7 @@ public class UsbDeviceManager implements ActivityManagerInternal.ScreenObserver
&& mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
setScreenUnlockedFunctions();
} else {
- setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
+ setEnabledFunctions(UsbManager.FUNCTION_MTP, false);
}
}
updateUsbFunctions();
@@ -1012,7 +1012,9 @@ public class UsbDeviceManager implements ActivityManagerInternal.ScreenObserver
&& mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
setScreenUnlockedFunctions();
} else {
- setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
+ Slog.e(TAG, "finishBoot");
+ //setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
+ setEnabledFunctions(UsbManager.FUNCTION_MTP, false);
}
if (mCurrentAccessory != null) {
mUsbDeviceManager.getCurrentSettings().accessoryAttached(mCurrentAccessory);