Android 如何实现usb驱动自动安装?
前言
欢迎大家我分享和推荐好用的代码段~~
声明
欢迎转载,但请保留文章原始出处:
CSDN:http://www.csdn.net
雨季o莫忧离:http://blog.csdn.net/luckkof
正文
......} else if ("REZEROCMD".equals(state)) {
/*When recieve REZEROCMD, it means that PC has installed a proper driver, so can switch to other USB function(UMS)*/
Slog.w(TAG, "PC knows me");
mIsPcKnowMe = true;
setCurrentFunctions(UsbManager.USB_FUNCTION_MASS_STORAGE, false); //修改此处的USB_FUNCTION_MASS_STORAGE为USB_FUNCTION_MTP
return;......
1. f_mass_storage.c
static int do_scsi_command(struct fsg_common *common)
{case REZERO_UNIT:
printk("Get REZERO_UNIT command = %x\r\n", common->cmnd[1]);
if (common->cmnd[1] == 0xB)
common->android_callback(1);
else if (common->cmnd[1] == 0xD)
common->android_callback(2);......}
static void android_work(struct work_struct *data)
{......char *rezero_event[2] = { "USB_STATE=REZEROCMD", NULL };
char *showcdrom_event[2] = { "USB_STATE=SHOWCDROMCMD", NULL };
......if (dev->rezero_cmd == 1) {
uevent_envp_cdrom = rezero_event;
dev->rezero_cmd = 0;
} else if (dev->rezero_cmd == 2) {
uevent_envp_cdrom = showcdrom_event;
dev->rezero_cmd = 0;
}
......if (uevent_envp_cdrom) {
kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, uevent_envp_cdrom);
xlog_printk(ANDROID_LOG_INFO, USB_LOG, "%s: sent uevent %s\n", __func__, uevent_envp_cdrom[0]);
} else {
xlog_printk(ANDROID_LOG_INFO, USB_LOG, "%s: did not send zero uevent\n", __func__);
}
}void mass_storage_callback(unsigned char cmd_type)
{struct android_dev *dev = _android_dev;
if (cmd_type != 0)
dev->rezero_cmd = cmd_type;
schedule_work(&dev->work);
}
public void updateState(String state) {......int connected, configured;if (DEBUG) SXlog.d(TAG, "updateState - " + state);
Message msg;...} else if ("REZEROCMD".equals(state)) {
/*When recieve REZEROCMD, it means that PC has installed a proper driver, so can switch to other USB function(UMS)*/
Slog.w(TAG, "PC knows me");
mIsPcKnowMe = true;
setCurrentFunctions(UsbManager.USB_FUNCTION_MASS_STORAGE, false);
return;
} else if ("SHOWCDROMCMD".equals(state)) {
/*When recieve REZEROCMD, it means that PC has installed a proper driver, so can switch to other USB function(UMS)*/
Slog.w(TAG, "SHOW CD-ROM CMD");
setCurrentFunctions(UsbManager.USB_FUNCTION_BICR, false);
return;......}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。