Search code examples
androidlinux-kernelsdkadbroot-access

Executing commands as root on API 31 + / File system access


I am currently trying to get full access to file system through the working app. I tested it on rooted AVDs with API levels 26, 27, 31, 32 While executing commands through terminal manually is no problem (also programmatically on apis 26/27), there seems to be no access to file system on apis 31 / 32 when I call same commands from the app. Even though 'whoami' clearly returns 'root'

So:

//Fails
val command = "su -c 'touch /data/data/something.../ 
//Succeeds
val cmd = "su -c 'touch /storage/something.../ 
//Also succeeds 
val cmd = "su -c 'ps -ef'

I guess it is something with file system on high apis. Is there any work around.

Probably not permission problem. Its just that my app can't see the whole file system. The above command "su -c 'touch /data/data/something.../ returns 'No such file or directory'. Its not the case when you run the command from terminal


Solution

  • If anyone is wondering, su process will see the whole file system with --mount-master option. As su --help states, the option is to "force run in the global mount namespace"