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>

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  

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

service <name> <pathname> [ <argument> ]*
     <option>
     <option>
     ...
	 
<name> ——表示service 的名字
<pathname> ——表示service所在路径,此处的service是可执行文件,所以一定有存储路径
<argument> ——启动service所带的参数 
<option> ——对此service的约束选项

2.4. 选项 Option  

Option用来定义Service的行为,决定了Service将在何时启动,如何运行等。常用的Option有包括以下一些。	
class <name> 为一service指定一个类名,所有有相同类名的service可以一同启动或停止。如果没有用class选项指定类名,该service属于"default"。
disabled 这种类型的服务不会自动启动。它必须明确的使用名字启动
oneshot  退出不重启服务(名副其实,一次性)

for example……

service  network_control /system/bin/network_control.sh
    class main
    disabled
    oneshot    

service lcdparamservice /system/bin/lcdparamservice 
   class main

 2.5.看服务是否运行

getprop | grep svc

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]

  

 

  

  

posted @ 2020-12-25 16:55  CrushGirl  阅读(733)  评论(0编辑  收藏  举报