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目录