0
votes

Android application in java having permission issues when accessing sysfs entry.

try{
 FileOutputStream fos = new FileOutputStream("/sys/class/shift_reg/shift_reg/value");
 byte mybyte = 1;
 fos.write(mybyte);
 fos.close();
} catch ( Exception e) {
 Log.d(TAG, "Failed in writing to Shift Register");      <------- I am always getting this exception.
}

1) Have tried putting 'setenforce 0'. Does't work. Even though enforce level is permissive.

2) Do I have to access using JNI way: ( android-app -> jni -> driver )

3) I have set file permission as 0777 for the sysfs node file.

Dmesg Error message:

[ 417.176302] type=1400 audit(418.589:63): avc: denied { write } for pid=3164 comm="com.android.cam" name="value" dev="sysfs" ino=9749 scontext=u:r:untrusted_app:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1

ps -Z

u:r:untrusted_app:s0 u0_a67 4360 333
com.android.cam

1

1 Answers

0
votes

Following are some of the options I came across.

1. Direct access from the application [ Android Application(.java) -> jni -> driver ] Do I need to implement jni.
[Doubt] Will the jni solution will not have same permission issue as only java application.

[Ans]This won’t work.

2. Signing my application as 'platform_app'. Currently it shows as 'untrusted_app'

[Ans] Platform app is still in app domain. This won’t work.

3. Using any existing android hardware API. Would it possible to reuse something from existing ones( modifying something from existing ones ) 1) android.hardware 2) android.hardware.input

[Ans] Yes. Probably easiest way but be careful not to conflict with other modules that use the HAL you are modifying.

4. Adding a new custom system service I believe there are 2 options of adding a system service 1) Adding inside the System Server 2) Adding outside of the System Server

[Ans] Yes. One of proper solutions.

5. Will developing the app using NDK help with permissions

[Ans] An app is still in app domain. You will not get permissions.

Note:

System service implementations github:

https://github.com/opersys/opersys-hal-hw