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.
- 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 +239 -196
- android_env/components/adb_call_parser_test.py +179 -209
- android_env/components/adb_controller.py +90 -52
- android_env/components/adb_controller_test.py +187 -16
- android_env/components/adb_log_stream.py +17 -5
- android_env/components/adb_log_stream_test.py +17 -3
- android_env/components/app_screen_checker.py +17 -15
- android_env/components/app_screen_checker_test.py +7 -8
- android_env/components/config_classes.py +203 -0
- android_env/components/coordinator.py +102 -338
- android_env/components/coordinator_test.py +59 -199
- 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 +52 -10
- android_env/components/errors_test.py +110 -0
- android_env/components/log_stream.py +7 -5
- android_env/components/log_stream_test.py +1 -1
- android_env/components/logcat_thread.py +9 -8
- android_env/components/logcat_thread_test.py +3 -4
- android_env/components/{utils.py → pixel_fns.py} +20 -20
- android_env/components/{utils_test.py → pixel_fns_test.py} +20 -15
- android_env/components/setup_step_interpreter.py +47 -39
- android_env/components/setup_step_interpreter_test.py +4 -4
- android_env/components/simulators/__init__.py +1 -1
- android_env/components/simulators/base_simulator.py +116 -44
- 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 +67 -77
- android_env/components/simulators/emulator/emulator_launcher_test.py +153 -49
- android_env/components/simulators/emulator/emulator_simulator.py +276 -95
- android_env/components/simulators/emulator/emulator_simulator_test.py +314 -89
- android_env/components/simulators/fake/__init__.py +1 -1
- android_env/components/simulators/fake/fake_simulator.py +17 -25
- android_env/components/simulators/fake/fake_simulator_test.py +29 -12
- android_env/components/specs.py +18 -28
- android_env/components/specs_test.py +1 -44
- android_env/components/task_manager.py +48 -48
- android_env/components/task_manager_test.py +71 -60
- android_env/env_interface.py +37 -23
- android_env/environment.py +83 -51
- android_env/environment_test.py +68 -29
- 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 +17 -6
- 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 +68 -63
- 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 +505 -142
- android_env/proto/snapshot.proto +169 -0
- android_env/proto/snapshot_pb2.py +47 -0
- android_env/proto/snapshot_pb2.pyi +117 -0
- android_env/proto/snapshot_pb2_grpc.py +24 -0
- android_env/proto/snapshot_service.proto +289 -0
- android_env/proto/snapshot_service_pb2.py +54 -0
- android_env/proto/snapshot_service_pb2.pyi +86 -0
- android_env/proto/snapshot_service_pb2_grpc.py +487 -0
- android_env/proto/state.proto +63 -0
- android_env/proto/state_pb2.py +63 -0
- android_env/proto/state_pb2.pyi +85 -0
- android_env/proto/state_pb2_grpc.py +24 -0
- android_env/proto/task.proto +5 -1
- android_env/proto/task_pb2.py +42 -31
- 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 +34 -13
- android_env/wrappers/base_wrapper_test.py +22 -16
- android_env/wrappers/discrete_action_wrapper.py +18 -17
- android_env/wrappers/discrete_action_wrapper_test.py +4 -4
- android_env/wrappers/flat_interface_wrapper.py +5 -5
- android_env/wrappers/flat_interface_wrapper_test.py +7 -11
- android_env/wrappers/float_pixels_wrapper.py +9 -10
- android_env/wrappers/float_pixels_wrapper_test.py +3 -3
- android_env/wrappers/gym_wrapper.py +19 -13
- android_env/wrappers/gym_wrapper_test.py +3 -5
- android_env/wrappers/image_rescale_wrapper.py +18 -21
- android_env/wrappers/image_rescale_wrapper_test.py +25 -37
- android_env/wrappers/last_action_wrapper.py +16 -13
- android_env/wrappers/last_action_wrapper_test.py +44 -51
- android_env/wrappers/rate_limit_wrapper.py +6 -3
- android_env/wrappers/rate_limit_wrapper_test.py +22 -1
- android_env/wrappers/tap_action_wrapper.py +16 -17
- android_env/wrappers/tap_action_wrapper_test.py +51 -16
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/METADATA +14 -18
- android_env-1.2.3.dist-info/RECORD +141 -0
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/WHEEL +1 -1
- android_env/proto/raw_observation.proto +0 -39
- android_env/proto/raw_observation_pb2.py +0 -27
- android_env/proto/raw_observation_pb2_grpc.py +0 -4
- android_env-1.2.1.dist-info/RECORD +0 -81
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info/licenses}/LICENSE +0 -0
- {android_env-1.2.1.dist-info → android_env-1.2.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,227 @@
|
|
1
|
+
# coding=utf-8
|
2
|
+
# Copyright 2024 DeepMind Technologies Limited.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
from unittest import mock
|
17
|
+
|
18
|
+
from absl.testing import absltest
|
19
|
+
from absl.testing import parameterized
|
20
|
+
from android_env.components import action_fns
|
21
|
+
from android_env.components import action_type as action_type_lib
|
22
|
+
from android_env.components import errors
|
23
|
+
from android_env.components.simulators import base_simulator
|
24
|
+
import numpy as np
|
25
|
+
|
26
|
+
|
27
|
+
class ActionFnsTest(parameterized.TestCase):
|
28
|
+
|
29
|
+
def test_send_action_to_simulator_missing_action_type(self):
|
30
|
+
"""A `KeyError` should be raised if the action is missing "action_type"."""
|
31
|
+
|
32
|
+
# Arrange.
|
33
|
+
simulator = mock.create_autospec(base_simulator.BaseSimulator)
|
34
|
+
action = {'some_key': np.array(123, np.int32)}
|
35
|
+
|
36
|
+
# Act & Assert.
|
37
|
+
self.assertRaises(
|
38
|
+
KeyError,
|
39
|
+
action_fns.send_action_to_simulator,
|
40
|
+
action,
|
41
|
+
simulator,
|
42
|
+
800,
|
43
|
+
600,
|
44
|
+
1,
|
45
|
+
)
|
46
|
+
|
47
|
+
def test_send_action_to_simulator_sendactionerror(self):
|
48
|
+
"""Returns `False` if the simulator raises a SendActionError."""
|
49
|
+
|
50
|
+
# Arrange.
|
51
|
+
simulator = mock.create_autospec(base_simulator.BaseSimulator)
|
52
|
+
simulator.send_touch.side_effect = errors.SendActionError('oops!')
|
53
|
+
action = {
|
54
|
+
'action_type': action_type_lib.ActionType.TOUCH,
|
55
|
+
'touch_position': np.array([0.3, 0.5], np.float32),
|
56
|
+
}
|
57
|
+
|
58
|
+
# Act.
|
59
|
+
output = action_fns.send_action_to_simulator(
|
60
|
+
action,
|
61
|
+
simulator,
|
62
|
+
800,
|
63
|
+
600,
|
64
|
+
1,
|
65
|
+
)
|
66
|
+
|
67
|
+
# Assert.
|
68
|
+
self.assertFalse(output)
|
69
|
+
simulator.send_touch.assert_called_once()
|
70
|
+
|
71
|
+
def test_send_action_to_simulator_touch_success_one_finger(self):
|
72
|
+
"""Returns `True` with a proper 1-finger touch action."""
|
73
|
+
|
74
|
+
# Arrange.
|
75
|
+
simulator = mock.create_autospec(base_simulator.BaseSimulator)
|
76
|
+
action = {
|
77
|
+
'action_type': action_type_lib.ActionType.TOUCH,
|
78
|
+
'touch_position': np.array([0.2, 0.5], np.float32),
|
79
|
+
}
|
80
|
+
|
81
|
+
# Act.
|
82
|
+
output = action_fns.send_action_to_simulator(
|
83
|
+
action,
|
84
|
+
simulator,
|
85
|
+
800,
|
86
|
+
600,
|
87
|
+
1,
|
88
|
+
)
|
89
|
+
|
90
|
+
# Assert.
|
91
|
+
self.assertTrue(output)
|
92
|
+
simulator.send_touch.assert_called_once_with(
|
93
|
+
[(np.int32(160), np.int32(300), True, 0)]
|
94
|
+
)
|
95
|
+
|
96
|
+
def test_send_action_to_simulator_touch_success_multiple_finger(self):
|
97
|
+
"""Returns `True` with a proper 3-finger touch action."""
|
98
|
+
|
99
|
+
# Arrange.
|
100
|
+
simulator = mock.create_autospec(base_simulator.BaseSimulator)
|
101
|
+
action = {
|
102
|
+
'action_type': action_type_lib.ActionType.TOUCH,
|
103
|
+
'touch_position': np.array([0.2, 0.5], np.float32),
|
104
|
+
'action_type_2': action_type_lib.ActionType.LIFT,
|
105
|
+
'touch_position_2': np.array([0.1, 0.2], np.float32),
|
106
|
+
'action_type_3': action_type_lib.ActionType.TOUCH,
|
107
|
+
'touch_position_3': np.array([0.5, 0.2], np.float32),
|
108
|
+
}
|
109
|
+
|
110
|
+
# Act.
|
111
|
+
output = action_fns.send_action_to_simulator(
|
112
|
+
action,
|
113
|
+
simulator,
|
114
|
+
800,
|
115
|
+
600,
|
116
|
+
3,
|
117
|
+
)
|
118
|
+
|
119
|
+
# Assert.
|
120
|
+
self.assertTrue(output)
|
121
|
+
simulator.send_touch.assert_called_once_with([
|
122
|
+
(np.int32(160), np.int32(300), True, 0),
|
123
|
+
(np.int32(80), np.int32(120), False, 1),
|
124
|
+
(np.int32(400), np.int32(120), True, 2),
|
125
|
+
])
|
126
|
+
|
127
|
+
def test_send_action_to_simulator_keydown_success(self):
|
128
|
+
"""Returns `True` with a proper keydown action."""
|
129
|
+
|
130
|
+
# Arrange.
|
131
|
+
simulator = mock.create_autospec(base_simulator.BaseSimulator)
|
132
|
+
action = {
|
133
|
+
'action_type': action_type_lib.ActionType.KEYDOWN,
|
134
|
+
'keycode': np.array([21], np.int32),
|
135
|
+
}
|
136
|
+
|
137
|
+
# Act.
|
138
|
+
output = action_fns.send_action_to_simulator(
|
139
|
+
action,
|
140
|
+
simulator,
|
141
|
+
800,
|
142
|
+
600,
|
143
|
+
1,
|
144
|
+
)
|
145
|
+
|
146
|
+
# Assert.
|
147
|
+
self.assertTrue(output)
|
148
|
+
simulator.send_key.assert_called_once_with(21, event_type='keydown')
|
149
|
+
|
150
|
+
def test_send_action_to_simulator_keyup_success(self):
|
151
|
+
"""Returns `True` with a proper keyup action."""
|
152
|
+
|
153
|
+
# Arrange.
|
154
|
+
simulator = mock.create_autospec(base_simulator.BaseSimulator)
|
155
|
+
action = {
|
156
|
+
'action_type': action_type_lib.ActionType.KEYUP,
|
157
|
+
'keycode': np.array([42], np.int32),
|
158
|
+
}
|
159
|
+
|
160
|
+
# Act.
|
161
|
+
output = action_fns.send_action_to_simulator(
|
162
|
+
action,
|
163
|
+
simulator,
|
164
|
+
800,
|
165
|
+
600,
|
166
|
+
1,
|
167
|
+
)
|
168
|
+
|
169
|
+
# Assert.
|
170
|
+
self.assertTrue(output)
|
171
|
+
simulator.send_key.assert_called_once_with(42, event_type='keyup')
|
172
|
+
|
173
|
+
def test_send_action_to_simulator_keypress_success(self):
|
174
|
+
"""Returns `True` with a proper keypress action."""
|
175
|
+
|
176
|
+
# Arrange.
|
177
|
+
simulator = mock.create_autospec(base_simulator.BaseSimulator)
|
178
|
+
action = {
|
179
|
+
'action_type': action_type_lib.ActionType.KEYPRESS,
|
180
|
+
'keycode': np.array([96], np.int32),
|
181
|
+
}
|
182
|
+
|
183
|
+
# Act.
|
184
|
+
output = action_fns.send_action_to_simulator(
|
185
|
+
action,
|
186
|
+
simulator,
|
187
|
+
800,
|
188
|
+
600,
|
189
|
+
1,
|
190
|
+
)
|
191
|
+
|
192
|
+
# Assert.
|
193
|
+
self.assertTrue(output)
|
194
|
+
simulator.send_key.assert_called_once_with(96, event_type='keypress')
|
195
|
+
|
196
|
+
@parameterized.named_parameters(
|
197
|
+
(
|
198
|
+
'one_finger',
|
199
|
+
1,
|
200
|
+
{
|
201
|
+
'action_type': np.array(action_type_lib.ActionType.LIFT),
|
202
|
+
'touch_position': np.array([0, 0]),
|
203
|
+
},
|
204
|
+
),
|
205
|
+
(
|
206
|
+
'two_fingers',
|
207
|
+
2,
|
208
|
+
{
|
209
|
+
'action_type': np.array(action_type_lib.ActionType.LIFT),
|
210
|
+
'touch_position': np.array([0, 0]),
|
211
|
+
'action_type_2': np.array(action_type_lib.ActionType.LIFT),
|
212
|
+
'touch_position_2': np.array([0, 0]),
|
213
|
+
},
|
214
|
+
),
|
215
|
+
)
|
216
|
+
def test_lift_all_fingers_action(
|
217
|
+
self, num_fingers: int, expected_action: dict[str, np.ndarray]
|
218
|
+
):
|
219
|
+
"""Returns the expected action."""
|
220
|
+
|
221
|
+
output = action_fns.lift_all_fingers_action(num_fingers)
|
222
|
+
for k, v in expected_action.items():
|
223
|
+
np.testing.assert_array_equal(v, output[k])
|
224
|
+
|
225
|
+
|
226
|
+
if __name__ == '__main__':
|
227
|
+
absltest.main()
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding=utf-8
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2024 DeepMind Technologies Limited.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -13,14 +13,37 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
"""The different kinds of actions that AndroidEnv supports.
|
16
|
+
"""The different kinds of actions that AndroidEnv supports.
|
17
|
+
|
18
|
+
The native action space of AndroidEnv consists of a tuple consisting of
|
19
|
+
- A position (x, y) ∈ [0, 1] x [0, 1], determining the location of the action on
|
20
|
+
the screen, and
|
21
|
+
- A discrete value, indicating the action type, which is in this file.
|
22
|
+
|
23
|
+
See https://arxiv.org/abs/2105.13231, section 2.2 for details.
|
24
|
+
"""
|
17
25
|
|
18
26
|
import enum
|
19
27
|
|
20
28
|
|
21
29
|
@enum.unique
|
22
30
|
class ActionType(enum.IntEnum):
|
23
|
-
"""Integer values to describe each supported action in AndroidEnv.
|
31
|
+
"""Integer values to describe each supported action in AndroidEnv.
|
32
|
+
|
33
|
+
Note for KEY* types:
|
34
|
+
- Only meaningful if connected to a _physical_ keyboard, _not_ virtual
|
35
|
+
keyboard.
|
36
|
+
- Added afterwards so they did not appear in the paper.
|
37
|
+
|
38
|
+
Attributes:
|
39
|
+
TOUCH: Touching the screen at a location.
|
40
|
+
LIFE: Lifting the (imaginary) pointer from the screen at a location.
|
41
|
+
REPEAT: Repeating the last chosen action.
|
42
|
+
KEYDOWN: Sending a key down event.
|
43
|
+
KEYUP: Sending a key up event.
|
44
|
+
KEYPRESS: Sending a key down event, immediately followed by a key up event.
|
45
|
+
"""
|
46
|
+
|
24
47
|
TOUCH = 0
|
25
48
|
LIFT = 1
|
26
49
|
REPEAT = 2
|