android 8.1添加开机启动服务

android 8.1添加开机启动服务

修改文件:

From 0ecbea62c6ceed9bc54a29524f04cd593e036eaa Mon Sep 17 00:00:00 2001
From: “xu.han747” [email protected]
Date: Wed, 25 Dec 2019 20:53:35 +0800
Subject: [PATCH] [Sim8950l_yunchongba]-system-[Add boot startup script]

Change-Id: I73f7a69afa275ac3108b5ec7bafbd5bff019ddb2

…/device/qcom/msm8953_32/initlogkernel.sh | 84 ++++++++++++++++++++++
…/device/qcom/msm8953_32/msm8953_32.mk | 3 +
…/device/qcom/sepolicy/common/file_contexts | 1 +
…/system/core/libcutils/fs_config.cpp | 1 +
sim8950l_yunchong/system/core/rootdir/init.rc | 6 ++
…/prebuilts/api/26.0/private/initlogkernel.te | 4 ++
…/prebuilts/api/26.0/public/initlogkernel.te | 4 ++
…/system/sepolicy/private/initlogkernel.te | 4 ++
sim8950l_yunchong/system/sepolicy/public/domain.te | 1 +
sim8950l_yunchong/system/sepolicy/public/init.te | 14 ++±
…/system/sepolicy/public/initlogkernel.te | 4 ++
11 files changed, 124 insertions(+), 2 deletions(-)
create mode 100644 sim8950l_yunchong/device/qcom/msm8953_32/initlogkernel.sh
create mode 100644 sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/initlogkernel.te
create mode 100644 sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/public/initlogkernel.te
create mode 100644 sim8950l_yunchong/system/sepolicy/private/initlogkernel.te
create mode 100644 sim8950l_yunchong/system/sepolicy/public/initlogkernel.te

diff --git a/sim8950l_yunchong/device/qcom/msm8953_32/initlogkernel.sh b/sim8950l_yunchong/device/qcom/msm8953_32/initlogkernel.sh
new file mode 100644
index 0000000…f9a099b
— /dev/null
+++ b/sim8950l_yunchong/device/qcom/msm8953_32/initlogkernel.sh
@@ -0,0 +1,84 @@
+#!/vendor/bin/sh
+
+LOG_TAG=“logcat”
+LOG_NAME="${0}:"
+
+logcat_pid=""
+cp_pid=""
+
+sdcard_path="/sdcard"
+mount | grep “/sdcard ext4” > /dev/null
+
+#while [ $? == 1 ]
+#do
+# sleep 1
+# mount | grep “/sdcard ext4”
+#done
+
+loge ()
+{

  • /system/bin/log -t L O G T A G − p e " LOG_TAG -p e " LOGTAGpe"LOG_NAME $@"
    +}

+logi ()
+{

  • /system/bin/log -t L O G T A G − p i " LOG_TAG -p i " LOGTAGpi"LOG_NAME $@"
    +}

+failed ()
+{

  • loge “$1: exit code $2”
  • exit $2
    +}
    +start_logcat ()
    +{
  • if [ ! -d “${sdcard_path}/log” ]; then
  •    /system/bin/mkdir ${sdcard_path}/log/
    
  • fi
  • if [ ! -d “${sdcard_path}/log/pstore” ]; then
  •    /system/bin/mkdir ${sdcard_path}/log/pstore/
    
  • fi
  • #if [ -f “/sys/fs/pstore/dmesg-ramoops-0” ]; then
  •    #/system/bin/tar czf  ${sdcard_path}/log/pstore/$(ls -l /sdcard/log/pstore/|grep "^-"|wc -l).tar.gz  sys/fs/pstore/  
    
  •    #rm /sys/fs/pstore/dmesg-ramoops-0
    
  • #fi
  • if [ ! -d “/mnt/external_sd” ]; then
  •    /system/bin/mkdir /mnt/external_sd/
    
  • fi
  • if [ ! -d “/mnt/external_sd/Log” ]; then
  •    /system/bin/mkdir /mnt/external_sd/Log/
    
  • fi
  • if [ ! -d “/mnt/external_sd/Log/drive/” ]; then
  •    /system/bin/mkdir /mnt/external_sd/Log/drive/
    
  • fi
  • /system/bin/chmod 777 /mnt/external_sd/Log/drive/
  • #/system/bin/cp /mnt/external_sd/Log/drive/logcat_kernel.log /mnt/external_sd/Log/drive/logcat_kernel.log.last
  • #/system/bin/mkdir ${sdcard_path}/log/
  • /system/bin/logcat -b kernel -f /mnt/external_sd/Log/drive/logcat_kernel.log -r1024 -n 25 -v time &
  • logcat_pid=$!
  • logi “start_logcat: logcat pid = $logcat_pid”
    +}

+kill_logcat ()
+{

  • logi “kill_logcat: pid = $logcat_pid”
  • careful not to kill zero or null!

  • kill -TERM $logcat_pid
  • this shell doesn’t exit now – wait returns for normal exit

+}
+
+# init does SIGTERM on ctl.stop for service
+#trap “kill_logcat” TERM INT
+
+start_logcat
+
+#wait $cp_pid
+#busybox sync
+wait $logcat_pid
+
+logi “logcat service stopped”
+
+exit 0
diff --git a/sim8950l_yunchong/device/qcom/msm8953_32/msm8953_32.mk b/sim8950l_yunchong/device/qcom/msm8953_32/msm8953_32.mk
index ca4661a…af7572e 100644
— a/sim8950l_yunchong/device/qcom/msm8953_32/msm8953_32.mk
+++ b/sim8950l_yunchong/device/qcom/msm8953_32/msm8953_32.mk
@@ -233,6 +233,9 @@ PRODUCT_COPY_FILES += \

#fstab.qcom
PRODUCT_PACKAGES += fstab.qcom
+#initkernellog
+PRODUCT_COPY_FILES += \

  • device/qcom/msm8953_32/initlogkernel.sh:$(TARGET_COPY_OUT_VENDOR)/bin/initlogkernel.sh

#OEM Services library
PRODUCT_PACKAGES += oem-services
diff --git a/sim8950l_yunchong/device/qcom/sepolicy/common/file_contexts b/sim8950l_yunchong/device/qcom/sepolicy/common/file_contexts
index 4dbd2ea…2b1b815 100755
— a/sim8950l_yunchong/device/qcom/sepolicy/common/file_contexts
+++ b/sim8950l_yunchong/device/qcom/sepolicy/common/file_contexts
@@ -698,6 +698,7 @@
/firmware/image(/.*)? u:object_r:firmware_file:s0

/(vendor|system/vendor)/bin/grep u:object_r:vendor_toolbox_exec:s0
+/(vendor|system/vendor)/bin/initlogkernel.sh u:object_r:initlogkernel_exec:s0
##################################
#vendor toolbox

diff --git a/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/file_contexts b/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/file_contexts
index 4dbd2ea…2b1b815 100755
— a/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/file_contexts
+++ b/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/file_contexts
@@ -698,6 +698,7 @@
/firmware/image(/.*)? u:object_r:firmware_file:s0

/(vendor|system/vendor)/bin/grep u:object_r:vendor_toolbox_exec:s0
+/(vendor|system/vendor)/bin/initlogkernel.sh u:object_r:initlogkernel_exec:s0
##################################
#vendor toolbox

diff --git a/sim8950l_yunchong/system/core/libcutils/fs_config.cpp b/sim8950l_yunchong/system/core/libcutils/fs_config.cpp
index 2ec2283…e45d06f 100644
— a/sim8950l_yunchong/system/core/libcutils/fs_config.cpp
+++ b/sim8950l_yunchong/system/core/libcutils/fs_config.cpp
@@ -157,6 +157,7 @@ static const struct fs_path_config android_files[] = {
{ 00440, AID_ROOT, AID_SHELL, 0, “system/etc/init.goldfish.rc” },
{ 00550, AID_ROOT, AID_SHELL, 0, “system/etc/init.goldfish.sh” },
{ 00550, AID_ROOT, AID_SHELL, 0, “system/etc/init.ril” },

  • { 00755, AID_ROOT, AID_SHELL, 0, “vendor/bin/initlogkernel.sh” },
    { 00555, AID_ROOT, AID_ROOT, 0, “system/etc/ppp/" },
    { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.
    ” },
    { 00440, AID_ROOT, AID_ROOT, 0, “system/etc/recovery.img” },
    diff --git a/sim8950l_yunchong/system/core/rootdir/init.rc b/sim8950l_yunchong/system/core/rootdir/init.rc
    index 9214c4b…5fe13bc 100644
    — a/sim8950l_yunchong/system/core/rootdir/init.rc
    +++ b/sim8950l_yunchong/system/core/rootdir/init.rc
    @@ -741,3 +741,9 @@ on property:ro.debuggable=1
    service flash_recovery /system/bin/install-recovery.sh
    class main
    oneshot

+service initlogkernel /verdor/bin/initlogkernel.sh

  • class main
  • user root
  • group root
  • oneshot
    diff --git a/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/initlogkernel.te b/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/initlogkernel.te
    new file mode 100644
    index 0000000…55ce43b
    — /dev/null
    +++ b/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/private/initlogkernel.te
    @@ -0,0 +1,4 @@
    +typeattribute yos coredomain;
    +typeattribute yos mlstrustedsubject;
    +init_daemon_domain(initlogkernel)

diff --git a/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/public/initlogkernel.te b/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/public/initlogkernel.te
new file mode 100644
index 0000000…a76d83d
— /dev/null
+++ b/sim8950l_yunchong/system/sepolicy/prebuilts/api/26.0/public/initlogkernel.te
@@ -0,0 +1,4 @@
+type initlogkernel, domain;
+type initlogkernel_exec, exec_type, vendor_file_type,file_type;
+
+
diff --git a/sim8950l_yunchong/system/sepolicy/private/initlogkernel.te b/sim8950l_yunchong/system/sepolicy/private/initlogkernel.te
new file mode 100644
index 0000000…55ce43b
— /dev/null
+++ b/sim8950l_yunchong/system/sepolicy/private/initlogkernel.te
@@ -0,0 +1,4 @@
+typeattribute yos coredomain;
+typeattribute yos mlstrustedsubject;
+init_daemon_domain(initlogkernel)
+
diff --git a/sim8950l_yunchong/system/sepolicy/public/domain.te b/sim8950l_yunchong/system/sepolicy/public/domain.te
index 69ea412…bd040f2 100644
— a/sim8950l_yunchong/system/sepolicy/public/domain.te
+++ b/sim8950l_yunchong/system/sepolicy/public/domain.te
@@ -407,6 +407,7 @@ neverallow {
vendor_file_type
exec_type
-yos_exec

  • -initlogkernel_exec
    }:dir_file_class_set { create write setattr relabelfrom append unlink link rename };

neverallow { domain -recovery -kernel with_asan(`-asan_extract’) } { system_file vendor_file_type exec_type }:dir_file_class_set relabelto;
diff --git a/sim8950l_yunchong/system/sepolicy/public/init.te b/sim8950l_yunchong/system/sepolicy/public/init.te
index 5ef66e6…ad8ee40 100644
— a/sim8950l_yunchong/system/sepolicy/public/init.te
+++ b/sim8950l_yunchong/system/sepolicy/public/init.te
@@ -428,7 +428,7 @@ neverallow init shell_data_file:lnk_file read;
neverallow init app_data_file:lnk_file read;

init should never execute a program without changing to another domain.

-neverallow init { file_type fs_type -yos_exec }:file execute_no_trans;
+neverallow init { file_type fs_type -yos_exec -initlogkernel_exec}:file execute_no_trans;

Init never adds or uses services via service_manager.

neverallow init service_manager_type:service_manager { add find };
@@ -439,4 +439,14 @@ neverallow init shell_data_file:dir { write add_name remove_name };

yos service

allow init yos_exec:dir { create setattr write add_name };
-allow init yos_exec:file { append setattr execute_no_trans create write };
\ No newline at end of file
+allow init yos_exec:file { append setattr execute_no_trans create write };
+
+# initlogkernel service
+allow init initlogkernel_exec:dir { read open };
+allow init initlogkernel_exec:dir search;
+allow init initlogkernel_exec:dir getattr;
+allow init initlogkernel_exec:capability dac_override;
+allow init initlogkernel_exec:dir { getattr search };
+allow init initlogkernel_exec:lnk_file read;
+allow init initlogkernel_exec:dir { write create add_name setattr };
+allow init initlogkernel_exec:file { read getattr open execute execute_no_trans };
diff --git a/sim8950l_yunchong/system/sepolicy/public/initlogkernel.te b/sim8950l_yunchong/system/sepolicy/public/initlogkernel.te
new file mode 100644
index 0000000…a76d83d
— /dev/null
+++ b/sim8950l_yunchong/system/sepolicy/public/initlogkernel.te
@@ -0,0 +1,4 @@
+type initlogkernel, domain;
+type initlogkernel_exec, exec_type, vendor_file_type,file_type;
+
+

diff --git a/sim8950l_yunchong/device/qcom/common/rootdir/etc/init.qcom.rc b/sim8950l_yunchong/device/qcom/common/rootdir/etc/init.qcom.rc
index 9214c4b…5fe13bc 100644
— a/sim8950l_yunchong/device/qcom/common/rootdir/etc/init.qcom.rc
+++ b/sim8950l_yunchong/device/qcom/common/rootdir/etc/init.qcom.rc
@@ -741,3 +741,9 @@ on property:ro.debuggable=1

  • chmod 0777 /vendor/initlogkernel.sh
    1.9.1

你可能感兴趣的:(android 8.1添加开机启动服务)