-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdevice.py
41 lines (28 loc) · 1.15 KB
/
device.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import subprocess
from utils import Utils
from modules.LogSystem import LogSystem
class DeviceCommunication:
def __init__(self):
self.devices = []
self.log = LogSystem("adb")
def list_devices(self):
self.log.info("Getting list of devices")
adb_location = Utils.get_adb_location()
command = """{} devices""".format(adb_location)
info = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read()
devices = []
for device in info.decode().splitlines():
if 'devices attached' in device:
continue
device_serial = device.split('\t')[0].strip()
if not device_serial:
continue
if '\tunauthorized' in device:
self.log.warning("{} unauthorized. Trust this device. Ignoring...".format(device_serial))
continue
devices.append(device_serial)
message = "Found {} device".format(len(devices))
if (len(devices) != 1):
message += "s"
self.log.info("{}".format(message))
return devices