adb 设备命令

一、adb 设备命令
1、查看机型时,可以使用以下命令
$ adb shell getprop ro.product.model

2.如果我们忘记具体系统属性的名字
$ adb shell getprop | grep product

3.获取设备号
$ adb shell getprop ro.serialno

4.我们还可以通过 adb devices 命令来查看设备信息:
$ adb devices
查看型号等详细信息使用以下命令
$ adb devices -l

二、
#获取手机名称 NAME = 'adb shell getprop ro.product.model'
#获取手机版本 VERSION = 'adb shell getprop ro.build.version.release'
#获取手机厂商 PRODUCER = 'adb shell getprop ro.product.brand'

获取以上信息python代码:

1 import os
2 deviceName = os.popen('adb shell getprop ro.product.model').read()
3 print(deviceName)
4 platformVersion = os.popen('adb shell getprop ro.build.version.release').read() print(platformVersion)
5 device = os.popen('adb shell getprop ro.product.name ').read()
6 print(device)



三、获取多个设备号
直接上代码:

 1 #coding=utf-8
 2 import re
 3 import os
 4 
 5 #获取设备多台设备号列表
 6 def get_deviceid():                            
 7     str_init=' '                             
 8     all_info= os.popen('adb devices').readlines()
 9     print('adb devices 输出的内容是:',all_info)
10 
11     for i in range(len(all_info)):
12         str_init+=all_info[i]                 
13     devices_name=re.findall('
(.+?)	',str_init,re.S)   
14 
15     print('所有设备名称:
',devices_name)
16     return devices_name
17 
18 r=get_deviceid()
19 print(r[0])

 四、---待完善
1、需求
最近需要给多台pad安装apk包,但是之前的串形脚本,一台pad装一个apk需要1分钟,80台就需要80分钟,于是乎我考虑能不能让任务池进行批量并行安装apk。

2、实现思路:
想到使用多进程的方式即使用python的pool.map方法,给每个任务池分配任务,起多任务池并行处理任务,废话不多说,
直接上代码:
#!/usr/bin/env python
# -*- encoding: utf-8
-*- import os
import time
from multiprocessing
import Pool
list=[]

def getDevicesAll():
    #获取devices数量和名称
    devices = []
    try:
        for dName_ in os.popen("adb devices"):
            if " " in dName_:
                if dName_.find("emulator") < 0:
                    devices.append(dName_.split(" ")[0])
        devices.sort(cmp=None, key=None, reverse=False)
        print(devices)
    except:
        pass
    print(u" 设备名称: %s 总数量:%s台" % (devices, len(devices)))
    return devices

def quickinstall(device):    
    #卸载原有apk
    try:
        os.system('adb -s ' + device + ' uninstall 包名')
        os.system('adb -s ' + device + ' uninstall 包名')
    except:
        print(device + "卸载失败 ")
    print(device + "卸载成功 ")
    try:
        for i in list:
            os.system('adb -s ' + device + ' install ' + i)
    except:
        print(device + "安装失败 ")
    print(device + "安装成功 ")

def qainstall(devices):
    starttime=time.time()
    pool = Pool(8) #创建8个任务池
    result=pool.map(quickinstall,devices)
    endtime=time.time()
    pool.close()
    pool.join()
    print(endtime-starttime) #打印时间
    
if __name__ == "__main__":
    filesname = '/Users/用户名/Desktop/package'    
    #获取安装包
    for parent, dirnames, filnames in os.walk(filesname):
        for filname in filnames:
            path = os.path.join(parent, filname)
            list.append(path)
    try:
        devices = getDevicesAll()
    except:
        print("获取设备出错")
    res = input("输入1开始更新:")
    if int(res) == 1:
        try:
            qainstall(devices)
    except:
        print("更新失败")
    Touch(devices)



原文地址:https://www.cnblogs.com/lisa2016/p/11082627.html