美文网首页
文件开放权限

文件开放权限

作者: gbmaotai | 来源:发表于2018-09-05 10:24 被阅读0次

    SEAndroid 为Sys设备节点开放访问(读或写)权限方法(如:sys/class/leds/red_aux/brightness)

    1.APP层写节点之前,必须确保当前应用程序能够有权限去读写

    否则是无法正常写入的,如果应用没有权限写设备节点,首先进入源码目录中system/core/rootdir/init.rc;
    修改内容如下:

           //开放节点让系统进程可以访问
         chown system system /sys/class/leds/red_aux/brightness
           //修改设备节点可读可写
         chmod 0666 /sys/class/leds/red_aux/brightness
    

    2.修改file.te

    进入/device/XXX/sepolicy/common
    找到file.te文件,加入以下的类型声明:
    定义selinux type

    # leds file
    type sysfs_ledred_leds, fs_type, sysfs_type;
    

    3.修改file_contexts

    进入/device/XXX/sepolicy/common
    找到修改file_contexts文件
    绑定sysfs_ledred_leds到对应的实际节点,加入以下声明:

    /sys/devices/soc/75b5000.i2c/i2c-7/7-0045/leds/red_aux/brightness u:object_r:sysfs_ledred_leds:s0
    

    4.修改sysetem_app.te文件

    找到修改sysetem_app.te文件
    加入以下权限声明:

    allow system_app sysfs_ledred_leds:file rw_file_perms;
    

    //rw_file_perms代表读写权限,该话的意思事允许system_app进程能够拥有对sysfs_ledred_leds的这个字符设备的读写权限;如果system_server 则表示是system_server进程

    allow system_app sysfs_ledred_leds:file { create open read setattr write };
    

    注意:以上的sysfs_ledred_leds必须与file.te文件中声明的文件类型、名称必须一致。

    5.APP

    APP 配置为系统APP
    在AndroidMainefest.xml中配置
    android:sharedUserId=”android.uid.system”;

    write_init("/sys/class/leds/red_aux/brightness", 255);
    

    6.kernel 中sysfs 读写权限

    S_IWUGO 全部用户读写

    S_IWUSR 用户读写

    相关文章

      网友评论

          本文标题:文件开放权限

          本文链接:https://www.haomeiwen.com/subject/hcoowftx.html