Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

refactor: update UI input, fix screen coordinate bounds, manage accessibility node lifecycle, and standardize tool definitions and behaviors

Rishabh Bajpai9613f1c2bfab
diff --git a/app/src/main/java/com/gotcha/tools/AppNavigatorSession.kt b/app/src/main/java/com/gotcha/tools/AppNavigatorSession.kt
index d7ba9bf..c45b57c 100644
--- a/app/src/main/java/com/gotcha/tools/AppNavigatorSession.kt
+++ b/app/src/main/java/com/gotcha/tools/AppNavigatorSession.kt
@@ -209,7 +209,7 @@ You are a mobile app navigation agent. Your job is to operate Android apps step
- swipe(direction) or swipe(x1,y1,x2,y2, normalized=true) — swipe/scroll
- input_text(text) — type into the focused field
- press_key(key) — back, home, enter
-- sleep(ms) — wait briefly (max 3000ms)
+- sleep(duration_seconds) — wait briefly (1-3)
- ask_final_answer(answer) — done! Provide the final summary.
"""
}
diff --git a/app/src/main/java/com/gotcha/tools/ScreenPerception.kt b/app/src/main/java/com/gotcha/tools/ScreenPerception.kt
index a313b48..f500f88 100644
--- a/app/src/main/java/com/gotcha/tools/ScreenPerception.kt
+++ b/app/src/main/java/com/gotcha/tools/ScreenPerception.kt
@@ -175,8 +175,8 @@ object ScreenPerception {
}
fun normalizeToPixel(modelX: Int, modelY: Int, displayW: Int, displayH: Int): Pair<Int, Int> {
- val actualX = (modelX.toFloat() / 1000f * displayW).toInt().coerceIn(0, displayW)
- val actualY = (modelY.toFloat() / 1000f * displayH).toInt().coerceIn(0, displayH)
+ val actualX = (modelX.toFloat() / 1000f * displayW).toInt().coerceIn(0, displayW - 1)
+ val actualY = (modelY.toFloat() / 1000f * displayH).toInt().coerceIn(0, displayH - 1)
return Pair(actualX, actualY)
}
@@ -398,7 +398,12 @@ object ScreenPerception {
}
for (i in 0 until node.childCount) {
- collectElements(node.getChild(i), out, max, index)
+ val child = node.getChild(i)
+ try {
+ collectElements(child, out, max, index)
+ } finally {
+ child?.recycle()
+ }
}
}
}
diff --git a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
index b66ef2c..0848c27 100644
--- a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
+++ b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
@@ -1353,7 +1353,7 @@ object ToolDefinitions {
putJsonObject("properties") {
putJsonObject("key") {
put("type", "string")
- put("description", "One of: enter, back, home, recents, notifications, quick_settings, lock_screen, delete, tab, escape.")
+ put("description", "One of: enter, back, home, recents, notifications, quick_settings, lock_screen.")
}
}
putJsonArray("required") { add("key") }
diff --git a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt b/app/src/main/java/com/gotcha/tools/ToolExecutor.kt
index e745391..82f1108 100644
--- a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt
+++ b/app/src/main/java/com/gotcha/tools/ToolExecutor.kt
@@ -348,7 +348,7 @@ class ToolExecutor(
"tap" -> {
var x = args.requireInt("x")
var y = args.requireInt("y")
- val normalized = args.requireBoolean("normalized") ?: false
+ val normalized = args.requireBoolean("normalized") ?: true
if (normalized && x != null && y != null) {
val (w, h) = ScreenPerception.getScreenDimensions()
val (nx, ny) = ScreenPerception.normalizeToPixel(x, y, w, h)
@@ -360,7 +360,7 @@ class ToolExecutor(
direction = args.requireString("direction"),
x1 = args.requireInt("x1"), y1 = args.requireInt("y1"),
x2 = args.requireInt("x2"), y2 = args.requireInt("y2"),
- normalized = args.requireBoolean("normalized") ?: false,
+ normalized = args.requireBoolean("normalized") ?: true,
index = args.requireInt("index")
)
"tap_index" -> {
@@ -370,7 +370,7 @@ class ToolExecutor(
"long_press" -> {
var x = args.requireInt("x")
var y = args.requireInt("y")
- val normalized = args.requireBoolean("normalized") ?: false
+ val normalized = args.requireBoolean("normalized") ?: true
if (normalized && x != null && y != null) {
val (w, h) = ScreenPerception.getScreenDimensions()
val pixelCoords = ScreenPerception.normalizeToPixel(x, y, w, h)
diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
index b6f527e..50b08cf 100644
--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt
@@ -164,10 +164,11 @@ fun SettingsScreen(
onExpandedChange = { modelExpanded = it }
) {
OutlinedTextField(
- value = model.ifEmpty { "(select model)" },
- onValueChange = {},
+ value = model,
+ onValueChange = { model = it },
readOnly = false,
label = { Text("Main model") },
+ placeholder = { Text("(select model)") },
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = modelExpanded) },
modifier = Modifier.fillMaxWidth().menuAnchor()
)