1、关闭手机状态栏,减少点击关闭WiFi的次数。
adb shell settings put global policy_control immersive.full=*
2、解决monkey偶尔跑到关闭wifi。
思路:定时检测wifi状态,如果是关闭的,就打开wifi设置页面,打开wifi按钮,然后就会自动连接了。
python代码如下:(PS:不是所有手机可用,跟安卓系统版本有一定关系,adb命令不是所有系统可用,对于安卓新版本可能有更换)
def check_wifi():
check_wifi="adb shell dumpsys wifi |grep 'Wi-Fi is'"
setting_command="adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings"
open_wifi_command="adb shell input keyevent 19 & adb shell input keyevent 23"
wifi_state = execute_shell(check_wifi) #execute_shell是另外一个写的方法,执行shell命令并返回结果
if "disabled" in wifi_state:
execute_shell(setting_command)
execute_shell(open_wifi_command)
if "disabled" in wifi_state: #双重保险
utils_exec_shell(open_wifi_command)
3、解决gps关闭问题。
定时执行打开gps:adb shell settings put secure location_providers_allowed +gps