我正在尝试将 USB 大容量存储设备安装到运行 android things 的 Raspberry Pi。我遇到了this显示如何使用命令行 ADB shell 挂载它的答案。
但问题是每次我的设备启动时我都必须运行这些命令。我想在启动 Activity 的 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 设备?
最佳答案
您只能在已获得 root 权限的 Android 中运行这些命令。出于安全原因,Android Things(作为 Android)不允许执行 shell 命令。
关于android - 开始 Activity 时将 USB 拇指驱动器挂载到 android things,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43865719/