Android init.rc启动shell脚本
init.rc启动shell脚本
- 0. 前言
- 1. 编写脚本 test.sh
- 2. 修改 .mk 配置文件,将创建的 test.sh 编译到系统分区
- 3. 配置 SELinux 权限
- 3.1 创建 test.te
- 3.2 配置 service.te
- 3.3 配置 file_context
- 4. 配置 init.rc
- 5. 重新编译并刷入
- 6. 注意事项
0. 前言
最近在解决客户的一个问题的时候,帮忙调试了一个开机脚本,其中涉及了部分SELinux的权限的配置,因此记录一下,该案例基于 amlogic S905L3A 芯片开发,在Android P上进行的测试,在其他设备上大同小异,请自行查找或替换为对应的路径。
注:Android P上为了区分系统和厂商定制化内容,脚本应编译至vendor/bin下,而不是system/bin下。
1. 编写脚本 test.sh
举个例子:
#!/system/bin/sh
# 该脚本只是演示,请根据自己需求编写脚本
if [ -f /data/system/test.xml ]; thenecho "test already set"
elsecp /system/test.xml /data/system/test.xmlchmod 0600 /data/system/test.xmlchown system:system /data/system/test.xmlfi
脚本具体放置位置可以自行安排
2. 修改 .mk 配置文件,将创建的 test.sh 编译到系统分区
PRODUCT_COPY_FILES += \device/amlogic/$(PRODUCT_DIR)/files/tcp_control.sh:vendor/bin/tcp_control.sh \
将工程中的device/amlogic/$(PRODUCT_DIR)/files/tcp_control.sh
copy至vendor/bin/tcp_control.sh
3. 配置 SELinux 权限
3.1 创建 test.te
在 service.te
文件所在的目录下创建 test.te
type testshell, domain;
type testshell_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(testshell)#配置脚本中需要的权限,可以无
allow testshell vendor_shell_exec:file { execute_no_trans };
allow testshell device:chr_file { ioctl };
#allow testshell system_file:file { execute };
#allow testshell toolbox_exec:file { map };
allow testshell storage_file:dir { search };
allow testshell storage_file:lnk_file { read };
allow testshell mnt_user_file:lnk_file { read };
allow testshell mnt_user_file:dir { search };
allow testshell sdcardfs:dir { search write add_name create };
#allow testshell media_rw_data_file:dir { read open search write };
allow testshell system_data_file:file { getattr };
3.2 配置 service.te
在 service.te
中增加一行
...
type test_service, app_api_service, ephemeral_app_api_service, system_server_service, service_manager_type;
...
3.3 配置 file_context
在 file_contexts
中增加一行
#test
/vendor/bin/test.sh u:object_r:testshell_exec:s0
具体到我的工程,SELinux 配置所在的路径为 device/amlogic/common/sepolicy
, test.te
、service.te
、file_context
都在该目录下。
4. 配置 init.rc
在 init.rc
文件中找到 on boot
,在其中增加一行 exec -- /vendor/bin/test.sh
,如下
on boot......# execute test.sh exec -- /vendor/bin/test.sh
具体到我的工程,target
对应的 init.rc
文件为device/amlogic/p291_iptv/init.amlogic.board.rc
5. 重新编译并刷入
重新编译并刷入,查看脚本中指令生效(如复制文件,设置属性等),从而验证 test.sh 脚本是否被执行,也可以通过 adb shell dmesg
命令查看开机日志检查是否有脚本中的打印。
6. 注意事项
案例中的路径可能和你工程路径不一致,请自行查找或替换为对应的路径。
Android init.rc启动shell脚本相关推荐
- android开机后自动执行shell,init.rc启动 shell脚本
[Android] 在開機的時候,執行你想要的 shell script 雖然 init.rc 很好用,但還是有其缺陷... 像是我要 echo 某些字串到檔案時,他就做不到了 :( 所以可以搭配一個 ...
- Android8.0 开机启动脚本,Android开机启动shell脚本(Android 8.0测试OK)
Android 下做开机启动shell脚本的大致流程如下: 目录 写shell脚本 为脚本写te文件 在init.rc中启动脚本 添加Selinux权限 写shell脚本 比如新建一个init.tes ...
- Android 开机启动shell脚本
接到一个集成功能的需求,然后看了一下是由上层应用 + linux进程实现的功能,需要增加开机自动启动linux进程,没弄过有点懵. 这个不怎么正确,仅供参考,在权限那块需要更改,放到system下 环 ...
- android init.rc中启动的service 默认是disable的,后续如何启动此服务
如果 android init.rc中启动的service 默认是disable的,如何才能启动此服务呢? init.rc中可以直接启动service 附带的参数决定启动程序的状态,例如数据业务中配置 ...
- Android init.rc 服务启动不成功
Android init.rc 服务启动不成功 问题 在开发过程中发现一个问题,我们需要在开机的时候判断硬件版本号去启动服务, 服务的名字是ledservice和ledservice4,但是发现每次烧 ...
- Android init.rc文件解析过程详解(三)
Android init.rc文件解析过程详解(三) 三.相关结构体 1.listnode listnode结构体用于建立双向链表,这种结构广泛用于kernel代码中, android源代码中定义了l ...
- Android init.rc文件格式解析
/****************************************************************************** Android init.rc文件格式解 ...
- Android init.rc文件解析过程详解(一)
Android init.rc文件解析过程详解(一) 一.init.rc文件结构介绍 init.rc文件基本组成单位是section, section分为三种类型,分别由三个关键字(所谓关键字 ...
- android init.rc 到底在哪里?
这些天想加一个启动进程到android的启动里面,结果找了半天修改启动的办法,大多提到是在init.rc里面修改,但是网上很多版本都没研究清楚啊 1 不知道源码的情况下,从安装包里面拿 通过下面的例子 ...
最新文章
- flutter利用高德如何获取地理位置信息bug处理
- vue通过class获取dom_.NET Core通过Json或直接获取图形验证码(务必收藏备用)
- php显示doc文件乱码,如何解决php doc 乱码问题
- mysql三表where查询_mysql三表查询sql语句
- python 之Requests库学习笔记
- 最近刚写的——三维饼图
- Linux正则表达式与grep
- Aloha:一个略屌的分布式任务调度框架
- nanopi制作个人服务器,NanoPi K2 服务器系统镜像
- 汉字字符编码的科普笔记(GB2312汉字编码,Unicode与UTF-8,字符映射表,vim,文泉驿,正则表达式)
- linux中的sg工具,sg3_utils工具windows系统下的使用
- 使用ARCGIS多重缓冲区分析工具建立颜色渐变行政边界
- vue.js根据数据循环生成表格_Vue Elenent实现表格相同数据列合并
- 误差条图各部分的代表意思_【小强视界】混凝土搅拌站计量误差原因分析及控制措施...
- 4.8 单元格背景样式的设置 [原创Excel教程]
- Brew doctor warns about “Warning: A newer Command Line Tools release is available”
- 刷脸支付就是会员为大商户管理与运营提供帮助
- 限制电脑使用指定的软件
- 极路由1S升级系统之后再刷机学习记录
- 原来路由器的USB接口这么强大!这样设置,路由器秒变私有云盘