android11-开机自启脚本

发布时间:2023年12月19日

1. 编写myshell脚本

diff --git a/device/rockchip/rk356x/ok3568_r/myshell.sh b/device/rockchip/rk356x/ok3568_r/myshell.sh
new file mode 100644
index 0000000000..c78b6d93bd
--- /dev/null
+++ b/device/rockchip/rk356x/ok3568_r/myshell.sh
@@ -0,0 +1,4 @@
+#!/vendor/bin/sh
+
+echo "1.sh finished" > /dev/console

2. 拷贝myshell脚本

diff --git a/device/rockchip/rk356x/ok3568_r/ok3568_r.mk b/device/rockchip/rk356x/ok3568_r/ok3568_r.mk
index 66a21909d2..317d9096cd 100644
--- a/device/rockchip/rk356x/ok3568_r/ok3568_r.mk
+++ b/device/rockchip/rk356x/ok3568_r/ok3568_r.mk
@@ -45,7 +45,9 @@ PRODUCT_PROPERTY_OVERRIDES += persist.wifi.sleep.delay.ms=0
 PRODUCT_PROPERTY_OVERRIDES += persist.bt.power.down=true
 
 PRODUCT_COPY_FILES += \
-    $(LOCAL_PATH)/bootanimation.zip:system/media/bootanimation.zip
+    $(LOCAL_PATH)/bootanimation.zip:system/media/bootanimation.zip \
+    $(LOCAL_PATH)/myshell.sh:$(TARGET_COPY_OUT_VENDOR)/bin/myshell.sh
 
 PRODUCT_PACKAGES += \
     watchdogtest \

3. 编写selinux规则

diff --git a/device/rockchip/common/sepolicy/vendor/myshell.te b/device/rockchip/common/sepolicy/vendor/myshell.te
new file mode 100644
index 0000000000..eeb52cb9ac
--- /dev/null
+++ b/device/rockchip/common/sepolicy/vendor/myshell.te
@@ -0,0 +1,11 @@
+type myshell, domain;
+type myshell_exec, exec_type, vendor_file_type, file_type;
+
+init_daemon_domain(myshell)
+
+allow myshell vendor_shell_exec:file rx_file_perms;
+allow myshell vendor_toolbox_exec:file rx_file_perms;
+allow myshell console_device:chr_file { open write };
+allow myshell myshell:capability { sys_module };
+allow myshell vendor_file:system { module_load };
+

4. 编写selinux规则上下文

diff --git a/device/rockchip/common/sepolicy/vendor/file_contexts b/device/rockchip/common/sepolicy/vendor/file_contexts
index df2a46abdc..53f21d46c6 100644
--- a/device/rockchip/common/sepolicy/vendor/file_contexts
+++ b/device/rockchip/common/sepolicy/vendor/file_contexts
@@ -238,3 +238,4 @@
 #flash_img
 /vendor/bin/flash_img.sh u:object_r:vendor_install_recovery_exec:s0
 
+/vendor/bin/myshell.sh    u:object_r:myshell_exec:s0

5. 编写myshell服务并启动myshell服务

diff --git a/system/core/rootdir/init.rc b/system/core/rootdir/init.rc
index a9af0b094d..02610df121 100644
--- a/system/core/rootdir/init.rc
+++ b/system/core/rootdir/init.rc
@@ -978,11 +978,20 @@ on property:vold.decrypt=trigger_shutdown_framework
     class_reset_post_data core
     class_reset_post_data hal
 
+service myshell /vendor/bin/myshell.sh
+    class main
+    user root
+    group root
+    disabled
+    oneshot
+
 on property:sys.boot_completed=1
     bootchart stop
     # Setup per_boot directory so other .rc could start to use it on boot_completed
     exec - system system -- /bin/rm -rf /data/per_boot
     mkdir /data/per_boot 0700 system system encryption=Require key=per_boot_ref
+    start myshell
+
 
 # system server cannot write to /proc/sys files,
 # and chown/chmod does not work for /proc/sys/ entries.

6. 编译烧写镜像测试

请添加图片描述

文章来源:https://blog.csdn.net/qq_42952079/article/details/135095032
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。