【发布时间】:2017-10-07 12:32:55
【问题描述】:
我正在尝试将 USB 大容量存储设备安装到运行 android 设备的 Raspberry Pi 上。我遇到了this 答案,它显示了如何使用命令行 ADB shell 安装它。
但问题是我每次设备启动时都必须运行这些命令。我想在我的启动活动的onCreate() 中安装 USB 驱动器。这是代码:
//Here is the mount drive function which I called in onCreate of my activity.
private void mountDrive() throws IOException, InterruptedException {
Process mProcess = Runtime.getRuntime().exec("/system/xbin/su");
BufferedReader reader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
DataOutputStream dos = new DataOutputStream(mProcess.getOutputStream());
dos.writeBytes("mkdir /mnt/usb\n");
dos.flush();
dos.writeBytes("mount -t vfat -o rw /dev/block/sda1 /mnt/usb\n");
dos.flush();
dos.writeBytes("exit\n");
//Read the response
String line, result = "";
while ((line = reader.readLine()) != null) {
result += line;
Log.d("CMD","RESULT:"+result);
}
reader.close();
dos.flush();
dos.close();
mProcess.waitFor();
}
但我收到此错误:
I/sh: type=1400 audit(0.0:31): avc: denied { read } for name="/" dev="mmcblk0p6" ino=2 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:rootfs:s0 tclass=dir permissive=1
I/sh: type=1400 audit(0.0:32): avc: denied { open } for path="/" dev="mmcblk0p6" ino=2 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:rootfs:s0 tclass=dir permissive=1
W/System.err: java.io.IOException: Cannot run program "su": error=13, Permission denied
W/System.err: at java.lang.ProcessBuilder.start(ProcessBuilder.java:983)
W/System.err: at java.lang.Runtime.exec(Runtime.java:691)
W/System.err: at java.lang.Runtime.exec(Runtime.java:524)
W/System.err: at java.lang.Runtime.exec(Runtime.java:421)
如何在 Android Things 上使用我的应用程序安装 USB 设备?
【问题讨论】:
-
Android 下是自动挂载的。所以我想知道为什么这不会在 Android Things 下发生。
标签: android raspberry-pi3 usb-drive android-things