android-env 1.2.2__py3-none-any.whl → 1.2.3__py3-none-any.whl
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.
- android_env/__init__.py +1 -1
- android_env/components/__init__.py +1 -1
- android_env/components/a11y/__init__.py +15 -0
- android_env/components/a11y/a11y_events.py +118 -0
- android_env/components/a11y/a11y_events_test.py +173 -0
- android_env/components/a11y/a11y_forests.py +128 -0
- android_env/components/a11y/a11y_forests_test.py +237 -0
- android_env/components/a11y/a11y_servicer.py +199 -0
- android_env/components/a11y/a11y_servicer_test.py +224 -0
- android_env/components/action_fns.py +132 -0
- android_env/components/action_fns_test.py +227 -0
- android_env/components/action_type.py +26 -3
- android_env/components/adb_call_parser.py +233 -185
- android_env/components/adb_call_parser_test.py +165 -163
- android_env/components/adb_controller.py +19 -28
- android_env/components/adb_controller_test.py +100 -9
- android_env/components/adb_log_stream.py +3 -3
- android_env/components/adb_log_stream_test.py +1 -1
- android_env/components/app_screen_checker.py +15 -13
- android_env/components/app_screen_checker_test.py +1 -1
- android_env/components/config_classes.py +203 -0
- android_env/components/coordinator.py +53 -338
- android_env/components/coordinator_test.py +26 -283
- android_env/components/device_settings.py +174 -0
- android_env/components/device_settings_test.py +228 -0
- android_env/components/dumpsys_thread.py +3 -4
- android_env/components/dumpsys_thread_test.py +1 -1
- android_env/components/errors.py +2 -5
- android_env/components/errors_test.py +1 -1
- android_env/components/log_stream.py +2 -2
- android_env/components/log_stream_test.py +1 -1
- android_env/components/logcat_thread.py +9 -8
- android_env/components/logcat_thread_test.py +2 -3
- android_env/components/{utils.py → pixel_fns.py} +19 -20
- android_env/components/{utils_test.py → pixel_fns_test.py} +20 -15
- android_env/components/setup_step_interpreter.py +45 -37
- android_env/components/setup_step_interpreter_test.py +1 -1
- android_env/components/simulators/__init__.py +1 -1
- android_env/components/simulators/base_simulator.py +79 -23
- android_env/components/simulators/base_simulator_test.py +131 -9
- android_env/components/simulators/emulator/__init__.py +1 -1
- android_env/components/simulators/emulator/emulator_launcher.py +62 -81
- android_env/components/simulators/emulator/emulator_launcher_test.py +120 -43
- android_env/components/simulators/emulator/emulator_simulator.py +111 -98
- android_env/components/simulators/emulator/emulator_simulator_test.py +174 -138
- android_env/components/simulators/fake/__init__.py +1 -1
- android_env/components/simulators/fake/fake_simulator.py +9 -17
- android_env/components/simulators/fake/fake_simulator_test.py +23 -8
- android_env/components/specs.py +1 -1
- android_env/components/specs_test.py +1 -1
- android_env/components/task_manager.py +26 -31
- android_env/components/task_manager_test.py +1 -18
- android_env/env_interface.py +1 -17
- android_env/environment.py +27 -17
- android_env/environment_test.py +51 -25
- android_env/loader.py +57 -43
- android_env/loader_test.py +115 -35
- android_env/proto/__init__.py +1 -1
- android_env/proto/a11y/__init__.py +15 -0
- android_env/proto/a11y/a11y.proto +75 -0
- android_env/proto/a11y/a11y_pb2.py +54 -0
- android_env/proto/a11y/a11y_pb2.pyi +49 -0
- android_env/proto/a11y/a11y_pb2_grpc.py +202 -0
- android_env/proto/a11y/android_accessibility_action.proto +32 -0
- android_env/proto/a11y/android_accessibility_action_pb2.py +37 -0
- android_env/proto/a11y/android_accessibility_action_pb2.pyi +13 -0
- android_env/proto/a11y/android_accessibility_action_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_forest.proto +29 -0
- android_env/proto/a11y/android_accessibility_forest_pb2.py +38 -0
- android_env/proto/a11y/android_accessibility_forest_pb2.pyi +13 -0
- android_env/proto/a11y/android_accessibility_forest_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_node_info.proto +122 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span.proto +49 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2.py +39 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2.pyi +28 -0
- android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_node_info_pb2.py +42 -0
- android_env/proto/a11y/android_accessibility_node_info_pb2.pyi +75 -0
- android_env/proto/a11y/android_accessibility_node_info_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_tree.proto +29 -0
- android_env/proto/a11y/android_accessibility_tree_pb2.py +38 -0
- android_env/proto/a11y/android_accessibility_tree_pb2.pyi +13 -0
- android_env/proto/a11y/android_accessibility_tree_pb2_grpc.py +24 -0
- android_env/proto/a11y/android_accessibility_window_info.proto +84 -0
- android_env/proto/a11y/android_accessibility_window_info_pb2.py +41 -0
- android_env/proto/a11y/android_accessibility_window_info_pb2.pyi +48 -0
- android_env/proto/a11y/android_accessibility_window_info_pb2_grpc.py +24 -0
- android_env/proto/a11y/rect.proto +30 -0
- android_env/proto/a11y/rect_pb2.py +37 -0
- android_env/proto/a11y/rect_pb2.pyi +17 -0
- android_env/proto/a11y/rect_pb2_grpc.py +24 -0
- android_env/proto/adb.proto +13 -1
- android_env/proto/adb_pb2.py +120 -107
- android_env/proto/adb_pb2.pyi +396 -0
- android_env/proto/adb_pb2_grpc.py +20 -0
- android_env/proto/emulator_controller.proto +1 -1
- android_env/proto/emulator_controller_pb2.py +142 -131
- android_env/proto/emulator_controller_pb2.pyi +672 -0
- android_env/proto/emulator_controller_pb2_grpc.py +497 -136
- android_env/proto/snapshot.proto +1 -1
- android_env/proto/snapshot_pb2.py +30 -19
- android_env/proto/snapshot_pb2.pyi +117 -0
- android_env/proto/snapshot_pb2_grpc.py +20 -0
- android_env/proto/snapshot_service.proto +1 -1
- android_env/proto/snapshot_service_pb2.py +36 -25
- android_env/proto/snapshot_service_pb2.pyi +86 -0
- android_env/proto/snapshot_service_pb2_grpc.py +119 -28
- android_env/proto/state.proto +1 -1
- android_env/proto/state_pb2.py +46 -35
- android_env/proto/state_pb2.pyi +85 -0
- android_env/proto/state_pb2_grpc.py +20 -0
- android_env/proto/task.proto +4 -1
- android_env/proto/task_pb2.py +41 -30
- android_env/proto/task_pb2.pyi +160 -0
- android_env/proto/task_pb2_grpc.py +20 -0
- android_env/wrappers/__init__.py +1 -1
- android_env/wrappers/a11y_grpc_wrapper.py +500 -0
- android_env/wrappers/a11y_grpc_wrapper_test.py +849 -0
- android_env/wrappers/base_wrapper.py +1 -5
- android_env/wrappers/base_wrapper_test.py +1 -7
- android_env/wrappers/discrete_action_wrapper.py +15 -14
- android_env/wrappers/discrete_action_wrapper_test.py +1 -1
- android_env/wrappers/flat_interface_wrapper.py +5 -5
- android_env/wrappers/flat_interface_wrapper_test.py +1 -1
- android_env/wrappers/float_pixels_wrapper.py +5 -4
- android_env/wrappers/float_pixels_wrapper_test.py +1 -1
- android_env/wrappers/gym_wrapper.py +1 -1
- android_env/wrappers/gym_wrapper_test.py +1 -1
- android_env/wrappers/image_rescale_wrapper.py +13 -10
- android_env/wrappers/image_rescale_wrapper_test.py +1 -1
- android_env/wrappers/last_action_wrapper.py +5 -4
- android_env/wrappers/last_action_wrapper_test.py +1 -1
- android_env/wrappers/rate_limit_wrapper.py +1 -1
- android_env/wrappers/rate_limit_wrapper_test.py +1 -1
- android_env/wrappers/tap_action_wrapper.py +12 -12
- android_env/wrappers/tap_action_wrapper_test.py +49 -14
- {android_env-1.2.2.dist-info → android_env-1.2.3.dist-info}/METADATA +14 -16
- android_env-1.2.3.dist-info/RECORD +141 -0
- {android_env-1.2.2.dist-info → android_env-1.2.3.dist-info}/WHEEL +1 -1
- android_env-1.2.2.dist-info/RECORD +0 -88
- {android_env-1.2.2.dist-info → android_env-1.2.3.dist-info/licenses}/LICENSE +0 -0
- {android_env-1.2.2.dist-info → android_env-1.2.3.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding=utf-8
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 DeepMind Technologies Limited.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -13,12 +13,11 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
"""Tests for adb_call_parser."""
|
17
|
-
|
18
16
|
import builtins
|
19
17
|
import os
|
20
18
|
import subprocess
|
21
19
|
import sys
|
20
|
+
import tempfile
|
22
21
|
from unittest import mock
|
23
22
|
|
24
23
|
from absl.testing import absltest
|
@@ -31,31 +30,32 @@ from android_env.proto import adb_pb2
|
|
31
30
|
class AdbCallParserTest(parameterized.TestCase):
|
32
31
|
|
33
32
|
def test_unknown_command(self):
|
33
|
+
"""Gets UNKNOWN_COMMAND for an empty request."""
|
34
34
|
adb = mock.create_autospec(adb_controller.AdbController)
|
35
|
-
parser = adb_call_parser.AdbCallParser(
|
36
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
35
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
37
36
|
request = adb_pb2.AdbRequest()
|
38
37
|
response = parser.parse(request)
|
39
|
-
self.assertEqual(
|
40
|
-
|
38
|
+
self.assertEqual(
|
39
|
+
response.status, adb_pb2.AdbResponse.Status.UNKNOWN_COMMAND
|
40
|
+
)
|
41
41
|
|
42
42
|
def test_invalid_timeout(self):
|
43
43
|
"""AdbRequest.timeout_sec must be positive."""
|
44
44
|
adb = mock.create_autospec(adb_controller.AdbController)
|
45
|
-
parser = adb_call_parser.AdbCallParser(
|
46
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
45
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
47
46
|
request = adb_pb2.AdbRequest()
|
48
47
|
request.tap.x = 123
|
49
48
|
request.timeout_sec = -5
|
50
49
|
response = parser.parse(request)
|
51
|
-
self.assertEqual(
|
52
|
-
|
50
|
+
self.assertEqual(
|
51
|
+
response.status, adb_pb2.AdbResponse.Status.FAILED_PRECONDITION
|
52
|
+
)
|
53
53
|
|
54
54
|
@mock.patch.object(os.path, 'exists', autospec=True)
|
55
55
|
def test_install_apk_file_not_found(self, mock_exists):
|
56
|
+
"""Should fail installing APK when it is not found."""
|
56
57
|
adb = mock.create_autospec(adb_controller.AdbController)
|
57
|
-
parser = adb_call_parser.AdbCallParser(
|
58
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
58
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
59
59
|
request = adb_pb2.AdbRequest()
|
60
60
|
request.install_apk.filesystem.path = '/my/home/game.apk'
|
61
61
|
mock_exists.return_value = False
|
@@ -67,9 +67,9 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
67
67
|
|
68
68
|
@mock.patch.object(os.path, 'exists', autospec=True)
|
69
69
|
def test_install_apk_successful(self, mock_exists):
|
70
|
+
"""Should succeed installing an arbitrary APK."""
|
70
71
|
adb = mock.create_autospec(adb_controller.AdbController)
|
71
|
-
parser = adb_call_parser.AdbCallParser(
|
72
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
72
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
73
73
|
request = adb_pb2.AdbRequest()
|
74
74
|
request.install_apk.filesystem.path = '/my/home/game.apk'
|
75
75
|
mock_exists.return_value = True
|
@@ -80,10 +80,41 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
80
80
|
adb.execute_command.assert_called_once_with(
|
81
81
|
['install', '-r', '-t', '-g', '/my/home/game.apk'], None)
|
82
82
|
|
83
|
+
@mock.patch.object(tempfile, 'NamedTemporaryFile', autospec=True)
|
84
|
+
def test_install_apk_from_blob(self, mock_tempfile):
|
85
|
+
"""Should succeed installing APK from blob."""
|
86
|
+
adb = mock.create_autospec(adb_controller.AdbController)
|
87
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
88
|
+
request = adb_pb2.AdbRequest()
|
89
|
+
blob_content = b'A fake blob content'
|
90
|
+
request.install_apk.blob.contents = blob_content
|
91
|
+
mock_tempfile.return_value.__enter__.return_value.name = '/my/home/test.apk'
|
92
|
+
mock_tempfile.return_value.__enter__.return_value.write.return_value = None
|
93
|
+
|
94
|
+
response = parser.parse(request)
|
95
|
+
self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
|
96
|
+
self.assertEmpty(response.error_message)
|
97
|
+
adb.execute_command.assert_called_once_with(
|
98
|
+
['install', '-r', '-t', '-g', '/my/home/test.apk'], None
|
99
|
+
)
|
100
|
+
# pytype: disable=attribute-error
|
101
|
+
expected_tempfile_kwargs = (
|
102
|
+
{'suffix': '.apk', 'delete_on_close': False}
|
103
|
+
if sys.version_info > (3, 12)
|
104
|
+
else {'suffix': '.apk'}
|
105
|
+
)
|
106
|
+
mock_tempfile.assert_has_calls([
|
107
|
+
mock.call(**expected_tempfile_kwargs), # Constructor
|
108
|
+
mock.call().__enter__(), # Enter context
|
109
|
+
mock.call().__enter__().write(blob_content), # Call write function
|
110
|
+
mock.call().__exit__(None, None, None), # Exit context
|
111
|
+
])
|
112
|
+
# pytype: enable=attribute-error
|
113
|
+
|
83
114
|
def test_start_activity_empty_full_activity(self):
|
115
|
+
"""A start_activity command should always have a nonempty activity."""
|
84
116
|
adb = mock.create_autospec(adb_controller.AdbController)
|
85
|
-
parser = adb_call_parser.AdbCallParser(
|
86
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
117
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
87
118
|
request = adb_pb2.AdbRequest()
|
88
119
|
request.start_activity.extra_args.extend(['blah'])
|
89
120
|
response = parser.parse(request)
|
@@ -96,8 +127,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
96
127
|
command_output = (b'Stopping: my.project.SplashActivity\n'
|
97
128
|
b'Starting: Intent { cmp=my.project.SplashActivity }\n')
|
98
129
|
adb.execute_command.return_value = command_output
|
99
|
-
parser = adb_call_parser.AdbCallParser(
|
100
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
130
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
101
131
|
request = adb_pb2.AdbRequest()
|
102
132
|
request.start_activity.full_activity = 'my.project.SplashActivity'
|
103
133
|
request.start_activity.extra_args.extend(['blah'])
|
@@ -118,8 +148,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
118
148
|
command_output = (b'Stopping: my.project.SplashActivity\n'
|
119
149
|
b'Starting: Intent { cmp=my.project.SplashActivity }\n')
|
120
150
|
adb.execute_command.return_value = command_output
|
121
|
-
parser = adb_call_parser.AdbCallParser(
|
122
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
151
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
123
152
|
request = adb_pb2.AdbRequest()
|
124
153
|
request.start_activity.full_activity = 'my.project.SplashActivity'
|
125
154
|
request.start_activity.extra_args.extend(['blah'])
|
@@ -141,8 +170,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
141
170
|
b'Starting: Intent { cmp=my.project.SplashActivity }\n'
|
142
171
|
b'Error: Activity not started, unknown error code 101\n')
|
143
172
|
adb.execute_command.return_value = command_output
|
144
|
-
parser = adb_call_parser.AdbCallParser(
|
145
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
173
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
146
174
|
request = adb_pb2.AdbRequest()
|
147
175
|
request.start_activity.full_activity = 'my.project.SplashActivity'
|
148
176
|
request.start_activity.extra_args.extend(['blah'])
|
@@ -154,8 +182,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
154
182
|
|
155
183
|
def test_force_stop(self):
|
156
184
|
adb = mock.create_autospec(adb_controller.AdbController)
|
157
|
-
parser = adb_call_parser.AdbCallParser(
|
158
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
185
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
159
186
|
request = adb_pb2.AdbRequest()
|
160
187
|
request.force_stop.package_name = 'my.project'
|
161
188
|
response = parser.parse(request)
|
@@ -166,8 +193,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
166
193
|
|
167
194
|
def test_grant_permissions_empty_package_name(self):
|
168
195
|
adb = mock.create_autospec(adb_controller.AdbController)
|
169
|
-
parser = adb_call_parser.AdbCallParser(
|
170
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
196
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
171
197
|
request = adb_pb2.AdbRequest()
|
172
198
|
request.package_manager.grant.permissions.extend(['perm1', 'perm2'])
|
173
199
|
response = parser.parse(request)
|
@@ -177,8 +203,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
177
203
|
|
178
204
|
def test_grant_permissions_empty_permissions(self):
|
179
205
|
adb = mock.create_autospec(adb_controller.AdbController)
|
180
|
-
parser = adb_call_parser.AdbCallParser(
|
181
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
206
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
182
207
|
request = adb_pb2.AdbRequest()
|
183
208
|
request.package_manager.grant.package_name = 'my.project'
|
184
209
|
response = parser.parse(request)
|
@@ -189,8 +214,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
189
214
|
def test_grant_permissions_successful(self):
|
190
215
|
adb = mock.create_autospec(adb_controller.AdbController)
|
191
216
|
adb.execute_command.return_value = b'whatever'
|
192
|
-
parser = adb_call_parser.AdbCallParser(
|
193
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
217
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
194
218
|
request = adb_pb2.AdbRequest()
|
195
219
|
request.package_manager.grant.package_name = 'my.project'
|
196
220
|
request.package_manager.grant.permissions.extend(['perm1', 'perm2'])
|
@@ -204,8 +228,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
204
228
|
|
205
229
|
def test_press_button_invalid_button(self):
|
206
230
|
adb = mock.create_autospec(adb_controller.AdbController)
|
207
|
-
parser = adb_call_parser.AdbCallParser(
|
208
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
231
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
209
232
|
request = adb_pb2.AdbRequest()
|
210
233
|
request.press_button.button = 99999
|
211
234
|
response = parser.parse(request)
|
@@ -216,8 +239,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
216
239
|
def test_press_button_successful(self):
|
217
240
|
adb = mock.create_autospec(adb_controller.AdbController)
|
218
241
|
adb.execute_command.return_value = b''
|
219
|
-
parser = adb_call_parser.AdbCallParser(
|
220
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
242
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
221
243
|
# HOME.
|
222
244
|
request = adb_pb2.AdbRequest()
|
223
245
|
request.press_button.button = adb_pb2.AdbRequest.PressButton.Button.HOME
|
@@ -248,8 +270,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
248
270
|
adb.execute_command.return_value = (
|
249
271
|
b' taskId=12345: my.project.AnotherActivity visible=true'
|
250
272
|
b' topActivity=ComponentInfo{my.project.AnotherActivity}')
|
251
|
-
parser = adb_call_parser.AdbCallParser(
|
252
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
273
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
253
274
|
request = adb_pb2.AdbRequest()
|
254
275
|
request.start_screen_pinning.full_activity = 'my.project.AmazingActivity'
|
255
276
|
response = parser.parse(request)
|
@@ -263,8 +284,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
263
284
|
adb.execute_command.return_value = (
|
264
285
|
b' taskId=12345: my.project.AmazingActivity visible=true'
|
265
286
|
b' topActivity=ComponentInfo{my.project.AmazingActivity}')
|
266
|
-
parser = adb_call_parser.AdbCallParser(
|
267
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
287
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
268
288
|
request = adb_pb2.AdbRequest()
|
269
289
|
request.start_screen_pinning.full_activity = 'my.project.AmazingActivity'
|
270
290
|
response = parser.parse(request)
|
@@ -280,8 +300,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
280
300
|
adb.execute_command.return_value = (
|
281
301
|
b' taskId=12345: my.project.MainActivity visible=true'
|
282
302
|
b' topActivity=ComponentInfo{my.project.TopActivity}')
|
283
|
-
parser = adb_call_parser.AdbCallParser(
|
284
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
303
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
285
304
|
request = adb_pb2.AdbRequest()
|
286
305
|
request.start_screen_pinning.full_activity = 'my.project.MainActivity'
|
287
306
|
response = parser.parse(request)
|
@@ -297,8 +316,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
297
316
|
adb.execute_command.return_value = (
|
298
317
|
b' taskId=12345: my.project.MainActivity visible=true'
|
299
318
|
b' topActivity=ComponentInfo{my.project.TopActivity}')
|
300
|
-
parser = adb_call_parser.AdbCallParser(
|
301
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
319
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
302
320
|
request = adb_pb2.AdbRequest()
|
303
321
|
request.start_screen_pinning.full_activity = 'my.project.TopActivity'
|
304
322
|
response = parser.parse(request)
|
@@ -311,8 +329,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
311
329
|
|
312
330
|
def test_send_broadcast_empty_action(self):
|
313
331
|
adb = mock.create_autospec(adb_controller.AdbController)
|
314
|
-
parser = adb_call_parser.AdbCallParser(
|
315
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
332
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
316
333
|
request = adb_pb2.AdbRequest(
|
317
334
|
send_broadcast=adb_pb2.AdbRequest.SendBroadcast())
|
318
335
|
response = parser.parse(request)
|
@@ -322,18 +339,26 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
322
339
|
|
323
340
|
def test_send_broadcast_successful(self):
|
324
341
|
adb = mock.create_autospec(adb_controller.AdbController)
|
325
|
-
parser = adb_call_parser.AdbCallParser(
|
326
|
-
|
342
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
343
|
+
request = adb_pb2.AdbRequest()
|
344
|
+
request.send_broadcast.action = 'SOME-ACTION'
|
345
|
+
response = parser.parse(request)
|
346
|
+
self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
|
347
|
+
self.assertEmpty(response.error_message)
|
348
|
+
|
349
|
+
def test_send_broadcast_with_component_successful(self):
|
350
|
+
adb = mock.create_autospec(adb_controller.AdbController)
|
351
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
327
352
|
request = adb_pb2.AdbRequest()
|
328
353
|
request.send_broadcast.action = 'SOME-ACTION'
|
354
|
+
request.send_broadcast.component = 'SOME-COMPONENT'
|
329
355
|
response = parser.parse(request)
|
330
356
|
self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
|
331
357
|
self.assertEmpty(response.error_message)
|
332
358
|
|
333
359
|
def test_uninstall_package_empty_package_name(self):
|
334
360
|
adb = mock.create_autospec(adb_controller.AdbController)
|
335
|
-
parser = adb_call_parser.AdbCallParser(
|
336
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
361
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
337
362
|
request = adb_pb2.AdbRequest()
|
338
363
|
request.uninstall_package.package_name = ''
|
339
364
|
response = parser.parse(request)
|
@@ -344,8 +369,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
344
369
|
def test_uninstall_package_successful(self):
|
345
370
|
adb = mock.create_autospec(adb_controller.AdbController)
|
346
371
|
adb.execute_command.return_value = b'package:my.package'
|
347
|
-
parser = adb_call_parser.AdbCallParser(
|
348
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
372
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
349
373
|
request = adb_pb2.AdbRequest()
|
350
374
|
request.uninstall_package.package_name = 'my.package'
|
351
375
|
response = parser.parse(request)
|
@@ -355,8 +379,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
355
379
|
def test_get_current_activity_no_visible_task(self):
|
356
380
|
adb = mock.create_autospec(adb_controller.AdbController)
|
357
381
|
adb.execute_command.return_value = None
|
358
|
-
parser = adb_call_parser.AdbCallParser(
|
359
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
382
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
360
383
|
request = adb_pb2.AdbRequest(
|
361
384
|
get_current_activity=adb_pb2.AdbRequest.GetCurrentActivity())
|
362
385
|
response = parser.parse(request)
|
@@ -372,8 +395,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
372
395
|
def test_get_orientation_empty_dumpsys(self):
|
373
396
|
adb = mock.create_autospec(adb_controller.AdbController)
|
374
397
|
adb.execute_command.return_value = b''
|
375
|
-
parser = adb_call_parser.AdbCallParser(
|
376
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
398
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
377
399
|
request = adb_pb2.AdbRequest(
|
378
400
|
get_orientation=adb_pb2.AdbRequest.GetOrientationRequest())
|
379
401
|
response = parser.parse(request)
|
@@ -385,8 +407,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
385
407
|
def test_get_orientation_invalid_device_no_surface_orientation(self):
|
386
408
|
adb = mock.create_autospec(adb_controller.AdbController)
|
387
409
|
adb.execute_command.return_value = b' PhysicalWidth: -123px'
|
388
|
-
parser = adb_call_parser.AdbCallParser(
|
389
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
410
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
390
411
|
request = adb_pb2.AdbRequest(
|
391
412
|
get_orientation=adb_pb2.AdbRequest.GetOrientationRequest())
|
392
413
|
response = parser.parse(request)
|
@@ -396,21 +417,26 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
396
417
|
None)
|
397
418
|
|
398
419
|
@parameterized.named_parameters(
|
399
|
-
('rotation_0', b
|
400
|
-
('rotation_90', b
|
401
|
-
('rotation_180', b
|
402
|
-
('rotation_270', b
|
420
|
+
('rotation_0', b""" SurfaceOrientation: 0""", 0),
|
421
|
+
('rotation_90', b""" SurfaceOrientation: 1""", 1),
|
422
|
+
('rotation_180', b""" SurfaceOrientation: 2""", 2),
|
423
|
+
('rotation_270', b""" SurfaceOrientation: 3""", 3),
|
424
|
+
('rotation_0_new', b""" InputDeviceOrientation: 0""", 0),
|
425
|
+
('rotation_90_new', b""" InputDeviceOrientation: 1""", 1),
|
426
|
+
('rotation_180_new', b""" InputDeviceOrientation: 2""", 2),
|
427
|
+
('rotation_270_new', b""" InputDeviceOrientation: 3""", 3),
|
403
428
|
)
|
404
|
-
def test_get_orientation_success(
|
429
|
+
def test_get_orientation_success(
|
430
|
+
self, orientation: bytes, expected_orientation: int
|
431
|
+
):
|
405
432
|
adb = mock.create_autospec(adb_controller.AdbController)
|
406
|
-
adb.execute_command.return_value =
|
407
|
-
|
408
|
-
SurfaceOrientation: """ + orientation + b"""
|
433
|
+
adb.execute_command.return_value = (
|
434
|
+
b"""SomeRandomKey: 12345\n""" + orientation + b"""
|
409
435
|
MoreRandomStuff: awesome_value
|
410
436
|
"""
|
437
|
+
)
|
411
438
|
|
412
|
-
parser = adb_call_parser.AdbCallParser(
|
413
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
439
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
414
440
|
request = adb_pb2.AdbRequest(
|
415
441
|
get_orientation=adb_pb2.AdbRequest.GetOrientationRequest())
|
416
442
|
response = parser.parse(request)
|
@@ -423,8 +449,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
423
449
|
def test_get_current_activity_no_matches(self):
|
424
450
|
adb = mock.create_autospec(adb_controller.AdbController)
|
425
451
|
adb.execute_command.return_value = b'whatever'
|
426
|
-
parser = adb_call_parser.AdbCallParser(
|
427
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
452
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
428
453
|
request = adb_pb2.AdbRequest(
|
429
454
|
get_current_activity=adb_pb2.AdbRequest.GetCurrentActivity())
|
430
455
|
for platform in ['win32', 'linux']:
|
@@ -445,8 +470,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
445
470
|
def test_get_current_activity_successful(self):
|
446
471
|
adb = mock.create_autospec(adb_controller.AdbController)
|
447
472
|
adb.execute_command.return_value = b'{MyAwesomeActivity}'
|
448
|
-
parser = adb_call_parser.AdbCallParser(
|
449
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
473
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
450
474
|
request = adb_pb2.AdbRequest(
|
451
475
|
get_current_activity=adb_pb2.AdbRequest.GetCurrentActivity())
|
452
476
|
for platform in ['win32', 'linux']:
|
@@ -465,8 +489,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
465
489
|
def test_push_no_path(self):
|
466
490
|
adb = mock.create_autospec(adb_controller.AdbController)
|
467
491
|
adb.execute_command.return_value = b'whatever'
|
468
|
-
parser = adb_call_parser.AdbCallParser(
|
469
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
492
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
470
493
|
request = adb_pb2.AdbRequest(
|
471
494
|
push=adb_pb2.AdbRequest.Push(content=b'Has content but no path'))
|
472
495
|
response = parser.parse(request)
|
@@ -478,8 +501,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
478
501
|
def test_push_successful(self):
|
479
502
|
adb = mock.create_autospec(adb_controller.AdbController)
|
480
503
|
adb.execute_command.return_value = b'whatever'
|
481
|
-
parser = adb_call_parser.AdbCallParser(
|
482
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
504
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
483
505
|
request = adb_pb2.AdbRequest(
|
484
506
|
push=adb_pb2.AdbRequest.Push(
|
485
507
|
content=b'My text.', path='/sdcard/my_file.txt'))
|
@@ -501,8 +523,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
501
523
|
def test_pull_no_path(self):
|
502
524
|
adb = mock.create_autospec(adb_controller.AdbController)
|
503
525
|
adb.execute_command.return_value = b'whatever'
|
504
|
-
parser = adb_call_parser.AdbCallParser(
|
505
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
526
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
506
527
|
request = adb_pb2.AdbRequest(pull=adb_pb2.AdbRequest.Pull())
|
507
528
|
response = parser.parse(request)
|
508
529
|
self.assertEqual(response.status,
|
@@ -516,8 +537,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
516
537
|
adb.execute_command.return_value = b'whatever'
|
517
538
|
mock_open.return_value.__enter__ = mock_open
|
518
539
|
mock_open.return_value.read.return_value = b'S3cR3t. dO nOt TeLl ANYONE'
|
519
|
-
parser = adb_call_parser.AdbCallParser(
|
520
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
540
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
521
541
|
request = adb_pb2.AdbRequest(
|
522
542
|
pull=adb_pb2.AdbRequest.Pull(path='/sdcard/my_file.txt'))
|
523
543
|
|
@@ -539,8 +559,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
539
559
|
def test_input_text_no_text(self):
|
540
560
|
adb = mock.create_autospec(adb_controller.AdbController)
|
541
561
|
adb.execute_command.return_value = b'whatever'
|
542
|
-
parser = adb_call_parser.AdbCallParser(
|
543
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
562
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
544
563
|
request = adb_pb2.AdbRequest(input_text=adb_pb2.AdbRequest.InputText())
|
545
564
|
response = parser.parse(request)
|
546
565
|
self.assertEqual(response.status,
|
@@ -551,8 +570,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
551
570
|
def test_input_text_successful(self):
|
552
571
|
adb = mock.create_autospec(adb_controller.AdbController)
|
553
572
|
adb.execute_command.return_value = b'whatever'
|
554
|
-
parser = adb_call_parser.AdbCallParser(
|
555
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
573
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
556
574
|
request = adb_pb2.AdbRequest(
|
557
575
|
input_text=adb_pb2.AdbRequest.InputText(
|
558
576
|
text='The Greatest Text of All Time'))
|
@@ -573,8 +591,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
573
591
|
def test_tap_failed(self, request: adb_pb2.AdbRequest):
|
574
592
|
adb = mock.create_autospec(adb_controller.AdbController)
|
575
593
|
adb.execute_command.return_value = b'whatever'
|
576
|
-
parser = adb_call_parser.AdbCallParser(
|
577
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
594
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
578
595
|
response = parser.parse(request)
|
579
596
|
self.assertEqual(response.status,
|
580
597
|
adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
|
@@ -584,8 +601,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
584
601
|
def test_tap_successful(self):
|
585
602
|
adb = mock.create_autospec(adb_controller.AdbController)
|
586
603
|
adb.execute_command.return_value = b'whatever'
|
587
|
-
parser = adb_call_parser.AdbCallParser(
|
588
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
604
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
589
605
|
request = adb_pb2.AdbRequest(tap=adb_pb2.AdbRequest.Tap(x=135, y=246))
|
590
606
|
response = parser.parse(request)
|
591
607
|
self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
|
@@ -622,8 +638,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
622
638
|
def test_settings_failures(self, request):
|
623
639
|
adb = mock.create_autospec(adb_controller.AdbController)
|
624
640
|
adb.execute_command.return_value = b'whatever'
|
625
|
-
parser = adb_call_parser.AdbCallParser(
|
626
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
641
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
627
642
|
request = adb_pb2.AdbRequest(settings=request)
|
628
643
|
response = parser.parse(request)
|
629
644
|
self.assertEqual(response.status,
|
@@ -634,8 +649,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
634
649
|
def test_settings_success_get(self):
|
635
650
|
adb = mock.create_autospec(adb_controller.AdbController)
|
636
651
|
adb.execute_command.return_value = b'here it is!'
|
637
|
-
parser = adb_call_parser.AdbCallParser(
|
638
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
652
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
639
653
|
|
640
654
|
request = adb_pb2.AdbRequest.SettingsRequest(
|
641
655
|
name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.SYSTEM,
|
@@ -652,8 +666,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
652
666
|
def test_settings_success_put(self):
|
653
667
|
adb = mock.create_autospec(adb_controller.AdbController)
|
654
668
|
adb.execute_command.return_value = b'Done for ya!'
|
655
|
-
parser = adb_call_parser.AdbCallParser(
|
656
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
669
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
657
670
|
|
658
671
|
request = adb_pb2.AdbRequest.SettingsRequest(
|
659
672
|
name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.SECURE,
|
@@ -670,8 +683,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
670
683
|
def test_settings_success_delete(self):
|
671
684
|
adb = mock.create_autospec(adb_controller.AdbController)
|
672
685
|
adb.execute_command.return_value = b'Key deleted.'
|
673
|
-
parser = adb_call_parser.AdbCallParser(
|
674
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
686
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
675
687
|
|
676
688
|
request = adb_pb2.AdbRequest.SettingsRequest(
|
677
689
|
name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.GLOBAL,
|
@@ -712,8 +724,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
712
724
|
def test_settings_success_reset(self, mode, package_name, expected_arg):
|
713
725
|
adb = mock.create_autospec(adb_controller.AdbController)
|
714
726
|
adb.execute_command.return_value = b'Pkg reset.'
|
715
|
-
parser = adb_call_parser.AdbCallParser(
|
716
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
727
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
717
728
|
|
718
729
|
request = adb_pb2.AdbRequest.SettingsRequest(
|
719
730
|
name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.GLOBAL,
|
@@ -731,8 +742,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
731
742
|
def test_settings_success_list(self):
|
732
743
|
adb = mock.create_autospec(adb_controller.AdbController)
|
733
744
|
adb.execute_command.return_value = b'volume_ring=5\nvolume_system=7'
|
734
|
-
parser = adb_call_parser.AdbCallParser(
|
735
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
745
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
736
746
|
|
737
747
|
request = adb_pb2.AdbRequest.SettingsRequest(
|
738
748
|
name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.SYSTEM,
|
@@ -752,8 +762,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
752
762
|
expected_output = b'generic_output'
|
753
763
|
args = ['shell', 'am', 'broadcast', '-n', 'receiver', '-a', 'action']
|
754
764
|
adb.execute_command.return_value = expected_output
|
755
|
-
parser = adb_call_parser.AdbCallParser(
|
756
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
765
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
757
766
|
|
758
767
|
generic_request = adb_pb2.AdbRequest.GenericRequest(args=args)
|
759
768
|
request = adb_pb2.AdbRequest(generic=generic_request)
|
@@ -769,8 +778,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
769
778
|
args = ['shell', 'am', 'broadcast', '-n', 'receiver', '-a', 'action']
|
770
779
|
adb.execute_command.side_effect = subprocess.CalledProcessError(
|
771
780
|
cmd='cmd', output='adb_error', returncode=-1)
|
772
|
-
parser = adb_call_parser.AdbCallParser(
|
773
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
781
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
774
782
|
|
775
783
|
generic_request = adb_pb2.AdbRequest.GenericRequest(args=args)
|
776
784
|
request = adb_pb2.AdbRequest(generic=generic_request)
|
@@ -786,8 +794,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
786
794
|
args = ['shell', 'am', 'broadcast', '-n', 'receiver', '-a', 'action']
|
787
795
|
adb.execute_command.side_effect = subprocess.TimeoutExpired(
|
788
796
|
cmd='cmd', timeout=10)
|
789
|
-
parser = adb_call_parser.AdbCallParser(
|
790
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
797
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
791
798
|
|
792
799
|
generic_request = adb_pb2.AdbRequest.GenericRequest(args=args)
|
793
800
|
request = adb_pb2.AdbRequest(generic=generic_request)
|
@@ -821,8 +828,7 @@ class AdbCallParserTest(parameterized.TestCase):
|
|
821
828
|
def test_package_manager_list_bad_output(self, request):
|
822
829
|
adb = mock.create_autospec(adb_controller.AdbController)
|
823
830
|
adb.execute_command.return_value = b"""Something irrelevant."""
|
824
|
-
parser = adb_call_parser.AdbCallParser(
|
825
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
831
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
826
832
|
response = parser.parse(request)
|
827
833
|
response.package_manager.output = b"""Something irrelevant."""
|
828
834
|
self.assertEmpty(response.package_manager.list.items)
|
@@ -842,8 +848,7 @@ feature:android.software.backup
|
|
842
848
|
feature:android.software.webview
|
843
849
|
"""
|
844
850
|
adb.execute_command.return_value = output
|
845
|
-
parser = adb_call_parser.AdbCallParser(
|
846
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
851
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
847
852
|
request = adb_pb2.AdbRequest(
|
848
853
|
package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
|
849
854
|
list=adb_pb2.AdbRequest.PackageManagerRequest.List(
|
@@ -887,8 +892,7 @@ library:javax.obex
|
|
887
892
|
library:org.apache.http.legacy
|
888
893
|
"""
|
889
894
|
adb.execute_command.return_value = output
|
890
|
-
parser = adb_call_parser.AdbCallParser(
|
891
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
895
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
892
896
|
request = adb_pb2.AdbRequest(
|
893
897
|
package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
|
894
898
|
list=adb_pb2.AdbRequest.PackageManagerRequest.List(
|
@@ -928,8 +932,7 @@ package:com.awesome.company
|
|
928
932
|
package:com.another.great.thingie
|
929
933
|
"""
|
930
934
|
adb.execute_command.return_value = output
|
931
|
-
parser = adb_call_parser.AdbCallParser(
|
932
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
935
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
933
936
|
request = adb_pb2.AdbRequest(
|
934
937
|
package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
|
935
938
|
list=adb_pb2.AdbRequest.PackageManagerRequest.List(
|
@@ -950,8 +953,7 @@ package:com.another.great.thingie
|
|
950
953
|
def test_package_manager_clear_no_package_name(self):
|
951
954
|
adb = mock.create_autospec(adb_controller.AdbController)
|
952
955
|
adb.execute_command.return_value = b"""Something irrelevant."""
|
953
|
-
parser = adb_call_parser.AdbCallParser(
|
954
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
956
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
955
957
|
|
956
958
|
request = adb_pb2.AdbRequest(
|
957
959
|
package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
|
@@ -968,8 +970,7 @@ package:com.another.great.thingie
|
|
968
970
|
def test_package_manager_clear_successful_no_user_id(self):
|
969
971
|
adb = mock.create_autospec(adb_controller.AdbController)
|
970
972
|
adb.execute_command.return_value = b"""Some successful message."""
|
971
|
-
parser = adb_call_parser.AdbCallParser(
|
972
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
973
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
973
974
|
|
974
975
|
request = adb_pb2.AdbRequest(
|
975
976
|
package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
|
@@ -987,8 +988,7 @@ package:com.another.great.thingie
|
|
987
988
|
def test_package_manager_clear_successful_with_user_id(self):
|
988
989
|
adb = mock.create_autospec(adb_controller.AdbController)
|
989
990
|
adb.execute_command.return_value = b"""Some successful message."""
|
990
|
-
parser = adb_call_parser.AdbCallParser(
|
991
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
991
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
992
992
|
|
993
993
|
request = adb_pb2.AdbRequest(
|
994
994
|
package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
|
@@ -1007,8 +1007,7 @@ package:com.another.great.thingie
|
|
1007
1007
|
"""An empty `DumpsysRequest` is a valid request."""
|
1008
1008
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1009
1009
|
adb.execute_command.return_value = b'whatever'
|
1010
|
-
parser = adb_call_parser.AdbCallParser(
|
1011
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1010
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1012
1011
|
request = adb_pb2.AdbRequest(dumpsys=adb_pb2.AdbRequest.DumpsysRequest())
|
1013
1012
|
|
1014
1013
|
response = parser.parse(request)
|
@@ -1029,8 +1028,7 @@ package:com.another.great.thingie
|
|
1029
1028
|
def test_dumpsys_negative_timeouts(self, request):
|
1030
1029
|
"""`DumpsysRequest.timeout_{sec, ms}` if passed, should be positive."""
|
1031
1030
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1032
|
-
parser = adb_call_parser.AdbCallParser(
|
1033
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1031
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1034
1032
|
|
1035
1033
|
response = parser.parse(request)
|
1036
1034
|
|
@@ -1048,8 +1046,7 @@ package:com.another.great.thingie
|
|
1048
1046
|
def test_dumpsys_timeout_successful(self, timeout_sec, timeout_ms, expected):
|
1049
1047
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1050
1048
|
adb.execute_command.return_value = b'whatever'
|
1051
|
-
parser = adb_call_parser.AdbCallParser(
|
1052
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1049
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1053
1050
|
request = adb_pb2.AdbRequest(
|
1054
1051
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
|
1055
1052
|
timeout_sec=timeout_sec, timeout_ms=timeout_ms))
|
@@ -1076,8 +1073,7 @@ package:com.another.great.thingie
|
|
1076
1073
|
def test_dumpsys_priority_timeout_successful(self, priority, expected):
|
1077
1074
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1078
1075
|
adb.execute_command.return_value = b'whatever'
|
1079
|
-
parser = adb_call_parser.AdbCallParser(
|
1080
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1076
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1081
1077
|
request = adb_pb2.AdbRequest(
|
1082
1078
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(priority=priority))
|
1083
1079
|
|
@@ -1087,38 +1083,49 @@ package:com.another.great.thingie
|
|
1087
1083
|
self.assertEmpty(response.error_message)
|
1088
1084
|
adb.execute_command.assert_called_once_with(expected, timeout=None)
|
1089
1085
|
|
1090
|
-
|
1091
|
-
|
1086
|
+
@parameterized.named_parameters(
|
1087
|
+
(
|
1088
|
+
'window_service',
|
1089
|
+
adb_pb2.AdbRequest.DumpsysRequest(list_only=True, service='window'),
|
1090
|
+
),
|
1091
|
+
(
|
1092
|
+
'arbitrary_args',
|
1093
|
+
adb_pb2.AdbRequest.DumpsysRequest(
|
1094
|
+
list_only=True, args=['myoption', 'anotheroption']
|
1095
|
+
),
|
1096
|
+
),
|
1097
|
+
(
|
1098
|
+
'skip_usb',
|
1099
|
+
adb_pb2.AdbRequest.DumpsysRequest(
|
1100
|
+
list_only=True, skip_services=['usb']
|
1101
|
+
),
|
1102
|
+
),
|
1103
|
+
)
|
1104
|
+
def test_dumpsys_list_only_cannot_be_combined(
|
1105
|
+
self, dumpsys_request: adb_pb2.AdbRequest.DumpsysRequest
|
1106
|
+
):
|
1107
|
+
"""When `list_only==True`, the request cannot contain a few fields."""
|
1108
|
+
|
1109
|
+
# Arrange.
|
1092
1110
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1093
1111
|
adb.execute_command.return_value = b'whatever'
|
1094
|
-
parser = adb_call_parser.AdbCallParser(
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
]:
|
1107
|
-
request = adb_pb2.AdbRequest(
|
1108
|
-
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(list_only=True, **d))
|
1109
|
-
|
1110
|
-
response = parser.parse(request)
|
1111
|
-
|
1112
|
-
self.assertEqual(response.status,
|
1113
|
-
adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
|
1114
|
-
self.assertNotEmpty(response.error_message)
|
1115
|
-
adb.execute_command.assert_not_called()
|
1112
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1113
|
+
request = adb_pb2.AdbRequest(dumpsys=dumpsys_request)
|
1114
|
+
|
1115
|
+
# Act.
|
1116
|
+
response = parser.parse(request)
|
1117
|
+
|
1118
|
+
# Assert.
|
1119
|
+
self.assertEqual(
|
1120
|
+
response.status, adb_pb2.AdbResponse.Status.FAILED_PRECONDITION
|
1121
|
+
)
|
1122
|
+
self.assertNotEmpty(response.error_message)
|
1123
|
+
adb.execute_command.assert_not_called()
|
1116
1124
|
|
1117
1125
|
def test_dumpsys_list_only_success(self):
|
1118
1126
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1119
1127
|
adb.execute_command.return_value = b'whatever'
|
1120
|
-
parser = adb_call_parser.AdbCallParser(
|
1121
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1128
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1122
1129
|
request = adb_pb2.AdbRequest(
|
1123
1130
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(list_only=True))
|
1124
1131
|
|
@@ -1133,8 +1140,7 @@ package:com.another.great.thingie
|
|
1133
1140
|
"""When using `DumpsysRequest.skip_service`, it cannot contain `.service`."""
|
1134
1141
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1135
1142
|
adb.execute_command.return_value = b'whatever'
|
1136
|
-
parser = adb_call_parser.AdbCallParser(
|
1137
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1143
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1138
1144
|
request = adb_pb2.AdbRequest(
|
1139
1145
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
|
1140
1146
|
service='wifi', skip_services=['window', 'usb']))
|
@@ -1149,8 +1155,7 @@ package:com.another.great.thingie
|
|
1149
1155
|
def test_dumpsys_skip_services(self):
|
1150
1156
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1151
1157
|
adb.execute_command.return_value = b'whatever'
|
1152
|
-
parser = adb_call_parser.AdbCallParser(
|
1153
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1158
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1154
1159
|
request = adb_pb2.AdbRequest(
|
1155
1160
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
|
1156
1161
|
skip_services=['window', 'usb']))
|
@@ -1165,8 +1170,7 @@ package:com.another.great.thingie
|
|
1165
1170
|
def test_dumpsys_single_service(self):
|
1166
1171
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1167
1172
|
adb.execute_command.return_value = b'whatever'
|
1168
|
-
parser = adb_call_parser.AdbCallParser(
|
1169
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1173
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1170
1174
|
request = adb_pb2.AdbRequest(
|
1171
1175
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(service='window'))
|
1172
1176
|
|
@@ -1180,8 +1184,7 @@ package:com.another.great.thingie
|
|
1180
1184
|
def test_dumpsys_single_service_with_args(self):
|
1181
1185
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1182
1186
|
adb.execute_command.return_value = b'whatever'
|
1183
|
-
parser = adb_call_parser.AdbCallParser(
|
1184
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1187
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1185
1188
|
request = adb_pb2.AdbRequest(
|
1186
1189
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
|
1187
1190
|
service='window', args=['arg1', 'arg2']))
|
@@ -1196,8 +1199,7 @@ package:com.another.great.thingie
|
|
1196
1199
|
def test_dumpsys_single_service_with_proto(self):
|
1197
1200
|
adb = mock.create_autospec(adb_controller.AdbController)
|
1198
1201
|
adb.execute_command.return_value = b'some binary output'
|
1199
|
-
parser = adb_call_parser.AdbCallParser(
|
1200
|
-
adb, tmp_dir=absltest.get_default_test_tmpdir())
|
1202
|
+
parser = adb_call_parser.AdbCallParser(adb)
|
1201
1203
|
request = adb_pb2.AdbRequest(
|
1202
1204
|
dumpsys=adb_pb2.AdbRequest.DumpsysRequest(service='window', proto=True))
|
1203
1205
|
|