ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android 应用读写设备节点

2022-01-22 20:01:19  阅读:334  来源: 互联网

标签:fos 读写 system dev 节点 sys device Android 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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有