adb-agent-bridge 0.1.0__tar.gz
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.
- adb_agent_bridge-0.1.0/LICENSE +202 -0
- adb_agent_bridge-0.1.0/NOTICE +11 -0
- adb_agent_bridge-0.1.0/PKG-INFO +203 -0
- adb_agent_bridge-0.1.0/README.md +189 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge/__init__.py +85 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge/actions.py +80 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge/cli.py +83 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge/device.py +35 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge/marks.py +54 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge/server.py +44 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge/ui.py +78 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge.egg-info/PKG-INFO +203 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge.egg-info/SOURCES.txt +22 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge.egg-info/dependency_links.txt +1 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge.egg-info/entry_points.txt +2 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge.egg-info/requires.txt +1 -0
- adb_agent_bridge-0.1.0/adb_agent_bridge.egg-info/top_level.txt +1 -0
- adb_agent_bridge-0.1.0/pyproject.toml +22 -0
- adb_agent_bridge-0.1.0/setup.cfg +4 -0
- adb_agent_bridge-0.1.0/tests/test_actions.py +115 -0
- adb_agent_bridge-0.1.0/tests/test_bridge.py +28 -0
- adb_agent_bridge-0.1.0/tests/test_marks.py +53 -0
- adb_agent_bridge-0.1.0/tests/test_server.py +67 -0
- adb_agent_bridge-0.1.0/tests/test_ui.py +72 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
ADB Agent Bridge
|
|
2
|
+
Copyright 2026 Kelvin Lee
|
|
3
|
+
|
|
4
|
+
Developed by Kelvin Lee (https://github.com/kelvincushman/adb-agent-bridge).
|
|
5
|
+
Redistributions of this software must retain this attribution in accordance
|
|
6
|
+
with the Apache License, Version 2.0.
|
|
7
|
+
|
|
8
|
+
The unicode text-input approach was inspired by ADBKeyboard
|
|
9
|
+
(https://github.com/senzhk/ADBKeyBoard). No ADBKeyboard source code is
|
|
10
|
+
included in this project; it is used only as an optional on-device IME,
|
|
11
|
+
driven via its documented broadcast intents.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: adb-agent-bridge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast, accurate agent-to-Android control over plain ADB: semantic UI addressing via uiautomator, no on-device install
|
|
5
|
+
Author: Kelvin Lee
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/kelvincushman/adb-agent-bridge
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Requires-Dist: Pillow>=10.1
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# ADB Agent Bridge
|
|
16
|
+
|
|
17
|
+
Fast, accurate agent→Android control over plain ADB. Nothing to install on the
|
|
18
|
+
device: the accessibility tree Android already exposes via `uiautomator dump`
|
|
19
|
+
gives every element's text, resource-id, content-desc, and bounds — so an AI
|
|
20
|
+
agent taps element centers instead of guessing pixels from screenshots.
|
|
21
|
+
|
|
22
|
+
**Developed by [Kelvin Lee](https://github.com/kelvincushman)** · Apache-2.0
|
|
23
|
+
|
|
24
|
+
## Why this exists
|
|
25
|
+
|
|
26
|
+
This tool came out of running a real fleet of Android phones driven by AI
|
|
27
|
+
agents — [ContentSwarm](https://github.com/kelvincushman/ContentSwarm), an
|
|
28
|
+
open phone-agent framework for content automation, with
|
|
29
|
+
[Orphus](https://github.com/kelvincushman/orphus) as the agent harness
|
|
30
|
+
driving it. The stack we inherited was built the way most phone automation
|
|
31
|
+
is: **for humans watching a screen, not for agents**. Two things made it
|
|
32
|
+
slow and unreliable:
|
|
33
|
+
|
|
34
|
+
- **The blind pixel loop.** Every action meant: capture a 1–2 MB screenshot,
|
|
35
|
+
send it to a vision model, have the model guess an (x, y) coordinate, then
|
|
36
|
+
`input tap` and hope. 2–5 seconds per action, and vision models regress raw
|
|
37
|
+
pixel coordinates poorly — taps missed, flows derailed, retries compounded.
|
|
38
|
+
- **The text dance.** Typing one caption meant swapping the IME with four
|
|
39
|
+
1-second sleeps (~4s per field), and the on-screen keyboard hid the app's
|
|
40
|
+
media picker at exactly the wrong moment.
|
|
41
|
+
|
|
42
|
+
The fix turned out to require almost nothing new. Android already ships the
|
|
43
|
+
whole answer over plain ADB, on every device, with zero on-device install:
|
|
44
|
+
`uiautomator dump` returns the full view hierarchy — the same tree an
|
|
45
|
+
accessibility service sees — as XML. Parse it host-side, find the element by
|
|
46
|
+
its text or id, tap its bounds center. **Element-center taps can't miss.**
|
|
47
|
+
Text goes through a broadcast to [ADBKeyboard](https://github.com/senzhk/ADBKeyBoard)
|
|
48
|
+
in ~100ms, with the IME switched once per session instead of once per field.
|
|
49
|
+
|
|
50
|
+
The guiding principle throughout: *the laziest solution that actually works*.
|
|
51
|
+
No custom accessibility service, no signed APKs, no on-device daemon — until
|
|
52
|
+
measured latency proves one is needed. Every dump is timed
|
|
53
|
+
(`Bridge.device.last_dump_ms`) so that decision is made with data, not vibes.
|
|
54
|
+
|
|
55
|
+
## The three addressing tiers
|
|
56
|
+
|
|
57
|
+
1. **Semantic** (default): `find(text="Post")` → tap the element's center.
|
|
58
|
+
Exact, layout-robust, no vision model in the loop.
|
|
59
|
+
2. **Set-of-Marks / grid** (vision fallback): when the tree is thin (games,
|
|
60
|
+
canvas, some WebViews), `marks()` draws numbered boxes on a screenshot —
|
|
61
|
+
the model picks a number, you tap that element. Or address a 10-column
|
|
62
|
+
grid cell like `"C7"`.
|
|
63
|
+
3. **Raw coordinates**: `tap((x, y))` still works when you need it.
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
pip install "adb-agent-bridge @ git+https://github.com/kelvincushman/adb-agent-bridge"
|
|
69
|
+
# or from a checkout: pip install -e .
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
(Not yet on PyPI — install from git. Pin a commit SHA with `@<sha>` for
|
|
73
|
+
reproducible installs.)
|
|
74
|
+
|
|
75
|
+
Requirements:
|
|
76
|
+
|
|
77
|
+
- `adb` on the host PATH, device with USB debugging enabled.
|
|
78
|
+
- [ADBKeyboard](https://github.com/senzhk/ADBKeyBoard) on the device for fast
|
|
79
|
+
and unicode text input (recommended). Without it, plain-ASCII text still
|
|
80
|
+
works via `input text`.
|
|
81
|
+
|
|
82
|
+
## Quick start
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from adb_agent_bridge import Bridge
|
|
86
|
+
|
|
87
|
+
b = Bridge() # or Bridge("SERIAL") with multiple devices
|
|
88
|
+
b.ui() # -> [Element(text=..., id=..., bounds=...), ...]
|
|
89
|
+
b.find(text="Post") # first element whose text matches
|
|
90
|
+
b.tap(b.find(text="Post")) # taps the element's center — can't miss
|
|
91
|
+
b.tap((540, 1200)) # raw coordinates
|
|
92
|
+
b.tap("C7") # grid cell (10 square columns A-J, rows from 1)
|
|
93
|
+
b.text("hello world") # ~100ms, no IME dance
|
|
94
|
+
b.text("héllo 👋", clear=True) # unicode/emoji; clear empties the field first
|
|
95
|
+
b.swipe(540, 1600, 540, 400) # scroll
|
|
96
|
+
b.key(66) # keyevent (66 = ENTER)
|
|
97
|
+
b.screenshot("screen.png")
|
|
98
|
+
|
|
99
|
+
path, legend = b.marks() # numbered Set-of-Marks screenshot; the
|
|
100
|
+
b.tap(legend[3]) # vision model picks a number, you tap it
|
|
101
|
+
|
|
102
|
+
b.prefetch_ui() # start the next dump in the background
|
|
103
|
+
# ... do other work (e.g. the model decides the next action) ...
|
|
104
|
+
b.ui() # returns the prefetched result instantly
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
CLI (installed as `aab`):
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
aab ui # dump elements, one per line (dump latency on stderr)
|
|
111
|
+
aab tap --text Post # tap by text / --id / --desc
|
|
112
|
+
aab tap --grid C7 # or grid cell, or: aab tap 540 1200
|
|
113
|
+
aab text "a caption" # --clear to empty the field first
|
|
114
|
+
aab marks annotated.png # numbered overlay + legend for the vision fallback
|
|
115
|
+
aab screenshot out.png
|
|
116
|
+
aab swipe 540 1600 540 400
|
|
117
|
+
aab key 66 # keyevent (66 = ENTER)
|
|
118
|
+
aab -s SERIAL ... # pick a device when several are connected
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
After a session, restore the device's normal keyboard with
|
|
122
|
+
`adb shell ime reset` (the bridge leaves ADBKeyboard active for speed).
|
|
123
|
+
|
|
124
|
+
## Measured performance
|
|
125
|
+
|
|
126
|
+
All numbers measured live on a Samsung SM-S721B (Galaxy S24 FE), host on USB:
|
|
127
|
+
|
|
128
|
+
| Operation | Cost | Notes |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| `tap` / `swipe` / `key` | ~0.1s | `input` is cheap on modern Android |
|
|
131
|
+
| `text()` via ADBKeyboard | ~0.1s | any length, any unicode |
|
|
132
|
+
| first `text()` of a session | ~1.5s | one-time IME switch + settle wait |
|
|
133
|
+
| `screenshot()` | ~0.8s | `screencap -p` over exec-out |
|
|
134
|
+
| `ui()` — `uiautomator dump` | **2.1–3.0s** | the bottleneck: fresh uiautomator process per call |
|
|
135
|
+
| `ui()` on very heavy screens | up to ~6s | seen on Facebook Marketplace's tree |
|
|
136
|
+
| old vision loop (replaced) | 2–5s/action | plus missed taps and retries |
|
|
137
|
+
| old IME text dance (replaced) | ~4s/field | now ~0.1s |
|
|
138
|
+
|
|
139
|
+
Two findings worth knowing:
|
|
140
|
+
|
|
141
|
+
- `input text` costs ~35ms **per character** (key events are injected one by
|
|
142
|
+
one), so a 60-char caption takes ~2s. The ADBKeyboard broadcast commits the
|
|
143
|
+
whole string at once — that's why it's the primary text path.
|
|
144
|
+
- Switching the IME and broadcasting immediately drops the text: the IME
|
|
145
|
+
hasn't bound to the field yet. One settle wait after the once-per-session
|
|
146
|
+
switch fixes what the old stack worked around with four sleeps per field.
|
|
147
|
+
|
|
148
|
+
An agent action cycle (dump → find → tap) is therefore ~2.5s, ~95% of it the
|
|
149
|
+
dump. Two ways to attack that, both built in:
|
|
150
|
+
|
|
151
|
+
- **Prefetch** (`prefetch_ui()`): start the next dump right after an action so
|
|
152
|
+
it overlaps the caller's own work — in an agent loop the model's 1–3s of
|
|
153
|
+
thinking hides most of the dump for free. Roughly 2× on real flows, no
|
|
154
|
+
device changes.
|
|
155
|
+
- **The optional fast backend** below: ~5–8× flat, one APK install per device.
|
|
156
|
+
|
|
157
|
+
## Optional fast backend (fleet phones)
|
|
158
|
+
|
|
159
|
+
Plain devices need nothing and keep working unchanged. For sub-second action
|
|
160
|
+
cycles, install [openatx/android-uiautomator-server](https://github.com/openatx/android-uiautomator-server)
|
|
161
|
+
(MIT) on the device and keep its instrumentation running:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
adb install app-uiautomator.apk
|
|
165
|
+
adb install app-uiautomator-test.apk
|
|
166
|
+
adb shell am instrument -w com.github.uiautomator.test/androidx.test.runner.AndroidJUnitRunner
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
It keeps uiautomator alive and serves the same hierarchy XML over HTTP —
|
|
170
|
+
Bridge probes for it once per session (`adb forward` + `/ping`) and uses it
|
|
171
|
+
automatically; `aab ui` reports which backend served the dump, and if the
|
|
172
|
+
server dies mid-session the bridge falls back to plain dumps. Expected dumps:
|
|
173
|
+
~0.1–0.3s instead of 2–3s. **Not yet verified against real hardware** — the
|
|
174
|
+
plain-ADB path remains the default and the regression baseline.
|
|
175
|
+
|
|
176
|
+
## Limitations
|
|
177
|
+
|
|
178
|
+
- Thin or absent view trees (games, canvas-drawn UIs, some WebViews) — use
|
|
179
|
+
the Set-of-Marks / grid fallback tier.
|
|
180
|
+
- `FLAG_SECURE` screens refuse screenshots (banking apps, private modes).
|
|
181
|
+
- `uiautomator dump` can fail mid-animation; the bridge retries once, then
|
|
182
|
+
raises so callers can fall back to the vision tier.
|
|
183
|
+
- Unicode text, `clear=`, and fast typing need ADBKeyboard installed.
|
|
184
|
+
|
|
185
|
+
## Roadmap
|
|
186
|
+
|
|
187
|
+
- **Fleet-phone verification of the fast backend** — the HTTP backend ships
|
|
188
|
+
mock-tested; its first live run happens on a fleet device, not a personal
|
|
189
|
+
phone.
|
|
190
|
+
- **[ContentSwarm](https://github.com/kelvincushman/ContentSwarm)
|
|
191
|
+
integration** — element-target taps, layout-robust flow recording with
|
|
192
|
+
per-replay run reports, a `/ui` endpoint, and prefetch-during-model-thinking
|
|
193
|
+
— lives downstream of this library, driven by
|
|
194
|
+
[Orphus](https://github.com/kelvincushman/orphus) agents.
|
|
195
|
+
|
|
196
|
+
## License & credits
|
|
197
|
+
|
|
198
|
+
Apache-2.0, © 2026 Kelvin Lee. See `LICENSE` and `NOTICE` — redistributions
|
|
199
|
+
must retain the attribution notice.
|
|
200
|
+
|
|
201
|
+
ADBKeyboard by [senzhk](https://github.com/senzhk/ADBKeyBoard) inspired the
|
|
202
|
+
unicode input approach and is driven via its documented broadcast intents.
|
|
203
|
+
This project contains no ADBKeyboard code.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# ADB Agent Bridge
|
|
2
|
+
|
|
3
|
+
Fast, accurate agent→Android control over plain ADB. Nothing to install on the
|
|
4
|
+
device: the accessibility tree Android already exposes via `uiautomator dump`
|
|
5
|
+
gives every element's text, resource-id, content-desc, and bounds — so an AI
|
|
6
|
+
agent taps element centers instead of guessing pixels from screenshots.
|
|
7
|
+
|
|
8
|
+
**Developed by [Kelvin Lee](https://github.com/kelvincushman)** · Apache-2.0
|
|
9
|
+
|
|
10
|
+
## Why this exists
|
|
11
|
+
|
|
12
|
+
This tool came out of running a real fleet of Android phones driven by AI
|
|
13
|
+
agents — [ContentSwarm](https://github.com/kelvincushman/ContentSwarm), an
|
|
14
|
+
open phone-agent framework for content automation, with
|
|
15
|
+
[Orphus](https://github.com/kelvincushman/orphus) as the agent harness
|
|
16
|
+
driving it. The stack we inherited was built the way most phone automation
|
|
17
|
+
is: **for humans watching a screen, not for agents**. Two things made it
|
|
18
|
+
slow and unreliable:
|
|
19
|
+
|
|
20
|
+
- **The blind pixel loop.** Every action meant: capture a 1–2 MB screenshot,
|
|
21
|
+
send it to a vision model, have the model guess an (x, y) coordinate, then
|
|
22
|
+
`input tap` and hope. 2–5 seconds per action, and vision models regress raw
|
|
23
|
+
pixel coordinates poorly — taps missed, flows derailed, retries compounded.
|
|
24
|
+
- **The text dance.** Typing one caption meant swapping the IME with four
|
|
25
|
+
1-second sleeps (~4s per field), and the on-screen keyboard hid the app's
|
|
26
|
+
media picker at exactly the wrong moment.
|
|
27
|
+
|
|
28
|
+
The fix turned out to require almost nothing new. Android already ships the
|
|
29
|
+
whole answer over plain ADB, on every device, with zero on-device install:
|
|
30
|
+
`uiautomator dump` returns the full view hierarchy — the same tree an
|
|
31
|
+
accessibility service sees — as XML. Parse it host-side, find the element by
|
|
32
|
+
its text or id, tap its bounds center. **Element-center taps can't miss.**
|
|
33
|
+
Text goes through a broadcast to [ADBKeyboard](https://github.com/senzhk/ADBKeyBoard)
|
|
34
|
+
in ~100ms, with the IME switched once per session instead of once per field.
|
|
35
|
+
|
|
36
|
+
The guiding principle throughout: *the laziest solution that actually works*.
|
|
37
|
+
No custom accessibility service, no signed APKs, no on-device daemon — until
|
|
38
|
+
measured latency proves one is needed. Every dump is timed
|
|
39
|
+
(`Bridge.device.last_dump_ms`) so that decision is made with data, not vibes.
|
|
40
|
+
|
|
41
|
+
## The three addressing tiers
|
|
42
|
+
|
|
43
|
+
1. **Semantic** (default): `find(text="Post")` → tap the element's center.
|
|
44
|
+
Exact, layout-robust, no vision model in the loop.
|
|
45
|
+
2. **Set-of-Marks / grid** (vision fallback): when the tree is thin (games,
|
|
46
|
+
canvas, some WebViews), `marks()` draws numbered boxes on a screenshot —
|
|
47
|
+
the model picks a number, you tap that element. Or address a 10-column
|
|
48
|
+
grid cell like `"C7"`.
|
|
49
|
+
3. **Raw coordinates**: `tap((x, y))` still works when you need it.
|
|
50
|
+
|
|
51
|
+
## Install
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
pip install "adb-agent-bridge @ git+https://github.com/kelvincushman/adb-agent-bridge"
|
|
55
|
+
# or from a checkout: pip install -e .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
(Not yet on PyPI — install from git. Pin a commit SHA with `@<sha>` for
|
|
59
|
+
reproducible installs.)
|
|
60
|
+
|
|
61
|
+
Requirements:
|
|
62
|
+
|
|
63
|
+
- `adb` on the host PATH, device with USB debugging enabled.
|
|
64
|
+
- [ADBKeyboard](https://github.com/senzhk/ADBKeyBoard) on the device for fast
|
|
65
|
+
and unicode text input (recommended). Without it, plain-ASCII text still
|
|
66
|
+
works via `input text`.
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from adb_agent_bridge import Bridge
|
|
72
|
+
|
|
73
|
+
b = Bridge() # or Bridge("SERIAL") with multiple devices
|
|
74
|
+
b.ui() # -> [Element(text=..., id=..., bounds=...), ...]
|
|
75
|
+
b.find(text="Post") # first element whose text matches
|
|
76
|
+
b.tap(b.find(text="Post")) # taps the element's center — can't miss
|
|
77
|
+
b.tap((540, 1200)) # raw coordinates
|
|
78
|
+
b.tap("C7") # grid cell (10 square columns A-J, rows from 1)
|
|
79
|
+
b.text("hello world") # ~100ms, no IME dance
|
|
80
|
+
b.text("héllo 👋", clear=True) # unicode/emoji; clear empties the field first
|
|
81
|
+
b.swipe(540, 1600, 540, 400) # scroll
|
|
82
|
+
b.key(66) # keyevent (66 = ENTER)
|
|
83
|
+
b.screenshot("screen.png")
|
|
84
|
+
|
|
85
|
+
path, legend = b.marks() # numbered Set-of-Marks screenshot; the
|
|
86
|
+
b.tap(legend[3]) # vision model picks a number, you tap it
|
|
87
|
+
|
|
88
|
+
b.prefetch_ui() # start the next dump in the background
|
|
89
|
+
# ... do other work (e.g. the model decides the next action) ...
|
|
90
|
+
b.ui() # returns the prefetched result instantly
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
CLI (installed as `aab`):
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
aab ui # dump elements, one per line (dump latency on stderr)
|
|
97
|
+
aab tap --text Post # tap by text / --id / --desc
|
|
98
|
+
aab tap --grid C7 # or grid cell, or: aab tap 540 1200
|
|
99
|
+
aab text "a caption" # --clear to empty the field first
|
|
100
|
+
aab marks annotated.png # numbered overlay + legend for the vision fallback
|
|
101
|
+
aab screenshot out.png
|
|
102
|
+
aab swipe 540 1600 540 400
|
|
103
|
+
aab key 66 # keyevent (66 = ENTER)
|
|
104
|
+
aab -s SERIAL ... # pick a device when several are connected
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
After a session, restore the device's normal keyboard with
|
|
108
|
+
`adb shell ime reset` (the bridge leaves ADBKeyboard active for speed).
|
|
109
|
+
|
|
110
|
+
## Measured performance
|
|
111
|
+
|
|
112
|
+
All numbers measured live on a Samsung SM-S721B (Galaxy S24 FE), host on USB:
|
|
113
|
+
|
|
114
|
+
| Operation | Cost | Notes |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| `tap` / `swipe` / `key` | ~0.1s | `input` is cheap on modern Android |
|
|
117
|
+
| `text()` via ADBKeyboard | ~0.1s | any length, any unicode |
|
|
118
|
+
| first `text()` of a session | ~1.5s | one-time IME switch + settle wait |
|
|
119
|
+
| `screenshot()` | ~0.8s | `screencap -p` over exec-out |
|
|
120
|
+
| `ui()` — `uiautomator dump` | **2.1–3.0s** | the bottleneck: fresh uiautomator process per call |
|
|
121
|
+
| `ui()` on very heavy screens | up to ~6s | seen on Facebook Marketplace's tree |
|
|
122
|
+
| old vision loop (replaced) | 2–5s/action | plus missed taps and retries |
|
|
123
|
+
| old IME text dance (replaced) | ~4s/field | now ~0.1s |
|
|
124
|
+
|
|
125
|
+
Two findings worth knowing:
|
|
126
|
+
|
|
127
|
+
- `input text` costs ~35ms **per character** (key events are injected one by
|
|
128
|
+
one), so a 60-char caption takes ~2s. The ADBKeyboard broadcast commits the
|
|
129
|
+
whole string at once — that's why it's the primary text path.
|
|
130
|
+
- Switching the IME and broadcasting immediately drops the text: the IME
|
|
131
|
+
hasn't bound to the field yet. One settle wait after the once-per-session
|
|
132
|
+
switch fixes what the old stack worked around with four sleeps per field.
|
|
133
|
+
|
|
134
|
+
An agent action cycle (dump → find → tap) is therefore ~2.5s, ~95% of it the
|
|
135
|
+
dump. Two ways to attack that, both built in:
|
|
136
|
+
|
|
137
|
+
- **Prefetch** (`prefetch_ui()`): start the next dump right after an action so
|
|
138
|
+
it overlaps the caller's own work — in an agent loop the model's 1–3s of
|
|
139
|
+
thinking hides most of the dump for free. Roughly 2× on real flows, no
|
|
140
|
+
device changes.
|
|
141
|
+
- **The optional fast backend** below: ~5–8× flat, one APK install per device.
|
|
142
|
+
|
|
143
|
+
## Optional fast backend (fleet phones)
|
|
144
|
+
|
|
145
|
+
Plain devices need nothing and keep working unchanged. For sub-second action
|
|
146
|
+
cycles, install [openatx/android-uiautomator-server](https://github.com/openatx/android-uiautomator-server)
|
|
147
|
+
(MIT) on the device and keep its instrumentation running:
|
|
148
|
+
|
|
149
|
+
```sh
|
|
150
|
+
adb install app-uiautomator.apk
|
|
151
|
+
adb install app-uiautomator-test.apk
|
|
152
|
+
adb shell am instrument -w com.github.uiautomator.test/androidx.test.runner.AndroidJUnitRunner
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
It keeps uiautomator alive and serves the same hierarchy XML over HTTP —
|
|
156
|
+
Bridge probes for it once per session (`adb forward` + `/ping`) and uses it
|
|
157
|
+
automatically; `aab ui` reports which backend served the dump, and if the
|
|
158
|
+
server dies mid-session the bridge falls back to plain dumps. Expected dumps:
|
|
159
|
+
~0.1–0.3s instead of 2–3s. **Not yet verified against real hardware** — the
|
|
160
|
+
plain-ADB path remains the default and the regression baseline.
|
|
161
|
+
|
|
162
|
+
## Limitations
|
|
163
|
+
|
|
164
|
+
- Thin or absent view trees (games, canvas-drawn UIs, some WebViews) — use
|
|
165
|
+
the Set-of-Marks / grid fallback tier.
|
|
166
|
+
- `FLAG_SECURE` screens refuse screenshots (banking apps, private modes).
|
|
167
|
+
- `uiautomator dump` can fail mid-animation; the bridge retries once, then
|
|
168
|
+
raises so callers can fall back to the vision tier.
|
|
169
|
+
- Unicode text, `clear=`, and fast typing need ADBKeyboard installed.
|
|
170
|
+
|
|
171
|
+
## Roadmap
|
|
172
|
+
|
|
173
|
+
- **Fleet-phone verification of the fast backend** — the HTTP backend ships
|
|
174
|
+
mock-tested; its first live run happens on a fleet device, not a personal
|
|
175
|
+
phone.
|
|
176
|
+
- **[ContentSwarm](https://github.com/kelvincushman/ContentSwarm)
|
|
177
|
+
integration** — element-target taps, layout-robust flow recording with
|
|
178
|
+
per-replay run reports, a `/ui` endpoint, and prefetch-during-model-thinking
|
|
179
|
+
— lives downstream of this library, driven by
|
|
180
|
+
[Orphus](https://github.com/kelvincushman/orphus) agents.
|
|
181
|
+
|
|
182
|
+
## License & credits
|
|
183
|
+
|
|
184
|
+
Apache-2.0, © 2026 Kelvin Lee. See `LICENSE` and `NOTICE` — redistributions
|
|
185
|
+
must retain the attribution notice.
|
|
186
|
+
|
|
187
|
+
ADBKeyboard by [senzhk](https://github.com/senzhk/ADBKeyBoard) inspired the
|
|
188
|
+
unicode input approach and is driven via its documented broadcast intents.
|
|
189
|
+
This project contains no ADBKeyboard code.
|