MTP(Media Transfer Protocol)
是常用的文件传输协议,接上 Typec 到PC就可以直接访问设备存储。
源码中USB模式由 UsbDeviceManager
控制,修改补丁如下:
rk3576_neardi_Android14/frameworks/base$
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 3d012f6eacc0..36b36527fdb7 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -1010,7 +1010,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
&& mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
setScreenUnlockedFunctions(operationId);
} else {
- setEnabledFunctions(UsbManager.FUNCTION_NONE, false, operationId);
+ setEnabledFunctions(UsbManager.FUNCTION_MTP, false, operationId);
}
}
updateUsbFunctions();
@@ -1263,7 +1263,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
&& mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
setScreenUnlockedFunctions(operationId);
} else {
- setEnabledFunctions(UsbManager.FUNCTION_NONE, false, operationId);
+ setEnabledFunctions(UsbManager.FUNCTION_MTP, false, operationId);
}
if (mCurrentAccessory != null) {
mUsbDeviceManager.getCurrentSettings().accessoryAttached(mCurrentAccessory);
重新编译并烧录
烧录完后设备重新启动后会看到如下界面,表示切换成MTP:
