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 !!