How to run my command as root privilege on android device in programmatically

92 Views Asked by At

I have a shell script which is so simple, I wanted to run my shell script on android device as root permission.

My current code is

private void testShellScript() {
        try {
            String commandWithPath = "/data/local/tmp/testSharath.sh";
            ProcessBuilder processBuilder = new ProcessBuilder("/system/bin/sh", "-c", commandWithPath);
            processBuilder.directory(new File("/data/local/tmp/"));
            Process process = null;
            try {
                process = processBuilder.start();
                // Continue with handling the process
            } catch (IOException e) {
                TestLogger.info("Failed due to " + e);
                e.printStackTrace();
                // Handle the exception
            }
            
        } catch(Exception e){
            e.printStackTrace();
        }
    }

Error while executing :

type=1400 audit(0.0:1594): avc: denied { execute } for name="testSharath.sh" dev="dm-0" ino=65547 scontext=u:r:untrusted_app:s0:c192,c256,c512,c768 tcontext=u:object_r:shell_data_file:s0 tclass=file permissive=1
2023-11-20 01:07:47.830 18982-18982 sh                      pid-18982                            I  type=1400 audit(0.0:1595): avc: denied { execute_no_trans } for path="/data/local/tmp/testSharath.sh" dev="dm-0" ino=65547 scontext=u:r:untrusted_app:s0:c192,c256,c512,c768 tcontext=u:object_r:shell_data_file:s0 tclass=file permissive=1
2023-11-20 01:07:47.845 17931-18985 Unknown Source          com.lotus.sync.traveler              I  Initializing. Device is up-to-date as of today at 1:07 AM.
2023-11-20 01:07:47.851 17931-17983 System.out              com.lotus.sync.traveler              I  Command executed with exit code: 1
0

There are 0 best solutions below