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
type my_device, dev_type;
/dev/ttyXXX u:object_r:my_device:s0
audit2allow"
allow xxxx my_device:chr_file {read write} # this do not pose a problem but it does not solve it either
#allow xxxx sysfs:file {read write} # -> AOSP do not permit those apps to write on sysfs. error in compilation (neverallow rule) (commented out)
* in "frameworks/base/core/res/AndroidManifest.xml": ... "permission android:name="android.permission.UART_PERMISSION" ... etc, etc
* in "frameworks/base/data/etc/platform.xml": ... "<permission name="android.permission.UART_PERMISSION" > \ <group gid="uart_grp" />... etc, etc...
* in "system/core/include/private/android_filesystem_config.h": ... "#define AID_UART_GRP 2901"... ..." { "uart_grp", AID_UART_GRP, },
* in "system/core/rootdir/ueventd.rx": ... "/dev/ttyXXX 0660 system uart_grp" # tried with uart_grp:uart_grp too = same luck
* in the manifest of the app: ... "<uses-permission android:name="android.permission.UART_PERMISSION"/>
#init.{hardware}.rc
on property:sys.boot_completed=1#UART5 on my device
chown root root /dev/ttymxc4
chmod 0777 /dev/ttymxc4
#GPIO5_IO14 (gpio_bank - 1) * 32 + gpio_bitwrite /sys/class/gpio/export 142
write /sys/class/gpio/gpio142/edge "both"
#ueventd.{hardware}.rc
+/dev/ttymxc* 0666 system system
/dev/ttymxc* 0666 root root
adb shell
su
chown root:root /dev/ttyXXX
chmod +rw /dev/ttyXXX
type my_device, dev_type, mlstrustedobject;