Android 系统增加一个开机运行的sh代码

1、打开Android开机初始化文件,/system/core/rootdir/init.rc,在文件最后添加:

# Copyright (C) 2012 The Android Open Source Project
#
# IMPORTANT: Do not create world writable files or directories.
# This is a common source of Android security bugs.
#

import /init.environ.rc
import /system/etc/init/hw/init.usb.rc
import /init.${ro.hardware}.rc
import /vendor/etc/init/hw/init.${ro.hardware}.rc
import /system/etc/init/hw/init.usb.configfs.rc
import /system/etc/init/hw/init.${ro.zygote}.rc

# Cgroups are mounted right before early-init using list from /etc/cgroups.json
on early-init
    # Disable sysrq from keyboard
    write /proc/sys/kernel/sysrq 0

    # Android doesn't need kernel module autoloading, and it causes SELinux
    # denials.  So disable it by setting modprobe to the empty string.  Note: to
    # explicitly set a sysctl to an empty string, a trailing newline is needed.
    write /proc/sys/kernel/modprobe \n
...............................................................
#add init service file

service youinit /system/bin/sh /system/bin/youinit.sh
   class main
   #user root
   user system
   group system
   disabled
   oneshot

on property:sys.boot_completed=1   
   start youinit

文件定义一个youinit 的service,这个service执行 youinit.sh。

on property:sys.boot_completed=1  是在接到系统启动完成后,开机服务。

service 的user,看脚本执行需要root权限,还是system权限。

2、编辑shell文件,并在编译时,将这个shell文件拷贝到/system/bin目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值