Android的***.sh的开机服务添加
生活随笔
收集整理的這篇文章主要介紹了
Android的***.sh的开机服务添加
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Android的***.sh的開機服務添加
- Android的***.sh的開機服務添加
- 1、寫好wifi_scan_android.sh
- 2、直接將wifi_scan_android放到./device/rockchip/rk3288下
- 3、修改makefile文件
- 4、添加啟動服務
- 5、修改權限
- 6、添加exec
- 6、添加***.te文件
- 最后的幾點注意
Android的***.sh的開機服務添加
看網上資料結合自己的rockchip平臺,由于無線網經常斷開,所以打算添加一個服務,來監測網絡情況并處理
1、寫好wifi_scan_android.sh
下面是腳本內容 代碼片.注意done后要有回車的一行。
// An sh shell #!/system/bin/sh while : doif ping -c 1 www.baidu.com$i > /dev/nullthenecho "online"#date >> /sdcard/online.logsleep 60elsesleep 4if ping -c www.baidu.com$i > /dev/nullthenecho "online"sleep 60#date >> /scard/online.logelsesleep 4if ping -c www.baidu.com$i > /dev/nullthenecho "online"sleep 60elsesleep 4if ping -c www.baidu.com$i > /dev/nullthenecho "online"sleep 60elseecho "offline"#date >> /sdcard/offline2.logsvc wifi disablesleep 2svc wifi enablesleep 120fifififi done2、直接將wifi_scan_android放到./device/rockchip/rk3288下
3、修改makefile文件
修改./device/rockchip/rk3288/device.mk,在相似的位置添加如下內容
# copy wifi_scan_android.sh for Vulkan features. xxdd PRODUCT_COPY_FILES += \device/rockchip/rk3288/wifi_scan_android:system/bin/wifi_scan_android4、添加啟動服務
在./system/core/rootdir/init.rc中添加如下內容
service wifi_scan /system/bin/wifi_scan_androidclass mainuser rootgroup root5、修改權限
打開./system/core/libcutils/fs_config.c
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" },{ 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" },{ 00444, AID_ROOT, AID_ROOT, 0, conf_dir + 1 },{ 00444, AID_ROOT, AID_ROOT, 0, conf_file + 1 },{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },{ 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" },{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" },{ 00644, AID_APP, AID_APP, 0, "data/data/*" },{ 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest/tests.txt" },{ 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest64/tests.txt" },{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest/*" },{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64/*" },/* the following two files are INTENTIONALLY set-uid, but they* are NOT included on user builds. */{ 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },/* the following files have enhanced capabilities and ARE included in user builds. */{ 00750, AID_ROOT, AID_SHELL, CAP_MASK_LONG(CAP_SETUID) | CAP_MASK_LONG(CAP_SETGID), "system/bin/run-as" },{ 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND), "system/bin/inputflinger" },/* Support FIFO scheduling mode in SurfaceFlinger. */{ 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), "system/bin/surfaceflinger" },{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" },{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" },{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },{ 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" },{ 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" },{ 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" },{ 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" },{ 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/xbin/*" },{ 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" },{ 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" },{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },{ 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },{ 00750, AID_ROOT, AID_SHELL, 0, "init*" },{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },{ 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },{ 00644, AID_ROOT, AID_ROOT, 0, 0 },{ 00777, AID_ROOT, AID_SHELL, 0, "system/bin/wifi_scan_adnroid" }, };可以看到,在該結構體的末尾加了{ 00777, AID_ROOT, AID_SHELL, 0, “system/bin/wifi_scan_adnroid” }, 來改變目標文件的權限。
6、添加exec
在./system/seplicy/file_contexts添加如下內容
/system/bin/wifi_scan_android u:object_r:wifi_scan_android_exec:s0圖片:
把相應的內容加到# System files下的合適位置
6、添加***.te文件
在./system/seplicy/下添加wifi_scan_android.te文件,內容如下
# cppreopts # # This command copies preopted files from the system_b partition to the data # partition. This domain ensures that we are only copying into specific # directories.## type cppreopts, domain, mlstrustedsubject; type wifi_scan_android, domain; type wifi_scan_android_exec, exec_type, file_type;# Technically not a daemon but we do want the transition from init domain to # cppreopts to occur. init_daemon_domain(wifi_scan_android)##domain_auto_trans(wifi_scan_android, preopt2cachename_exec, preopt2cachename);# Allow cppreopts copy files into the dalvik-cache ## allow wifi_scan_android dalvikcache_data_file:dir { add_name remove_name search write }; ## allow wifi_scan_android dalvikcache_data_file:file { create getattr open read rename write };# Allow cppreopts to execute itself using #!/system/bin/sh allow wifi_scan_android shell_exec:file rx_file_perms;# Allow us to run find on /postinstall allow wifi_scan_android system_file:dir { open read };# Allow running the cp command using cppreopts permissions. Needed so we can # write into dalvik-cache allow wifi_scan_android toolbox_exec:file rx_file_perms;最后的幾點注意
在Android下是/system/bin/sh
總結
以上是生活随笔為你收集整理的Android的***.sh的开机服务添加的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: github上传代码
- 下一篇: NV133FHM-N52屏在rk3288