Android学习

Android init.rc配置EVS App开机启动

2020-07-11  本文已影响0人  AnterC

1、init.rc相关知识参考https://www.jianshu.com/p/cb73a88b0eed,这里不详解。

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就能自启动了。

上一篇下一篇

猜你喜欢

热点阅读