版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/l460133921/article/details/72891678
为了完成公司项目的一个需求,需要添加一个binder服务xxx,并且设置成开机自启动。于是我在init.rc中添加了如下代码行:
service xxx /system/bin/xxx
class main
user root
编译boot后烧到手机,发现服务xxx无法启动,kernel log中有如下提示:
[ 20.076354s][pid:1,cpu7,init]init: Service xxx does not have a SELinux domain defined.
该提示说明没有定义SELinux domain,导致服务xxx无法自启动。为了解决这个问题我们按如下方式修改或添加sepolicy文件:
/system/bin/xxx u:object_r:xxx_exec:s0
需要为新增的进程增加域、执行权限
type xxx, domain;
type xxx_exec, exec_type, file_type;
然后启用这个域
init_daemon_domain(xxx)
- 编译bootimage
- 烧录bootimage
- 执行adb remount
- 执行adb shell restorecon system/bin/xxx
- 重启手机,查看kernel log中是否成功启动xxx服务