init: Service xxx does not have a SELinux domain defined.
该提示说明没有定义SELinux domain,导致服务xxx无法自启动。为了解决这个问题我们按如下方式修改或添加sepolicy文件:
● 修改system/seplicy/file_contexts文件,添加以下内容:
/system/bin/xxx u:object_r:xxx_exec:s0
● 新增xxx.te文件,并在其中添加如下内容:
需要为新增的进程增加域、执行权限
type xxx, domain;
type xxx_exec, exec_type, file_type;
然后启用这个域
init_daemon_domain(xxx)
allow idmap resource_cache_data_file:dir rw_dir_perms;
allow idmap resource_cache_data_file:file create_file_perms;
上面俩行是权限allow,可能会遇到权限还不够,具体增加方法看下面案列
●最后
有时候会遇到avc denied报错问题,这是因为安卓4.4(好像)以后增加了SELINUX权限问题
权限增加规则如下:
案列1)
<7>[11281.586780] avc: denied { read write } for pid=1217 comm="mediaserver" name="tfa9897"
dev="tmpfs" ino=4385 scontext=u:r:mediaserver:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=0
allow mediaserver device chr_file { open read write };
案列2)
<7>[11281.586780] avc: denied {dd} for pid=1217 comm="mediaserver" name="tfa9897" dev="tmpfs"
ino=4385 scontext=u:r:aa:s0 tcontext=u:object_r:bb:s0 tclass=ccc permissive=0
allow aa bb ccc { dd };