android-env 1.2.1__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.
Files changed (145) hide show
  1. android_env/__init__.py +1 -1
  2. android_env/components/__init__.py +1 -1
  3. android_env/components/a11y/__init__.py +15 -0
  4. android_env/components/a11y/a11y_events.py +118 -0
  5. android_env/components/a11y/a11y_events_test.py +173 -0
  6. android_env/components/a11y/a11y_forests.py +128 -0
  7. android_env/components/a11y/a11y_forests_test.py +237 -0
  8. android_env/components/a11y/a11y_servicer.py +199 -0
  9. android_env/components/a11y/a11y_servicer_test.py +224 -0
  10. android_env/components/action_fns.py +132 -0
  11. android_env/components/action_fns_test.py +227 -0
  12. android_env/components/action_type.py +26 -3
  13. android_env/components/adb_call_parser.py +239 -196
  14. android_env/components/adb_call_parser_test.py +179 -209
  15. android_env/components/adb_controller.py +90 -52
  16. android_env/components/adb_controller_test.py +187 -16
  17. android_env/components/adb_log_stream.py +17 -5
  18. android_env/components/adb_log_stream_test.py +17 -3
  19. android_env/components/app_screen_checker.py +17 -15
  20. android_env/components/app_screen_checker_test.py +7 -8
  21. android_env/components/config_classes.py +203 -0
  22. android_env/components/coordinator.py +102 -338
  23. android_env/components/coordinator_test.py +59 -199
  24. android_env/components/device_settings.py +174 -0
  25. android_env/components/device_settings_test.py +228 -0
  26. android_env/components/dumpsys_thread.py +3 -4
  27. android_env/components/dumpsys_thread_test.py +1 -1
  28. android_env/components/errors.py +52 -10
  29. android_env/components/errors_test.py +110 -0
  30. android_env/components/log_stream.py +7 -5
  31. android_env/components/log_stream_test.py +1 -1
  32. android_env/components/logcat_thread.py +9 -8
  33. android_env/components/logcat_thread_test.py +3 -4
  34. android_env/components/{utils.py → pixel_fns.py} +20 -20
  35. android_env/components/{utils_test.py → pixel_fns_test.py} +20 -15
  36. android_env/components/setup_step_interpreter.py +47 -39
  37. android_env/components/setup_step_interpreter_test.py +4 -4
  38. android_env/components/simulators/__init__.py +1 -1
  39. android_env/components/simulators/base_simulator.py +116 -44
  40. android_env/components/simulators/base_simulator_test.py +131 -9
  41. android_env/components/simulators/emulator/__init__.py +1 -1
  42. android_env/components/simulators/emulator/emulator_launcher.py +67 -77
  43. android_env/components/simulators/emulator/emulator_launcher_test.py +153 -49
  44. android_env/components/simulators/emulator/emulator_simulator.py +276 -95
  45. android_env/components/simulators/emulator/emulator_simulator_test.py +314 -89
  46. android_env/components/simulators/fake/__init__.py +1 -1
  47. android_env/components/simulators/fake/fake_simulator.py +17 -25
  48. android_env/components/simulators/fake/fake_simulator_test.py +29 -12
  49. android_env/components/specs.py +18 -28
  50. android_env/components/specs_test.py +1 -44
  51. android_env/components/task_manager.py +48 -48
  52. android_env/components/task_manager_test.py +71 -60
  53. android_env/env_interface.py +37 -23
  54. android_env/environment.py +83 -51
  55. android_env/environment_test.py +68 -29
  56. android_env/loader.py +57 -43
  57. android_env/loader_test.py +115 -35
  58. android_env/proto/__init__.py +1 -1
  59. android_env/proto/a11y/__init__.py +15 -0
  60. android_env/proto/a11y/a11y.proto +75 -0
  61. android_env/proto/a11y/a11y_pb2.py +54 -0
  62. android_env/proto/a11y/a11y_pb2.pyi +49 -0
  63. android_env/proto/a11y/a11y_pb2_grpc.py +202 -0
  64. android_env/proto/a11y/android_accessibility_action.proto +32 -0
  65. android_env/proto/a11y/android_accessibility_action_pb2.py +37 -0
  66. android_env/proto/a11y/android_accessibility_action_pb2.pyi +13 -0
  67. android_env/proto/a11y/android_accessibility_action_pb2_grpc.py +24 -0
  68. android_env/proto/a11y/android_accessibility_forest.proto +29 -0
  69. android_env/proto/a11y/android_accessibility_forest_pb2.py +38 -0
  70. android_env/proto/a11y/android_accessibility_forest_pb2.pyi +13 -0
  71. android_env/proto/a11y/android_accessibility_forest_pb2_grpc.py +24 -0
  72. android_env/proto/a11y/android_accessibility_node_info.proto +122 -0
  73. android_env/proto/a11y/android_accessibility_node_info_clickable_span.proto +49 -0
  74. android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2.py +39 -0
  75. android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2.pyi +28 -0
  76. android_env/proto/a11y/android_accessibility_node_info_clickable_span_pb2_grpc.py +24 -0
  77. android_env/proto/a11y/android_accessibility_node_info_pb2.py +42 -0
  78. android_env/proto/a11y/android_accessibility_node_info_pb2.pyi +75 -0
  79. android_env/proto/a11y/android_accessibility_node_info_pb2_grpc.py +24 -0
  80. android_env/proto/a11y/android_accessibility_tree.proto +29 -0
  81. android_env/proto/a11y/android_accessibility_tree_pb2.py +38 -0
  82. android_env/proto/a11y/android_accessibility_tree_pb2.pyi +13 -0
  83. android_env/proto/a11y/android_accessibility_tree_pb2_grpc.py +24 -0
  84. android_env/proto/a11y/android_accessibility_window_info.proto +84 -0
  85. android_env/proto/a11y/android_accessibility_window_info_pb2.py +41 -0
  86. android_env/proto/a11y/android_accessibility_window_info_pb2.pyi +48 -0
  87. android_env/proto/a11y/android_accessibility_window_info_pb2_grpc.py +24 -0
  88. android_env/proto/a11y/rect.proto +30 -0
  89. android_env/proto/a11y/rect_pb2.py +37 -0
  90. android_env/proto/a11y/rect_pb2.pyi +17 -0
  91. android_env/proto/a11y/rect_pb2_grpc.py +24 -0
  92. android_env/proto/adb.proto +17 -6
  93. android_env/proto/adb_pb2.py +120 -107
  94. android_env/proto/adb_pb2.pyi +396 -0
  95. android_env/proto/adb_pb2_grpc.py +20 -0
  96. android_env/proto/emulator_controller.proto +68 -63
  97. android_env/proto/emulator_controller_pb2.py +142 -131
  98. android_env/proto/emulator_controller_pb2.pyi +672 -0
  99. android_env/proto/emulator_controller_pb2_grpc.py +505 -142
  100. android_env/proto/snapshot.proto +169 -0
  101. android_env/proto/snapshot_pb2.py +47 -0
  102. android_env/proto/snapshot_pb2.pyi +117 -0
  103. android_env/proto/snapshot_pb2_grpc.py +24 -0
  104. android_env/proto/snapshot_service.proto +289 -0
  105. android_env/proto/snapshot_service_pb2.py +54 -0
  106. android_env/proto/snapshot_service_pb2.pyi +86 -0
  107. android_env/proto/snapshot_service_pb2_grpc.py +487 -0
  108. android_env/proto/state.proto +63 -0
  109. android_env/proto/state_pb2.py +63 -0
  110. android_env/proto/state_pb2.pyi +85 -0
  111. android_env/proto/state_pb2_grpc.py +24 -0
  112. android_env/proto/task.proto +5 -1
  113. android_env/proto/task_pb2.py +42 -31
  114. android_env/proto/task_pb2.pyi +160 -0
  115. android_env/proto/task_pb2_grpc.py +20 -0
  116. android_env/wrappers/__init__.py +1 -1
  117. android_env/wrappers/a11y_grpc_wrapper.py +500 -0
  118. android_env/wrappers/a11y_grpc_wrapper_test.py +849 -0
  119. android_env/wrappers/base_wrapper.py +34 -13
  120. android_env/wrappers/base_wrapper_test.py +22 -16
  121. android_env/wrappers/discrete_action_wrapper.py +18 -17
  122. android_env/wrappers/discrete_action_wrapper_test.py +4 -4
  123. android_env/wrappers/flat_interface_wrapper.py +5 -5
  124. android_env/wrappers/flat_interface_wrapper_test.py +7 -11
  125. android_env/wrappers/float_pixels_wrapper.py +9 -10
  126. android_env/wrappers/float_pixels_wrapper_test.py +3 -3
  127. android_env/wrappers/gym_wrapper.py +19 -13
  128. android_env/wrappers/gym_wrapper_test.py +3 -5
  129. android_env/wrappers/image_rescale_wrapper.py +18 -21
  130. android_env/wrappers/image_rescale_wrapper_test.py +25 -37
  131. android_env/wrappers/last_action_wrapper.py +16 -13
  132. android_env/wrappers/last_action_wrapper_test.py +44 -51
  133. android_env/wrappers/rate_limit_wrapper.py +6 -3
  134. android_env/wrappers/rate_limit_wrapper_test.py +22 -1
  135. android_env/wrappers/tap_action_wrapper.py +16 -17
  136. android_env/wrappers/tap_action_wrapper_test.py +51 -16
  137. {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/METADATA +14 -18
  138. android_env-1.2.3.dist-info/RECORD +141 -0
  139. {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/WHEEL +1 -1
  140. android_env/proto/raw_observation.proto +0 -39
  141. android_env/proto/raw_observation_pb2.py +0 -27
  142. android_env/proto/raw_observation_pb2_grpc.py +0 -4
  143. android_env-1.2.1.dist-info/RECORD +0 -81
  144. {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info/licenses}/LICENSE +0 -0
  145. {android_env-1.2.1.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 2022 DeepMind Technologies Limited.
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(response.status,
40
- adb_pb2.AdbResponse.Status.UNKNOWN_COMMAND)
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(response.status,
52
- adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
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)
@@ -93,12 +124,10 @@ class AdbCallParserTest(parameterized.TestCase):
93
124
 
94
125
  def test_start_activity_successful(self):
95
126
  adb = mock.create_autospec(adb_controller.AdbController)
96
- command_output = (
97
- b'Stopping: my.project.SplashActivity\n'
98
- b'Starting: Intent { cmp=my.project.SplashActivity }\n')
127
+ command_output = (b'Stopping: my.project.SplashActivity\n'
128
+ b'Starting: Intent { cmp=my.project.SplashActivity }\n')
99
129
  adb.execute_command.return_value = command_output
100
- parser = adb_call_parser.AdbCallParser(
101
- adb, tmp_dir=absltest.get_default_test_tmpdir())
130
+ parser = adb_call_parser.AdbCallParser(adb)
102
131
  request = adb_pb2.AdbRequest()
103
132
  request.start_activity.full_activity = 'my.project.SplashActivity'
104
133
  request.start_activity.extra_args.extend(['blah'])
@@ -110,17 +139,16 @@ class AdbCallParserTest(parameterized.TestCase):
110
139
  mock.call([
111
140
  'shell', 'am', 'start', '-S', '-W', '-n',
112
141
  'my.project.SplashActivity', 'blah'
113
- ], timeout=None),
142
+ ],
143
+ timeout=None),
114
144
  ])
115
145
 
116
146
  def test_start_activity_successful_no_force_stop(self):
117
147
  adb = mock.create_autospec(adb_controller.AdbController)
118
- command_output = (
119
- b'Stopping: my.project.SplashActivity\n'
120
- b'Starting: Intent { cmp=my.project.SplashActivity }\n')
148
+ command_output = (b'Stopping: my.project.SplashActivity\n'
149
+ b'Starting: Intent { cmp=my.project.SplashActivity }\n')
121
150
  adb.execute_command.return_value = command_output
122
- parser = adb_call_parser.AdbCallParser(
123
- adb, tmp_dir=absltest.get_default_test_tmpdir())
151
+ parser = adb_call_parser.AdbCallParser(adb)
124
152
  request = adb_pb2.AdbRequest()
125
153
  request.start_activity.full_activity = 'my.project.SplashActivity'
126
154
  request.start_activity.extra_args.extend(['blah'])
@@ -138,25 +166,23 @@ class AdbCallParserTest(parameterized.TestCase):
138
166
 
139
167
  def test_start_activity_error(self):
140
168
  adb = mock.create_autospec(adb_controller.AdbController)
141
- command_output = (
142
- b'Stopping: my.project.SplashActivity\n'
143
- b'Starting: Intent { cmp=my.project.SplashActivity }\n'
144
- b'Error: Activity not started, unknown error code 101\n')
169
+ command_output = (b'Stopping: my.project.SplashActivity\n'
170
+ b'Starting: Intent { cmp=my.project.SplashActivity }\n'
171
+ b'Error: Activity not started, unknown error code 101\n')
145
172
  adb.execute_command.return_value = command_output
146
- parser = adb_call_parser.AdbCallParser(
147
- adb, tmp_dir=absltest.get_default_test_tmpdir())
173
+ parser = adb_call_parser.AdbCallParser(adb)
148
174
  request = adb_pb2.AdbRequest()
149
175
  request.start_activity.full_activity = 'my.project.SplashActivity'
150
176
  request.start_activity.extra_args.extend(['blah'])
151
177
  response = parser.parse(request)
152
178
  self.assertEqual(response.status, adb_pb2.AdbResponse.Status.INTERNAL_ERROR)
153
- self.assertEqual(response.error_message,
154
- f'start_activity failed with error: {str(command_output)}')
179
+ self.assertEqual(
180
+ response.error_message,
181
+ f'start_activity failed with error: {str(command_output)}')
155
182
 
156
183
  def test_force_stop(self):
157
184
  adb = mock.create_autospec(adb_controller.AdbController)
158
- parser = adb_call_parser.AdbCallParser(
159
- adb, tmp_dir=absltest.get_default_test_tmpdir())
185
+ parser = adb_call_parser.AdbCallParser(adb)
160
186
  request = adb_pb2.AdbRequest()
161
187
  request.force_stop.package_name = 'my.project'
162
188
  response = parser.parse(request)
@@ -167,8 +193,7 @@ class AdbCallParserTest(parameterized.TestCase):
167
193
 
168
194
  def test_grant_permissions_empty_package_name(self):
169
195
  adb = mock.create_autospec(adb_controller.AdbController)
170
- parser = adb_call_parser.AdbCallParser(
171
- adb, tmp_dir=absltest.get_default_test_tmpdir())
196
+ parser = adb_call_parser.AdbCallParser(adb)
172
197
  request = adb_pb2.AdbRequest()
173
198
  request.package_manager.grant.permissions.extend(['perm1', 'perm2'])
174
199
  response = parser.parse(request)
@@ -178,8 +203,7 @@ class AdbCallParserTest(parameterized.TestCase):
178
203
 
179
204
  def test_grant_permissions_empty_permissions(self):
180
205
  adb = mock.create_autospec(adb_controller.AdbController)
181
- parser = adb_call_parser.AdbCallParser(
182
- adb, tmp_dir=absltest.get_default_test_tmpdir())
206
+ parser = adb_call_parser.AdbCallParser(adb)
183
207
  request = adb_pb2.AdbRequest()
184
208
  request.package_manager.grant.package_name = 'my.project'
185
209
  response = parser.parse(request)
@@ -190,8 +214,7 @@ class AdbCallParserTest(parameterized.TestCase):
190
214
  def test_grant_permissions_successful(self):
191
215
  adb = mock.create_autospec(adb_controller.AdbController)
192
216
  adb.execute_command.return_value = b'whatever'
193
- parser = adb_call_parser.AdbCallParser(
194
- adb, tmp_dir=absltest.get_default_test_tmpdir())
217
+ parser = adb_call_parser.AdbCallParser(adb)
195
218
  request = adb_pb2.AdbRequest()
196
219
  request.package_manager.grant.package_name = 'my.project'
197
220
  request.package_manager.grant.permissions.extend(['perm1', 'perm2'])
@@ -205,8 +228,7 @@ class AdbCallParserTest(parameterized.TestCase):
205
228
 
206
229
  def test_press_button_invalid_button(self):
207
230
  adb = mock.create_autospec(adb_controller.AdbController)
208
- parser = adb_call_parser.AdbCallParser(
209
- adb, tmp_dir=absltest.get_default_test_tmpdir())
231
+ parser = adb_call_parser.AdbCallParser(adb)
210
232
  request = adb_pb2.AdbRequest()
211
233
  request.press_button.button = 99999
212
234
  response = parser.parse(request)
@@ -217,8 +239,7 @@ class AdbCallParserTest(parameterized.TestCase):
217
239
  def test_press_button_successful(self):
218
240
  adb = mock.create_autospec(adb_controller.AdbController)
219
241
  adb.execute_command.return_value = b''
220
- parser = adb_call_parser.AdbCallParser(
221
- adb, tmp_dir=absltest.get_default_test_tmpdir())
242
+ parser = adb_call_parser.AdbCallParser(adb)
222
243
  # HOME.
223
244
  request = adb_pb2.AdbRequest()
224
245
  request.press_button.button = adb_pb2.AdbRequest.PressButton.Button.HOME
@@ -249,8 +270,7 @@ class AdbCallParserTest(parameterized.TestCase):
249
270
  adb.execute_command.return_value = (
250
271
  b' taskId=12345: my.project.AnotherActivity visible=true'
251
272
  b' topActivity=ComponentInfo{my.project.AnotherActivity}')
252
- parser = adb_call_parser.AdbCallParser(
253
- adb, tmp_dir=absltest.get_default_test_tmpdir())
273
+ parser = adb_call_parser.AdbCallParser(adb)
254
274
  request = adb_pb2.AdbRequest()
255
275
  request.start_screen_pinning.full_activity = 'my.project.AmazingActivity'
256
276
  response = parser.parse(request)
@@ -264,8 +284,7 @@ class AdbCallParserTest(parameterized.TestCase):
264
284
  adb.execute_command.return_value = (
265
285
  b' taskId=12345: my.project.AmazingActivity visible=true'
266
286
  b' topActivity=ComponentInfo{my.project.AmazingActivity}')
267
- parser = adb_call_parser.AdbCallParser(
268
- adb, tmp_dir=absltest.get_default_test_tmpdir())
287
+ parser = adb_call_parser.AdbCallParser(adb)
269
288
  request = adb_pb2.AdbRequest()
270
289
  request.start_screen_pinning.full_activity = 'my.project.AmazingActivity'
271
290
  response = parser.parse(request)
@@ -281,8 +300,7 @@ class AdbCallParserTest(parameterized.TestCase):
281
300
  adb.execute_command.return_value = (
282
301
  b' taskId=12345: my.project.MainActivity visible=true'
283
302
  b' topActivity=ComponentInfo{my.project.TopActivity}')
284
- parser = adb_call_parser.AdbCallParser(
285
- adb, tmp_dir=absltest.get_default_test_tmpdir())
303
+ parser = adb_call_parser.AdbCallParser(adb)
286
304
  request = adb_pb2.AdbRequest()
287
305
  request.start_screen_pinning.full_activity = 'my.project.MainActivity'
288
306
  response = parser.parse(request)
@@ -298,8 +316,7 @@ class AdbCallParserTest(parameterized.TestCase):
298
316
  adb.execute_command.return_value = (
299
317
  b' taskId=12345: my.project.MainActivity visible=true'
300
318
  b' topActivity=ComponentInfo{my.project.TopActivity}')
301
- parser = adb_call_parser.AdbCallParser(
302
- adb, tmp_dir=absltest.get_default_test_tmpdir())
319
+ parser = adb_call_parser.AdbCallParser(adb)
303
320
  request = adb_pb2.AdbRequest()
304
321
  request.start_screen_pinning.full_activity = 'my.project.TopActivity'
305
322
  response = parser.parse(request)
@@ -310,63 +327,38 @@ class AdbCallParserTest(parameterized.TestCase):
310
327
  mock.call(['shell', 'am', 'task', 'lock', '12345'], None),
311
328
  ])
312
329
 
313
- def test_start_intent_empty_data_uri(self):
314
- adb = mock.create_autospec(adb_controller.AdbController)
315
- parser = adb_call_parser.AdbCallParser(
316
- adb, tmp_dir=absltest.get_default_test_tmpdir())
317
- request = adb_pb2.AdbRequest()
318
- request.start_intent.action = 'BEST_ACTION'
319
- request.start_intent.package_name = 'my.project'
320
- response = parser.parse(request)
321
- self.assertEqual(response.status,
322
- adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
323
- self.assertNotEmpty(response.error_message)
324
-
325
- def test_start_intent_empty_action(self):
330
+ def test_send_broadcast_empty_action(self):
326
331
  adb = mock.create_autospec(adb_controller.AdbController)
327
- parser = adb_call_parser.AdbCallParser(
328
- adb, tmp_dir=absltest.get_default_test_tmpdir())
329
- request = adb_pb2.AdbRequest()
330
- request.start_intent.data_uri = '{"some": 123}'
331
- request.start_intent.package_name = 'my.project'
332
+ parser = adb_call_parser.AdbCallParser(adb)
333
+ request = adb_pb2.AdbRequest(
334
+ send_broadcast=adb_pb2.AdbRequest.SendBroadcast())
332
335
  response = parser.parse(request)
333
336
  self.assertEqual(response.status,
334
337
  adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
335
338
  self.assertNotEmpty(response.error_message)
336
339
 
337
- def test_start_intent_empty_package_name(self):
340
+ def test_send_broadcast_successful(self):
338
341
  adb = mock.create_autospec(adb_controller.AdbController)
339
- parser = adb_call_parser.AdbCallParser(
340
- adb, tmp_dir=absltest.get_default_test_tmpdir())
342
+ parser = adb_call_parser.AdbCallParser(adb)
341
343
  request = adb_pb2.AdbRequest()
342
- request.start_intent.data_uri = '{"some": 123}'
343
- request.start_intent.action = 'BEST_ACTION'
344
+ request.send_broadcast.action = 'SOME-ACTION'
344
345
  response = parser.parse(request)
345
- self.assertEqual(response.status,
346
- adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
347
- self.assertNotEmpty(response.error_message)
346
+ self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
347
+ self.assertEmpty(response.error_message)
348
348
 
349
- def test_start_intent_successful(self):
349
+ def test_send_broadcast_with_component_successful(self):
350
350
  adb = mock.create_autospec(adb_controller.AdbController)
351
- parser = adb_call_parser.AdbCallParser(
352
- adb, tmp_dir=absltest.get_default_test_tmpdir())
351
+ parser = adb_call_parser.AdbCallParser(adb)
353
352
  request = adb_pb2.AdbRequest()
354
- request.start_intent.data_uri = '{"some": 123}'
355
- request.start_intent.action = 'BEST_ACTION'
356
- request.start_intent.package_name = 'my.project'
353
+ request.send_broadcast.action = 'SOME-ACTION'
354
+ request.send_broadcast.component = 'SOME-COMPONENT'
357
355
  response = parser.parse(request)
358
356
  self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
359
357
  self.assertEmpty(response.error_message)
360
- adb.execute_command.assert_called_once_with([
361
- 'shell', 'am', 'start', '-a', 'BEST_ACTION', '-d', '{"some": 123}',
362
- 'my.project'
363
- ],
364
- timeout=None)
365
358
 
366
359
  def test_uninstall_package_empty_package_name(self):
367
360
  adb = mock.create_autospec(adb_controller.AdbController)
368
- parser = adb_call_parser.AdbCallParser(
369
- adb, tmp_dir=absltest.get_default_test_tmpdir())
361
+ parser = adb_call_parser.AdbCallParser(adb)
370
362
  request = adb_pb2.AdbRequest()
371
363
  request.uninstall_package.package_name = ''
372
364
  response = parser.parse(request)
@@ -377,8 +369,7 @@ class AdbCallParserTest(parameterized.TestCase):
377
369
  def test_uninstall_package_successful(self):
378
370
  adb = mock.create_autospec(adb_controller.AdbController)
379
371
  adb.execute_command.return_value = b'package:my.package'
380
- parser = adb_call_parser.AdbCallParser(
381
- adb, tmp_dir=absltest.get_default_test_tmpdir())
372
+ parser = adb_call_parser.AdbCallParser(adb)
382
373
  request = adb_pb2.AdbRequest()
383
374
  request.uninstall_package.package_name = 'my.package'
384
375
  response = parser.parse(request)
@@ -388,8 +379,7 @@ class AdbCallParserTest(parameterized.TestCase):
388
379
  def test_get_current_activity_no_visible_task(self):
389
380
  adb = mock.create_autospec(adb_controller.AdbController)
390
381
  adb.execute_command.return_value = None
391
- parser = adb_call_parser.AdbCallParser(
392
- adb, tmp_dir=absltest.get_default_test_tmpdir())
382
+ parser = adb_call_parser.AdbCallParser(adb)
393
383
  request = adb_pb2.AdbRequest(
394
384
  get_current_activity=adb_pb2.AdbRequest.GetCurrentActivity())
395
385
  response = parser.parse(request)
@@ -405,8 +395,7 @@ class AdbCallParserTest(parameterized.TestCase):
405
395
  def test_get_orientation_empty_dumpsys(self):
406
396
  adb = mock.create_autospec(adb_controller.AdbController)
407
397
  adb.execute_command.return_value = b''
408
- parser = adb_call_parser.AdbCallParser(
409
- adb, tmp_dir=absltest.get_default_test_tmpdir())
398
+ parser = adb_call_parser.AdbCallParser(adb)
410
399
  request = adb_pb2.AdbRequest(
411
400
  get_orientation=adb_pb2.AdbRequest.GetOrientationRequest())
412
401
  response = parser.parse(request)
@@ -418,8 +407,7 @@ class AdbCallParserTest(parameterized.TestCase):
418
407
  def test_get_orientation_invalid_device_no_surface_orientation(self):
419
408
  adb = mock.create_autospec(adb_controller.AdbController)
420
409
  adb.execute_command.return_value = b' PhysicalWidth: -123px'
421
- parser = adb_call_parser.AdbCallParser(
422
- adb, tmp_dir=absltest.get_default_test_tmpdir())
410
+ parser = adb_call_parser.AdbCallParser(adb)
423
411
  request = adb_pb2.AdbRequest(
424
412
  get_orientation=adb_pb2.AdbRequest.GetOrientationRequest())
425
413
  response = parser.parse(request)
@@ -429,21 +417,26 @@ class AdbCallParserTest(parameterized.TestCase):
429
417
  None)
430
418
 
431
419
  @parameterized.named_parameters(
432
- ('rotation_0', b'0', 0),
433
- ('rotation_90', b'1', 1),
434
- ('rotation_180', b'2', 2),
435
- ('rotation_270', b'3', 3),
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),
436
428
  )
437
- def test_get_orientation_success(self, orientation, expected_orientation):
429
+ def test_get_orientation_success(
430
+ self, orientation: bytes, expected_orientation: int
431
+ ):
438
432
  adb = mock.create_autospec(adb_controller.AdbController)
439
- adb.execute_command.return_value = b"""
440
- SomeRandomKey: 12345
441
- SurfaceOrientation: """ + orientation + b"""
433
+ adb.execute_command.return_value = (
434
+ b"""SomeRandomKey: 12345\n""" + orientation + b"""
442
435
  MoreRandomStuff: awesome_value
443
436
  """
437
+ )
444
438
 
445
- parser = adb_call_parser.AdbCallParser(
446
- adb, tmp_dir=absltest.get_default_test_tmpdir())
439
+ parser = adb_call_parser.AdbCallParser(adb)
447
440
  request = adb_pb2.AdbRequest(
448
441
  get_orientation=adb_pb2.AdbRequest.GetOrientationRequest())
449
442
  response = parser.parse(request)
@@ -456,8 +449,7 @@ class AdbCallParserTest(parameterized.TestCase):
456
449
  def test_get_current_activity_no_matches(self):
457
450
  adb = mock.create_autospec(adb_controller.AdbController)
458
451
  adb.execute_command.return_value = b'whatever'
459
- parser = adb_call_parser.AdbCallParser(
460
- adb, tmp_dir=absltest.get_default_test_tmpdir())
452
+ parser = adb_call_parser.AdbCallParser(adb)
461
453
  request = adb_pb2.AdbRequest(
462
454
  get_current_activity=adb_pb2.AdbRequest.GetCurrentActivity())
463
455
  for platform in ['win32', 'linux']:
@@ -478,8 +470,7 @@ class AdbCallParserTest(parameterized.TestCase):
478
470
  def test_get_current_activity_successful(self):
479
471
  adb = mock.create_autospec(adb_controller.AdbController)
480
472
  adb.execute_command.return_value = b'{MyAwesomeActivity}'
481
- parser = adb_call_parser.AdbCallParser(
482
- adb, tmp_dir=absltest.get_default_test_tmpdir())
473
+ parser = adb_call_parser.AdbCallParser(adb)
483
474
  request = adb_pb2.AdbRequest(
484
475
  get_current_activity=adb_pb2.AdbRequest.GetCurrentActivity())
485
476
  for platform in ['win32', 'linux']:
@@ -498,8 +489,7 @@ class AdbCallParserTest(parameterized.TestCase):
498
489
  def test_push_no_path(self):
499
490
  adb = mock.create_autospec(adb_controller.AdbController)
500
491
  adb.execute_command.return_value = b'whatever'
501
- parser = adb_call_parser.AdbCallParser(
502
- adb, tmp_dir=absltest.get_default_test_tmpdir())
492
+ parser = adb_call_parser.AdbCallParser(adb)
503
493
  request = adb_pb2.AdbRequest(
504
494
  push=adb_pb2.AdbRequest.Push(content=b'Has content but no path'))
505
495
  response = parser.parse(request)
@@ -511,8 +501,7 @@ class AdbCallParserTest(parameterized.TestCase):
511
501
  def test_push_successful(self):
512
502
  adb = mock.create_autospec(adb_controller.AdbController)
513
503
  adb.execute_command.return_value = b'whatever'
514
- parser = adb_call_parser.AdbCallParser(
515
- adb, tmp_dir=absltest.get_default_test_tmpdir())
504
+ parser = adb_call_parser.AdbCallParser(adb)
516
505
  request = adb_pb2.AdbRequest(
517
506
  push=adb_pb2.AdbRequest.Push(
518
507
  content=b'My text.', path='/sdcard/my_file.txt'))
@@ -534,8 +523,7 @@ class AdbCallParserTest(parameterized.TestCase):
534
523
  def test_pull_no_path(self):
535
524
  adb = mock.create_autospec(adb_controller.AdbController)
536
525
  adb.execute_command.return_value = b'whatever'
537
- parser = adb_call_parser.AdbCallParser(
538
- adb, tmp_dir=absltest.get_default_test_tmpdir())
526
+ parser = adb_call_parser.AdbCallParser(adb)
539
527
  request = adb_pb2.AdbRequest(pull=adb_pb2.AdbRequest.Pull())
540
528
  response = parser.parse(request)
541
529
  self.assertEqual(response.status,
@@ -549,8 +537,7 @@ class AdbCallParserTest(parameterized.TestCase):
549
537
  adb.execute_command.return_value = b'whatever'
550
538
  mock_open.return_value.__enter__ = mock_open
551
539
  mock_open.return_value.read.return_value = b'S3cR3t. dO nOt TeLl ANYONE'
552
- parser = adb_call_parser.AdbCallParser(
553
- adb, tmp_dir=absltest.get_default_test_tmpdir())
540
+ parser = adb_call_parser.AdbCallParser(adb)
554
541
  request = adb_pb2.AdbRequest(
555
542
  pull=adb_pb2.AdbRequest.Pull(path='/sdcard/my_file.txt'))
556
543
 
@@ -572,8 +559,7 @@ class AdbCallParserTest(parameterized.TestCase):
572
559
  def test_input_text_no_text(self):
573
560
  adb = mock.create_autospec(adb_controller.AdbController)
574
561
  adb.execute_command.return_value = b'whatever'
575
- parser = adb_call_parser.AdbCallParser(
576
- adb, tmp_dir=absltest.get_default_test_tmpdir())
562
+ parser = adb_call_parser.AdbCallParser(adb)
577
563
  request = adb_pb2.AdbRequest(input_text=adb_pb2.AdbRequest.InputText())
578
564
  response = parser.parse(request)
579
565
  self.assertEqual(response.status,
@@ -584,8 +570,7 @@ class AdbCallParserTest(parameterized.TestCase):
584
570
  def test_input_text_successful(self):
585
571
  adb = mock.create_autospec(adb_controller.AdbController)
586
572
  adb.execute_command.return_value = b'whatever'
587
- parser = adb_call_parser.AdbCallParser(
588
- adb, tmp_dir=absltest.get_default_test_tmpdir())
573
+ parser = adb_call_parser.AdbCallParser(adb)
589
574
  request = adb_pb2.AdbRequest(
590
575
  input_text=adb_pb2.AdbRequest.InputText(
591
576
  text='The Greatest Text of All Time'))
@@ -606,8 +591,7 @@ class AdbCallParserTest(parameterized.TestCase):
606
591
  def test_tap_failed(self, request: adb_pb2.AdbRequest):
607
592
  adb = mock.create_autospec(adb_controller.AdbController)
608
593
  adb.execute_command.return_value = b'whatever'
609
- parser = adb_call_parser.AdbCallParser(
610
- adb, tmp_dir=absltest.get_default_test_tmpdir())
594
+ parser = adb_call_parser.AdbCallParser(adb)
611
595
  response = parser.parse(request)
612
596
  self.assertEqual(response.status,
613
597
  adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
@@ -617,8 +601,7 @@ class AdbCallParserTest(parameterized.TestCase):
617
601
  def test_tap_successful(self):
618
602
  adb = mock.create_autospec(adb_controller.AdbController)
619
603
  adb.execute_command.return_value = b'whatever'
620
- parser = adb_call_parser.AdbCallParser(
621
- adb, tmp_dir=absltest.get_default_test_tmpdir())
604
+ parser = adb_call_parser.AdbCallParser(adb)
622
605
  request = adb_pb2.AdbRequest(tap=adb_pb2.AdbRequest.Tap(x=135, y=246))
623
606
  response = parser.parse(request)
624
607
  self.assertEqual(response.status, adb_pb2.AdbResponse.Status.OK)
@@ -655,8 +638,7 @@ class AdbCallParserTest(parameterized.TestCase):
655
638
  def test_settings_failures(self, request):
656
639
  adb = mock.create_autospec(adb_controller.AdbController)
657
640
  adb.execute_command.return_value = b'whatever'
658
- parser = adb_call_parser.AdbCallParser(
659
- adb, tmp_dir=absltest.get_default_test_tmpdir())
641
+ parser = adb_call_parser.AdbCallParser(adb)
660
642
  request = adb_pb2.AdbRequest(settings=request)
661
643
  response = parser.parse(request)
662
644
  self.assertEqual(response.status,
@@ -667,8 +649,7 @@ class AdbCallParserTest(parameterized.TestCase):
667
649
  def test_settings_success_get(self):
668
650
  adb = mock.create_autospec(adb_controller.AdbController)
669
651
  adb.execute_command.return_value = b'here it is!'
670
- parser = adb_call_parser.AdbCallParser(
671
- adb, tmp_dir=absltest.get_default_test_tmpdir())
652
+ parser = adb_call_parser.AdbCallParser(adb)
672
653
 
673
654
  request = adb_pb2.AdbRequest.SettingsRequest(
674
655
  name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.SYSTEM,
@@ -685,8 +666,7 @@ class AdbCallParserTest(parameterized.TestCase):
685
666
  def test_settings_success_put(self):
686
667
  adb = mock.create_autospec(adb_controller.AdbController)
687
668
  adb.execute_command.return_value = b'Done for ya!'
688
- parser = adb_call_parser.AdbCallParser(
689
- adb, tmp_dir=absltest.get_default_test_tmpdir())
669
+ parser = adb_call_parser.AdbCallParser(adb)
690
670
 
691
671
  request = adb_pb2.AdbRequest.SettingsRequest(
692
672
  name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.SECURE,
@@ -703,8 +683,7 @@ class AdbCallParserTest(parameterized.TestCase):
703
683
  def test_settings_success_delete(self):
704
684
  adb = mock.create_autospec(adb_controller.AdbController)
705
685
  adb.execute_command.return_value = b'Key deleted.'
706
- parser = adb_call_parser.AdbCallParser(
707
- adb, tmp_dir=absltest.get_default_test_tmpdir())
686
+ parser = adb_call_parser.AdbCallParser(adb)
708
687
 
709
688
  request = adb_pb2.AdbRequest.SettingsRequest(
710
689
  name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.GLOBAL,
@@ -745,8 +724,7 @@ class AdbCallParserTest(parameterized.TestCase):
745
724
  def test_settings_success_reset(self, mode, package_name, expected_arg):
746
725
  adb = mock.create_autospec(adb_controller.AdbController)
747
726
  adb.execute_command.return_value = b'Pkg reset.'
748
- parser = adb_call_parser.AdbCallParser(
749
- adb, tmp_dir=absltest.get_default_test_tmpdir())
727
+ parser = adb_call_parser.AdbCallParser(adb)
750
728
 
751
729
  request = adb_pb2.AdbRequest.SettingsRequest(
752
730
  name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.GLOBAL,
@@ -764,8 +742,7 @@ class AdbCallParserTest(parameterized.TestCase):
764
742
  def test_settings_success_list(self):
765
743
  adb = mock.create_autospec(adb_controller.AdbController)
766
744
  adb.execute_command.return_value = b'volume_ring=5\nvolume_system=7'
767
- parser = adb_call_parser.AdbCallParser(
768
- adb, tmp_dir=absltest.get_default_test_tmpdir())
745
+ parser = adb_call_parser.AdbCallParser(adb)
769
746
 
770
747
  request = adb_pb2.AdbRequest.SettingsRequest(
771
748
  name_space=adb_pb2.AdbRequest.SettingsRequest.Namespace.SYSTEM,
@@ -785,8 +762,7 @@ class AdbCallParserTest(parameterized.TestCase):
785
762
  expected_output = b'generic_output'
786
763
  args = ['shell', 'am', 'broadcast', '-n', 'receiver', '-a', 'action']
787
764
  adb.execute_command.return_value = expected_output
788
- parser = adb_call_parser.AdbCallParser(
789
- adb, tmp_dir=absltest.get_default_test_tmpdir())
765
+ parser = adb_call_parser.AdbCallParser(adb)
790
766
 
791
767
  generic_request = adb_pb2.AdbRequest.GenericRequest(args=args)
792
768
  request = adb_pb2.AdbRequest(generic=generic_request)
@@ -802,8 +778,7 @@ class AdbCallParserTest(parameterized.TestCase):
802
778
  args = ['shell', 'am', 'broadcast', '-n', 'receiver', '-a', 'action']
803
779
  adb.execute_command.side_effect = subprocess.CalledProcessError(
804
780
  cmd='cmd', output='adb_error', returncode=-1)
805
- parser = adb_call_parser.AdbCallParser(
806
- adb, tmp_dir=absltest.get_default_test_tmpdir())
781
+ parser = adb_call_parser.AdbCallParser(adb)
807
782
 
808
783
  generic_request = adb_pb2.AdbRequest.GenericRequest(args=args)
809
784
  request = adb_pb2.AdbRequest(generic=generic_request)
@@ -819,8 +794,7 @@ class AdbCallParserTest(parameterized.TestCase):
819
794
  args = ['shell', 'am', 'broadcast', '-n', 'receiver', '-a', 'action']
820
795
  adb.execute_command.side_effect = subprocess.TimeoutExpired(
821
796
  cmd='cmd', timeout=10)
822
- parser = adb_call_parser.AdbCallParser(
823
- adb, tmp_dir=absltest.get_default_test_tmpdir())
797
+ parser = adb_call_parser.AdbCallParser(adb)
824
798
 
825
799
  generic_request = adb_pb2.AdbRequest.GenericRequest(args=args)
826
800
  request = adb_pb2.AdbRequest(generic=generic_request)
@@ -854,8 +828,7 @@ class AdbCallParserTest(parameterized.TestCase):
854
828
  def test_package_manager_list_bad_output(self, request):
855
829
  adb = mock.create_autospec(adb_controller.AdbController)
856
830
  adb.execute_command.return_value = b"""Something irrelevant."""
857
- parser = adb_call_parser.AdbCallParser(
858
- adb, tmp_dir=absltest.get_default_test_tmpdir())
831
+ parser = adb_call_parser.AdbCallParser(adb)
859
832
  response = parser.parse(request)
860
833
  response.package_manager.output = b"""Something irrelevant."""
861
834
  self.assertEmpty(response.package_manager.list.items)
@@ -875,8 +848,7 @@ feature:android.software.backup
875
848
  feature:android.software.webview
876
849
  """
877
850
  adb.execute_command.return_value = output
878
- parser = adb_call_parser.AdbCallParser(
879
- adb, tmp_dir=absltest.get_default_test_tmpdir())
851
+ parser = adb_call_parser.AdbCallParser(adb)
880
852
  request = adb_pb2.AdbRequest(
881
853
  package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
882
854
  list=adb_pb2.AdbRequest.PackageManagerRequest.List(
@@ -920,8 +892,7 @@ library:javax.obex
920
892
  library:org.apache.http.legacy
921
893
  """
922
894
  adb.execute_command.return_value = output
923
- parser = adb_call_parser.AdbCallParser(
924
- adb, tmp_dir=absltest.get_default_test_tmpdir())
895
+ parser = adb_call_parser.AdbCallParser(adb)
925
896
  request = adb_pb2.AdbRequest(
926
897
  package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
927
898
  list=adb_pb2.AdbRequest.PackageManagerRequest.List(
@@ -961,8 +932,7 @@ package:com.awesome.company
961
932
  package:com.another.great.thingie
962
933
  """
963
934
  adb.execute_command.return_value = output
964
- parser = adb_call_parser.AdbCallParser(
965
- adb, tmp_dir=absltest.get_default_test_tmpdir())
935
+ parser = adb_call_parser.AdbCallParser(adb)
966
936
  request = adb_pb2.AdbRequest(
967
937
  package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
968
938
  list=adb_pb2.AdbRequest.PackageManagerRequest.List(
@@ -983,8 +953,7 @@ package:com.another.great.thingie
983
953
  def test_package_manager_clear_no_package_name(self):
984
954
  adb = mock.create_autospec(adb_controller.AdbController)
985
955
  adb.execute_command.return_value = b"""Something irrelevant."""
986
- parser = adb_call_parser.AdbCallParser(
987
- adb, tmp_dir=absltest.get_default_test_tmpdir())
956
+ parser = adb_call_parser.AdbCallParser(adb)
988
957
 
989
958
  request = adb_pb2.AdbRequest(
990
959
  package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
@@ -1001,8 +970,7 @@ package:com.another.great.thingie
1001
970
  def test_package_manager_clear_successful_no_user_id(self):
1002
971
  adb = mock.create_autospec(adb_controller.AdbController)
1003
972
  adb.execute_command.return_value = b"""Some successful message."""
1004
- parser = adb_call_parser.AdbCallParser(
1005
- adb, tmp_dir=absltest.get_default_test_tmpdir())
973
+ parser = adb_call_parser.AdbCallParser(adb)
1006
974
 
1007
975
  request = adb_pb2.AdbRequest(
1008
976
  package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
@@ -1020,8 +988,7 @@ package:com.another.great.thingie
1020
988
  def test_package_manager_clear_successful_with_user_id(self):
1021
989
  adb = mock.create_autospec(adb_controller.AdbController)
1022
990
  adb.execute_command.return_value = b"""Some successful message."""
1023
- parser = adb_call_parser.AdbCallParser(
1024
- adb, tmp_dir=absltest.get_default_test_tmpdir())
991
+ parser = adb_call_parser.AdbCallParser(adb)
1025
992
 
1026
993
  request = adb_pb2.AdbRequest(
1027
994
  package_manager=adb_pb2.AdbRequest.PackageManagerRequest(
@@ -1040,8 +1007,7 @@ package:com.another.great.thingie
1040
1007
  """An empty `DumpsysRequest` is a valid request."""
1041
1008
  adb = mock.create_autospec(adb_controller.AdbController)
1042
1009
  adb.execute_command.return_value = b'whatever'
1043
- parser = adb_call_parser.AdbCallParser(
1044
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1010
+ parser = adb_call_parser.AdbCallParser(adb)
1045
1011
  request = adb_pb2.AdbRequest(dumpsys=adb_pb2.AdbRequest.DumpsysRequest())
1046
1012
 
1047
1013
  response = parser.parse(request)
@@ -1062,8 +1028,7 @@ package:com.another.great.thingie
1062
1028
  def test_dumpsys_negative_timeouts(self, request):
1063
1029
  """`DumpsysRequest.timeout_{sec, ms}` if passed, should be positive."""
1064
1030
  adb = mock.create_autospec(adb_controller.AdbController)
1065
- parser = adb_call_parser.AdbCallParser(
1066
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1031
+ parser = adb_call_parser.AdbCallParser(adb)
1067
1032
 
1068
1033
  response = parser.parse(request)
1069
1034
 
@@ -1081,8 +1046,7 @@ package:com.another.great.thingie
1081
1046
  def test_dumpsys_timeout_successful(self, timeout_sec, timeout_ms, expected):
1082
1047
  adb = mock.create_autospec(adb_controller.AdbController)
1083
1048
  adb.execute_command.return_value = b'whatever'
1084
- parser = adb_call_parser.AdbCallParser(
1085
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1049
+ parser = adb_call_parser.AdbCallParser(adb)
1086
1050
  request = adb_pb2.AdbRequest(
1087
1051
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
1088
1052
  timeout_sec=timeout_sec, timeout_ms=timeout_ms))
@@ -1109,8 +1073,7 @@ package:com.another.great.thingie
1109
1073
  def test_dumpsys_priority_timeout_successful(self, priority, expected):
1110
1074
  adb = mock.create_autospec(adb_controller.AdbController)
1111
1075
  adb.execute_command.return_value = b'whatever'
1112
- parser = adb_call_parser.AdbCallParser(
1113
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1076
+ parser = adb_call_parser.AdbCallParser(adb)
1114
1077
  request = adb_pb2.AdbRequest(
1115
1078
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(priority=priority))
1116
1079
 
@@ -1120,38 +1083,49 @@ package:com.another.great.thingie
1120
1083
  self.assertEmpty(response.error_message)
1121
1084
  adb.execute_command.assert_called_once_with(expected, timeout=None)
1122
1085
 
1123
- def test_dumpsys_list_only_cannot_be_combined(self):
1124
- """When passing `-l`, the request cannot contain a few fields."""
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.
1125
1110
  adb = mock.create_autospec(adb_controller.AdbController)
1126
1111
  adb.execute_command.return_value = b'whatever'
1127
- parser = adb_call_parser.AdbCallParser(
1128
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1129
- for d in [
1130
- {
1131
- 'service': 'window'
1132
- },
1133
- {
1134
- 'args': ['myoption', 'anotheroption']
1135
- },
1136
- {
1137
- 'skip_services': 'usb'
1138
- },
1139
- ]:
1140
- request = adb_pb2.AdbRequest(
1141
- dumpsys=adb_pb2.AdbRequest.DumpsysRequest(list_only=True, **d))
1142
-
1143
- response = parser.parse(request)
1144
-
1145
- self.assertEqual(response.status,
1146
- adb_pb2.AdbResponse.Status.FAILED_PRECONDITION)
1147
- self.assertNotEmpty(response.error_message)
1148
- 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()
1149
1124
 
1150
1125
  def test_dumpsys_list_only_success(self):
1151
1126
  adb = mock.create_autospec(adb_controller.AdbController)
1152
1127
  adb.execute_command.return_value = b'whatever'
1153
- parser = adb_call_parser.AdbCallParser(
1154
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1128
+ parser = adb_call_parser.AdbCallParser(adb)
1155
1129
  request = adb_pb2.AdbRequest(
1156
1130
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(list_only=True))
1157
1131
 
@@ -1166,8 +1140,7 @@ package:com.another.great.thingie
1166
1140
  """When using `DumpsysRequest.skip_service`, it cannot contain `.service`."""
1167
1141
  adb = mock.create_autospec(adb_controller.AdbController)
1168
1142
  adb.execute_command.return_value = b'whatever'
1169
- parser = adb_call_parser.AdbCallParser(
1170
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1143
+ parser = adb_call_parser.AdbCallParser(adb)
1171
1144
  request = adb_pb2.AdbRequest(
1172
1145
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
1173
1146
  service='wifi', skip_services=['window', 'usb']))
@@ -1182,8 +1155,7 @@ package:com.another.great.thingie
1182
1155
  def test_dumpsys_skip_services(self):
1183
1156
  adb = mock.create_autospec(adb_controller.AdbController)
1184
1157
  adb.execute_command.return_value = b'whatever'
1185
- parser = adb_call_parser.AdbCallParser(
1186
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1158
+ parser = adb_call_parser.AdbCallParser(adb)
1187
1159
  request = adb_pb2.AdbRequest(
1188
1160
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
1189
1161
  skip_services=['window', 'usb']))
@@ -1198,8 +1170,7 @@ package:com.another.great.thingie
1198
1170
  def test_dumpsys_single_service(self):
1199
1171
  adb = mock.create_autospec(adb_controller.AdbController)
1200
1172
  adb.execute_command.return_value = b'whatever'
1201
- parser = adb_call_parser.AdbCallParser(
1202
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1173
+ parser = adb_call_parser.AdbCallParser(adb)
1203
1174
  request = adb_pb2.AdbRequest(
1204
1175
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(service='window'))
1205
1176
 
@@ -1213,8 +1184,7 @@ package:com.another.great.thingie
1213
1184
  def test_dumpsys_single_service_with_args(self):
1214
1185
  adb = mock.create_autospec(adb_controller.AdbController)
1215
1186
  adb.execute_command.return_value = b'whatever'
1216
- parser = adb_call_parser.AdbCallParser(
1217
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1187
+ parser = adb_call_parser.AdbCallParser(adb)
1218
1188
  request = adb_pb2.AdbRequest(
1219
1189
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(
1220
1190
  service='window', args=['arg1', 'arg2']))
@@ -1229,8 +1199,7 @@ package:com.another.great.thingie
1229
1199
  def test_dumpsys_single_service_with_proto(self):
1230
1200
  adb = mock.create_autospec(adb_controller.AdbController)
1231
1201
  adb.execute_command.return_value = b'some binary output'
1232
- parser = adb_call_parser.AdbCallParser(
1233
- adb, tmp_dir=absltest.get_default_test_tmpdir())
1202
+ parser = adb_call_parser.AdbCallParser(adb)
1234
1203
  request = adb_pb2.AdbRequest(
1235
1204
  dumpsys=adb_pb2.AdbRequest.DumpsysRequest(service='window', proto=True))
1236
1205
 
@@ -1241,5 +1210,6 @@ package:com.another.great.thingie
1241
1210
  adb.execute_command.assert_called_once_with(
1242
1211
  ['shell', 'dumpsys', 'window', '--proto'], timeout=None)
1243
1212
 
1213
+
1244
1214
  if __name__ == '__main__':
1245
1215
  absltest.main()