#利用ADB DEVICES结果判断指定手机是否正常连接,如果为offline,则adb disconnect sjh;adb connect sjh
#如果没有,则执行adb connect sjh
def jianchaad(sjh):
aakk="adb devices"
zh=[]
lx=[]
p = subprocess.Popen(aakk, shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
#print(out.splitlines()[24:27])
for line in out.splitlines():
if "offline" in line.decode('utf-8'): #decode()将byte转化为str,encode()则相反
av=line.decode('utf-8').replace(" ","").replace("device","").replace(":5555","")
lx.append(av)
if "device" in line.decode('utf-8') and "List" not in line.decode('utf-8') and "offline" not in line.decode('utf-8') :
#print(line.decode('utf-8'))
av=line.decode('utf-8').replace(" ","").replace("device","").replace(":5555","")#替换掉所有的空格,device, :5555
zh.append(av)
#print(av,len(av))
if sjh in lx:#检查离线状态的
aaak="adb disconnect {0}".format(sjh)
process = subprocess.Popen(aaak,shell=True)
time.sleep(5)
aaak="adb connect {0}".format(sjh)
process = subprocess.Popen(aaak,shell=True)
else:
if sjh not in zh:
aaak="adb connect {0}".format(sjh)
process = subprocess.Popen(aaak,shell=True)