I need to change the permission of /dev/tty* file as I am writing data on that port. I am able to change the permission from the windows command prompt by entering the adb shell as root.
But when I reboot the device, the permissions are not persisted. Instead, they are set to default values.
So, every time I need to run my app after reboot, I need to change the permissions.
I tried to run the adb commands from the app by using Runtime.exec()
method but that does not change anything as the app does not have permission to change the file ownership permissions.
This is how I executed the command from app ( tested it in emulator in this case) :
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chown root:root /dev/ttyS0 \n");
os.writeBytes("chmod 777 /dev/ttyS0 \n");
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
When the "su" command gets executed, it gives the error su: uid 10044 not allowed to su
Because of that, on executing chown or chmod gives error Unable to chmod Operation Not permitted
So, how do I change permissions and ownership of that file ?
Any help is highly appreciated !
Thanks !!
The default (from the Google AOSP source)
su
binary checksUID
it is being run with. Onlyroot
andshell
users are allowed to runsu
. You won't be able to runsu
from your application unless you install the patchedsu
binary which does not check theUID
.All what
adb root
command does is executing the following commands on the device:But I am positive that you are asking a wrong question here. There is no reason why
su
command would not work for your purpose.The command you should be executing to change the tty device permissions is:
Also in android the
.
is used as a delimiter between user and group fields in thechown
command instead of the:
. The proper command would be:Another common mistake is trying to use standard Linux
su
options like-c
. AOSP version ofsu
is much simpler: