device/fsl/imx8q/etc/reboot_adb
device/fsl/imx8q/mek_8q/BoardConfig.mk
device/fsl/imx8q/mek_8q/init_car.rc
device/fsl/imx8q/sepolicy_car/file_contexts
device/fsl/imx8q/sepolicy_car/reboot_adb.te
system/core/init/init.cpp
shell文件中,执行的shell命令:
device/fsl/imx8q/etc/reboot_adb
#!/bin/sh
#show log
echo "init.rc adb reboot"
am broadcast -a android.intent.action.REBOOT -n com.ad.carcontrol/com.ad.carcontrol.StaticBroadcastReceiver
#chown system:system /sys/devices/platform/5b0d0000.usb/ci_hdrc.0/driver/ci_hdrc.0/role
#setenforce 0
#ip addr add 10.10.10.10/24 dev eth0
#ip rule add from all lookup main pref 9999
#chmod 0777 /vendor/etc/wifi/* -R
#chmod 0777 /data/misc/wifi/* -R
#chown wifi:wifi /vendor/etc/wifi/*
#chown wifi:wifi /sys/module/bcmdhd/parameters
#chown wifi:wifi /sys/module/bcmdhd/parameters/firmware_path
#chown wifi:wifi /sys/module/bcmdhd/parameters/nvram_path
#chown system:system /sys/class/backlight/lvds_backlight@1/brightness
#chmod 777 /sys/class/backlight/lvds_backlight@1
#chown wifi:wifi /data/misc/wifi/* -R
#sleep 1
#setenforce 1
将reboot_adb的shell脚本拷贝到vendor/bin/目录下
device/fsl/imx8q/mek_8q/BoardConfig.mk
PRODUCT_COPY_FILES += \
hardware/gps/u-blox/gps.conf:system/etc/gps.conf \
hardware/gps/u-blox/u-blox.conf:vendor/etc/u-blox.conf \
device/fsl/imx8q/etc/busybox:system/bin/busybox \
device/fsl/imx8q/etc/selinuxswitch:vendor/bin/selinuxswitch \
device/fsl/imx8q/etc/reboot_adb:vendor/bin/reboot_adb
init.rc文件中添加一个service,用于执行/vendor/bin/reboot_adb的shell脚本
并且,添加vendor.reboot和vendor.reboot.adb.event属性值变化的监听
device/fsl/imx8q/mek_8q/init_car.rc
#add by sunxiaolin start 20191031
service reboot_adb /vendor/bin/reboot_adb
class main
user root
group root shell
disabled
oneshot
#add by sunxiaolin start 20191031
on property:sys.powerctl=*
start reboot_adb
on property:vendor.reboot=*
start reboot_adb
on property:vendor.reboot.adb.event=1
start reboot_adb
#add by sunxiaolin start 20191031
添加脚本reboot_adb的执行权限
device/fsl/imx8q/sepolicy_car/file_contexts
# Persist STSensors calibration filesystem
/persist/STCalibration(/.*)? u:object_r:persist_STSensors_file:s0
# STSensors_deamon
/vendor/bin/evs_service u:object_r:evs_service_exec:s0
/vendor/bin/selinuxswitch u:object_r:selinuxswitch_exec:s0
/system/bin/STSensors_daemon u:object_r:STSensors_exec:s0
/vendor/bin/reboot_adb u:object_r:reboot_adb_exec:s0
添加reboot_adb脚本的SELinux权限
device/fsl/imx8q/sepolicy_car/reboot_adb.te
type reboot_adb, domain;
type reboot_adb_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(reboot_adb)
set_prop(reboot_adb, public_vendor_default_prop)
allow reboot_adb vendor_shell_exec:file rx_file_perms;
allow reboot_adb vendor_toolbox_exec:file rx_file_perms;
# Allow insmod
allow reboot_adb self:capability sys_module;
allow reboot_adb system_file:file { getattr setattr open read write create };
allow reboot_adb vendor_file:file { getattr setattr open read write create };
allow reboot_adb wc_prop:property_service { set };
allow reboot_adb shell_exec:file { map read execute getattr setattr create append };
allow reboot_adb sysfs:file { getattr setattr };
allow reboot_adb sysfs:dir { getattr setattr };
allow reboot_adb reboot_adb:capability { dac_read_search chown fowner fsetid };
allow reboot_adb toolbox_exec:file { getattr setattr execute read open write execute_no_trans map };
allow reboot_adb wifi_data_file:dir { read getattr setattr open search };
allow reboot_adb wifi_data_file:file { read getattr setattr };
allow reboot_adb wpa_socket:dir { read getattr setattr open search };
allow reboot_adb wpa_socket:file { read getattr setattr };
allow reboot_adb wpa_socket:sock_file { read getattr setattr };
allow reboot_adb selinuxfs:file { read write open };
allow reboot_adb system_wpa_socket:sock_file { read getattr setattr };
allow reboot_adb kernel:security { setenforce };
这样当属性vendor.reboot变化的时候或者vendor.reboot.adb.event=1的时候,就会执行reboot_adb脚本中的shell命令。
adb shell setprop vendor.reboot reboot
adb shell setprop vendor.reboot.adb.event 1