参考:https://blog.csdn.net/yingzhao80/article/details/45511351
Android下USB Accessory设备连接后处理流程
(1)手动切到device mode,也就是开启OTG 模式(mtk 9652可以用sw的方式做切换,但是只有port0才可以切换)
echo 1> /sys/devices/Mstar-otq/software_id
cat/sys/devices/Mstar-otq/software.id确认
(2) 需要开启adb mode(这个很重要,之前一直是mtp模式下去试,usb的wevent log一点都没有,浪要了很多时间跟kernel的xd debug,试了很多次发现需要切到adb mode下才会监续下去)
Development option里顶开启usb debugging即司
getprop |grep -i usb 确认一下
(3) 确认板子是否有accessory的feature
device-common .mk
#usb accessory configuration
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.usb.accessory.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.accessory.xml
device.mk
# usb accessory
PRODUCT_PACKAGES +=\
com.android.future.usb.accessory
mtv_core_hardware.xml
- <!--feature name="android.hardware.usb.accessory"/-->
+ <feature name="android.hardware.usb.accessory"/>
console:/ # pm list features | grep -i usb
feature android.hardware.usb.accessory
feature:android.hardware.usb.host
(4)adb mode下连接无人机,会kernel panic
但是cat init.xxxx.usb.rc里是由这个action的,直接抓kernel log也没有相关报错,orz
很奇怪,用linux vim也没看到有这个..
推荐用cat -v去查看,能看到某些特殊字符
mkdirM-BM- /config/usb_gadget/g1/functions/accessory.gs2
修改init.XXX.usb.rc,去掉M-BM-
这一步,真的是运气爆棚,恰好用busybox vi发现,不然真的GG,不知哪位前辈埋的坑
(5)获取不到无人机usbaccessory的信息(mAccessoryStrings=null),导致startAccessoryMode的enableAccessory= null
395 private void startAccessoryMode() {
396 if (!mHasUsbAccessory) return;
397
398 mAccessoryStrings = nativeGetAccessoryStrings();
399 boolean enableAudio = (nativeGetAudioMode() == AUDIO_MODE_SOURCE);
400 // don't start accessory mode if our mandatory strings have not been set
401 boolean enableAccessory = (mAccessoryStrings != null &&
402 mAccessoryStrings[UsbAccessory.MANUFACTURER_STRING] != null &&
403 mAccessoryStrings[UsbAccessory.MODEL_STRING] != null);
404
405 long functions = UsbManager.FUNCTION_NONE;
406 if (enableAccessory) {
407 functions |= UsbManager.FUNCTION_ACCESSORY;
408 }
409 if (enableAudio) {
410 functions |= UsbManager.FUNCTION_AUDIO_SOURCE;
411 }
412
413 if (functions != UsbManager.FUNCTION_NONE) {
414 mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_ACCESSORY_MODE_ENTER_TIMEOUT),
415 ACCESSORY_REQUEST_TIMEOUT);
416 setCurrentFunctions(functions);
417 }
418 }
这里mAccessoryStrings = nativeGetAccessoryStrings()为null,导致enableAccessory=false没有往下走,猜测无人机配置有问题,需要driver去查,但是三不管地带,而且由于客户人力不够,配合提供反馈及其有限情况下,只能我这边先上层动一刀了
修改:获取不到AccessoryString就默认默认配置一个,使其go on
(6)kernel log一直在循环发送USB_STATE的uevent CONNECTED COONFIGURED DISCONNECTED
(7)按现在目前设置为dji,可以跳过那个没有获取到无人机信息导致进不去accessory mode的问题,但是这边看flow,后面会根据配置信息去匹配能响应的activity
这就需要客户在自己的apk中去配置了