android8.1上开机启动应用的权限配置

        在android8.1上,我们写hidl接口,并让它开机启动它定义的service的时候,经常是在它的rc文件里配置。例如我在hardware\interfaces\下有个文件夹avi_memory\1.0\default,里面有个[email protected],它的内容如下:

service avi_memory /vendor/bin/hw/[email protected]
    class hal
    user system
    group system 

        然后将这个[email protected]推到设备的vendor/etc/init目录下,这在android8之前,就可以完成开机启动我们的avi_memory服务了。但是在android8以后,还需要配置它的selinux权限,无论selinux权限是否关闭,都要配置。配置比较简单, 以启动这个vendor下的bin文件为例,只需要配置下面四处即可:

        1.)system\sepolicy\vendor\file_contexts文件最下面加上一句:

/(vendor|system/vendor)/bin/hw/android\.hardware\.avi_memory@1\.0-service              u:object_r:hal_avi_memory_exec:s0

        2.)在system\sepolicy\vendor目录下新增一个文件hal_avi_memory.te

type hal_avi_memory, domain;
type hal_avi_memory_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(hal_avi_memory)

        3. )在system\sepolicy\prebuilts\api\26.0\private\file_contexts里,增加如下一条:

/(vendor|system/vendor)/bin/hw/android\.hardware\.avi_memory@1\.0-service     u:object_r:hal_avi_memory_exec:s0

        4. )在system\sepolicy\prebuilts\api\26.0\private下新增一个文件hal_avi_memory.te

type hal_avi_memory, domain;
type hal_avi_memory_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(hal_avi_memory)

        这样配置后,再全编译刷机,以后开机就可以自动启动我们的bin文件[email protected]了。

        上面讲的是在vendor下的bin文件,如果我们要启动的是system下的bin文件,配置略有不同,不过也是改动四处。比如我们在frameworks\av\services\下有个自定义的服务autotimestampserver,在这个文件夹下有个autotimestampserver.rc,它的内容如下:

service autotimestampserver /system/bin/autotimestampserver
    class main
    user system
    group system

        我们想要开机启动autotimestampserver这个Bin文件,需要如下配置四处:

        1.)在system\sepolicy\prebuilts\api\26.0\private\file_contexts里新增如下一行代码:

/system/bin/autotimestampserver u:object_r:autotimestampserver_exec:s0

        2.)在sepolicy\prebuilts\api\26.0\private下新增文件autotimestampserver.te

type autotimestampserver, coredomain;
type autotimestampserver_exec, exec_type, file_type;
init_daemon_domain(autotimestampserver)

        3.)在system\sepolicy\private\file_contexts里新增如下一行代码:

/system/bin/autotimestampserver u:object_r:autotimestampserver_exec:s0

        4.)在system\sepolicy\private下新增文件autotimestampserver.te

type autotimestampserver, coredomain;
type autotimestampserver_exec, exec_type, file_type;
init_daemon_domain(autotimestampserver)

        如上面四步配置后,即可开机启动我们system/bin下的文件了。

猜你喜欢

转载自blog.csdn.net/xuhui_7810/article/details/103886433