I cannot programatically access files on my rooted Galaxy s10+

31 views Asked by At

I have Rooted my Galaxy s10+ (SM-G975f/exynos) using Magisk and am trying to access "/sys/devices/virtual/sensors/light_sensor/lux". I am trying to firstly change the permissions on the file so that i can access /lux.

My function to change file permissions is:

private boolean changeFilePermissions(String filePath, String permissions) {
        String command = "su -c chmod " + permissions + " " + filePath;

        Process process = null;
        DataOutputStream os = null;

        try {
            //created command variable as not using it can cause issues if directly quoted
            process = Runtime.getRuntime().exec(command);
            os = new DataOutputStream(process.getOutputStream());

            Log.d("RootShell", "Executing command: " + command);
            os.writeBytes("exit\n");
            //Fails Here
            os.flush(); // flush stream before closing // Also fails here

            int exitCode = process.waitFor(); // waitfor returns intvalue !0 = abnormal execution

            Log.d("RootShell", "Command execution successful: " + exitCode);
            return true;
        } catch (IOException | InterruptedException e) {
            //extra details
            Log.e("Rootshell", "Error executing command ", e);
            e.printStackTrace();
        } finally {
            if (os != null) {
                try {
                   
                    os.close(); 
                } catch (IOException e) {
                    //More details
                    Log.e("Rootshell", "error closing OutputStream", e);
                    e.printStackTrace();
                }
            }
            return false;
        }
    }

I get this error on logcat enter image description here

I think the issue is that even though i have root i cant programmatically access /sys/devices/virtual/sensors/light_sensor/lux" as when i run "setenforce 0" i get "enforcing" on Termux. So SELinux is blocking me i think

It is also of note that when i use the AIDE i can see the contents of the file. (i used root explorer as a potental fix to set rwxrwxrwx which makes me think even more its SElinux)enter image description here

Would the solution be to maybe reroot the phone with a custom ROM (not sure if this is the correct thing) that allows for permissable SELinux? I have looked and i cant find out how be able to do that.

Any help would be really appreciated

0

There are 0 answers