Skip to content
Advertisement

Android file permissions on Android 6.0

I want to list files and directories under "/proc" in Android. When running as my application process, many files are not readable.


If I list the directory as the shell user I get the following output:

JavaScript

If I list the the directory as my app process (using run-as [PACKAGE_NAME]):

JavaScript

Obviously, the files that I received a “Permission denied” error on cannot be read using new java.io.File("/proc").listFiles(); either.


My question:

Why can’t my application process read these directories? The permissions give “other” users read access (“dr-xr-xr-x”).

Advertisement

Answer

Android 5 and above use SELinux which uses two forms of access control. Traditional Linux uses a Discretionary Access Control List. The SE component also enforces a Mandatory Access Control List. The former is default allow, the latter is default deny.

You, or a process, only have access to an object if both sets of permissions allow you. Access is determined by SE contexts. Shell and app contexts have different permissions, and unfortunately there isn’t any known way to give an app shell context.

You can view Security Contexts using:

JavaScript

I don’t have a Marshmallow device to test, however what might give your app the necessary context is getting the usagestatsmanager permission. A user would have to enable it security settings, and I’m told Samsung devices don’t have the necessary menu. Shot in the dark mind you.

If you want to try it, see this question: How to check if “android.permission.PACKAGE_USAGE_STATS” permission is given?

This page might give you more info on permissions: https://su.chainfire.eu/#selinux

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement