Android的***.sh的开机服务添加

Android的***.sh的开机服务添加

看网上资料结合自己的rockchip平台,由于无线网经常断开,所以打算添加一个服务,来监测网络情况并处理

1、写好wifi_scan_android.sh

下面是脚本内容 代码片.注意done后要有回车的一行。

// An sh shell
#!/system/bin/sh
while :
do
	if ping -c 1 www.baidu.com$i > /dev/null
	    then
		echo "online"
		#date >> /sdcard/online.log
		sleep 60
	    else
		sleep 4
		if ping -c www.baidu.com$i > /dev/null
		    then
			echo "online"
			sleep 60
			#date >> /scard/online.log
		    else
			sleep 4
			if ping -c www.baidu.com$i > /dev/null
			    then
				echo "online"
				sleep 60
			    else
				sleep 4
				if ping -c www.baidu.com$i > /dev/null
				    then
					echo "online"
					sleep 60
				    else
					echo "offline"
					#date >> /sdcard/offline2.log
					svc wifi disable
					sleep 2
					svc wifi enable
					sleep 120
				fi
			fi
		fi
	fi
done

2、直接将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_android

4、添加启动服务

在./system/core/rootdir/init.rc中添加如下内容

service wifi_scan /system/bin/wifi_scan_android
    class main
    user root
    group root

5、修改权限

打开./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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值