1

As part of my research, I need to root my Android test devices and try to get some user specific and device specific identifiable information without any permissions through passing root commands in Java.

I rooted one device (Android 8.1.0 Oreo), and used the code in this stackoverflow page to test it out.

The method looks like this:

public void runCommand(String...commands) {
    try {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream dataOutputStream = new DataOutputStream(process.getOutputStream());
        for(String s : commands) {
            dataOutputStream.writeBytes(s + "\n");
        }
        dataOutputStream.writeBytes("exit\n");
        dataOutputStream.flush();
        try {
            process.waitFor();
        } catch(Exception e) {
            logToFile(this, e.getMessage());
        }
        logToFile(this, "recording saved.");
        dataOutputStream.close();
    } catch (Exception e) {
        logToFile(this, e.getMessage());
    }

And call to this method is done in onCreate() method as such:

runCommand("screenrecord --time-limit 9 " + getApplicationContext().getFilesDir() + "/sRec.mp4\n");

The .mp4 file is saved to the location I specified above, however I cannot view or save it through Device File Explorer in Android Studio.

So when I launch the app, device asks me to grant superuser privileges, and I do. I can see in Device File Explorer that the screen recording is actually done, and the file is not empty.

When I try to save or open the .mp4 file in Android Studio, I get the following error:

Error opening contents of device file "sRec.mp4": cp: /data/local/tmp/temp0eec6269-ee1f-48f3-b78e-93999fbed07a: Permission denied

The file according to Device File Explorer is at data/data/myapplication/files. But Windows File Explorer does not show this file in this location. I am stumped.

I did not request any permissions since the point is getting the information without them. Is there something I can do here?

rodo
  • 13
  • 2
  • Note: I also tried to run chmod 777 commands in `onCreate()` method, but that also did not help. Like this is the first code the app runs: `Runtime.getRuntime().exec("chmod -R 777 " + getApplicationContext().getFilesDir());`. But it still doesnt work. – rodo Aug 16 '21 at 17:38

0 Answers0