上层读写自己添加节点文件/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