Android init.rc
丙记零号田 http://www.ccbu.cc/index.php/framework/51.html
一.init.rc脚本包括了文件系统初始化、装载的许多过程。init.rc的工作主要是:
1)设置一些环境变量
2)创建system、sdcard、data、cache等目录
3)把一些文件系统mount到一些目录去,如,mount tmpfs tmpfs /sqlite_stmt_journals
4)设置一些文件的用户群组、权限
5)设置一些线程参数
6)设置TCP缓存大小
init脚本的关键字(如mkdir,chmod,service等等)可以参考init进程的system/core/init/keyword.h文件
修改init.rc文件内容的唯一方式是修改Android的ROM中的内核镜像(boot.img)
二.init.rc包括四种类型的语句:
动作 Action
命令 Command
服务 Service
选项 Option
2.1. 动作 Action
on <trigger> ##触发条件
<command1> ##执行命令
<command2> ##可以同时执行多个命令
<command3>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | sys.boot_completed 开机完成 #当属性sys.boot_completed被设置为 1 时执行 # cpu min freq must change to 126M when boot completed on property:sys.boot_completed= 1 write /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 0 setprop persist.sys.first_booting false start up_eth0 # for Internet adb on property:netadb.status= true setprop service.adb.tcp.port 5555 restart adbd # for Internet adb on property:netadb.status= false setprop service.adb.tcp.port 0 restart adbd on property:net.control= true start network_control on property:net.control= false stop network_control on property:persist.adb_connect.status= true write /sys/bus/platform/drivers/usb20_otg/force_usb_mode 2 on property:persist.adb_connect.status= false write /sys/bus/platform/drivers/usb20_otg/force_usb_mode 1 |
2.2. 命令 Command
1 2 3 4 5 | setprop <name> <value> 设置系统属性<name>为<value> start <service> 启动一个服务(如果服务尚未启动) stop <service> 停止服务(如果正在运行) wait <path> [ <timeout> ] poll特定的<path>,出现后返回,或timeout到达。如果timeout没有指定,默认为 5 秒 write <path> <string> 打开一个位于<path>的文件,写入(不是追加)字符串<string> |
2.3. 服务 Service
1 2 3 4 5 6 7 8 9 | service <name> <pathname> [ <argument> ]* <option> <option> ... <name> ——表示service 的名字 <pathname> ——表示service所在路径,此处的service是可执行文件,所以一定有存储路径 <argument> ——启动service所带的参数 <option> ——对此service的约束选项 |
2.4. 选项 Option
1 2 3 4 | Option用来定义Service的行为,决定了Service将在何时启动,如何运行等。常用的Option有包括以下一些。 class <name> 为一service指定一个类名,所有有相同类名的service可以一同启动或停止。如果没有用 class 选项指定类名,该service属于 "default" 。 disabled 这种类型的服务不会自动启动。它必须明确的使用名字启动 oneshot 退出不重启服务(名副其实,一次性) |
for example……
1 2 3 4 5 6 7 | service network_control /system/bin/network_control.sh class main disabled oneshot service lcdparamservice /system/bin/lcdparamservice class main |
2.5.看服务是否运行
getprop | grep svc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | shell @rk312x :/ $ getprop | grep svc getprop | grep svc [init.svc.adbd]: [running] [init.svc.akmd]: [stopped] [init.svc.bootanim]: [stopped] [init.svc.console]: [running] [init.svc.daemonsu]: [stopped] [init.svc.dhcpcd_eth0]: [stopped] [init.svc.displayd]: [running] [init.svc.drm]: [running] [init.svc.drmservice]: [stopped] [init.svc.healthd]: [running] [init.svc.installd]: [running] [init.svc.keystore]: [running] [init.svc.lcdparamservice]: [running] [init.svc.lmkd]: [running] [init.svc.logd]: [running] [init.svc.media]: [running] [init.svc.netd]: [running] [init.svc.ril-daemon]: [running] [init.svc.sdcard]: [stopping] [init.svc.servicemanager]: [running] [init.svc.surfaceflinger]: [running] [init.svc.ueventd]: [running] [init.svc.up_eth0]: [stopped] [init.svc.vold]: [running] [init.svc.zygote]: [running] |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】