1、添加需要自启动的可以执行文件:
(1)可执行C文件:system/core/init_start/needInitStartService.c
例如:
#include <stdio.h>
#include <cutils/properties.h>
int main()
{
FILE * fp;
char buffer[16];
fp=popen("/system/bin/modetool -s | grep +QCSN: | sed 's/\"/ /g' | awk '{print $2}'","r");
fgets(buffer,sizeof(buffer),fp);
property_set("persist.sys.getSNumber",buffer);
pclose(fp);
return 0;
}
(2)打包Android.mk文件system/core/init_start/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
#LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_SRC_FILES:= \
drmservice.c
LOCAL_MULTILIB := 32
LOCAL_C_INCLUDES += bionic \
$(call include-path-for, libhardware_legacy)/hardware_legacy
LOCAL_MODULE:=needInitStartService
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES := libfs_mgr libcutils
#libc
LOCAL_SHARED_LIBRARIES := libhardware_legacy libnetutils liblog
include $(BUILD_EXECUTABLE)
2、添加可执行文件needInitStartService打包到固件操作
device/qcom/msmXXXX_64/msmXXXX_64.mk
+ PRODUCT_PACKAGES += needInitStartService
PRODUCT_COPY_FILES += $(call find-copy-subdir-files,*,device/qcom/XXXX_64/xsy,data/xsy)
PRODUCT_COPY_FILES += $(call find-copy-subdir-files,*,device/qcom/msmXXXX_64/xsy,vendor/app/xsy)
3、添加开机自启动权限
(1)、file_contexts中添加device/qcom/sepolicy/vendor/msmXXXX/file_contexts
/dev/block/platform/soc/7824900.sdhci/by-name/sbl1_[ab] u:object_r:xbl_block_device:s0
+ /system/bin/needInitStartService u:object_r:needInitStartService_exec:s0
(2)、具体权限添加,新建此文件device/qcom/sepolicy/vendor/msmXXXX/needInitStartService.te
# needInitStartService service
type needInitStartService, domain,coredomain;
type needInitStartService_exec, exec_type,file_type;
init_daemon_domain(needInitStartService)
allow needInitStartService shell_exec:file {execute read open execute_no_trans getattr};
allow needInitStartService property_socket:sock_file {write};
allow needInitStartService init:unix_stream_socket {connectto};
allow needInitStartService system_file:file { execute_no_trans };
allow needInitStartService system_data_file:file { getattr };
allow needInitStartService toolbox_exec:file { getattr execute read open execute_no_trans};
allow needInitStartService vendor_toolbox_exec:file { getattr execute};
allow needInitStartService smd_device:chr_file { read write open};
allow needInitStartService system_prop:property_service { set};
3、init.rc将启动文件添加成service在系统开机后自启动:
# This allows the ledtrig-transient properties to be created here so
# that they can be chown'd to system:system later on boot
write /sys/class/leds/vibrator/trigger "transient"
+ chmod 777 /system/bin/needInitStartService
+ setprop persist.sys.getSNumber 000000000000000
# Healthd can trigger a full boot from charger mode by signaling this
# property when the power button is held.
class_reset late_start
class_reset main
+service needInitStartService/system/bin/needInitStartService
+ class main
+ oneshot
on property:sys.boot_completed=1
bootchart stop
+ start needInitStartService
# system server cannot write to /proc/sys files,
# and chown/chmod does not work for /proc/sys/ entries.
## Daemon processes to be run by init.
##
service ueventd /sbin/ueventd
class core
critical
至此添加一个可执行的文件开机自启动完成