forked from Swind/pure-python-adb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
94 lines (71 loc) · 2.52 KB
/
__init__.py
File metadata and controls
94 lines (71 loc) · 2.52 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from ppadb.device import Device
from ppadb.command import Command
class Host(Command):
CONNECT_RESULT_PATTERN = r"(connected to|already connected)"
OFFLINE = "offline"
DEVICE = "device"
BOOTLOADER = "bootloader"
def _execute_cmd(self, cmd, with_response=True):
with self.create_connection() as conn:
conn.send(cmd)
if with_response:
result = conn.receive()
return result
else:
conn.check_status()
def devices(self, state=None):
cmd = "host:devices"
result = self._execute_cmd(cmd)
devices = []
for line in result.split("\n"):
if not line:
break
tokens = line.split()
if state and len(tokens) > 1 and tokens[1] != state:
continue
devices.append(Device(self, tokens[0]))
return devices
def features(self):
cmd = "host:features"
result = self._execute_cmd(cmd)
features = result.split(",")
return features
def version(self):
with self.create_connection() as conn:
conn.send("host:version")
version = conn.receive()
return int(version, 16)
def kill(self):
"""
Ask the ADB server to quit immediately. This is used when the
ADB client detects that an obsolete server is running after an
upgrade.
"""
with self.create_connection() as conn:
conn.send("host:kill")
return True
def killforward_all(self):
cmd = "host:killforward-all"
self._execute_cmd(cmd, with_response=False)
def list_forward(self):
cmd = "host:list-forward"
result = self._execute_cmd(cmd)
device_forward_map = {}
for line in result.split("\n"):
if line:
serial, local, remote = line.split()
if serial not in device_forward_map:
device_forward_map[serial] = {}
device_forward_map[serial][local] = remote
return device_forward_map
def remote_connect(self, host, port):
cmd = "host:connect:%s:%d" % (host, port)
result = self._execute_cmd(cmd)
return "connected" in result
def remote_disconnect(self, host=None, port=None):
cmd = "host:disconnect:"
if host:
cmd = "host:disconnect:{}".format(host)
if port:
cmd = "{}:{}".format(cmd, port)
return self._execute_cmd(cmd)