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
@@ -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 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,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