get the list of files in /dev directory in android

162 Views Asked by At

I need get the list of files in /dev directory, but always get null as result.

File dev = new File("/dev");
File[] files = dev.listFiles();

And my logs show: untrusted_app:

type=1400 audit(0.0:49408): avc: denied { read } for name="/" dev="tmpfs" ino=4097 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=dir permissive=0

My application run on an aosp compiled system, so I can change any kernel configuration. I'm using Android Nougat 7.1 (api 25) and I can't change the Android version because of other dependencies on my system.

After adding the MOUNT_UNMOUNT_FILESYSTEMS permission I got PERMISSION_DENIED

int value = checkCallingOrSelfPermission("android.permission.MOUNT_UNMOUNT_FILESYSTEMS");

Then I added my app to private apps directory as system apps. After that, if I check the permission MOUNT_UNMOUNT_FILESYSTEMS, it returns PERMISSION_GRANTED but I still get null as a result of the list of files in the /dev directory.

if (checkCallingOrSelfPermission("android.permission.MOUNT_UNMOUNT_FILESYSTEMS") == PackageManager.PERMISSION_GRANTED) {
    File dev = new File("/dev");
    File[] files = dev.listFiles(); 
}

And my logs replace the untrusted_app by priv_app:

type=1400 audit(0.0:4685): avc: denied { read } for name="/" dev="tmpfs" ino=1541 scontext=u:r:priv_app:s0:c512,c768 tcontext=u:object_r:device:s0 tclass=dir permissive=0

0

There are 0 best solutions below