android11-开机自启脚本

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. 编写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.

4. 编写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 };
+

5. 编写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

6. 编译烧写镜像测试

请添加图片描述

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Android 9中,应用程序不能自动启动,除非用户明确地启用了自动启动权限。这是为了保护用户的隐私和设备的性能。 如果您需要在设备启动时自动运行脚本,可以考虑创建一个后台服务,并在启动启动该服务。以下是一个简单的示例: 1. 创建一个后台服务类: ``` public class MyService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { // 在此处编写需要自动运行的脚本 return START_STICKY; } @Override public IBinder onBind(Intent intent) { return null; } } ``` 2. 在AndroidManifest.xml文件中声明该服务: ``` <service android:name=".MyService" android:enabled="true" android:exported="false" /> ``` 3. 在应用程序的启动Activity或Application类中启动该服务: ``` Intent intent = new Intent(this, MyService.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { startForegroundService(intent); } else { startService(intent); } ``` 请注意,为了在Android 9及更高版本中正常工作,您需要启动一个前台服务。这可以通过调用startForegroundService()代替startService()来实现。 在启动服务时,您还需要请求自动启动权限。这可以通过向用户显示一个对话框并要求他们手动启用此权限来实现。以下是一个简单的示例: ``` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(); String packageName = getPackageName(); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); if (!pm.isIgnoringBatteryOptimizations(packageName)) { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + packageName)); startActivity(intent); } } ``` 请注意,这只是一个示例,您需要根据您的应用程序需求进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Paper_Love

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值