从零开始自定义安卓系统(9) 初始化脚本
从零开始自定义安卓系统(9) 初始化脚本
init.rc
init.rc是安卓用于定义系统启动时操作的格式, 安卓启动会尝试读取
/{system,system_ext,vendor,odm,product}/etc/init/ 目录下的rc文件
如果要实现开机时运行一个自定义脚本, 只需要在产品的mk文件里添加
| |
然后在init.bluebird.rc 里编辑即可
如果出于测试目的可以选择直接在系统内编辑,上述文件然后重启
rc文件语法
rc文件语法有两块 一块是定义服务, 一块是定义触发动作.
服务定义语法
| |
disabled 禁止自启, 直到被调用. oneshot 使得服务不会被重复调用和重启, 用于只执行一次的脚本
然后定义什么时候触发
| |
aosp定义的阶段触发器有
early-fs- Start vold.fs- Vold is up. Mount partitions not marked as first-stage or latemounted.post-fs- Configure anything dependent on early mounts.late-fs- Mount partitions marked as latemounted.post-fs-data- Mount and configure/data; set up encryption./metadatais reformatted here if it couldn’t mount in first-stage init.zygote-start- Start the zygote.early-boot- After zygote has started.boot- Afterearly-bootactions have completed.
也可以通过prop属性方式控制触发, 例如 dev.bootcomplete
| |
如果使用服务形式,可能需要修改
selinux策略, 以增加服务权限以进行操作 如文件操作 参考 https://source.android.com/docs/security/features/selinux?hl=zh-cn