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('\n(.+?)\t',str_init,re.S)   
14 
15     print('所有設備名稱:\n',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 "\t" in dName_:
                if dName_.find("emulator") < 0:
                    devices.append(dName_.split("\t")[0])
        devices.sort(cmp=None, key=None, reverse=False)
        print(devices)
    except:
        pass
    print(u"\n設備名稱: %s \n總數量:%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 + "卸載失敗\n")
    print(device + "卸載成功\n")
    try:
        for i in list:
            os.system('adb -s ' + device + ' install ' + i)
    except:
        print(device + "安裝失敗\n")
    print(device + "安裝成功\n")

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)




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM