Android 应用读写设备节点
作者:互联网
配置设备节点权限:
// android/device/qcom/***/init.target.rc
// 该目录下添加对应设备节点的配置
# Add /dev/sys
chmod 0660 /dev/sys
// android/device/qcom/common/rootdir/etc/uevented.qcon.rc
// 该目录下添加对应设备节点的配置
# Add /dev/sys
/dev/sys 0666 system system
// android/device/qcom/sepolicy/private/platform_app.te
// 该目录下添加对应设备节点的配置
# Add /dev/sys
allow platform_app device:chr_file { open read write ioctl };
// android/system/sepolicy/private/system_server.te
// android/system/sepolicy/prebuilts/api/28.0/private/system_server.te
// 该目录下添加对应设备节点的配置,两个目录需保持一致
#Add /dev/sys
allow system_server device:chr_file {open read write getattr };
// android/system/sepolicy/public/domain.te
// android/system/sepolicy/prebuilts/api/28.0/public/domain.te
// 该目录下添加对应设备节点的配置,两个目录需保持一致
# Don't allow raw read/write/open access to generic device.
# Rather force a relabel to a more specific type.
# 注释掉
# neverallow domain device:chr_file { open read write };
写入设备节点
final String FILE_PATH = "/sys/dev";
private void writeSysFile(){
final File file = new File(PATH_REPORT) ;
String cmd = "1";
FileOutputStream fos = null;
try{
fos = new FileOutputStream(file);
fos.write(cmd.getBytes());
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null){
try {
fos.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
}
标签:fos,读写,system,dev,节点,sys,device,Android,android 来源: https://blog.csdn.net/Sqq_yj/article/details/122623193