最近一个用户提了一个故障,用户的描述为
更新了好几次版本,都不能完美实现使用Type-C to Type-C线外接USB音频解码器或者U盘/移动硬盘。查询资料后发现是因为系统.\system\etc\permissions目录下缺少android.hardware.usb.host.xml文件,导致系统无法在正常情况下进入USB Host模式,而必须使用额外的USB Type-C to Type-A Hub才能触发OTG默认。
首先android.hardware.usb.host.xml,手机是有的,目录在这个地方
./vendor/etc/permissions/android.hardware.usb.host.xml
作用是,声明设备支持OTG功能,给Android系统中的API或者apk读写usb设备加入访问权限。Google CTS测试也会检查这一文件,检查到这个文件后就会进行otg相关的测试。
低端项目如果没有otg功能,比如硬件不满足,为了避免CTS进行相关测试,需要将改文件删除,如
data/vendor/etc/permissions/android.hardware.usb.host.xml added
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- This is the standard feature indicating that the device can communicate
with USB devices as the USB host. -->
<permissions>
</permissions>
moduleconfig.mk
ifeq ($(TEST_OTG_NONE),true)
USB_HOST_DISABLE_ITEM :=$(dir $(lastword $(MAKEFILE_LIST)))data/vendor/etc/permissions/android.hardware.usb.host.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.host.xml
PRODUCT_COPY_FILES := $(USB_HOST_DISABLE_ITEM) $(PRODUCT_COPY_FILES)
endif
所以用户说的这个文件和故障本身不是一个问题。用户的故障是USB电气兼容性问题,需要调试参数解决。如果有硬件问题,调试参数也是解决不了的。