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.
|
@@ -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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
91
|
-
simulator = emulator_simulator.EmulatorSimulator(
|
92
|
-
tmp_dir=tmp_dir,
|
93
|
+
config = config_classes.EmulatorConfig(
|
93
94
|
logfile_path='fake/logfile/path',
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
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
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
#
|
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
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
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
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
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
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
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
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
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
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
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
|
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:
|
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
|
-
|
111
|
-
|
112
|
-
|
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
|
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
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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(
|
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')
|
android_env/components/specs.py
CHANGED