1.packages/apps/Settings / src/com/android/settings/deviceinfo/UsbBackend.java
getUsbDataMode() 中 // select none if no found
return -1; // ... 《修改为 return 0; 或者// select none if no found
if (isTestSwitchOn()){ return 0; }else{ return MODE_DATA_MTP; } 》2.frameworks/base / services/usb/java/com/android/server/usb/UsbDeviceManager.java
case MSG_UPDATE_STATE:
if (!mConnected) {
// When a disconnect occurs, relock access to sensitive user data mUsbDataUnlocked = false; }else if(mConnected){ if(UsbManager.containsFunction(getDefaultFunctions(),UsbManager.USB_FUNCTION_MTP)){ mUsbDataUnlocked = true; } }
//判断是否为测试模式:
private boolean isTestSwitchOn(){
try { final String configPath="//sys//class//android_usb//android0//usb_mode"; FileInputStream inStream=new FileInputStream(configPath); byte[] buffer= new byte[1]; int nu=inStream.read(buffer); inStream.close(); if (nu > 0){ if("1".equals(new String(buffer))){ return true; }else { return false; } }else { return true; } } catch (FileNotFoundException e) { e.printStackTrace(); // default test mode without usb_mode file. return true; } catch (IOException e) { e.printStackTrace(); } return false; }