mozdevice 4.1.2__tar.gz → 4.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mozdevice-4.1.2 → mozdevice-4.2.0}/PKG-INFO +15 -12
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice/adb.py +166 -136
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice/remote_process_monitor.py +9 -14
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice.egg-info/PKG-INFO +15 -12
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice.egg-info/not-zip-safe +1 -1
- {mozdevice-4.1.2 → mozdevice-4.2.0}/setup.cfg +7 -7
- {mozdevice-4.1.2 → mozdevice-4.2.0}/setup.py +5 -3
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice/__init__.py +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice/adb_android.py +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice/version_codes.py +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice.egg-info/SOURCES.txt +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice.egg-info/dependency_links.txt +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice.egg-info/requires.txt +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/mozdevice.egg-info/top_level.txt +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/tests/test_chown.py +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/tests/test_escape_command_line.py +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/tests/test_is_app_installed.py +0 -0
- {mozdevice-4.1.2 → mozdevice-4.2.0}/tests/test_socket_connection.py +0 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: mozdevice
|
|
3
|
-
Version: 4.
|
|
4
|
-
Summary: Mozilla-authored device management
|
|
5
|
-
Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
|
|
6
|
-
Author: Mozilla Automation and Testing Team
|
|
7
|
-
Author-email: tools@lists.mozilla.org
|
|
8
|
-
License: MPL
|
|
9
|
-
Classifier: Programming Language :: Python ::
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mozdevice
|
|
3
|
+
Version: 4.2.0
|
|
4
|
+
Summary: Mozilla-authored device management
|
|
5
|
+
Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
|
|
6
|
+
Author: Mozilla Automation and Testing Team
|
|
7
|
+
Author-email: tools@lists.mozilla.org
|
|
8
|
+
License: MPL
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Requires-Dist: mozlog>=6.0
|
|
14
|
+
|
|
15
|
+
see https://firefox-source-docs.mozilla.org/mozbase/index.html
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import io
|
|
6
6
|
import os
|
|
7
|
-
import pipes
|
|
8
7
|
import posixpath
|
|
9
8
|
import re
|
|
10
9
|
import shlex
|
|
@@ -18,15 +17,12 @@ import traceback
|
|
|
18
17
|
from shutil import copytree
|
|
19
18
|
from threading import Thread
|
|
20
19
|
|
|
21
|
-
import six
|
|
22
|
-
from six.moves import range
|
|
23
|
-
|
|
24
20
|
from . import version_codes
|
|
25
21
|
|
|
26
22
|
_TEST_ROOT = None
|
|
27
23
|
|
|
28
24
|
|
|
29
|
-
class ADBProcess
|
|
25
|
+
class ADBProcess:
|
|
30
26
|
"""ADBProcess encapsulates the data related to executing the adb process."""
|
|
31
27
|
|
|
32
28
|
def __init__(self, args, use_stdout_pipe=False, timeout=None):
|
|
@@ -38,10 +34,7 @@ class ADBProcess(object):
|
|
|
38
34
|
if use_stdout_pipe:
|
|
39
35
|
self.stdout_file = subprocess.PIPE
|
|
40
36
|
# Reading utf-8 from the stdout pipe
|
|
41
|
-
|
|
42
|
-
Popen_args["encoding"] = "utf-8"
|
|
43
|
-
else:
|
|
44
|
-
Popen_args["universal_newlines"] = True
|
|
37
|
+
Popen_args["encoding"] = "utf-8"
|
|
45
38
|
else:
|
|
46
39
|
self.stdout_file = tempfile.NamedTemporaryFile(mode="w+b")
|
|
47
40
|
Popen_args["stdout"] = self.stdout_file
|
|
@@ -84,7 +77,7 @@ class ADBProcess(object):
|
|
|
84
77
|
content = ""
|
|
85
78
|
else:
|
|
86
79
|
self.stdout_file.seek(0, os.SEEK_SET)
|
|
87
|
-
content =
|
|
80
|
+
content = self.stdout_file.read().rstrip().decode()
|
|
88
81
|
return content
|
|
89
82
|
|
|
90
83
|
def __str__(self):
|
|
@@ -92,7 +85,7 @@ class ADBProcess(object):
|
|
|
92
85
|
# to be independent of the individual failing device.
|
|
93
86
|
arg_string = " ".join(self.args)
|
|
94
87
|
arg_string = re.sub(r" -s [\w-]+", "", arg_string)
|
|
95
|
-
return "args:
|
|
88
|
+
return "args: {}, exitcode: {}, stdout: {}".format(
|
|
96
89
|
arg_string,
|
|
97
90
|
self.exitcode,
|
|
98
91
|
self.stdout,
|
|
@@ -179,7 +172,7 @@ class ADBDeviceFactoryError(Exception):
|
|
|
179
172
|
pass
|
|
180
173
|
|
|
181
174
|
|
|
182
|
-
class ADBCommand
|
|
175
|
+
class ADBCommand:
|
|
183
176
|
"""ADBCommand provides a basic interface to adb commands
|
|
184
177
|
which is used to provide the 'command' methods for the
|
|
185
178
|
classes ADBHost and ADBDevice.
|
|
@@ -236,7 +229,7 @@ class ADBCommand(object):
|
|
|
236
229
|
self._polling_interval = 0.001
|
|
237
230
|
self._adb_version = ""
|
|
238
231
|
|
|
239
|
-
self._logger.debug("
|
|
232
|
+
self._logger.debug(f"{self.__class__.__name__}: {self.__dict__}")
|
|
240
233
|
|
|
241
234
|
# catch early a missing or non executable adb command
|
|
242
235
|
# and get the adb version while we are at it.
|
|
@@ -245,7 +238,7 @@ class ADBCommand(object):
|
|
|
245
238
|
[adb, "version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
|
246
239
|
).communicate()
|
|
247
240
|
re_version = re.compile(r"Android Debug Bridge version (.*)")
|
|
248
|
-
if isinstance(output[0],
|
|
241
|
+
if isinstance(output[0], bytes):
|
|
249
242
|
self._adb_version = re_version.match(
|
|
250
243
|
output[0].decode("utf-8", "replace")
|
|
251
244
|
).group(1)
|
|
@@ -258,7 +251,7 @@ class ADBCommand(object):
|
|
|
258
251
|
)
|
|
259
252
|
|
|
260
253
|
except Exception as exc:
|
|
261
|
-
raise ADBError("
|
|
254
|
+
raise ADBError(f"{exc}: {adb} is not executable.")
|
|
262
255
|
|
|
263
256
|
def _get_logger(self, logger_name, verbose):
|
|
264
257
|
logger = None
|
|
@@ -907,19 +900,21 @@ class ADBDevice(ADBCommand):
|
|
|
907
900
|
boot_completed = False
|
|
908
901
|
while not boot_completed and (time.time() - start_time) <= float(timeout):
|
|
909
902
|
try:
|
|
910
|
-
self.shell_output(
|
|
903
|
+
self.shell_output(
|
|
904
|
+
"/system/bin/ls /system/bin/ls", timeout=timeout, attempts=3
|
|
905
|
+
)
|
|
911
906
|
boot_completed = True
|
|
912
907
|
self._ls = "/system/bin/ls"
|
|
913
908
|
except ADBError as e1:
|
|
914
|
-
self._logger.debug("detect /system/bin/ls {}"
|
|
909
|
+
self._logger.debug(f"detect /system/bin/ls {e1}")
|
|
915
910
|
try:
|
|
916
911
|
self.shell_output(
|
|
917
|
-
"/system/xbin/ls /system/xbin/ls", timeout=timeout
|
|
912
|
+
"/system/xbin/ls /system/xbin/ls", timeout=timeout, attempts=3
|
|
918
913
|
)
|
|
919
914
|
boot_completed = True
|
|
920
915
|
self._ls = "/system/xbin/ls"
|
|
921
916
|
except ADBError as e2:
|
|
922
|
-
self._logger.debug("detect /system/xbin/ls : {}"
|
|
917
|
+
self._logger.debug(f"detect /system/xbin/ls : {e2}")
|
|
923
918
|
if not boot_completed:
|
|
924
919
|
time.sleep(2)
|
|
925
920
|
if not boot_completed:
|
|
@@ -933,11 +928,13 @@ class ADBDevice(ADBCommand):
|
|
|
933
928
|
boot_completed = False
|
|
934
929
|
while not boot_completed and (time.time() - start_time) <= float(timeout):
|
|
935
930
|
try:
|
|
936
|
-
self.shell_output(
|
|
931
|
+
self.shell_output(
|
|
932
|
+
f"{self._ls} -1A {ls_dir}", timeout=timeout, attempts=3
|
|
933
|
+
)
|
|
937
934
|
boot_completed = True
|
|
938
935
|
self._ls += " -1A"
|
|
939
936
|
except ADBError as e:
|
|
940
|
-
self._logger.debug("detect ls -1A: {}"
|
|
937
|
+
self._logger.debug(f"detect ls -1A: {e}")
|
|
941
938
|
if "No such file or directory" not in str(e):
|
|
942
939
|
boot_completed = True
|
|
943
940
|
self._ls += " -a"
|
|
@@ -956,6 +953,9 @@ class ADBDevice(ADBCommand):
|
|
|
956
953
|
remove_builtins = set()
|
|
957
954
|
for builtin in self.BUILTINS:
|
|
958
955
|
try:
|
|
956
|
+
# It is important not to retry ls (with attempts=) here
|
|
957
|
+
# since many of these calls are expected to fail:
|
|
958
|
+
# additional retries can introduce a significant delay.
|
|
959
959
|
self.ls("/system/*bin/%s" % builtin, timeout=timeout)
|
|
960
960
|
self._logger.debug("Removing %s from BUILTINS" % builtin)
|
|
961
961
|
remove_builtins.add(builtin)
|
|
@@ -995,11 +995,11 @@ class ADBDevice(ADBCommand):
|
|
|
995
995
|
if match:
|
|
996
996
|
self._chmod_R = True
|
|
997
997
|
except ADBError as e:
|
|
998
|
-
self._logger.debug("Check chmod -R: {}"
|
|
998
|
+
self._logger.debug(f"Check chmod -R: {e}")
|
|
999
999
|
match = re_recurse.search(str(e))
|
|
1000
1000
|
if match:
|
|
1001
1001
|
self._chmod_R = True
|
|
1002
|
-
self._logger.info("Native chmod -R support: {
|
|
1002
|
+
self._logger.info(f"Native chmod -R support: {self._chmod_R}")
|
|
1003
1003
|
|
|
1004
1004
|
# Do we have chown -R?
|
|
1005
1005
|
try:
|
|
@@ -1009,8 +1009,8 @@ class ADBDevice(ADBCommand):
|
|
|
1009
1009
|
if match:
|
|
1010
1010
|
self._chown_R = True
|
|
1011
1011
|
except ADBError as e:
|
|
1012
|
-
self._logger.debug("Check chown -R: {}"
|
|
1013
|
-
self._logger.info("Native chown -R support: {
|
|
1012
|
+
self._logger.debug(f"Check chown -R: {e}")
|
|
1013
|
+
self._logger.info(f"Native chown -R support: {self._chown_R}")
|
|
1014
1014
|
|
|
1015
1015
|
try:
|
|
1016
1016
|
cleared = self.shell_bool('logcat -P ""', timeout=timeout)
|
|
@@ -1086,7 +1086,7 @@ class ADBDevice(ADBCommand):
|
|
|
1086
1086
|
self._have_su = True
|
|
1087
1087
|
self._logger.info("su -c supported")
|
|
1088
1088
|
except ADBError as e:
|
|
1089
|
-
self._logger.debug("Check for su -c failed: {}"
|
|
1089
|
+
self._logger.debug(f"Check for su -c failed: {e}")
|
|
1090
1090
|
|
|
1091
1091
|
# Check if Android's su 0 command works.
|
|
1092
1092
|
# If we already have detected su -c support, we can skip this check.
|
|
@@ -1099,7 +1099,7 @@ class ADBDevice(ADBCommand):
|
|
|
1099
1099
|
self._have_android_su = True
|
|
1100
1100
|
self._logger.info("su 0 supported")
|
|
1101
1101
|
except ADBError as e:
|
|
1102
|
-
self._logger.debug("Check for su 0 failed: {}"
|
|
1102
|
+
self._logger.debug(f"Check for su 0 failed: {e}")
|
|
1103
1103
|
|
|
1104
1104
|
# Guarantee that /data/local/tmp exists and is accessible to all.
|
|
1105
1105
|
# It is a fatal error if /data/local/tmp does not exist and can not be created.
|
|
@@ -1113,11 +1113,11 @@ class ADBDevice(ADBCommand):
|
|
|
1113
1113
|
# See https://github.com/aosp-mirror/platform_build/commit/
|
|
1114
1114
|
# fbba7fe06312241c7eb8c592ec2ac630e4316d55
|
|
1115
1115
|
stack_trace_dir = self.shell_output(
|
|
1116
|
-
"getprop dalvik.vm.stack-trace-dir", timeout=timeout
|
|
1116
|
+
"getprop dalvik.vm.stack-trace-dir", timeout=timeout, attempts=3
|
|
1117
1117
|
)
|
|
1118
1118
|
if not stack_trace_dir:
|
|
1119
1119
|
stack_trace_file = self.shell_output(
|
|
1120
|
-
"getprop dalvik.vm.stack-trace-file", timeout=timeout
|
|
1120
|
+
"getprop dalvik.vm.stack-trace-file", timeout=timeout, attempts=3
|
|
1121
1121
|
)
|
|
1122
1122
|
if stack_trace_file:
|
|
1123
1123
|
stack_trace_dir = posixpath.dirname(stack_trace_file)
|
|
@@ -1148,7 +1148,7 @@ class ADBDevice(ADBCommand):
|
|
|
1148
1148
|
"""
|
|
1149
1149
|
for attempt in range(self._device_ready_retry_attempts):
|
|
1150
1150
|
sys_boot_completed = self.shell_output(
|
|
1151
|
-
"getprop sys.boot_completed", timeout=timeout
|
|
1151
|
+
"getprop sys.boot_completed", timeout=timeout, attempts=3
|
|
1152
1152
|
)
|
|
1153
1153
|
if sys_boot_completed == "1":
|
|
1154
1154
|
break
|
|
@@ -1181,7 +1181,7 @@ class ADBDevice(ADBCommand):
|
|
|
1181
1181
|
or ":" not in serial
|
|
1182
1182
|
)
|
|
1183
1183
|
|
|
1184
|
-
if isinstance(device,
|
|
1184
|
+
if isinstance(device, str):
|
|
1185
1185
|
# Treat this as a device serial
|
|
1186
1186
|
if not is_valid_serial(device):
|
|
1187
1187
|
raise ValueError(
|
|
@@ -1274,7 +1274,7 @@ class ADBDevice(ADBCommand):
|
|
|
1274
1274
|
def _sync(self, timeout=None):
|
|
1275
1275
|
"""Sync the file system using shell_output in order that exceptions
|
|
1276
1276
|
are raised to the caller."""
|
|
1277
|
-
self.shell_output("sync", timeout=timeout)
|
|
1277
|
+
self.shell_output("sync", timeout=timeout, attempts=3)
|
|
1278
1278
|
|
|
1279
1279
|
@staticmethod
|
|
1280
1280
|
def _should_quote(arg):
|
|
@@ -1292,8 +1292,6 @@ class ADBDevice(ADBCommand):
|
|
|
1292
1292
|
"""Utility function to return quoted version of command argument."""
|
|
1293
1293
|
if hasattr(shlex, "quote"):
|
|
1294
1294
|
quote = shlex.quote
|
|
1295
|
-
elif hasattr(pipes, "quote"):
|
|
1296
|
-
quote = pipes.quote
|
|
1297
1295
|
else:
|
|
1298
1296
|
|
|
1299
1297
|
def quote(arg):
|
|
@@ -1330,7 +1328,7 @@ class ADBDevice(ADBCommand):
|
|
|
1330
1328
|
offset = 1
|
|
1331
1329
|
while length - offset >= 0:
|
|
1332
1330
|
file_obj.seek(-offset, os.SEEK_END)
|
|
1333
|
-
char =
|
|
1331
|
+
char = file_obj.read(1).decode()
|
|
1334
1332
|
if not char:
|
|
1335
1333
|
break
|
|
1336
1334
|
if char != "\r" and char != "\n":
|
|
@@ -1355,8 +1353,8 @@ class ADBDevice(ADBCommand):
|
|
|
1355
1353
|
# appropriate match.
|
|
1356
1354
|
file_obj.seek(0, os.SEEK_SET)
|
|
1357
1355
|
for line in file_obj:
|
|
1358
|
-
|
|
1359
|
-
match = re_returncode.search(
|
|
1356
|
+
line_str = line.decode()
|
|
1357
|
+
match = re_returncode.search(line_str)
|
|
1360
1358
|
if match:
|
|
1361
1359
|
exitcode = int(match.group(1))
|
|
1362
1360
|
break
|
|
@@ -1411,7 +1409,7 @@ class ADBDevice(ADBCommand):
|
|
|
1411
1409
|
self._debuggable_packages[package] = True
|
|
1412
1410
|
except ADBError as e:
|
|
1413
1411
|
self._debuggable_packages[package] = False
|
|
1414
|
-
self._logger.warning("Package
|
|
1412
|
+
self._logger.warning(f"Package {package} is not debuggable: {str(e)}")
|
|
1415
1413
|
return self._debuggable_packages[package]
|
|
1416
1414
|
|
|
1417
1415
|
@property
|
|
@@ -1620,7 +1618,7 @@ class ADBDevice(ADBCommand):
|
|
|
1620
1618
|
global _TEST_ROOT
|
|
1621
1619
|
if self._test_root == value:
|
|
1622
1620
|
return
|
|
1623
|
-
self._logger.debug("Setting test_root from
|
|
1621
|
+
self._logger.debug(f"Setting test_root from {self._test_root} to {value}")
|
|
1624
1622
|
old_test_root = self._test_root
|
|
1625
1623
|
self._test_root = value
|
|
1626
1624
|
if self._share_test_root:
|
|
@@ -1686,7 +1684,7 @@ class ADBDevice(ADBCommand):
|
|
|
1686
1684
|
self.mkdir(proof_dir)
|
|
1687
1685
|
self.rm(proof_dir, recursive=True)
|
|
1688
1686
|
except ADBError as e:
|
|
1689
|
-
self._logger.warning("
|
|
1687
|
+
self._logger.warning(f"{test_root} is not writable: {str(e)}")
|
|
1690
1688
|
return False
|
|
1691
1689
|
|
|
1692
1690
|
return True
|
|
@@ -1776,7 +1774,7 @@ class ADBDevice(ADBCommand):
|
|
|
1776
1774
|
self.SOCKET_DIRECTION_FORWARD,
|
|
1777
1775
|
self.SOCKET_DIRECTION_REVERSE,
|
|
1778
1776
|
]:
|
|
1779
|
-
raise ValueError("Invalid direction specifier {}"
|
|
1777
|
+
raise ValueError(f"Invalid direction specifier {direction}")
|
|
1780
1778
|
|
|
1781
1779
|
def create_socket_connection(
|
|
1782
1780
|
self, direction, local, remote, allow_rebind=True, timeout=None
|
|
@@ -1995,7 +1993,7 @@ class ADBDevice(ADBCommand):
|
|
|
1995
1993
|
"""
|
|
1996
1994
|
|
|
1997
1995
|
def _timed_read_line_handler(signum, frame):
|
|
1998
|
-
raise
|
|
1996
|
+
raise OSError("ReadLineTimeout")
|
|
1999
1997
|
|
|
2000
1998
|
def _timed_read_line(filehandle, timeout=None):
|
|
2001
1999
|
"""
|
|
@@ -2031,15 +2029,15 @@ class ADBDevice(ADBCommand):
|
|
|
2031
2029
|
elif self._have_su:
|
|
2032
2030
|
cmd = "su -c %s" % ADBDevice._quote(cmd)
|
|
2033
2031
|
elif self._run_as_package and enable_run_as:
|
|
2034
|
-
cmd = "run-as
|
|
2032
|
+
cmd = f"run-as {self._run_as_package} {cmd}"
|
|
2035
2033
|
else:
|
|
2036
2034
|
pass
|
|
2037
2035
|
|
|
2038
2036
|
# prepend cwd and env to command if necessary
|
|
2039
2037
|
if cwd:
|
|
2040
|
-
cmd = "cd
|
|
2038
|
+
cmd = f"cd {cwd} && {cmd}"
|
|
2041
2039
|
if env:
|
|
2042
|
-
envstr = "&& ".join(["export
|
|
2040
|
+
envstr = "&& ".join([f"export {x[0]}={x[1]}" for x in env.items()])
|
|
2043
2041
|
cmd = envstr + "&& " + cmd
|
|
2044
2042
|
# Before Android 7, an exitcode 0 for the process on the host
|
|
2045
2043
|
# did not mean that the exitcode of the Android process was
|
|
@@ -2083,7 +2081,16 @@ class ADBDevice(ADBCommand):
|
|
|
2083
2081
|
time.sleep(self._polling_interval)
|
|
2084
2082
|
exitcode = adb_process.proc.poll()
|
|
2085
2083
|
else:
|
|
2086
|
-
|
|
2084
|
+
# https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
|
|
2085
|
+
#
|
|
2086
|
+
# NamedTemporaryFile with delete=True, Windows cannot open this file
|
|
2087
|
+
# file normally. We have to add the temporary flag.
|
|
2088
|
+
def opener(path, flags):
|
|
2089
|
+
if sys.platform == "win32":
|
|
2090
|
+
flags |= os.O_TEMPORARY
|
|
2091
|
+
return os.open(path, flags, mode=0o666)
|
|
2092
|
+
|
|
2093
|
+
stdout2 = open(adb_process.stdout_file.name, "rb", opener=opener)
|
|
2087
2094
|
partial = b""
|
|
2088
2095
|
while ((time.time() - start_time) <= float(timeout)) and exitcode is None:
|
|
2089
2096
|
try:
|
|
@@ -2094,7 +2101,7 @@ class ADBDevice(ADBCommand):
|
|
|
2094
2101
|
partial = b""
|
|
2095
2102
|
line = line.rstrip()
|
|
2096
2103
|
if self._verbose:
|
|
2097
|
-
self._logger.info(
|
|
2104
|
+
self._logger.info(line.decode())
|
|
2098
2105
|
stdout_callback(line)
|
|
2099
2106
|
else:
|
|
2100
2107
|
# no more output available now, but more to come?
|
|
@@ -2102,7 +2109,7 @@ class ADBDevice(ADBCommand):
|
|
|
2102
2109
|
else:
|
|
2103
2110
|
# no new output, so sleep and poll
|
|
2104
2111
|
time.sleep(self._polling_interval)
|
|
2105
|
-
except
|
|
2112
|
+
except OSError:
|
|
2106
2113
|
pass
|
|
2107
2114
|
exitcode = adb_process.proc.poll()
|
|
2108
2115
|
if exitcode is None:
|
|
@@ -2188,7 +2195,9 @@ class ADBDevice(ADBCommand):
|
|
|
2188
2195
|
|
|
2189
2196
|
adb_process.stdout_file.close()
|
|
2190
2197
|
|
|
2191
|
-
def shell_output(
|
|
2198
|
+
def shell_output(
|
|
2199
|
+
self, cmd, env=None, cwd=None, timeout=None, enable_run_as=False, attempts=1
|
|
2200
|
+
):
|
|
2192
2201
|
"""Executes an adb shell on the device returning stdout.
|
|
2193
2202
|
|
|
2194
2203
|
:param str cmd: The command to be executed.
|
|
@@ -2206,6 +2215,20 @@ class ADBDevice(ADBCommand):
|
|
|
2206
2215
|
:raises: :exc:`ADBTimeoutError`
|
|
2207
2216
|
:exc:`ADBError`
|
|
2208
2217
|
"""
|
|
2218
|
+
for attempt in range(attempts):
|
|
2219
|
+
try:
|
|
2220
|
+
output = self._shell_output(
|
|
2221
|
+
cmd, env=env, cwd=cwd, timeout=timeout, enable_run_as=enable_run_as
|
|
2222
|
+
)
|
|
2223
|
+
return output
|
|
2224
|
+
except ADBError:
|
|
2225
|
+
if attempt >= attempts - 1:
|
|
2226
|
+
raise
|
|
2227
|
+
# pause for an arbitrary length of time, to allow for recovery from
|
|
2228
|
+
# intermittent failures that might persist for a short time
|
|
2229
|
+
time.sleep(2)
|
|
2230
|
+
|
|
2231
|
+
def _shell_output(self, cmd, env=None, cwd=None, timeout=None, enable_run_as=False):
|
|
2209
2232
|
adb_process = None
|
|
2210
2233
|
try:
|
|
2211
2234
|
adb_process = self.shell(
|
|
@@ -2277,7 +2300,7 @@ class ADBDevice(ADBCommand):
|
|
|
2277
2300
|
if "failed to clear" not in str(e):
|
|
2278
2301
|
raise
|
|
2279
2302
|
self._logger.warning(
|
|
2280
|
-
"retryable logcat clear error?: {}. Retrying..."
|
|
2303
|
+
f"retryable logcat clear error?: {str(e)}. Retrying..."
|
|
2281
2304
|
)
|
|
2282
2305
|
try:
|
|
2283
2306
|
self.command_output(cmds, timeout=timeout)
|
|
@@ -2285,9 +2308,7 @@ class ADBDevice(ADBCommand):
|
|
|
2285
2308
|
except ADBProcessError as e2:
|
|
2286
2309
|
if "failed to clear" not in str(e):
|
|
2287
2310
|
raise
|
|
2288
|
-
self._logger.warning(
|
|
2289
|
-
"Ignoring failure to clear logcat: {}.".format(str(e2))
|
|
2290
|
-
)
|
|
2311
|
+
self._logger.warning(f"Ignoring failure to clear logcat: {str(e2)}.")
|
|
2291
2312
|
|
|
2292
2313
|
def get_logcat(
|
|
2293
2314
|
self,
|
|
@@ -2354,7 +2375,7 @@ class ADBDevice(ADBCommand):
|
|
|
2354
2375
|
:raises: :exc:`ADBTimeoutError`
|
|
2355
2376
|
:exc:`ADBError`
|
|
2356
2377
|
"""
|
|
2357
|
-
output = self.shell_output("getprop %s" % prop, timeout=timeout)
|
|
2378
|
+
output = self.shell_output("getprop %s" % prop, timeout=timeout, attempts=3)
|
|
2358
2379
|
return output
|
|
2359
2380
|
|
|
2360
2381
|
def get_state(self, timeout=None):
|
|
@@ -2429,11 +2450,11 @@ class ADBDevice(ADBCommand):
|
|
|
2429
2450
|
self._logger.debug("get_ip_address: ifconfig")
|
|
2430
2451
|
for interface in interfaces:
|
|
2431
2452
|
try:
|
|
2432
|
-
output = self.shell_output(
|
|
2433
|
-
|
|
2434
|
-
self._logger.warning(
|
|
2435
|
-
"get_ip_address ifconfig %s: %s" % (interface, str(e))
|
|
2453
|
+
output = self.shell_output(
|
|
2454
|
+
"ifconfig %s" % interface, timeout=timeout, attempts=3
|
|
2436
2455
|
)
|
|
2456
|
+
except ADBError as e:
|
|
2457
|
+
self._logger.warning(f"get_ip_address ifconfig {interface}: {str(e)}")
|
|
2437
2458
|
output = ""
|
|
2438
2459
|
|
|
2439
2460
|
for line in output.splitlines():
|
|
@@ -2481,7 +2502,7 @@ class ADBDevice(ADBCommand):
|
|
|
2481
2502
|
r"(\w+)\s+UP\s+([1-9]\d{0,2}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
|
|
2482
2503
|
)
|
|
2483
2504
|
try:
|
|
2484
|
-
output = self.shell_output("netcfg", timeout=timeout)
|
|
2505
|
+
output = self.shell_output("netcfg", timeout=timeout, attempts=3)
|
|
2485
2506
|
except ADBError as e:
|
|
2486
2507
|
self._logger.warning("get_ip_address netcfg: %s" % str(e))
|
|
2487
2508
|
output = ""
|
|
@@ -2494,7 +2515,7 @@ class ADBDevice(ADBCommand):
|
|
|
2494
2515
|
matched_ip = None
|
|
2495
2516
|
elif matched_ip and matched_interface in interfaces:
|
|
2496
2517
|
self._logger.debug(
|
|
2497
|
-
"get_ip_address: found:
|
|
2518
|
+
f"get_ip_address: found: {matched_interface} {matched_ip}"
|
|
2498
2519
|
)
|
|
2499
2520
|
return matched_ip
|
|
2500
2521
|
self._logger.debug("get_ip_address: not found")
|
|
@@ -2538,10 +2559,10 @@ class ADBDevice(ADBCommand):
|
|
|
2538
2559
|
tmpf = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
|
2539
2560
|
tmpf.write("\n".join(commands))
|
|
2540
2561
|
tmpf.close()
|
|
2541
|
-
script = "/sdcard/{
|
|
2562
|
+
script = f"/sdcard/{os.path.basename(tmpf.name)}"
|
|
2542
2563
|
self.push(tmpf.name, script)
|
|
2543
2564
|
self.shell_output(
|
|
2544
|
-
"sh {}"
|
|
2565
|
+
f"sh {script}", enable_run_as=enable_run_as, timeout=timeout
|
|
2545
2566
|
)
|
|
2546
2567
|
finally:
|
|
2547
2568
|
if tmpf:
|
|
@@ -2577,9 +2598,7 @@ class ADBDevice(ADBCommand):
|
|
|
2577
2598
|
# detected.
|
|
2578
2599
|
path = posixpath.normpath(path.strip())
|
|
2579
2600
|
enable_run_as = self.enable_run_as_for_path(path)
|
|
2580
|
-
self._logger.debug(
|
|
2581
|
-
"chmod: path=%s, recursive=%s, mask=%s" % (path, recursive, mask)
|
|
2582
|
-
)
|
|
2601
|
+
self._logger.debug(f"chmod: path={path}, recursive={recursive}, mask={mask}")
|
|
2583
2602
|
if self.is_path_internal_storage(path, timeout=timeout):
|
|
2584
2603
|
# External storage on Android is case-insensitive and permissionless
|
|
2585
2604
|
# therefore even with the proper privileges it is not possible
|
|
@@ -2596,7 +2615,7 @@ class ADBDevice(ADBCommand):
|
|
|
2596
2615
|
command.append(mask)
|
|
2597
2616
|
|
|
2598
2617
|
if recursive and not self._chmod_R:
|
|
2599
|
-
paths = self.ls(path, recursive=True, timeout=timeout)
|
|
2618
|
+
paths = self.ls(path, recursive=True, timeout=timeout, attempts=3)
|
|
2600
2619
|
base = " ".join(command)
|
|
2601
2620
|
commands = [" ".join([base, entry]) for entry in paths]
|
|
2602
2621
|
self.batch_execute(commands, timeout=timeout, enable_run_as=enable_run_as)
|
|
@@ -2604,7 +2623,10 @@ class ADBDevice(ADBCommand):
|
|
|
2604
2623
|
command.append(path)
|
|
2605
2624
|
try:
|
|
2606
2625
|
self.shell_output(
|
|
2607
|
-
cmd=" ".join(command),
|
|
2626
|
+
cmd=" ".join(command),
|
|
2627
|
+
timeout=timeout,
|
|
2628
|
+
enable_run_as=enable_run_as,
|
|
2629
|
+
attempts=3,
|
|
2608
2630
|
)
|
|
2609
2631
|
except ADBProcessError as e:
|
|
2610
2632
|
if "No such file or directory" not in str(e):
|
|
@@ -2646,7 +2668,7 @@ class ADBDevice(ADBCommand):
|
|
|
2646
2668
|
if group:
|
|
2647
2669
|
# officially supported notation is : but . has been checked with
|
|
2648
2670
|
# sdk 17 and it works.
|
|
2649
|
-
command.append("{owner}.{group}"
|
|
2671
|
+
command.append(f"{owner}.{group}")
|
|
2650
2672
|
else:
|
|
2651
2673
|
command.append(owner)
|
|
2652
2674
|
|
|
@@ -2654,7 +2676,7 @@ class ADBDevice(ADBCommand):
|
|
|
2654
2676
|
# recursive desired, but chown -R is not supported natively.
|
|
2655
2677
|
# like with chmod, get the list of subpaths, put them into a script
|
|
2656
2678
|
# then run it with adb with one call.
|
|
2657
|
-
paths = self.ls(path, recursive=True, timeout=timeout)
|
|
2679
|
+
paths = self.ls(path, recursive=True, timeout=timeout, attempts=3)
|
|
2658
2680
|
base = " ".join(command)
|
|
2659
2681
|
commands = [" ".join([base, entry]) for entry in paths]
|
|
2660
2682
|
|
|
@@ -2664,7 +2686,10 @@ class ADBDevice(ADBCommand):
|
|
|
2664
2686
|
# command can simply be run as provided by the user.
|
|
2665
2687
|
command.append(path)
|
|
2666
2688
|
self.shell_output(
|
|
2667
|
-
cmd=" ".join(command),
|
|
2689
|
+
cmd=" ".join(command),
|
|
2690
|
+
timeout=timeout,
|
|
2691
|
+
enable_run_as=enable_run_as,
|
|
2692
|
+
attempts=3,
|
|
2668
2693
|
)
|
|
2669
2694
|
|
|
2670
2695
|
def _test_path(self, argument, path, timeout=None):
|
|
@@ -2687,7 +2712,7 @@ class ADBDevice(ADBCommand):
|
|
|
2687
2712
|
enable_run_as = self.enable_run_as_for_path(path)
|
|
2688
2713
|
if not enable_run_as and not self._device_serial.startswith("emulator"):
|
|
2689
2714
|
return self.shell_bool(
|
|
2690
|
-
"test -{
|
|
2715
|
+
f"test -{argument} {path}",
|
|
2691
2716
|
timeout=timeout,
|
|
2692
2717
|
enable_run_as=False,
|
|
2693
2718
|
)
|
|
@@ -2699,11 +2724,11 @@ class ADBDevice(ADBCommand):
|
|
|
2699
2724
|
)
|
|
2700
2725
|
if argument == "d":
|
|
2701
2726
|
return self.shell_bool(
|
|
2702
|
-
"ls -a {}/"
|
|
2727
|
+
f"ls -a {path}/", timeout=timeout, enable_run_as=enable_run_as
|
|
2703
2728
|
)
|
|
2704
2729
|
if argument == "e":
|
|
2705
2730
|
return self.shell_bool(
|
|
2706
|
-
"ls -a {}"
|
|
2731
|
+
f"ls -a {path}", timeout=timeout, enable_run_as=enable_run_as
|
|
2707
2732
|
)
|
|
2708
2733
|
raise ADBError("_test_path: Unknown argument %s" % argument)
|
|
2709
2734
|
|
|
@@ -2779,9 +2804,10 @@ class ADBDevice(ADBCommand):
|
|
|
2779
2804
|
if self.is_dir(path, timeout=timeout):
|
|
2780
2805
|
try:
|
|
2781
2806
|
data = self.shell_output(
|
|
2782
|
-
"
|
|
2807
|
+
f"{self._ls} {path}",
|
|
2783
2808
|
timeout=timeout,
|
|
2784
2809
|
enable_run_as=enable_run_as,
|
|
2810
|
+
attempts=3,
|
|
2785
2811
|
).splitlines()
|
|
2786
2812
|
self._logger.debug("list_files: data: %s" % data)
|
|
2787
2813
|
except ADBError:
|
|
@@ -2793,7 +2819,7 @@ class ADBDevice(ADBCommand):
|
|
|
2793
2819
|
self._logger.debug("list_files: %s" % data)
|
|
2794
2820
|
return data
|
|
2795
2821
|
|
|
2796
|
-
def ls(self, path, recursive=False, timeout=None):
|
|
2822
|
+
def ls(self, path, recursive=False, timeout=None, attempts=1):
|
|
2797
2823
|
"""Return a list of matching files/directories on the device.
|
|
2798
2824
|
|
|
2799
2825
|
The ls method emulates the behavior of the ls shell command.
|
|
@@ -2827,6 +2853,7 @@ class ADBDevice(ADBCommand):
|
|
|
2827
2853
|
This timeout is per adb call. The total time spent
|
|
2828
2854
|
may exceed this value. If it is not specified, the value
|
|
2829
2855
|
set in the ADBDevice constructor is used.
|
|
2856
|
+
:param int attempts: The maximum number of shell retries.
|
|
2830
2857
|
:return: list of files/directories contained in the directory.
|
|
2831
2858
|
:raises: :exc:`ADBTimeoutError`
|
|
2832
2859
|
"""
|
|
@@ -2850,25 +2877,26 @@ class ADBDevice(ADBCommand):
|
|
|
2850
2877
|
if model == "Nexus 4":
|
|
2851
2878
|
path += "*"
|
|
2852
2879
|
lines = self.shell_output(
|
|
2853
|
-
"
|
|
2880
|
+
f"{self._ls} {recursive_flag} {path}",
|
|
2854
2881
|
timeout=timeout,
|
|
2855
2882
|
enable_run_as=enable_run_as,
|
|
2883
|
+
attempts=attempts,
|
|
2856
2884
|
).splitlines()
|
|
2857
2885
|
for line in lines:
|
|
2858
|
-
|
|
2859
|
-
if not
|
|
2886
|
+
stripped_line = line.strip()
|
|
2887
|
+
if not stripped_line:
|
|
2860
2888
|
parent = ""
|
|
2861
2889
|
continue
|
|
2862
|
-
if
|
|
2863
|
-
parent =
|
|
2890
|
+
if stripped_line.endswith(":"): # This is a directory
|
|
2891
|
+
parent = stripped_line.replace(":", "/")
|
|
2864
2892
|
entry = parent
|
|
2865
2893
|
# Remove earlier entry which is marked as a file.
|
|
2866
2894
|
if parent[:-1] in entries:
|
|
2867
2895
|
del entries[parent[:-1]]
|
|
2868
2896
|
elif parent:
|
|
2869
|
-
entry = "
|
|
2897
|
+
entry = f"{parent}{stripped_line}"
|
|
2870
2898
|
else:
|
|
2871
|
-
entry =
|
|
2899
|
+
entry = stripped_line
|
|
2872
2900
|
entries[entry] = 1
|
|
2873
2901
|
entry_list = list(entries.keys())
|
|
2874
2902
|
entry_list.sort()
|
|
@@ -3129,7 +3157,7 @@ class ADBDevice(ADBCommand):
|
|
|
3129
3157
|
self.cp(remote, intermediate, recursive=True, timeout=timeout)
|
|
3130
3158
|
self.command_output(["pull", intermediate, local], timeout=timeout)
|
|
3131
3159
|
except ADBError as e:
|
|
3132
|
-
self._logger.error("pull
|
|
3160
|
+
self._logger.error(f"pull {intermediate} {local}: {str(e)}")
|
|
3133
3161
|
finally:
|
|
3134
3162
|
self.rm(intermediate, recursive=True, force=True, timeout=timeout)
|
|
3135
3163
|
finally:
|
|
@@ -3156,7 +3184,7 @@ class ADBDevice(ADBCommand):
|
|
|
3156
3184
|
|
|
3157
3185
|
with tempfile.NamedTemporaryFile() as tf:
|
|
3158
3186
|
self.pull(remote, tf.name, timeout=timeout)
|
|
3159
|
-
with
|
|
3187
|
+
with open(tf.name, mode="rb") as tf2:
|
|
3160
3188
|
# ADB pull does not support offset and length, but we can
|
|
3161
3189
|
# instead read only the requested portion of the local file
|
|
3162
3190
|
if offset is not None and length is not None:
|
|
@@ -3194,7 +3222,7 @@ class ADBDevice(ADBCommand):
|
|
|
3194
3222
|
cmd += " -r"
|
|
3195
3223
|
try:
|
|
3196
3224
|
self.shell_output(
|
|
3197
|
-
"
|
|
3225
|
+
f"{cmd} {path}", timeout=timeout, enable_run_as=enable_run_as
|
|
3198
3226
|
)
|
|
3199
3227
|
self._sync(timeout=timeout)
|
|
3200
3228
|
if self.exists(path, timeout=timeout):
|
|
@@ -3259,7 +3287,7 @@ class ADBDevice(ADBCommand):
|
|
|
3259
3287
|
if adb_process.exitcode:
|
|
3260
3288
|
raise ADBProcessError(adb_process)
|
|
3261
3289
|
# first line is the headers
|
|
3262
|
-
header =
|
|
3290
|
+
header = adb_process.stdout_file.readline().decode()
|
|
3263
3291
|
pid_i = -1
|
|
3264
3292
|
user_i = -1
|
|
3265
3293
|
els = header.split()
|
|
@@ -3282,7 +3310,7 @@ class ADBDevice(ADBCommand):
|
|
|
3282
3310
|
% (header, adb_process)
|
|
3283
3311
|
)
|
|
3284
3312
|
ret = []
|
|
3285
|
-
line =
|
|
3313
|
+
line = adb_process.stdout_file.readline().decode()
|
|
3286
3314
|
while line:
|
|
3287
3315
|
els = line.split()
|
|
3288
3316
|
try:
|
|
@@ -3292,9 +3320,7 @@ class ADBDevice(ADBCommand):
|
|
|
3292
3320
|
"get_process_list: %s %s\n%s"
|
|
3293
3321
|
% (header, line, traceback.format_exc())
|
|
3294
3322
|
)
|
|
3295
|
-
raise ADBError(
|
|
3296
|
-
"get_process_list: %s: %s: %s" % (header, line, adb_process)
|
|
3297
|
-
)
|
|
3323
|
+
raise ADBError(f"get_process_list: {header}: {line}: {adb_process}")
|
|
3298
3324
|
except IndexError:
|
|
3299
3325
|
self._logger.error(
|
|
3300
3326
|
"get_process_list: %s %s els %s pid_i %s user_i %s\n%s"
|
|
@@ -3304,7 +3330,7 @@ class ADBDevice(ADBCommand):
|
|
|
3304
3330
|
"get_process_list: %s: %s els %s pid_i %s user_i %s: %s"
|
|
3305
3331
|
% (header, line, els, pid_i, user_i, adb_process)
|
|
3306
3332
|
)
|
|
3307
|
-
line =
|
|
3333
|
+
line = adb_process.stdout_file.readline().decode()
|
|
3308
3334
|
self._logger.debug("get_process_list: %s" % ret)
|
|
3309
3335
|
return ret
|
|
3310
3336
|
finally:
|
|
@@ -3405,7 +3431,7 @@ class ADBDevice(ADBCommand):
|
|
|
3405
3431
|
:raises: :exc:`ADBTimeoutError`
|
|
3406
3432
|
:exc:`ADBError`
|
|
3407
3433
|
"""
|
|
3408
|
-
if not isinstance(process_name,
|
|
3434
|
+
if not isinstance(process_name, str):
|
|
3409
3435
|
raise ADBError("Process name %s is not a string" % process_name)
|
|
3410
3436
|
|
|
3411
3437
|
# Filter out extra spaces.
|
|
@@ -3453,7 +3479,7 @@ class ADBDevice(ADBCommand):
|
|
|
3453
3479
|
if self._have_cp:
|
|
3454
3480
|
r = "-R" if recursive else ""
|
|
3455
3481
|
self.shell_output(
|
|
3456
|
-
"cp
|
|
3482
|
+
f"cp {r} {source} {destination}",
|
|
3457
3483
|
timeout=timeout,
|
|
3458
3484
|
enable_run_as=enable_run_as,
|
|
3459
3485
|
)
|
|
@@ -3470,7 +3496,7 @@ class ADBDevice(ADBCommand):
|
|
|
3470
3496
|
if self.is_dir(destination, timeout=timeout):
|
|
3471
3497
|
# Copy the source file into the destination directory
|
|
3472
3498
|
destination = posixpath.join(destination, os.path.basename(source))
|
|
3473
|
-
self.shell_output("dd if
|
|
3499
|
+
self.shell_output(f"dd if={source} of={destination}", timeout=timeout)
|
|
3474
3500
|
self.chmod(destination, recursive=recursive, timeout=timeout)
|
|
3475
3501
|
self._sync(timeout=timeout)
|
|
3476
3502
|
return
|
|
@@ -3527,7 +3553,7 @@ class ADBDevice(ADBCommand):
|
|
|
3527
3553
|
source
|
|
3528
3554
|
) or self.enable_run_as_for_path(destination)
|
|
3529
3555
|
self.shell_output(
|
|
3530
|
-
"mv
|
|
3556
|
+
f"mv {source} {destination}",
|
|
3531
3557
|
timeout=timeout,
|
|
3532
3558
|
enable_run_as=enable_run_as,
|
|
3533
3559
|
)
|
|
@@ -3585,7 +3611,7 @@ class ADBDevice(ADBCommand):
|
|
|
3585
3611
|
"diskstats",
|
|
3586
3612
|
):
|
|
3587
3613
|
results[service] = self.shell_output(
|
|
3588
|
-
"dumpsys %s" % service, timeout=timeout
|
|
3614
|
+
"dumpsys %s" % service, timeout=timeout, attempts=3
|
|
3589
3615
|
)
|
|
3590
3616
|
return results
|
|
3591
3617
|
|
|
@@ -3622,19 +3648,19 @@ class ADBDevice(ADBCommand):
|
|
|
3622
3648
|
info["battery"] = self.get_battery_percentage(timeout=timeout)
|
|
3623
3649
|
if "disk" in directives:
|
|
3624
3650
|
info["disk"] = self.shell_output(
|
|
3625
|
-
"df /data /system /sdcard", timeout=timeout
|
|
3651
|
+
"df /data /system /sdcard", timeout=timeout, attempts=3
|
|
3626
3652
|
).splitlines()
|
|
3627
3653
|
if "id" in directives:
|
|
3628
3654
|
info["id"] = self.command_output(["get-serialno"], timeout=timeout)
|
|
3629
3655
|
if "os" in directives:
|
|
3630
3656
|
info["os"] = self.get_prop("ro.build.display.id", timeout=timeout)
|
|
3631
3657
|
if "process" in directives:
|
|
3632
|
-
ps = self.shell_output("ps", timeout=timeout)
|
|
3658
|
+
ps = self.shell_output("ps", timeout=timeout, attempts=3)
|
|
3633
3659
|
info["process"] = ps.splitlines()
|
|
3634
3660
|
if "systime" in directives:
|
|
3635
|
-
info["systime"] = self.shell_output("date", timeout=timeout)
|
|
3661
|
+
info["systime"] = self.shell_output("date", timeout=timeout, attempts=3)
|
|
3636
3662
|
if "uptime" in directives:
|
|
3637
|
-
uptime = self.shell_output("uptime", timeout=timeout)
|
|
3663
|
+
uptime = self.shell_output("uptime", timeout=timeout, attempts=3)
|
|
3638
3664
|
if uptime:
|
|
3639
3665
|
m = re.match(r"up time: ((\d+) days, )*(\d{2}):(\d{2}):(\d{2})", uptime)
|
|
3640
3666
|
if m:
|
|
@@ -3659,7 +3685,7 @@ class ADBDevice(ADBCommand):
|
|
|
3659
3685
|
@property
|
|
3660
3686
|
def enforcing(self):
|
|
3661
3687
|
try:
|
|
3662
|
-
enforce = self.shell_output("getenforce")
|
|
3688
|
+
enforce = self.shell_output("getenforce", attempts=3)
|
|
3663
3689
|
except ADBError as e:
|
|
3664
3690
|
enforce = ""
|
|
3665
3691
|
self._logger.warning("Unable to get SELinux enforcing due to %s." % e)
|
|
@@ -3672,7 +3698,7 @@ class ADBDevice(ADBCommand):
|
|
|
3672
3698
|
Permissive, 0, Enforcing, 1 but it is not validated.
|
|
3673
3699
|
"""
|
|
3674
3700
|
try:
|
|
3675
|
-
self.shell_output("setenforce %s" % value)
|
|
3701
|
+
self.shell_output("setenforce %s" % value, attempts=3)
|
|
3676
3702
|
self._logger.info("Setting SELinux %s" % value)
|
|
3677
3703
|
except ADBError as e:
|
|
3678
3704
|
self._logger.warning("Unable to set SELinux Permissive due to %s." % e)
|
|
@@ -3697,7 +3723,7 @@ class ADBDevice(ADBCommand):
|
|
|
3697
3723
|
percentage = 0
|
|
3698
3724
|
cmd = "dumpsys battery"
|
|
3699
3725
|
re_parameter = re.compile(r"\s+(\w+):\s+(\d+)")
|
|
3700
|
-
lines = self.shell_output(cmd, timeout=timeout).splitlines()
|
|
3726
|
+
lines = self.shell_output(cmd, timeout=timeout, attempts=3).splitlines()
|
|
3701
3727
|
for line in lines:
|
|
3702
3728
|
match = re_parameter.match(line)
|
|
3703
3729
|
if match:
|
|
@@ -3740,10 +3766,10 @@ class ADBDevice(ADBCommand):
|
|
|
3740
3766
|
verbose = self._verbose
|
|
3741
3767
|
try:
|
|
3742
3768
|
self._verbose = False
|
|
3743
|
-
data = self.shell_output(cmd, timeout=timeout)
|
|
3769
|
+
data = self.shell_output(cmd, timeout=timeout, attempts=3)
|
|
3744
3770
|
except Exception as e:
|
|
3745
3771
|
# dumpsys intermittently fails on some platforms.
|
|
3746
|
-
self._logger.info("_get_top_activity_P: Exception
|
|
3772
|
+
self._logger.info(f"_get_top_activity_P: Exception {cmd}: {e}")
|
|
3747
3773
|
return package
|
|
3748
3774
|
finally:
|
|
3749
3775
|
self._verbose = verbose
|
|
@@ -3771,10 +3797,10 @@ class ADBDevice(ADBCommand):
|
|
|
3771
3797
|
verbose = self._verbose
|
|
3772
3798
|
try:
|
|
3773
3799
|
self._verbose = False
|
|
3774
|
-
data = self.shell_output(cmd, timeout=timeout)
|
|
3800
|
+
data = self.shell_output(cmd, timeout=timeout, attempts=3)
|
|
3775
3801
|
except Exception as e:
|
|
3776
3802
|
# dumpsys intermittently fails on some platforms (4.3 arm emulator)
|
|
3777
|
-
self._logger.info("_get_top_activity_Q: Exception
|
|
3803
|
+
self._logger.info(f"_get_top_activity_Q: Exception {cmd}: {e}")
|
|
3778
3804
|
return package
|
|
3779
3805
|
finally:
|
|
3780
3806
|
self._verbose = verbose
|
|
@@ -3829,7 +3855,7 @@ class ADBDevice(ADBCommand):
|
|
|
3829
3855
|
# Invoke the pm list packages command to see if it is up and
|
|
3830
3856
|
# running.
|
|
3831
3857
|
data = self.shell_output(
|
|
3832
|
-
"pm list packages org.mozilla", timeout=timeout
|
|
3858
|
+
"pm list packages org.mozilla", timeout=timeout, attempts=3
|
|
3833
3859
|
)
|
|
3834
3860
|
if pm_error_string in data:
|
|
3835
3861
|
failure = data
|
|
@@ -3860,7 +3886,7 @@ class ADBDevice(ADBCommand):
|
|
|
3860
3886
|
:exc:`ADBError`
|
|
3861
3887
|
"""
|
|
3862
3888
|
try:
|
|
3863
|
-
self.shell_output("svc power stayon true", timeout=timeout)
|
|
3889
|
+
self.shell_output("svc power stayon true", timeout=timeout, attempts=3)
|
|
3864
3890
|
except ADBError as e:
|
|
3865
3891
|
# Executing this via adb shell errors, but not interactively.
|
|
3866
3892
|
# Any other exitcode is a real error.
|
|
@@ -3879,6 +3905,7 @@ class ADBDevice(ADBCommand):
|
|
|
3879
3905
|
"appops set %s android:write_settings allow" % app_name,
|
|
3880
3906
|
timeout=timeout,
|
|
3881
3907
|
enable_run_as=False,
|
|
3908
|
+
attempts=3,
|
|
3882
3909
|
)
|
|
3883
3910
|
|
|
3884
3911
|
def add_mock_location(self, app_name, timeout=None):
|
|
@@ -3890,6 +3917,7 @@ class ADBDevice(ADBCommand):
|
|
|
3890
3917
|
"appops set %s android:mock_location allow" % app_name,
|
|
3891
3918
|
timeout=timeout,
|
|
3892
3919
|
enable_run_as=False,
|
|
3920
|
+
attempts=3,
|
|
3893
3921
|
)
|
|
3894
3922
|
|
|
3895
3923
|
def grant_runtime_permissions(self, app_name, timeout=None):
|
|
@@ -3915,9 +3943,10 @@ class ADBDevice(ADBCommand):
|
|
|
3915
3943
|
for permission in permissions:
|
|
3916
3944
|
try:
|
|
3917
3945
|
self.shell_output(
|
|
3918
|
-
"pm grant
|
|
3946
|
+
f"pm grant {app_name} {permission}",
|
|
3919
3947
|
timeout=timeout,
|
|
3920
3948
|
enable_run_as=False,
|
|
3949
|
+
attempts=3,
|
|
3921
3950
|
)
|
|
3922
3951
|
except ADBError as e:
|
|
3923
3952
|
self._logger.warning(
|
|
@@ -3973,19 +4002,19 @@ class ADBDevice(ADBCommand):
|
|
|
3973
4002
|
except subprocess.TimeoutExpired:
|
|
3974
4003
|
raise ADBTimeoutError("ADBDevice: unable to generate key")
|
|
3975
4004
|
|
|
3976
|
-
apks_path = "{}/tmp.apks"
|
|
4005
|
+
apks_path = f"{temporaryDirectory}/tmp.apks"
|
|
3977
4006
|
java_path = os.path.join(java_home, "bin", "java")
|
|
3978
4007
|
build_apks = [
|
|
3979
4008
|
java_path,
|
|
3980
4009
|
"-jar",
|
|
3981
4010
|
bundletool,
|
|
3982
4011
|
"build-apks",
|
|
3983
|
-
"--bundle={}"
|
|
3984
|
-
"--output={}"
|
|
4012
|
+
f"--bundle={bundle_path}",
|
|
4013
|
+
f"--output={apks_path}",
|
|
3985
4014
|
"--connected-device",
|
|
3986
|
-
"--device-id={}"
|
|
3987
|
-
"--adb={
|
|
3988
|
-
"--ks={}"
|
|
4015
|
+
f"--device-id={device_serial}",
|
|
4016
|
+
f"--adb={self._adb_path}",
|
|
4017
|
+
f"--ks={keystore_path}",
|
|
3989
4018
|
"--ks-key-alias=androiddebugkey",
|
|
3990
4019
|
"--key-pass=pass:android",
|
|
3991
4020
|
"--ks-pass=pass:android",
|
|
@@ -4001,9 +4030,9 @@ class ADBDevice(ADBCommand):
|
|
|
4001
4030
|
"-jar",
|
|
4002
4031
|
bundletool,
|
|
4003
4032
|
"install-apks",
|
|
4004
|
-
"--apks={}"
|
|
4005
|
-
"--device-id={}"
|
|
4006
|
-
"--adb={
|
|
4033
|
+
f"--apks={apks_path}",
|
|
4034
|
+
f"--device-id={device_serial}",
|
|
4035
|
+
f"--adb={self._adb_path}",
|
|
4007
4036
|
]
|
|
4008
4037
|
self._logger.info("install_apks: %s" % install_apks)
|
|
4009
4038
|
|
|
@@ -4028,15 +4057,15 @@ class ADBDevice(ADBCommand):
|
|
|
4028
4057
|
:exc:`ADBError`
|
|
4029
4058
|
"""
|
|
4030
4059
|
dump_packages = "dumpsys package packages"
|
|
4031
|
-
packages_before = set(self.shell_output(dump_packages).split("\n"))
|
|
4060
|
+
packages_before = set(self.shell_output(dump_packages, attempts=3).split("\n"))
|
|
4032
4061
|
cmd = ["install"]
|
|
4033
4062
|
if replace:
|
|
4034
4063
|
cmd.append("-r")
|
|
4035
4064
|
cmd.append(apk_path)
|
|
4036
4065
|
data = self.command_output(cmd, timeout=timeout)
|
|
4037
4066
|
if data.find("Success") == -1:
|
|
4038
|
-
raise ADBError("install failed for
|
|
4039
|
-
packages_after = set(self.shell_output(dump_packages).split("\n"))
|
|
4067
|
+
raise ADBError(f"install failed for {apk_path}. Got: {data}")
|
|
4068
|
+
packages_after = set(self.shell_output(dump_packages, attempts=3).split("\n"))
|
|
4040
4069
|
packages_diff = packages_after - packages_before
|
|
4041
4070
|
package_name = None
|
|
4042
4071
|
re_pkg = re.compile(r"\s+pkg=Package{[^ ]+ (.*)}")
|
|
@@ -4061,12 +4090,15 @@ class ADBDevice(ADBCommand):
|
|
|
4061
4090
|
"""
|
|
4062
4091
|
pm_error_string = "Error: Could not access the Package Manager"
|
|
4063
4092
|
data = self.shell_output(
|
|
4064
|
-
"pm list package %s" % app_name,
|
|
4093
|
+
"pm list package %s" % app_name,
|
|
4094
|
+
timeout=timeout,
|
|
4095
|
+
enable_run_as=False,
|
|
4096
|
+
attempts=3,
|
|
4065
4097
|
)
|
|
4066
4098
|
if pm_error_string in data:
|
|
4067
4099
|
raise ADBError(pm_error_string)
|
|
4068
4100
|
output = [line for line in data.splitlines() if line.strip()]
|
|
4069
|
-
return any(["package:{}"
|
|
4101
|
+
return any([f"package:{app_name}" == out for out in output])
|
|
4070
4102
|
|
|
4071
4103
|
def launch_application(
|
|
4072
4104
|
self,
|
|
@@ -4122,7 +4154,7 @@ class ADBDevice(ADBCommand):
|
|
|
4122
4154
|
acmd.extend(
|
|
4123
4155
|
[
|
|
4124
4156
|
"-n",
|
|
4125
|
-
"
|
|
4157
|
+
f"{app_name}/{activity_name}",
|
|
4126
4158
|
]
|
|
4127
4159
|
)
|
|
4128
4160
|
if intent:
|
|
@@ -4151,9 +4183,7 @@ class ADBDevice(ADBCommand):
|
|
|
4151
4183
|
if "Error:" in cmd_output:
|
|
4152
4184
|
for line in cmd_output.split("\n"):
|
|
4153
4185
|
self._logger.info(line)
|
|
4154
|
-
raise ADBError(
|
|
4155
|
-
"launch_application %s/%s failed" % (app_name, activity_name)
|
|
4156
|
-
)
|
|
4186
|
+
raise ADBError(f"launch_application {app_name}/{activity_name} failed")
|
|
4157
4187
|
|
|
4158
4188
|
def launch_fennec(
|
|
4159
4189
|
self,
|
|
@@ -4239,7 +4269,7 @@ class ADBDevice(ADBCommand):
|
|
|
4239
4269
|
application.
|
|
4240
4270
|
:param str extra_args: Extra arguments to be parsed by the app.
|
|
4241
4271
|
:param str url: URL to open
|
|
4242
|
-
:param bool e10s:
|
|
4272
|
+
:param bool e10s: No longer used.
|
|
4243
4273
|
:param bool wait: If True, wait for application to start before
|
|
4244
4274
|
returning.
|
|
4245
4275
|
:param bool grant_runtime_permissions: Grant special runtime
|
|
@@ -4268,11 +4298,10 @@ class ADBDevice(ADBCommand):
|
|
|
4268
4298
|
for arg_count, arg in enumerate(extra_args):
|
|
4269
4299
|
extras["arg" + str(arg_count)] = arg
|
|
4270
4300
|
|
|
4271
|
-
extras["use_multiprocess"] = e10s
|
|
4272
4301
|
extras["out_file"] = out_file
|
|
4273
4302
|
self.launch_application(
|
|
4274
4303
|
app_name,
|
|
4275
|
-
"
|
|
4304
|
+
f"{app_name}.{activity_name}",
|
|
4276
4305
|
intent,
|
|
4277
4306
|
url=url,
|
|
4278
4307
|
extras=extras,
|
|
@@ -4308,7 +4337,7 @@ class ADBDevice(ADBCommand):
|
|
|
4308
4337
|
application.
|
|
4309
4338
|
:param str extra_args: Extra arguments to be parsed by the app.
|
|
4310
4339
|
:param str url: URL to open
|
|
4311
|
-
:param bool e10s:
|
|
4340
|
+
:param bool e10s: No longer used.
|
|
4312
4341
|
:param bool wait: If True, wait for application to start before
|
|
4313
4342
|
returning.
|
|
4314
4343
|
:param bool fail_if_running: Raise an exception if instance of
|
|
@@ -4336,10 +4365,9 @@ class ADBDevice(ADBCommand):
|
|
|
4336
4365
|
for arg_count, arg in enumerate(extra_args):
|
|
4337
4366
|
extras["arg" + str(arg_count)] = arg
|
|
4338
4367
|
|
|
4339
|
-
extras["use_multiprocess"] = e10s
|
|
4340
4368
|
self.launch_application(
|
|
4341
4369
|
app_name,
|
|
4342
|
-
"
|
|
4370
|
+
f"{app_name}.{activity_name}",
|
|
4343
4371
|
intent,
|
|
4344
4372
|
url=url,
|
|
4345
4373
|
extras=extras,
|
|
@@ -4370,7 +4398,9 @@ class ADBDevice(ADBCommand):
|
|
|
4370
4398
|
:exc:`ADBError`
|
|
4371
4399
|
"""
|
|
4372
4400
|
if self.version >= version_codes.HONEYCOMB:
|
|
4373
|
-
self.shell_output(
|
|
4401
|
+
self.shell_output(
|
|
4402
|
+
"am force-stop %s" % app_name, timeout=timeout, attempts=3
|
|
4403
|
+
)
|
|
4374
4404
|
else:
|
|
4375
4405
|
num_tries = 0
|
|
4376
4406
|
max_tries = 5
|
|
@@ -4410,7 +4440,7 @@ class ADBDevice(ADBCommand):
|
|
|
4410
4440
|
data = self.command_output(["uninstall", app_name], timeout=timeout)
|
|
4411
4441
|
if data.find("Success") == -1:
|
|
4412
4442
|
self._logger.debug("uninstall_app failed: %s" % data)
|
|
4413
|
-
raise ADBError("uninstall failed for
|
|
4443
|
+
raise ADBError(f"uninstall failed for {app_name}. Got: {data}")
|
|
4414
4444
|
self.run_as_package = None
|
|
4415
4445
|
if reboot:
|
|
4416
4446
|
self.reboot(timeout=timeout)
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
import re
|
|
6
6
|
import time
|
|
7
7
|
|
|
8
|
-
import six
|
|
9
|
-
|
|
10
8
|
from .adb import ADBTimeoutError
|
|
11
9
|
|
|
12
10
|
|
|
@@ -56,7 +54,6 @@ class RemoteProcessMonitor:
|
|
|
56
54
|
self.device.launch_activity(
|
|
57
55
|
self.app_name,
|
|
58
56
|
activity_name=activity,
|
|
59
|
-
e10s=e10s,
|
|
60
57
|
moz_env=env,
|
|
61
58
|
extra_args=args,
|
|
62
59
|
url=test_url,
|
|
@@ -89,15 +86,13 @@ class RemoteProcessMonitor:
|
|
|
89
86
|
except ADBTimeoutError:
|
|
90
87
|
raise
|
|
91
88
|
except Exception as e:
|
|
92
|
-
self.log.error(
|
|
93
|
-
"%s | exception reading log: %s" % (self.last_test_seen, str(e))
|
|
94
|
-
)
|
|
89
|
+
self.log.error(f"{self.last_test_seen} | exception reading log: {str(e)}")
|
|
95
90
|
return False
|
|
96
91
|
if not new_log_content:
|
|
97
92
|
return False
|
|
98
93
|
|
|
99
94
|
self.stdout_len += len(new_log_content)
|
|
100
|
-
new_log_content =
|
|
95
|
+
new_log_content = new_log_content.decode(errors="replace")
|
|
101
96
|
|
|
102
97
|
self.log_buffer += new_log_content
|
|
103
98
|
lines = self.log_buffer.split("\n")
|
|
@@ -116,7 +111,7 @@ class RemoteProcessMonitor:
|
|
|
116
111
|
|
|
117
112
|
for line in lines:
|
|
118
113
|
# This passes the line to the logger (to be logged or buffered)
|
|
119
|
-
if isinstance(line,
|
|
114
|
+
if isinstance(line, str):
|
|
120
115
|
# if line is unicode - let's encode it to bytes
|
|
121
116
|
parsed_messages = self.message_logger.write(
|
|
122
117
|
line.encode("UTF-8", "replace")
|
|
@@ -134,17 +129,17 @@ class RemoteProcessMonitor:
|
|
|
134
129
|
elif message.get("action") == "suite_end":
|
|
135
130
|
self.last_test_seen = "Last test finished"
|
|
136
131
|
elif message.get("action") == "log":
|
|
137
|
-
|
|
138
|
-
m = re.match(r".*:\s*(\d*)",
|
|
132
|
+
stripped_message = message["message"].strip()
|
|
133
|
+
m = re.match(r".*:\s*(\d*)", stripped_message)
|
|
139
134
|
if m:
|
|
140
135
|
try:
|
|
141
136
|
val = int(m.group(1))
|
|
142
|
-
if "Passed:" in
|
|
137
|
+
if "Passed:" in stripped_message:
|
|
143
138
|
self.counts["pass"] += val
|
|
144
139
|
self.last_test_seen = "Last test finished"
|
|
145
|
-
elif "Failed:" in
|
|
140
|
+
elif "Failed:" in stripped_message:
|
|
146
141
|
self.counts["fail"] += val
|
|
147
|
-
elif "Todo:" in
|
|
142
|
+
elif "Todo:" in stripped_message:
|
|
148
143
|
self.counts["todo"] += val
|
|
149
144
|
except ADBTimeoutError:
|
|
150
145
|
raise
|
|
@@ -203,7 +198,7 @@ class RemoteProcessMonitor:
|
|
|
203
198
|
|
|
204
199
|
# Flush anything added to stdout during the sleep
|
|
205
200
|
self.read_stdout()
|
|
206
|
-
self.log.info("wait for
|
|
201
|
+
self.log.info(f"wait for {self.app_name} complete; top activity={top}")
|
|
207
202
|
if top == self.app_name:
|
|
208
203
|
self.log.info("%s unexpectedly found running. Killing..." % self.app_name)
|
|
209
204
|
self.kill()
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: mozdevice
|
|
3
|
-
Version: 4.
|
|
4
|
-
Summary: Mozilla-authored device management
|
|
5
|
-
Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
|
|
6
|
-
Author: Mozilla Automation and Testing Team
|
|
7
|
-
Author-email: tools@lists.mozilla.org
|
|
8
|
-
License: MPL
|
|
9
|
-
Classifier: Programming Language :: Python ::
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mozdevice
|
|
3
|
+
Version: 4.2.0
|
|
4
|
+
Summary: Mozilla-authored device management
|
|
5
|
+
Home-page: https://wiki.mozilla.org/Auto-tools/Projects/Mozbase
|
|
6
|
+
Author: Mozilla Automation and Testing Team
|
|
7
|
+
Author-email: tools@lists.mozilla.org
|
|
8
|
+
License: MPL
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Requires-Dist: mozlog>=6.0
|
|
14
|
+
|
|
15
|
+
see https://firefox-source-docs.mozilla.org/mozbase/index.html
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
[bdist_wheel]
|
|
2
|
-
universal = 1
|
|
3
|
-
|
|
4
|
-
[egg_info]
|
|
5
|
-
tag_build =
|
|
6
|
-
tag_date = 0
|
|
7
|
-
|
|
1
|
+
[bdist_wheel]
|
|
2
|
+
universal = 1
|
|
3
|
+
|
|
4
|
+
[egg_info]
|
|
5
|
+
tag_build =
|
|
6
|
+
tag_date = 0
|
|
7
|
+
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
from setuptools import setup
|
|
6
6
|
|
|
7
7
|
PACKAGE_NAME = "mozdevice"
|
|
8
|
-
PACKAGE_VERSION = "4.
|
|
8
|
+
PACKAGE_VERSION = "4.2.0"
|
|
9
9
|
|
|
10
10
|
deps = ["mozlog >= 6.0"]
|
|
11
11
|
|
|
@@ -15,8 +15,10 @@ setup(
|
|
|
15
15
|
description="Mozilla-authored device management",
|
|
16
16
|
long_description="see https://firefox-source-docs.mozilla.org/mozbase/index.html",
|
|
17
17
|
classifiers=[
|
|
18
|
-
"Programming Language :: Python ::
|
|
19
|
-
"Programming Language :: Python :: 3.
|
|
18
|
+
"Programming Language :: Python :: 3.8",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
20
22
|
],
|
|
21
23
|
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
|
|
22
24
|
keywords="",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|