Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

fix(screen): stop wasting turns on a tree-blind app — held swipes, zoom before send

booboosuie4855a475853
diff --git a/app/src/main/java/net/kuafuai/andee/net/CommandDispatcher.kt b/app/src/main/java/net/kuafuai/andee/net/CommandDispatcher.kt
index d6e93fe..3a78c41 100644
--- a/app/src/main/java/net/kuafuai/andee/net/CommandDispatcher.kt
+++ b/app/src/main/java/net/kuafuai/andee/net/CommandDispatcher.kt
@@ -1189,7 +1189,8 @@ class CommandDispatcher(
val x2 = params.getInt("x2");
val y2 = params.getInt("y2")
val dur = params.optLong("duration_ms", 300L)
- passthroughForGesture { requireScreen().swipeNorm(x1, y1, x2, y2, dur) }
+ val fling = params.optBoolean("fling", false)
+ passthroughForGesture { requireScreen().swipeNorm(x1, y1, x2, y2, dur, fling) }
}
"screen.long_press" -> {
diff --git a/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt b/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt
index 0cf0cf6..c4fad83 100644
--- a/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt
+++ b/app/src/main/java/net/kuafuai/andee/net/ToolSchemas.kt
@@ -271,20 +271,21 @@ object ToolSchemas {
tool(
name = "swipe_by_coordinates",
method = "screen.swipe",
- description = "Swipe from one point to another: scroll lists, page carousels, drag things. To scroll a list DOWN (see more content below), swipe from a point near the BOTTOM UP to a point near the TOP — fingers move opposite to content. All coordinates are RELATIVE 0-1000 like tap_by_coordinates. Duration controls speed: shorter = faster fling.",
+ description = "Swipe from one point to another: scroll lists, page carousels, drag things. To scroll a list DOWN (see more content below), swipe from a point near the BOTTOM UP to a point near the TOP — fingers move opposite to content. All coordinates are RELATIVE 0-1000 like tap_by_coordinates.\n\nBy default the finger stops at the end point before lifting, so the list moves about as far as the finger did and then stays put — no momentum. That makes the distance the control: to bring something 300 units further up into view, swipe 300 units. Set fling=true only to travel far (jump many screens through a long feed); a fling coasts on unpredictably, so take a fresh look afterwards rather than assuming where it stopped.",
required = listOf("x1", "y1", "x2", "y2"),
props = mapOf(
"x1" to prop("integer", "Start X, 0 (left) to 1000 (right)."),
"y1" to prop("integer", "Start Y, 0 (top) to 1000 (bottom)."),
"x2" to prop("integer", "End X, 0 (left) to 1000 (right)."),
"y2" to prop("integer", "End Y, 0 (top) to 1000 (bottom)."),
- "duration_ms" to prop("integer", "How long the swipe takes, in ms. Default 300.", default = 300),
+ "duration_ms" to prop("integer", "How long the finger takes to travel, in ms. Default 300.", default = 300),
+ "fling" to prop("boolean", "Lift while still moving, so the list keeps coasting. Default false.", default = false),
),
),
tool(
name = "type_text",
method = "screen.type",
- description = "Type text into the CURRENTLY FOCUSED input field (tap the field first — by e-number — then call this as the very next action; the keyboard opens by itself, do not re-tap the field). Existing content is REPLACED, not appended. Does not press Enter/Send — use submit_input for that.",
+ description = "Type text into the CURRENTLY FOCUSED input field (tap the field first — by e-number — then call this as the very next action; the keyboard opens by itself, do not re-tap the field). Existing content is REPLACED, not appended. Does not press Enter/Send — use submit_input for that.\n\nWhen a tap opened an input bar by itself — a reply/comment box sliding up with the keyboard (WeChat Moments 评论, a chat's reply bar) — the field is ALREADY focused: call this straight away, without tapping the field. On an app that hides its element tree this matters double: the input strip above the keyboard is thin and sits right on top of the post or message below it, so a tap aimed at it by grid cell lands on that content instead and opens it. This tool does not need the tree — it types through the editor's own input connection — so `performed: true` with the text read back is proof it went into the box.",
required = listOf("text"),
props = mapOf(
"text" to prop("string", "The text to enter."),
@@ -293,7 +294,7 @@ object ToolSchemas {
tool(
name = "submit_input",
method = "screen.submit_input",
- description = "Submit the currently focused input by firing its IME action (Enter / Send / Search / Next / Done — whichever the field was set up for). Typical uses: send a chat message after type_text, run a search. Use this instead of trying to press a keyboard Enter key — Android delivers 'Enter/Send' through this action, not a raw keystroke.",
+ description = "Submit the currently focused input by firing its IME action (Enter / Send / Search / Next / Done — whichever the field was set up for). Typical uses: send a chat message after type_text, run a search. Use this instead of trying to press a keyboard Enter key — Android delivers 'Enter/Send' through this action, not a raw keystroke.\n\nIt works only when the field itself declares a send/search action; many comment and reply boxes do not and send only from their own button (WeChat's comment box is one — this errors there, and that is the answer, not a fault). In that case tap the app's Send/发送 button — and on an app that hides its tree, zoom_screen_region on that button FIRST and tap with on=\"zoom\": the button sits in a thin strip right on top of the content below, and the device refuses a plain grid-cell tap right after typing there.",
required = emptyList(),
props = emptyMap(),
),
@@ -325,9 +326,17 @@ object ToolSchemas {
right on a grid line; this view is centred on the aim, so they are
never cut in half.
- The other form is x/y marking the region's CENTER in the usual
- 0-1000 space plus w/h for its size (try 200x300 for one control,
- 400x600 for a card) — a plain magnified look, no crosshair.
+ The other form is x/y marking the region's CENTER plus w/h for its
+ size (try 200x300 for one control, 400x600 for a card) — a plain
+ magnified look, no crosshair. All four are 0-1000 of the WHOLE SCREEN,
+ never pixels of an image you were shown: a screenshot arrives
+ downscaled (often ~576 wide as you see it), so a position measured in
+ its pixels is the wrong number here. Read the position off the grid
+ instead — cell D is 375-500 across, row 7 is 500-583 down, each column
+ 125 wide and each row ~83 tall — or simply use the cell form above,
+ which needs no numbers at all. Every zoom reports the screen rectangle
+ it actually showed (`region`); if that is not where you meant to look,
+ your numbers were in the wrong space.
This image is a magnified region, and it carries the SAME 8x12 grid in
LOWERCASE (a1..h12), labels at each cell's centre, so a label read off
@@ -346,10 +355,10 @@ object ToolSchemas {
props = mapOf(
"cell" to prop("string", "Grid cell of the full screenshot you are about to tap, e.g. \"D7\". Replaces x/y/w/h."),
"part" to propEnum("Which third of that cell — the same part you would tap. Omit for the centre.", ScreenController.PARTS),
- "x" to prop("integer", "Region center X, 0 (left) to 1000 (right). Use instead of cell."),
- "y" to prop("integer", "Region center Y, 0 (top) to 1000 (bottom). Use instead of cell."),
- "w" to prop("integer", "Region width in 0-1000 units, e.g. 200."),
- "h" to prop("integer", "Region height in 0-1000 units, e.g. 300."),
+ "x" to prop("integer", "Region center X, 0 (left) to 1000 (right) of the whole screen — not image pixels. Use instead of cell."),
+ "y" to prop("integer", "Region center Y, 0 (top) to 1000 (bottom) of the whole screen — not image pixels. Use instead of cell."),
+ "w" to prop("integer", "Region width in screen 0-1000 units, e.g. 200."),
+ "h" to prop("integer", "Region height in screen 0-1000 units, e.g. 300."),
),
),
tool(
@@ -417,6 +426,14 @@ object ToolSchemas {
pixel location) and after a tap that seemed to do nothing — a ring
sitting beside the button is a different problem from a ring on a
button that did not respond.
+
+ YOUR OWN BALL IS NEVER IN A SCREENSHOT. The device hides its floating
+ ball and every card of its own for the instant of capture, and moves
+ the ball aside when a tap would land under it. So a round shape, a
+ face or a blue character in the picture belongs to the app — an
+ avatar, a sticker, an article's cover image — and is never you, and
+ never something covering a button. If a button seems hidden, scroll
+ it into a clearer spot; do not route around the ball.
""".trimIndent(),
required = emptyList(),
props = emptyMap(),
diff --git a/app/src/main/java/net/kuafuai/andee/screen/A11yIme.kt b/app/src/main/java/net/kuafuai/andee/screen/A11yIme.kt
index 3d1e48f..4e58276 100644
--- a/app/src/main/java/net/kuafuai/andee/screen/A11yIme.kt
+++ b/app/src/main/java/net/kuafuai/andee/screen/A11yIme.kt
@@ -91,9 +91,28 @@ object A11yIme {
info.imeOptions and EditorInfo.IME_MASK_ACTION
}
if (action == 0 || action == EditorInfo.IME_ACTION_NONE) return false
+ // The editor's own "Enter must not act" — WeChat's comment box declares
+ // DONE with this flag and sends only from its button. Firing DONE there
+ // reports success and sends nothing.
+ if (info.actionId == 0 && info.imeOptions and EditorInfo.IME_FLAG_NO_ENTER_ACTION != 0) return false
return runCatching { conn.performEditorAction(action); true }.getOrDefault(false)
}
+ /** An editor is focused and bound to our input connection right now. */
+ fun editing(service: AccessibilityService): Boolean = connection(service) != null
+
+ /**
+ * The focused editor says Enter must not act (`IME_FLAG_NO_ENTER_ACTION`) and
+ * names no custom action — it sends only from its own button. On such a field
+ * `ACTION_IME_ENTER` still answers true while doing nothing (WeChat's comment
+ * box, measured 2026-10-19).
+ */
+ fun sendsOnlyFromButton(service: AccessibilityService): Boolean {
+ if (connection(service) == null) return false
+ val info = runCatching { service.inputMethod?.currentInputEditorInfo }.getOrNull() ?: return false
+ return info.actionId == 0 && info.imeOptions and EditorInfo.IME_FLAG_NO_ENTER_ACTION != 0
+ }
+
// ---- internals ----
/**
diff --git a/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt b/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt
index d9a4892..d834ee5 100644
--- a/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt
+++ b/app/src/main/java/net/kuafuai/andee/screen/ScreenController.kt
@@ -197,6 +197,14 @@ class ScreenController(
@Volatile
private var zoomAtMs = 0L
+ /**
+ * Set when [typeText] puts text into an editor on a tree-blind app; cleared by
+ * the next tap. While set, a tap that was not aimed off a fresh zoom is
+ * refused — see [requireAimedSend].
+ */
+ @Volatile
+ private var typedBlindAt = 0L
+
private class Aim(val nx: Int, val ny: Int, val label: String)
private fun cellLabel(col: Int, row: Int): String = "${('A' + col)}${row + 1}"
@@ -309,6 +317,7 @@ class ScreenController(
fun tapAim(on: String?, x: Int?, y: Int?, cell: String?, part: String?): JSONObject {
val a = resolveAim(on, x, y, cell, part)
+ requireAimedSend(on, cell)
val s = if (treeBlind()) snapToShape(a.nx, a.ny) else null
val nx = s?.nx ?: a.nx
val ny = s?.ny ?: a.ny
@@ -328,6 +337,39 @@ class ScreenController(
private class Snap(val nx: Int, val ny: Int, val moved: Boolean, val distPx: Int, val signature: FloatArray?)
+ /**
+ * The tap after typing on a tree-blind app is almost always "send", and its
+ * button sits in a strip a few dozen px tall directly on top of the content it
+ * replies to — on WeChat Moments a grid-cell guess landed on the shared article
+ * below in two runs out of two, opening it and leaving the comment unsent. A
+ * zoom taken after the typing is the only image that shows the strip at a size
+ * a model can hit, so until a zoom-aimed tap lands, every other tap is refused
+ * with that instruction. Expires after [SEND_AIM_WINDOW_MS] so a task that typed
+ * and moved on is not haunted by it.
+ */
+ private fun requireAimedSend(on: String?, cell: String?) {
+ val typed = typedBlindAt
+ if (typed == 0L) return
+ typedBlindAt = 0L
+ if (SystemClock.uptimeMillis() - typed > SEND_AIM_WINDOW_MS) return
+ // The box is gone (sent, dismissed, app left): nothing to protect.
+ if (!A11yIme.editing(service)) return
+ val fromZoom = on?.trim()?.lowercase() == "zoom" ||
+ (on.isNullOrBlank() && cell != null && cell.any { it.isLetter() } &&
+ cell.trim().all { it.isLowerCase() || !it.isLetter() })
+ if (fromZoom && zoomAtMs > typed) return
+ // Stays armed until a zoom-aimed tap clears it, or the next blind tap sails through.
+ typedBlindAt = typed
+ throw IllegalStateException(
+ "refused: you just typed into a box on an app that hides its tree, and this tap " +
+ "was not aimed off a fresh zoom. The Send button and the input sit in a thin " +
+ "strip right on top of the post/message below — a grid-cell tap here lands on " +
+ "that content and opens it, losing the send. NEXT: zoom_screen_region on the " +
+ "Send button (cell + part), then tap with on=\"zoom\" from THAT image. If you " +
+ "meant to tap something other than Send, the same applies: zoom first."
+ )
+ }
+
/** A tree of a handful of nodes says nothing about what is on screen — see [BLIND_TREE_NODES]. */
private fun treeBlind(): Boolean {
val root = runCatching { activeRoot() }.getOrNull() ?: return false
@@ -635,7 +677,7 @@ class ScreenController(
return out
}
- fun swipeNorm(nx1: Int, ny1: Int, nx2: Int, ny2: Int, durationMs: Long): JSONObject {
+ fun swipeNorm(nx1: Int, ny1: Int, nx2: Int, ny2: Int, durationMs: Long, fling: Boolean): JSONObject {
requireNorm(nx1, "x1"); requireNorm(ny1, "y1")
requireNorm(nx2, "x2"); requireNorm(ny2, "y2")
// Not a sample, but it moves everything on screen: without it the
@@ -646,6 +688,7 @@ class ScreenController(
nx1.toPixel(screenW), ny1.toPixel(screenH),
nx2.toPixel(screenW), ny2.toPixel(screenH),
durationMs,
+ fling,
)
}
@@ -1222,20 +1265,47 @@ class ScreenController(
}
}
- fun swipe(x1: Int, y1: Int, x2: Int, y2: Int, durationMs: Long): JSONObject {
+ /**
+ * Unless [fling], the finger holds still at the end before lifting. A stroke
+ * that lifts while moving hands the list its full release velocity, and a
+ * 400 ms swipe over 40% of the screen coasted the WeChat feed several screens
+ * past the post being aimed at (measured 2026-10-19). Held, the content moves
+ * about as far as the finger did. The hold is a continued stroke rather than
+ * a longer duration because release velocity is distance/duration — slowing
+ * the stroke shrinks the coast but never removes it.
+ */
+ fun swipe(x1: Int, y1: Int, x2: Int, y2: Int, durationMs: Long, fling: Boolean): JSONObject {
val path = Path().apply {
moveTo(x1.toFloat(), y1.toFloat())
lineTo(x2.toFloat(), y2.toFloat())
}
- val stroke = GestureDescription.StrokeDescription(path, 0L, durationMs)
val target = android.graphics.Rect(
minOf(x1, x2) - 4, minOf(y1, y2) - 4,
maxOf(x1, x2) + 4, maxOf(y1, y2) + 4,
)
val result = guardedGesture(target) {
- runGesture(GestureDescription.Builder().addStroke(stroke).build(), durationMs + 2000)
+ if (fling) {
+ val stroke = GestureDescription.StrokeDescription(path, 0L, durationMs)
+ runGesture(GestureDescription.Builder().addStroke(stroke).build(), durationMs + 2000)
+ } else {
+ val move = GestureDescription.StrokeDescription(path, 0L, durationMs, true)
+ val moved = runGesture(GestureDescription.Builder().addStroke(move).build(), durationMs + 2000)
+ if (moved.optBoolean("completed")) {
+ val still = Path().apply { moveTo(x2.toFloat(), y2.toFloat()) }
+ // A cancelled hold still leaves the list where the finger put it:
+ // ACTION_CANCEL ends a scroll without a fling.
+ runGesture(
+ GestureDescription.Builder()
+ .addStroke(move.continueStroke(still, 0L, SWIPE_HOLD_MS, false))
+ .build(),
+ SWIPE_HOLD_MS + 2000,
+ )
+ }
+ moved
+ }
}
return result.put("from", "$x1,$y1").put("to", "$x2,$y2").put("duration_ms", durationMs)
+ .put("fling", fling)
}
fun longPress(x: Int, y: Int, durationMs: Long): JSONObject {
@@ -1303,10 +1373,28 @@ class ScreenController(
root.recycle()
}
if (focused == null) {
+ // A withheld tree has no focus node to find, but an editor bound to our
+ // input connection is still there to type into.
+ if (A11yIme.editing(service)) {
+ typeViaA11yIme(text, secret)?.let { return markBlindTyping(it) }
+ }
throw IllegalStateException("no input focus (tap into an input field first)")
}
runCatching { if (focused !== root) focused.recycle() }
- return typeViaA11yIme(text, secret) ?: typeViaAdbKeyboard(text, secret)
+ return markBlindTyping(typeViaA11yIme(text, secret) ?: typeViaAdbKeyboard(text, secret))
+ }
+
+ private fun markBlindTyping(r: JSONObject): JSONObject {
+ if (r.optBoolean("performed") && treeBlind()) {
+ typedBlindAt = SystemClock.uptimeMillis()
+ r.put(
+ "next",
+ "Text is in the box. To send: if a Send/发送 button is visible, zoom_screen_region on it " +
+ "first and tap with on=\"zoom\" — a plain grid-cell tap is refused here, because this " +
+ "strip sits on top of the content below and a missed tap opens that instead.",
+ )
+ }
+ return r
}
/**
@@ -1520,6 +1608,32 @@ class ScreenController(
* When `id` is null we use the currently focused input.
*/
fun submitInput(id: String?): JSONObject {
+ if (id == null && A11yIme.sendsOnlyFromButton(service)) {
+ throw IllegalStateException(
+ "this field has no keyboard send action — it sends only from its own Send/发送 " +
+ "button. Tap that button" +
+ (if (treeBlind()) ": zoom_screen_region on it first and tap with on=\"zoom\"." else ".")
+ )
+ }
+ // An app that withholds its tree (WeChat on the Honor phone) has no focus
+ // node to find, yet its editor is still bound to our input connection —
+ // type_text reaches it that way. Ask the editor for its own action before
+ // calling that a failure.
+ if (id == null) {
+ val r = service.rootInActiveWindow
+ val focus = r?.findFocus(AccessibilityNodeInfo.FOCUS_INPUT)
+ focus?.recycle()
+ r?.recycle()
+ if (focus == null) {
+ if (A11yIme.editorAction(service)) {
+ return JSONObject().put("performed", true).put("via", A11yIme.VIA)
+ }
+ throw IllegalStateException(
+ "no input focus, and the focused editor (if any) declares no Send/Search action — " +
+ "tap into the field first, or tap the app's own send button"
+ )
+ }
+ }
val root = service.rootInActiveWindow ?: throw IllegalStateException("no active window")
try {
val target: AccessibilityNodeInfo = if (id != null) {
@@ -1565,6 +1679,8 @@ class ScreenController(
* caller that can't be the user, is also the one that never passes it.
*/
fun globalAction(action: String, actor: String = "brain"): JSONObject {
+ // Leaving the screen ends whatever was being typed into.
+ typedBlindAt = 0L
val code = when (action.lowercase()) {
"back" -> AccessibilityService.GLOBAL_ACTION_BACK
"home" -> AccessibilityService.GLOBAL_ACTION_HOME
@@ -1729,7 +1845,9 @@ class ScreenController(
"first send the same cell and part to zoom_screen_region: it " +
"shows a red crosshair where the tap would land, so you can " +
"confirm it or re-aim off the magnified image. The grid lines " +
- "and labels are drawn by the device and are not part of the app.",
+ "and labels are drawn by the device and are not part of the app. " +
+ "Your own floating ball is hidden for every capture, so nothing " +
+ "round or blue in this picture is you or is covering a button.",
)
}
// Piggyback the element list. The brain's known failure mode
@@ -3057,6 +3175,12 @@ class ScreenController(
/** The relative coordinate space the brain speaks: 0..1000 both axes. */
private const val NORM_MAX = 1000
+ /** How long after blind typing the zoom-before-send rule holds — see [requireAimedSend]. */
+ private const val SEND_AIM_WINDOW_MS = 120_000L
+
+ /** How long a non-fling swipe holds at its end point — see [swipe]. */
+ private const val SWIPE_HOLD_MS = 150L
+
/**
* Screenshot long side after downscale (generic_bridge value).
*