Forced USB drive for installation on Android devices at startup

I'm trying to connect a USB storage device to my Raspberry Pi, which runs android stuff. I came across this answer which shows how to mount it using the ADB command line. But the problem is that I have to run this command every time my device boots up. I want to install a USB drive in onCreate()my startup activity. Here is the code:

//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();
    }

But I get this error:

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)

How to mount a USB device using my application in Android Things?

+4
source share
2 answers

Android. Android Things ( Android) .

0

, . adb .

USB API Android Usb Host, libaums Usb - , FAT32.

0

Source: https://habr.com/ru/post/1676726/