2、添加service
在init.rc中添加evs app服务:
service evs_app /system/bin/evs_app --hw
class main
priority -20
user automotive_evs
group automotive_evs
选项 描述
console [<console>] 此服务需要一个控制台。可选的第二个参数选择特定的控制台而不是默认控制台
critical 这是一项设备关键型服务。 如果它在四分钟内退出四次以上,设备将重启进入恢复模式
disabled 服务不会自动运行,必须显式地通过服务器来启隐拍动。
setenv <name><value>设置环塌键境变量
socket <name><type><perm>[ <user>[ <group>[ <seclabel>] ] ] 在/dev/socket/下创建一个unix domain的socket,并传递创建的文件描述符fd给服务进程.其中type必须为dgram或stream,seqpacket.用户名和组名默认为0
enter_namespace <type><path>输入位于_path_的_ type_类型的命名空间。 _type_设置为“net”时仅支持网络命名空间。 请注意,只能输入给定_type_的一个名称空间
file <path><type>打开文件路径并将其fd传递给已启动的进程。 _type_必须是 “r”,“w”或“rw”。
user <username>在执行此服务之前先切换用户名。当前默认为root.
group <groupname>[ <groupname>* ] 类似于user,切换组名
capabilities <capability>[ <capability>* ] 执行此服务时设置功能
setrlimit <resource><cur><max>这将给定的rlimit应用于服务
seclabel <seclabel>Change to ‘seclabel’ before exec’ing this service
oneshot 当此服务退出时不会自动重启.
class <name>[ <name>* ] 给服务指定一个类属,这样方便 *** 作多个服务同时启动或停止.默认情况下为default
onrestart 当服务重启时执行一条指令
writepid <file>[ <file>* ] Write the child’s pid to the given files when it forks
priority <priority>调度服务进程的优先级。 该值必须在范围内 -20到19,-20优先级最高。
3、启动服务
class main的service会统一在class_start main时调起
4、配置selinux权限
(1)高版本的Android系统团携巧有一套SEAndroid安全机制,SEAndroid扩展自SELinux,如何配置这个evs app的selinux权限:在rc的同级目录下一般会有sepolicy文件夹,里面会有一个file_contexts文件,新建一个evs_app.te文件,参考 https://android.googlesource.com/platform/packages/services/Car/+/master/evs/sepolicy/evs_app.te ,内容如下:
# evs app
type evs_app, domain, coredomain
hal_client_domain(evs_app, hal_evs)
hal_client_domain(evs_app, hal_vehicle)
hal_client_domain(evs_app, hal_configstore)
hal_client_domain(evs_app, hal_graphics_allocator)
# allow init to launch processes in this context
type evs_app_exec, exec_type, file_type, system_file_type
init_daemon_domain(evs_app)
# gets access to its own files on disk
type evs_app_files, file_type, system_file_type
allow evs_app evs_app_files:file { getattr open read }
allow evs_app evs_app_files:dir search
# Allow use of gralloc buffers and EGL
allow evs_app gpu_device:chr_file rw_file_perms
allow evs_app ion_device:chr_file r_file_perms
allow evs_app system_file:dir r_dir_perms
# Allow use of binder and find surfaceflinger
binder_use(evs_app)
allow evs_app surfaceflinger_service:service_manager find
(2)在file_contexts中添加/system/bin/evs_app u:object_r:evs_app_exec:s0
(3)在attributes文件中添加缺失type:system/sepolicy/public/attributes和system/sepolicy/prebuilts/api/28.0/public/attributes中(对应版本)添加attribute system_file_type
5.做完上面这些,完整编译一次,烧录固件,开机时evs_app就能自启动了。
第一篇: Android系统启动之bootloader
第二篇: Android系统启动之Init流程(上)
第三篇: Android系统启动之Init流程(下)
第四篇: Android系统启动之init.rc文件解析过程
第五篇: Android系统启动之zyogte进程
第六篇: Android系判哗统启动之zyogte进程java(上)
第七篇: Android系统启动之zyogte进程java(下)
第八篇: Android系统启动之SystemServer
Android init.rc文件由系统第一个启动的init程序解析。是启动系统服务使用的文件。
主要包含了四种类型的语句:
Action和services显式声明了一个语句块,而commands和options属于最近声明的语句块。
在第一个语句块之前 的commands和options会被忽略.
基本规则如下:
动掘蚂行作表示了一组命令(commands)组成.动作包括一个触发器,决定了何时运行这个动作。
注意: 当触发器的条件满足时,这个动作会被增加到已被运行的队列尾。假设此动作在队列中已经存在,那么它将不会运行.
一个动作所包括的命令将被依次运行。
在"动作"(action)里面的,on后面物隐跟着的字符串是触发器(trigger),trigger是一个用于匹配某种事件类型的字符串,它将对应的Action的执行。
触发器(trigger)有几种格式:
常见的格式:
command是action的命令列表中的命令,或者是service中的选项 onrestart 的参数命令.
命令将在所属事件发生时被一个个地执行.
常见命令:
服务是指那些须要在系统初始化时就启动或退出时自己主动重新启动的程序.
解释一下各个参数:
options是Service的修订项。它们决定一个服务何时以及如何运行.
使用例子:
源码路径 system/core/init/init.cpp 中:
开始解析rc文件.
ParseConfig函数在文件 core/init/init_parser.cpp 140行:
ParseConfigFile函数:
Android init.rc文件浅析
安卓系统启动--3init.rc解析
init.rc深入学习
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)