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.
Files changed (142) 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 +233 -185
  14. android_env/components/adb_call_parser_test.py +165 -163
  15. android_env/components/adb_controller.py +19 -28
  16. android_env/components/adb_controller_test.py +100 -9
  17. android_env/components/adb_log_stream.py +3 -3
  18. android_env/components/adb_log_stream_test.py +1 -1
  19. android_env/components/app_screen_checker.py +15 -13
  20. android_env/components/app_screen_checker_test.py +1 -1
  21. android_env/components/config_classes.py +203 -0
  22. android_env/components/coordinator.py +53 -338
  23. android_env/components/coordinator_test.py +26 -283
  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 +2 -5
  29. android_env/components/errors_test.py +1 -1
  30. android_env/components/log_stream.py +2 -2
  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 +2 -3
  34. android_env/components/{utils.py → pixel_fns.py} +19 -20
  35. android_env/components/{utils_test.py → pixel_fns_test.py} +20 -15
  36. android_env/components/setup_step_interpreter.py +45 -37
  37. android_env/components/setup_step_interpreter_test.py +1 -1
  38. android_env/components/simulators/__init__.py +1 -1
  39. android_env/components/simulators/base_simulator.py +79 -23
  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 +62 -81
  43. android_env/components/simulators/emulator/emulator_launcher_test.py +120 -43
  44. android_env/components/simulators/emulator/emulator_simulator.py +111 -98
  45. android_env/components/simulators/emulator/emulator_simulator_test.py +174 -138
  46. android_env/components/simulators/fake/__init__.py +1 -1
  47. android_env/components/simulators/fake/fake_simulator.py +9 -17
  48. android_env/components/simulators/fake/fake_simulator_test.py +23 -8
  49. android_env/components/specs.py +1 -1
  50. android_env/components/specs_test.py +1 -1
  51. android_env/components/task_manager.py +26 -31
  52. android_env/components/task_manager_test.py +1 -18
  53. android_env/env_interface.py +1 -17
  54. android_env/environment.py +27 -17
  55. android_env/environment_test.py +51 -25
  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 +13 -1
  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 +1 -1
  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 +497 -136
  100. android_env/proto/snapshot.proto +1 -1
  101. android_env/proto/snapshot_pb2.py +30 -19
  102. android_env/proto/snapshot_pb2.pyi +117 -0
  103. android_env/proto/snapshot_pb2_grpc.py +20 -0
  104. android_env/proto/snapshot_service.proto +1 -1
  105. android_env/proto/snapshot_service_pb2.py +36 -25
  106. android_env/proto/snapshot_service_pb2.pyi +86 -0
  107. android_env/proto/snapshot_service_pb2_grpc.py +119 -28
  108. android_env/proto/state.proto +1 -1
  109. android_env/proto/state_pb2.py +46 -35
  110. android_env/proto/state_pb2.pyi +85 -0
  111. android_env/proto/state_pb2_grpc.py +20 -0
  112. android_env/proto/task.proto +4 -1
  113. android_env/proto/task_pb2.py +41 -30
  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 +1 -5
  120. android_env/wrappers/base_wrapper_test.py +1 -7
  121. android_env/wrappers/discrete_action_wrapper.py +15 -14
  122. android_env/wrappers/discrete_action_wrapper_test.py +1 -1
  123. android_env/wrappers/flat_interface_wrapper.py +5 -5
  124. android_env/wrappers/flat_interface_wrapper_test.py +1 -1
  125. android_env/wrappers/float_pixels_wrapper.py +5 -4
  126. android_env/wrappers/float_pixels_wrapper_test.py +1 -1
  127. android_env/wrappers/gym_wrapper.py +1 -1
  128. android_env/wrappers/gym_wrapper_test.py +1 -1
  129. android_env/wrappers/image_rescale_wrapper.py +13 -10
  130. android_env/wrappers/image_rescale_wrapper_test.py +1 -1
  131. android_env/wrappers/last_action_wrapper.py +5 -4
  132. android_env/wrappers/last_action_wrapper_test.py +1 -1
  133. android_env/wrappers/rate_limit_wrapper.py +1 -1
  134. android_env/wrappers/rate_limit_wrapper_test.py +1 -1
  135. android_env/wrappers/tap_action_wrapper.py +12 -12
  136. android_env/wrappers/tap_action_wrapper_test.py +49 -14
  137. {android_env-1.2.2.dist-info → android_env-1.2.3.dist-info}/METADATA +14 -16
  138. android_env-1.2.3.dist-info/RECORD +141 -0
  139. {android_env-1.2.2.dist-info → android_env-1.2.3.dist-info}/WHEEL +1 -1
  140. android_env-1.2.2.dist-info/RECORD +0 -88
  141. {android_env-1.2.2.dist-info → android_env-1.2.3.dist-info/licenses}/LICENSE +0 -0
  142. {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 2023 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.
@@ -23,6 +23,7 @@ from unittest import mock
23
23
  from absl.testing import absltest
24
24
  from android_env.components import adb_call_parser
25
25
  from android_env.components import adb_controller
26
+ from android_env.components import config_classes
26
27
  from android_env.components.simulators.emulator import emulator_launcher
27
28
  from android_env.components.simulators.emulator import emulator_simulator
28
29
  from android_env.proto import state_pb2
@@ -74,28 +75,32 @@ class EmulatorSimulatorTest(absltest.TestCase):
74
75
  return_value=self._launcher).start()
75
76
 
76
77
  def test_adb_device_name_not_empty(self):
77
- tmp_dir = absltest.get_default_test_tmpdir()
78
- simulator = emulator_simulator.EmulatorSimulator(
79
- tmp_dir=tmp_dir,
80
- emulator_launcher_args={'grpc_port': 1234},
81
- adb_controller_args={
82
- 'adb_path': '/my/adb',
83
- 'adb_server_port': 5037,
84
- })
78
+ config = config_classes.EmulatorConfig(
79
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
80
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
81
+ ),
82
+ adb_controller=config_classes.AdbControllerConfig(
83
+ adb_path='/my/adb',
84
+ adb_server_port=5037,
85
+ ),
86
+ )
87
+ simulator = emulator_simulator.EmulatorSimulator(config)
85
88
  self.assertNotEmpty(simulator.adb_device_name())
86
89
 
87
90
  @mock.patch.object(os.path, 'exists', autospec=True, return_value=True)
88
91
  @mock.patch.object(builtins, 'open', autospec=True)
89
92
  def test_logfile_path(self, mock_open, unused_mock_exists):
90
- tmp_dir = absltest.get_default_test_tmpdir()
91
- simulator = emulator_simulator.EmulatorSimulator(
92
- tmp_dir=tmp_dir,
93
+ config = config_classes.EmulatorConfig(
93
94
  logfile_path='fake/logfile/path',
94
- emulator_launcher_args={'grpc_port': 1234},
95
- adb_controller_args={
96
- 'adb_path': '/my/adb',
97
- 'adb_server_port': 5037,
98
- })
95
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
96
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
97
+ ),
98
+ adb_controller=config_classes.AdbControllerConfig(
99
+ adb_path='/my/adb',
100
+ adb_server_port=5037,
101
+ ),
102
+ )
103
+ simulator = emulator_simulator.EmulatorSimulator(config)
99
104
  mock_open.return_value.__enter__.return_value.read.return_value = (
100
105
  'fake_logs'.encode('utf-8'))
101
106
  logs = simulator.get_logs()
@@ -104,61 +109,76 @@ class EmulatorSimulatorTest(absltest.TestCase):
104
109
 
105
110
  @mock.patch.object(portpicker, 'is_port_free', return_value=True)
106
111
  def test_grpc_port(self, unused_mock_portpicker):
107
- simulator = emulator_simulator.EmulatorSimulator(
108
- tmp_dir=absltest.get_default_test_tmpdir(),
109
- emulator_launcher_args={},
110
- adb_controller_args={
111
- 'adb_path': '/my/adb',
112
- 'adb_server_port': 5037,
113
- 'prompt_regex': 'awesome>',
114
- })
115
- self.assertEqual(simulator._grpc_port, 8554)
112
+
113
+ launcher_config = config_classes.EmulatorLauncherConfig(
114
+ tmp_dir=self.create_tempdir().full_path
115
+ )
116
+ config = config_classes.EmulatorConfig(
117
+ emulator_launcher=launcher_config,
118
+ adb_controller=config_classes.AdbControllerConfig(
119
+ adb_path='/my/adb',
120
+ adb_server_port=5037,
121
+ ),
122
+ )
123
+ simulator = emulator_simulator.EmulatorSimulator(config)
124
+ self.assertEqual(launcher_config.grpc_port, 8554)
116
125
 
117
126
  @mock.patch.object(portpicker, 'is_port_free', return_value=False)
118
127
  def test_grpc_port_unavailable(self, unused_mock_portpicker):
119
- simulator = emulator_simulator.EmulatorSimulator(
120
- tmp_dir=absltest.get_default_test_tmpdir(),
121
- emulator_launcher_args={},
122
- adb_controller_args={
123
- 'adb_path': '/my/adb',
124
- 'adb_server_port': 5037,
125
- 'prompt_regex': 'awesome>',
126
- })
127
- self.assertNotEqual(simulator._grpc_port, 8554)
128
-
129
- def test_launch(self):
130
-
131
- # Make sure that adb_controller is started before Emulator is launched.
128
+
129
+ launcher_config = config_classes.EmulatorLauncherConfig(
130
+ tmp_dir=self.create_tempdir().full_path
131
+ )
132
+ config = config_classes.EmulatorConfig(
133
+ emulator_launcher=launcher_config,
134
+ adb_controller=config_classes.AdbControllerConfig(
135
+ adb_path='/my/adb',
136
+ adb_server_port=5037,
137
+ ),
138
+ )
139
+ simulator = emulator_simulator.EmulatorSimulator(config)
140
+ self.assertNotEqual(launcher_config.grpc_port, 8554)
141
+
142
+ def test_launch_operation_order(self):
143
+ """Makes sure that adb_controller is started before Emulator is launched."""
144
+
145
+ # Arrange.
132
146
  call_order = []
133
- self._adb_controller.init_server.side_effect = (
134
- lambda *a, **kw: call_order.append('init_server'))
147
+ self._adb_controller.init_server.side_effect = lambda: call_order.append(
148
+ 'init_server'
149
+ )
135
150
  self._launcher.launch_emulator_process.side_effect = (
136
- lambda *a, **kw: call_order.append('launch_emulator_process'))
137
-
138
- tmp_dir = absltest.get_default_test_tmpdir()
139
- simulator = emulator_simulator.EmulatorSimulator(
140
- tmp_dir=tmp_dir,
141
- emulator_launcher_args={'grpc_port': 1234},
142
- adb_controller_args={
143
- 'adb_path': '/my/adb',
144
- 'adb_server_port': 5037,
145
- 'prompt_regex': 'awesome>',
146
- })
151
+ lambda: call_order.append('launch_emulator_process')
152
+ )
153
+ config = config_classes.EmulatorConfig(
154
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
155
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
156
+ ),
157
+ adb_controller=config_classes.AdbControllerConfig(
158
+ adb_path='/my/adb',
159
+ adb_server_port=5037,
160
+ ),
161
+ )
162
+ simulator = emulator_simulator.EmulatorSimulator(config)
147
163
 
148
- # The simulator should launch and not crash.
149
- simulator.launch()
164
+ # Act.
165
+ simulator.launch() # The simulator should launch and not crash.
150
166
 
167
+ # Assert.
168
+ # The adb server should be initialized before launching the emulator.
151
169
  self.assertEqual(call_order, ['init_server', 'launch_emulator_process'])
152
170
 
153
171
  def test_close(self):
154
- tmp_dir = absltest.get_default_test_tmpdir()
155
- simulator = emulator_simulator.EmulatorSimulator(
156
- tmp_dir=tmp_dir,
157
- emulator_launcher_args={'grpc_port': 1234},
158
- adb_controller_args={
159
- 'adb_path': '/my/adb',
160
- 'adb_server_port': 5037,
161
- })
172
+ config = config_classes.EmulatorConfig(
173
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
174
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
175
+ ),
176
+ adb_controller=config_classes.AdbControllerConfig(
177
+ adb_path='/my/adb',
178
+ adb_server_port=5037,
179
+ ),
180
+ )
181
+ simulator = emulator_simulator.EmulatorSimulator(config)
162
182
 
163
183
  # The simulator should launch and not crash.
164
184
  simulator.launch()
@@ -169,31 +189,35 @@ class EmulatorSimulatorTest(absltest.TestCase):
169
189
  simulator.close()
170
190
 
171
191
  def test_value_error_if_launch_attempt_params_incorrect(self):
172
- tmp_dir = absltest.get_default_test_tmpdir()
173
192
  self.assertRaises(
174
193
  ValueError,
175
194
  emulator_simulator.EmulatorSimulator,
176
- tmp_dir=tmp_dir,
177
- emulator_launcher_args={'grpc_port': 1234},
178
- adb_controller_args={
179
- 'adb_path': '/my/adb',
180
- 'adb_server_port': 5037,
181
- },
182
- launch_n_times_without_reboot=2,
183
- launch_n_times_without_reinstall=1,
195
+ config=config_classes.EmulatorConfig(
196
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
197
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
198
+ ),
199
+ adb_controller=config_classes.AdbControllerConfig(
200
+ adb_path='/my/adb',
201
+ adb_server_port=5037,
202
+ ),
203
+ launch_n_times_without_reboot=2,
204
+ launch_n_times_without_reinstall=1,
205
+ ),
184
206
  )
185
207
 
186
208
  def test_launch_attempt_reboot(self):
187
- tmp_dir = absltest.get_default_test_tmpdir()
188
- simulator = emulator_simulator.EmulatorSimulator(
189
- tmp_dir=tmp_dir,
190
- emulator_launcher_args={'grpc_port': 1234},
191
- adb_controller_args={
192
- 'adb_path': '/my/adb',
193
- 'adb_server_port': 5037,
194
- },
209
+ config = config_classes.EmulatorConfig(
210
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
211
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
212
+ ),
213
+ adb_controller=config_classes.AdbControllerConfig(
214
+ adb_path='/my/adb',
215
+ adb_server_port=5037,
216
+ ),
195
217
  launch_n_times_without_reboot=1,
196
- launch_n_times_without_reinstall=2)
218
+ launch_n_times_without_reinstall=2,
219
+ )
220
+ simulator = emulator_simulator.EmulatorSimulator(config)
197
221
 
198
222
  # The simulator should launch and not crash.
199
223
  simulator.launch()
@@ -208,16 +232,18 @@ class EmulatorSimulatorTest(absltest.TestCase):
208
232
  self._launcher.launch_emulator_process.assert_called_once()
209
233
 
210
234
  def test_launch_attempt_reinstall_after_zero_attempts(self):
211
- tmp_dir = absltest.get_default_test_tmpdir()
212
- simulator = emulator_simulator.EmulatorSimulator(
213
- tmp_dir=tmp_dir,
214
- emulator_launcher_args={'grpc_port': 1234},
215
- adb_controller_args={
216
- 'adb_path': '/my/adb',
217
- 'adb_server_port': 5037,
218
- },
235
+ config = config_classes.EmulatorConfig(
236
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
237
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
238
+ ),
239
+ adb_controller=config_classes.AdbControllerConfig(
240
+ adb_path='/my/adb',
241
+ adb_server_port=5037,
242
+ ),
219
243
  launch_n_times_without_reboot=0,
220
- launch_n_times_without_reinstall=0)
244
+ launch_n_times_without_reinstall=0,
245
+ )
246
+ simulator = emulator_simulator.EmulatorSimulator(config)
221
247
 
222
248
  # The simulator should not reboot or reinstall on its very first launch.
223
249
  simulator.launch()
@@ -233,16 +259,18 @@ class EmulatorSimulatorTest(absltest.TestCase):
233
259
  self._launcher.launch_emulator_process.assert_called_once()
234
260
 
235
261
  def test_launch_attempt_reinstall(self):
236
- tmp_dir = absltest.get_default_test_tmpdir()
237
- simulator = emulator_simulator.EmulatorSimulator(
238
- tmp_dir=tmp_dir,
239
- emulator_launcher_args={'grpc_port': 1234},
240
- adb_controller_args={
241
- 'adb_path': '/my/adb',
242
- 'adb_server_port': 5037,
243
- },
262
+ config = config_classes.EmulatorConfig(
263
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
264
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
265
+ ),
266
+ adb_controller=config_classes.AdbControllerConfig(
267
+ adb_path='/my/adb',
268
+ adb_server_port=5037,
269
+ ),
244
270
  launch_n_times_without_reboot=1,
245
- launch_n_times_without_reinstall=2)
271
+ launch_n_times_without_reinstall=2,
272
+ )
273
+ simulator = emulator_simulator.EmulatorSimulator(config)
246
274
 
247
275
  # The simulator should launch and not crash.
248
276
  simulator.launch()
@@ -263,14 +291,16 @@ class EmulatorSimulatorTest(absltest.TestCase):
263
291
  self._launcher.launch_emulator_process.assert_called_once()
264
292
 
265
293
  def test_get_screenshot(self):
266
- tmp_dir = absltest.get_default_test_tmpdir()
267
- simulator = emulator_simulator.EmulatorSimulator(
268
- tmp_dir=tmp_dir,
269
- emulator_launcher_args={'grpc_port': 1234},
270
- adb_controller_args={
271
- 'adb_path': '/my/adb',
272
- 'adb_server_port': 5037,
273
- })
294
+ config = config_classes.EmulatorConfig(
295
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
296
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
297
+ ),
298
+ adb_controller=config_classes.AdbControllerConfig(
299
+ adb_path='/my/adb',
300
+ adb_server_port=5037,
301
+ ),
302
+ )
303
+ simulator = emulator_simulator.EmulatorSimulator(config)
274
304
 
275
305
  # The simulator should launch and not crash.
276
306
  simulator.launch()
@@ -287,15 +317,16 @@ class EmulatorSimulatorTest(absltest.TestCase):
287
317
  self.assertEqual(screenshot.shape, (1234, 5678, 3))
288
318
 
289
319
  def test_load_state(self):
290
- tmp_dir = absltest.get_default_test_tmpdir()
291
- simulator = emulator_simulator.EmulatorSimulator(
292
- tmp_dir=tmp_dir,
293
- emulator_launcher_args={'grpc_port': 1234},
294
- adb_controller_args={
295
- 'adb_path': '/my/adb',
296
- 'adb_server_port': 5037,
297
- },
320
+ config = config_classes.EmulatorConfig(
321
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
322
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
323
+ ),
324
+ adb_controller=config_classes.AdbControllerConfig(
325
+ adb_path='/my/adb',
326
+ adb_server_port=5037,
327
+ ),
298
328
  )
329
+ simulator = emulator_simulator.EmulatorSimulator(config)
299
330
 
300
331
  # The simulator should launch and not crash.
301
332
  simulator.launch()
@@ -340,15 +371,16 @@ class EmulatorSimulatorTest(absltest.TestCase):
340
371
  self.assertEqual(load_response.error_message, 'error')
341
372
 
342
373
  def test_save_state(self):
343
- tmp_dir = absltest.get_default_test_tmpdir()
344
- simulator = emulator_simulator.EmulatorSimulator(
345
- tmp_dir=tmp_dir,
346
- emulator_launcher_args={'grpc_port': 1234},
347
- adb_controller_args={
348
- 'adb_path': '/my/adb',
349
- 'adb_server_port': 5037,
350
- },
374
+ config = config_classes.EmulatorConfig(
375
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
376
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
377
+ ),
378
+ adb_controller=config_classes.AdbControllerConfig(
379
+ adb_path='/my/adb',
380
+ adb_server_port=5037,
381
+ ),
351
382
  )
383
+ simulator = emulator_simulator.EmulatorSimulator(config)
352
384
 
353
385
  # The simulator should launch and not crash.
354
386
  simulator.launch()
@@ -381,14 +413,16 @@ class EmulatorSimulatorTest(absltest.TestCase):
381
413
  self.assertEqual(save_response.error_message, 'error')
382
414
 
383
415
  def test_send_touch(self):
384
- tmp_dir = absltest.get_default_test_tmpdir()
385
- simulator = emulator_simulator.EmulatorSimulator(
386
- tmp_dir=tmp_dir,
387
- emulator_launcher_args={'grpc_port': 1234},
388
- adb_controller_args={
389
- 'adb_path': '/my/adb',
390
- 'adb_server_port': 5037,
391
- })
416
+ config = config_classes.EmulatorConfig(
417
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
418
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
419
+ ),
420
+ adb_controller=config_classes.AdbControllerConfig(
421
+ adb_path='/my/adb',
422
+ adb_server_port=5037,
423
+ ),
424
+ )
425
+ simulator = emulator_simulator.EmulatorSimulator(config)
392
426
 
393
427
  # The simulator should launch and not crash.
394
428
  simulator.launch()
@@ -436,14 +470,16 @@ class EmulatorSimulatorTest(absltest.TestCase):
436
470
  ])
437
471
 
438
472
  def test_send_key(self):
439
- tmp_dir = absltest.get_default_test_tmpdir()
440
- simulator = emulator_simulator.EmulatorSimulator(
441
- tmp_dir=tmp_dir,
442
- emulator_launcher_args={'grpc_port': 1234},
443
- adb_controller_args={
444
- 'adb_path': '/my/adb',
445
- 'adb_server_port': 5037,
446
- })
473
+ config = config_classes.EmulatorConfig(
474
+ emulator_launcher=config_classes.EmulatorLauncherConfig(
475
+ grpc_port=1234, tmp_dir=self.create_tempdir().full_path
476
+ ),
477
+ adb_controller=config_classes.AdbControllerConfig(
478
+ adb_path='/my/adb',
479
+ adb_server_port=5037,
480
+ ),
481
+ )
482
+ simulator = emulator_simulator.EmulatorSimulator(config)
447
483
 
448
484
  # The simulator should launch and not crash.
449
485
  simulator.launch()
@@ -1,5 +1,5 @@
1
1
  # coding=utf-8
2
- # Copyright 2023 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.
@@ -1,5 +1,5 @@
1
1
  # coding=utf-8
2
- # Copyright 2023 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.
@@ -18,10 +18,10 @@
18
18
  import random
19
19
  import threading
20
20
  import time
21
- from typing import Optional
22
21
 
23
22
  from absl import logging
24
23
  from android_env.components import adb_controller
24
+ from android_env.components import config_classes
25
25
  from android_env.components import log_stream
26
26
  from android_env.components.simulators import base_simulator
27
27
  import numpy as np
@@ -80,7 +80,7 @@ class FakeAdbController(adb_controller.AdbController):
80
80
  def execute_command(
81
81
  self,
82
82
  args: list[str],
83
- timeout: Optional[float] = None,
83
+ timeout: float | None = None,
84
84
  device_specific: bool = True,
85
85
  ) -> bytes:
86
86
  """Returns fake output for adb commands."""
@@ -106,18 +106,10 @@ class FakeAdbController(adb_controller.AdbController):
106
106
  class FakeSimulator(base_simulator.BaseSimulator):
107
107
  """FakeSimulator class."""
108
108
 
109
- def __init__(self,
110
- screen_dimensions: tuple[int, int] = (480, 320),
111
- **kwargs):
112
- """FakeSimulator class that can replace EmulatorSimulator in AndroidEnv.
113
-
114
- Args:
115
- screen_dimensions: desired screen dimensions in pixels. This determines
116
- the shape of the screenshots returned by get_screenshot().
117
- **kwargs: other keyword arguments for the base class.
118
- """
119
- super().__init__(**kwargs)
120
- self._screen_dimensions = np.array(screen_dimensions)
109
+ def __init__(self, config: config_classes.FakeSimulatorConfig):
110
+ """FakeSimulator class that can replace EmulatorSimulator in AndroidEnv."""
111
+ super().__init__(config)
112
+ self._screen_dimensions = np.array(config.screen_dimensions)
121
113
  logging.info('Created FakeSimulator.')
122
114
 
123
115
  def get_logs(self) -> str:
@@ -127,7 +119,7 @@ class FakeSimulator(base_simulator.BaseSimulator):
127
119
  return 'fake_simulator'
128
120
 
129
121
  def create_adb_controller(self):
130
- return FakeAdbController()
122
+ return FakeAdbController(config_classes.AdbControllerConfig())
131
123
 
132
124
  def create_log_stream(self) -> log_stream.LogStream:
133
125
  return FakeLogStream()
@@ -141,6 +133,6 @@ class FakeSimulator(base_simulator.BaseSimulator):
141
133
  def send_key(self, keycode: np.int32, event_type: str) -> None:
142
134
  del keycode, event_type
143
135
 
144
- def get_screenshot(self) -> np.ndarray:
136
+ def _get_screenshot_impl(self) -> np.ndarray:
145
137
  return np.random.randint(
146
138
  low=0, high=255, size=(*self._screen_dimensions, 3), dtype=np.uint8)
@@ -1,5 +1,5 @@
1
1
  # coding=utf-8
2
- # Copyright 2023 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.
@@ -17,6 +17,7 @@
17
17
 
18
18
  import re
19
19
  from absl.testing import absltest
20
+ from android_env.components import config_classes
20
21
  from android_env.components.simulators.fake import fake_simulator
21
22
  import numpy as np
22
23
 
@@ -24,18 +25,24 @@ import numpy as np
24
25
  class FakeSimulatorTest(absltest.TestCase):
25
26
 
26
27
  def test_device_name(self):
27
- simulator = fake_simulator.FakeSimulator(screen_dimensions=(320, 480))
28
+ simulator = fake_simulator.FakeSimulator(
29
+ config_classes.FakeSimulatorConfig(screen_dimensions=(320, 480))
30
+ )
28
31
  self.assertEqual(simulator.adb_device_name(), 'fake_simulator')
29
32
 
30
33
  def test_launch_close(self):
31
34
  # The simulator should launch and not crash.
32
- simulator = fake_simulator.FakeSimulator(screen_dimensions=(320, 480))
35
+ simulator = fake_simulator.FakeSimulator(
36
+ config_classes.FakeSimulatorConfig(screen_dimensions=(320, 480))
37
+ )
33
38
  simulator.launch()
34
39
  # Closing the simulator should also not crash.
35
40
  simulator.close()
36
41
 
37
42
  def test_get_screenshot(self):
38
- simulator = fake_simulator.FakeSimulator(screen_dimensions=(320, 480))
43
+ simulator = fake_simulator.FakeSimulator(
44
+ config_classes.FakeSimulatorConfig(screen_dimensions=(320, 480))
45
+ )
39
46
  simulator.launch()
40
47
 
41
48
  screenshot = simulator.get_screenshot()
@@ -43,7 +50,9 @@ class FakeSimulatorTest(absltest.TestCase):
43
50
  np.testing.assert_equal(screenshot.dtype, np.uint8)
44
51
 
45
52
  def test_log_stream(self):
46
- simulator = fake_simulator.FakeSimulator(screen_dimensions=(320, 480))
53
+ simulator = fake_simulator.FakeSimulator(
54
+ config_classes.FakeSimulatorConfig(screen_dimensions=(320, 480))
55
+ )
47
56
  simulator.launch()
48
57
  log_stream = simulator.create_log_stream()
49
58
  # Start yielding lines from LogStream.
@@ -61,7 +70,9 @@ class FakeSimulatorTest(absltest.TestCase):
61
70
  break
62
71
 
63
72
  def test_adb_output(self):
64
- simulator = fake_simulator.FakeSimulator(screen_dimensions=(320, 480))
73
+ simulator = fake_simulator.FakeSimulator(
74
+ config_classes.FakeSimulatorConfig(screen_dimensions=(320, 480))
75
+ )
65
76
  simulator.launch()
66
77
  adb_controller = simulator.create_adb_controller()
67
78
  line = adb_controller.execute_command(['shell', 'dumpsys', 'input'])
@@ -79,7 +90,9 @@ class FakeSimulatorTest(absltest.TestCase):
79
90
  'topActivity=ComponentInfo{fake_activity}')
80
91
 
81
92
  def test_send_touch(self):
82
- simulator = fake_simulator.FakeSimulator(screen_dimensions=(320, 480))
93
+ simulator = fake_simulator.FakeSimulator(
94
+ config_classes.FakeSimulatorConfig(screen_dimensions=(320, 480))
95
+ )
83
96
  simulator.launch()
84
97
  simulator.send_touch([(0, 1, True, 0)])
85
98
  simulator.send_touch([(0, 1, False, 0)])
@@ -87,7 +100,9 @@ class FakeSimulatorTest(absltest.TestCase):
87
100
  # without crashing anything.
88
101
 
89
102
  def test_send_key(self):
90
- simulator = fake_simulator.FakeSimulator(screen_dimensions=(320, 480))
103
+ simulator = fake_simulator.FakeSimulator(
104
+ config_classes.FakeSimulatorConfig(screen_dimensions=(320, 480))
105
+ )
91
106
  simulator.launch()
92
107
  simulator.send_key(np.int32(123), 'keydown')
93
108
  simulator.send_key(np.int32(123), 'keyup')
@@ -1,5 +1,5 @@
1
1
  # coding=utf-8
2
- # Copyright 2023 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.
@@ -1,5 +1,5 @@
1
1
  # coding=utf-8
2
- # Copyright 2023 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.