在 aosp 源码中,可以在 init.xxx.rc 中添加一些服务(不是四大组件的Service),比如
service my_service /vendor/bin/sh /vendor/bin/function.sh
console
oneshot
user root
group media system graphics input bluetooth shell drmrpc mediacodec
seclabel u:r:shell:s0
1.代码调用:
启动:
SystemProperties.set("ctl.start", "my_service");
停止:
SystemProperties.set("ctl.stop", "my_service");
可能会遇到权限问题,两方面入手 :
- 需要是系统应用:配置 android.uid.system ,打系统签名 ;
- 需要 Selinux 权限:根据 avc log 添加对应的权限 ;
2.串口快速验证:
启动:
setprop ctl.start my_service
停止:
setprop ctl.stop my_service