接到一个项目,说要更改USB的连接方式,说是只要保留只充电模式,想了一下,这应该很容易实现呀,所以就在上层做了一系列的操作,结果很悲催,对于USB连接,好像系统底层有一定的读取,所以导致USB用不了,所以就各种爬文,终于找到最简单的方法!
目录文件:device\mediatek\common\device.mk
关键字:persist.sys.usb.config
把mass_storage改成charging:就可以实现默认选择充电模式
ifeq ($(strip $(MTK_MASS_STORAGE)),yes)
ADDITIONAL_DEFAULT_PROPERTIES += persist.sys.usb.config=charging
else
ADDITIONAL_DEFAULT_PROPERTIES += persist.sys.usb.config=mtp
endif
或者默认使用其他功能请参照下面的字串:
public static final String USB_FUNCTION_MASS_STORAGE = mass_storage;
/**
* Name of the adb USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*
* {@hide}
*/
public static final String USB_FUNCTION_ADB = adb;
/**
* Name of the RNDIS ethernet USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*
* {@hide}
*/
public static final String USB_FUNCTION_RNDIS = rndis;
/**
* Name of the MTP USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*
* {@hide}
*/
public static final String USB_FUNCTION_MTP = mtp;
/**
* Name of the PTP USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*
* {@hide}
*/
public static final String USB_FUNCTION_PTP = ptp;
/**
* Name of the CHARGING USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*
* {@hide}
*/
public static final String USB_FUNCTION_CHARGING = charging;
/**
* Name of the audio source USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*
* {@hide}
*/
public static final String USB_FUNCTION_AUDIO_SOURCE = audio_source;
/**
* Name of the Accessory USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*
* {@hide}
*/
现在完成了一半,怎么可以删除其他选项呢?其实连接方式这个页面是动态添加的,主要的文件在:
\packages\apps\Settings\res\xml\user_settings.xml
根据这个Key可以找到java的代码:
\packages\apps\Settings\src\com\mediatek\settings\deviceinfo\UsbSettingsExts.java
其他的一些小知识:
usb的默认设置流程其实是在\frameworks\base\services\usb\java\com\android\server\usb这个目录下