Question

I recently upgraded on a Stock Android 4.1 on my transformer tf101. In my app, i need root access my USB camera plugged in to the device. Till now, i have done this by the following code:

        Runtime.getRuntime().exec("su");
        DataOutputStream oOutSream = new DataOutputStream( process.getOutputStream());
        oOutSream.writeBytes( "chmod -R 777 /dev/bus/usb/* \n" );
        oOutSream.flush();
        oOutSream.writeBytes("exit\n");
        oOutSream.flush();

I know, chmod 777 is NOT a good idea, but i haven't found any other solution so far. Well, after upgrading to 4.1 this is NOT working anymore. SuperSU prompts a Messagebox informing me that the app has requested root access, but it wont work. the strange thing is.. when i open up the adb shell from the pc, and enter those commands, it works flawlessly.

If i granted su access by the pc, my app works correctly, although random toasts show up informing me "root acces granted" or "root acces denied". Could it be a bug in SuperSU?

Thanks for the help!

Était-ce utile?

La solution

A better idea is to look at what permissions the usb devices have you want access.

For example using ls on your phone:

$ ls -l /dev/bus/usb/001/
crw-rw---- system   usb      189,   1 2012-09-15 19:18 002
crw-rw---- system   usb      189,   0 2012-09-15 19:18 001

I might be wrong here but I think in every android version the usb group has rw permissions for all usb devices. What you want to do is, launching your application with usb as group id.

You could do this, for example, by using su to elevate your process to root and then setting your group id using setgid. After that you can write to your usb devices without that chmod fiddeling which is really really not good.

Edit: Also, don't forget to drop the root permissions using setuid(whateverAppUID) after you're done setting the group id!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top