python+ADB 操作参考 https://www.jianshu.com/p/c3f27fd81955
细化思路分析
- 使用两台手机连上电脑,在cmd终端查看adb devices
- 使用python调取ADB-获取手机品牌、信息、手机型号、Android版本、分辨率信息
- 封装ADB命令脚本
- 所有的设备信息合并成列表
优化代码参考
获取设备信息,返回唯一值devices_id
'''获取设备信息,返回唯一值devices_id'''
device_id_list = []
devices = subprocess.check_output('adb devices').decode().strip().split("\r\n")
for i in range(1, len(devices)):
udid = devices[i].split('\t')[0]
device_id = {'device': udid}
device_id_list.append(device_id)
return device_id_list
def get_devices_id():
'''返回唯一值devices_id'''
deviceid = get_devices()
devices_id = []
for id in deviceid:
device_id = id['device']
devices_id.append(device_id)
return devices_id
获取手机品牌信息
def get_devices_brand():
'''获取手机品牌信息'''
devices_id = get_devices_id()
brand_list = []
for i in devices_id:
brand = subprocess.check_output('adb -s ' + i + ' shell getprop ro.product.brand').decode().strip()
device_brand = {'device_brand': brand}
brand_list.append(device_brand)
return brand_list
获取手机型号信息
def get_devices_model():
'''获取手机型号信息'''
devices_id = get_devices_id()
model_list = []
for i in devices_id:
model = subprocess.check_output('adb -s ' + i + ' shell getprop ro.product.model').decode().strip()
device_model = {'device_model': model}
model_list.append(device_model)
return model_list
获取Android版本信息
def get_devices_version():
'''获取Android版本信息'''
devices_id = get_devices_id()
version_list = []
for i in devices_id:
version = subprocess.check_output('adb -s ' + i + ' shell getprop ro.build.version.release').decode().strip()
device_version = {'device_version': version}
version_list.append(device_version)
return version_list
获取分辨率信息
def get_devices_wmsize():
'''获取分辨率信息'''
devices_id = get_devices_id()
wmsize_list = []
for i in devices_id:
wmsize = subprocess.check_output('adb -s ' + i + ' shell wm size').decode().strip()
device_wmsize = {'device_wmsize': wmsize}
wmsize_list.append(device_wmsize)
return wmsize_list
所有的设备信息组成列表
def get_devices_info():
'''所有的设备信息组成列表'''
devices_list_info = get_devices() + get_devices_brand() + get_devices_model() + get_devices_version() + get_devices_wmsize()
return devices_list_info
网友评论