android 8.0 mtk平臺新增讀寫檔案節點許可權
上層讀寫自己新增節點檔案/sys/bus/i2c/drivers/ac108/1-003b/ac108_debug/ac108_power:
FileOutputStream file;
try{
file = new FileOutputStream("/sys/bus/i2c/drivers/ac108/1-003b/ac108_debug/ac108_power");
file.write('1');//寫1或者0
file.close();
}catch(FileNotFoundException e){
e.printStacktrace();
}catch(IOException e){
e.printStacktrace();
}catch(Exception e){
e.printStacktrace();
}
提示沒有許可權:
01-01 11:58:49.822 W/ndroid.systemui( 620): type=1400 audit(0.0:47): avc: denied { write } for name="ac108_power" dev="sysfs" ino=15082 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:sysfs:s0 tclass=file permissive=0 01-01 11:58:49.827 W/System.err( 620): java.io.FileNotFoundException: /sys/bus/i2c/drivers/ac108/1-003b/ac108_debug/ac108_power (Permission denied)
讀寫如上節點需要新增selinux許可權,操作如下:
1.device/mediatek/mt8167/sepolicy/basic/platform_app.te: allow platform_app sysfs:file { write }; 2.system/sepolicy/public/platform_app.te中新增mlstrustedsubject type platform_app, domain, mlstrustedsubject; 3.system/sepolicy/private/app.te中新增-platform_app neverallow { appdomain -bluetooth -nfc -platform_app } sysfs:dir_file_class_set write;
指令查詢節點的值:
adb shell
cd /sys/bus/i2c/drivers/ac108/1-003b/ac108_debug
/sys/bus/i2c/drivers/ac108/1-003b/ac108_debug # cat ac108_power
指令寫節點的值:
/sys/bus/i2c/drivers/ac108/1-003b/ac108_debug # echo 1 > ac108_power