问题遇到的现象和发生背景
工作需要,开始学习Andorid,开发一个测试U盘设备的AndoridTool,但是U盘插入后有问题:
问题1:采用UsbDevice类,获取到了权限,也获取到了挂载路径,但是通过File找不到这个挂载路径(挂载路径是正确的),因此无法操作u盘设备
问题2:改用社区的 UsbMassStorageDevice类,能够获取到IUsbDevice、interface、configuration、endpotin等信息,但是在Init的时候,设备掉盘了,貌似错误是:access denied finding property
问题相关代码,请勿粘贴截图
问题一 代码:
File file = new File(path);//path是已经获取到的挂载路径:/mnt/media_rw/1F32-7EAE
if(file.exists()){
//挂载路径存在
{
else{
//挂载路径不存在
}
问题二代码:
//已经获取到了对应的UsbMassStorageDevice对象:massDevice,执行下面代码,会掉盘
massDevice.Init();//初始化,会掉盘
//============以下为源码
//Init里的内容:
setupDevice();//这里面会嗲盘
//setupDevice里的内容:
private fun setupDevice() {
usbCommunication = UsbCommunicationFactory
.createUsbCommunication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint)这里掉盘
//下面代码省略
}
//createUsbCommunication里面内容:
return if (underlyingUsbCommunication == UnderlyingUsbCommunication.DEVICE_CONNECTION_SYNC) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
JellyBeanMr2Communication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint) //这里面会掉盘,这个类貌似会进行通信
} else {
Log.i(TAG, "using workaround usb communication")
HoneyCombMr1Communication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint)
}
} else {
UsbRequestCommunication(usbManager, usbDevice, usbInterface, outEndpoint, inEndpoint)
}
运行结果及报错内容
问题1:找到了对应的挂载路径,但是挂载路径却不存在??
问题2:LogCat显示的信息:
E/libc: Access denied finding property "vendor.mali.config"
E/libc: Access denied finding property "persist.vendor.sf.fbc"
E/libc: Access denied finding property "persist.vendor.gpu.fbc"
E/libc: Access denied finding property "persist.vendor.vsp.fbc"
我尝试的操作
网上查阅了各种资料,都没能成功操作u盘设备
我想要达到的结果
两个问题有一个ok都行,但两个方法都失败了,想请教社区老哥,问题出在哪里?谢谢,问题二的权限是刚刚发现的,我继续尝试