环境平台:rk3399、android7.1.2、kernel4.4.126
有两个步骤
1、脚本添加
device/rockchip/common/init.rockchip.rc中添加:
service my_start_service /system/bin/sh /system/bin/my_start_service.sh
user root
disabled
onshot
on property:sys.boot_completed=1
Start my_start_service
device/rockchip/rk3399下创建my_start_service.sh
device/rockchip/rk3399/rk3399.mk中添加脚本拷贝:
PRODUCT_COPY_FILES += device/rockchip/rk3399/my_start_service.sh:system/bin/my_start_service.sh
2、Selinux域添加domain
只有第一步会报错:
Init: service my_start_service does not have a SELinux domain defined
添加并定义my_start_service的te文件:
device/rockchip/common/sepolicy下添加my_start_service.te:
type my_start_service,domain,mlstrustedsubject;
type my_start_service_exec,exec_type,file_type;
init_demon_domain(my_start_service)
device/rockchip/common/sepolicy/file_contexts中定义start.sh的安全上下文:
/system/bin/start.sh u:object_r:my_start_service_exec:s0
3、仍然报错SELinux domain defined
以上操作后还是报错:
Init: service my_start_service does not have a SELinux domain defined
根据查阅发现,在service后面还需加上seclabel:
service my_start_service /system/bin/sh /system/bin/my_start_service.sh
user root
disabled
onshot
seclabel u:r:my_start_service:s0
在启动Service前将seclabel设置为seclabel. 主要用于在rootfs上启动的service,比如ueventd, adbd。在系统分区上运行的service使其有自己的SELinux安全策略,如果不设置,默认使用init的安全策略。
原作者:布施