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.
Running Gotcha
A step-by-step guide to build, run, and configure the Gotcha Android app.
1. Prerequisites
| Requirement | Version / Notes |
|---|---|
| Android Studio | 2025.2 (Otter) or newer — this project uses AGP 9.3.1 / Gradle 9.5.0 / Kotlin 2.2.10 |
| JDK | 17+ to run the build (Gradle 9.5 / AGP 9.3 require it; current Android Studio bundles JDK 21). The project compiles to Java 17 bytecode |
| Android SDK | Platform 34 (Android 14) installed via SDK Manager |
| A device | A physical phone or an emulator running API 30 (Android 11) or higher |
A fresh clone has no local.properties — it is gitignored, so it is never
committed. Android Studio writes one pointing at your SDK the first time it
syncs the project, which is usually all you need.
To build from the command line before ever opening Android Studio, create it
yourself at the repo root (beside settings.gradle.kts):
# Windows
sdk.dir=C\:\\Users\\you\\AppData\\Local\\Android\\Sdk
# Linux
#sdk.dir=/home/you/Android/Sdk
# macOS
#sdk.dir=/Users/you/Library/Android/sdk
Keep each # at the start of its own line — in a .properties file a #
mid-line is part of the value, not a comment. Backslashes are escaped; forward
slashes work too.
Alternatively, set ANDROID_HOME in your environment and skip the file.
2. Open and build the project
- Launch Android Studio → File → Open → select the project root
(
.../Gotcha). Open the folder itself, not a subfolder. - Wait for Gradle sync to finish (bottom status bar). First sync downloads dependencies and may take a few minutes.
- If prompted to install SDK Platform 34 or build tools, accept.
If sync succeeds, app appears as a run configuration in the toolbar.
Samosa endpoints (optional, developers only)
This repository ships with inert placeholder endpoints, so a fresh checkout builds and runs but cannot reach the Samosa backend — "Samosa AI" sign-in will not work until you supply real values. Everything else, including the OpenAI-compatible provider flow, works out of the box.
Three build-time values control it:
| Variable | Placeholder | What it is |
|---|---|---|
SAMOSA_API_URL |
https://api.samosa-ai.example |
API root, no trailing slash. /v1/ and the auth root are derived from it. |
SAMOSA_SKILL_HOST |
samosa-ai.example |
Host allowed for community-skill imports |
SAMOSA_WEB_CLIENT_ID |
YOUR_GOOGLE_WEB_CLIENT_ID.… |
Google WEB OAuth client ID (not the Android one) |
Supply them either way — environment variables take precedence, so CI can override a developer's file:
# Option A — environment (per shell, nothing on disk)
export SAMOSA_API_URL="https://api.example.com"
export SAMOSA_SKILL_HOST="example.com"
export SAMOSA_WEB_CLIENT_ID="1234567890-abcdef.apps.googleusercontent.com"
./gradlew installDebug
# Option B — local.properties at the repo root (gitignored, persists across shells)
SAMOSA_API_URL=https://api.example.com
SAMOSA_SKILL_HOST=example.com
SAMOSA_WEB_CLIENT_ID=1234567890-abcdef.apps.googleusercontent.com
They are read in app/build.gradle.kts and exposed as BuildConfig.SAMOSA_*.
Changing either source triggers a rebuild of BuildConfig automatically.
Never commit real values.
local.propertiesis gitignored and the generatedBuildConfig.javalives underapp/build/, which is also ignored — but note the values are compiled into any APK you build, so treat a release APK built with real endpoints accordingly.
3. Get a device ready
Option A — Emulator (easiest):
- Tools → Device Manager → Create Device.
- Pick e.g. Pixel 7, then a system image with API 30+ (API 34 recommended). Prefer a Google APIs / Play image so the dialer, wallpaper, and other apps exist.
- Start the emulator (▶ in Device Manager).
Option B — Physical phone:
- On the phone: Settings → About phone, tap Build number 7× to enable Developer options.
- Settings → System → Developer options → USB debugging: ON.
- Plug in via USB and accept the "Allow USB debugging" prompt.
4. Run the app
- Select the
appconfiguration and your device/emulator in the toolbar. - Click Run ▶ (or
Shift+F10). - The app installs and launches. On first launch it opens the Settings screen because no API key is configured yet.
Command-line alternative
From the project root:
./gradlew assembleDebug # builds app/build/outputs/apk/debug/app-debug.apk
./gradlew installDebug # builds + installs onto the connected device
./gradlew testDebugUnitTest # runs the JVM unit tests
./gradlew detekt lintDebug # static analysis (detekt + Android Lint)
Continuous integration
The GitHub Actions workflow (.github/workflows/ci.yml) runs detekt → JVM unit
tests → Android Lint → assembleDebug, attaching test and analysis reports to
each run as artifacts. Automatic triggers are disabled to conserve Actions
budget, so it runs only when started manually from the Actions tab
(workflow_dispatch), on any branch.
Detekt and lint have no baselines — the whole repository must pass both
checks on every run, so any new finding fails CI immediately.
The unit tests shell out to a POSIX sh (TerminalTool), so they need Linux,
macOS, or Git Bash — on plain Windows they fail; use CI instead.
On-disk layout
All Gotcha-managed files on shared storage live under one root, data/GotchaStorage.kt:
/storage/emulated/0/Gotcha/
chats/<Slug_shortId>/ <- agent working dir (cwd for file tools)
Pictures/ <- camera captures
Recordings/ <- audio captures written via an explicit output_path
Screenshots/ <- agent read_screen_raw captures
.debug/ <- perception overlay dumps
calls/<sessionId>/ <- voice-call working dirs
old_chats/<Slug_shortId>/ <- archived on chat delete
Screenshots/ <- assistive-ball + Lens captures
Downloads/
Audio recordings started without an explicit output_path are the one exception: they go to the
device's public Recordings/ folder (via MediaStore on API 29+) so they are findable like any
other device recording, independent of which chat produced them.
Chat folders are named slug(title)_<first 8 chars of the session UUID> and renamed in place
when the title becomes known. Deleting a chat moves its working directory to old_chats/ instead
of deleting it.
5. Configure the LLM (required before chatting)
The app talks to any OpenAI-compatible /chat/completions endpoint. On the
Settings screen fill in three fields:
| Field | What to enter |
|---|---|
| API key | Your provider's secret key. Stored encrypted on-device (EncryptedSharedPreferences); never logged. |
| Base URL | The API root including /v1/, e.g. https://api.openai.com/v1/. A trailing slash is added automatically if missing. |
| Model name | The model id the provider expects, e.g. gpt-4o. |
The app calls POST {baseUrl}chat/completions, so the Base URL must be the part
before chat/completions.
Example provider settings
| Provider | Base URL | Example model |
|---|---|---|
| OpenAI | https://api.openai.com/v1/ |
gpt-4o |
| OpenRouter | https://openrouter.ai/api/v1/ |
openai/gpt-4o |
| Groq | https://api.groq.com/openai/v1/ |
llama-3.3-70b-versatile |
| Local (llama.cpp / LM Studio / Ollama's OpenAI shim) | http://10.0.2.2:<port>/v1/ (see note) |
model as served |
Emulator → localhost: an Android emulator reaches the host machine at
10.0.2.2, not127.0.0.1. So a server on your PC's port 1234 ishttp://10.0.2.2:1234/v1/from inside the emulator.Cleartext HTTP: the app currently allows
httpsfor sure; if you use a plainhttp://local endpoint and requests fail with a cleartext error, you need to enable cleartext traffic (see Troubleshooting).
Verify the connection
- Tap Test connection. It sends a cheap "ping" request and shows a centred
overlay —
Testing connection…while it runs, then✓ Connected: …on success or the error on failure, which fades out after ~2.5 s. - Tap Save. Then ← Back to reach the chat screen. Chat input stays disabled until a key is saved.
Whichever tool the model chooses, the model itself must support tool/function calling — most modern hosted models do.
6. Use it
Type natural-language requests. Examples:
What's my battery level?How much free storage do I have?Switch to dark mode.Dial +49 151 23456789(opens the dialer; you press call)List the files in my downloads folderSet a random wallpaperRun: getprop ro.build.version.releaseSwitch to dark mode and tell me my free storage(triggers two tool calls, then one summary)
Permissions & confirmations
- Sensitive actions (dial, wallpaper, cache clear, write file, run command, set brightness) pop an Allow / Deny dialog. You can disable this in Settings → Confirm sensitive actions.
- Confirmations while another app is in front (e.g. the accessibility tools
after
open_apphands control to Settings): the Allow / Deny prompt is drawn as a floating overlay on top of that app, so it stays visible and the agent doesn't block behind it. This needs the "Display over other apps" permission — grant it once for Gotcha, otherwise the confirmation falls back to the in-app dialog and, if it can't be shown, times out after 60 s (treated as a decline) rather than hanging. - Permissions are requested on first use. If you deny one, the assistant
explains what's needed instead of crashing. Two need manual grants:
- Storage (reading Downloads/Pictures/etc.): a standard runtime prompt.
- Set brightness (
WRITE_SETTINGS): the app deep-links you to Settings → Special app access → Modify system settings. Enable it for Gotcha, then ask again.
Notes on specific tools
- Dark mode changes the app theme on Android 12+; on older versions it reports that you must toggle it in system Settings.
- Wi-Fi opens the system Wi-Fi panel (apps can't toggle Wi-Fi directly on modern Android).
- run_command runs as the unprivileged app user (no root). Many system paths
are unreadable; destructive commands (
rm -r,dd,reboot,su, …) are blocked, with a 15 s timeout and 32 KB output cap. - run_termux_command runs inside Termux's user-space, which gives you a
real Linux shell with
pkg/apt, Python, git, compilers and the rest of the Unix tail. It is not a server: no root, no systemd, no kernel access, no persistence between calls, output capped at 32 KB, hard 600 s timeout, and 4 concurrent commands. Long-running processes need to be backgrounded withnohup ... &+disownand can be killed by Doze / battery savers — callsearch_skills('termux_background')for the full pattern. The default Termux mirror is slow or blocked on some networks; ifpkg installhangs, ask the user to open Termux and runtermux-change-repoonce. Seedocs/termux-setup.mdfor the one-time setup walkthrough.
Monitor vs Operator modes
The app has two agent modes you can switch between at any time (even mid-conversation):
- Monitor (read-only) — can inspect, list, and read; cannot create, modify, or delete. Allowed to open apps and open the dialer (intent hand-offs). Safe for exploration.
- Operator (full permissions) — has access to all 56 tools including write, delete, accessibility automation (tap/swipe/type), SMS, calls, alarms, and root commands.
Switch modes using the toggle in the chat screen header. The agent is informed of its current mode via the system prompt on every API call.
Speech (TTS/STT)
A microphone button next to the input field lets you speak instead of type (Speech-to-Text). Each assistant message has a speaker icon to read it aloud (Text-to-Speech). Configure the provider (Android built-in vs OpenAI-compatible API) in Settings. Two toggles decide which replies are spoken automatically:
- Auto-read replies aloud (off by default) speaks every new reply.
- Read aloud replies to voice messages (on by default) speaks the reply to a message you sent with the microphone, even when auto-read is off. Turn it off to dictate quietly; the speaker icon still reads any reply on demand.
Image reading
When the Accessibility Service is enabled, Monitor and Operator can capture the current screen and send it as an image to the LLM for visual understanding. This requires a vision-capable model (GPT-4o, Claude 3.5+, Gemini, etc.).
Accessibility toggle says "Controlled by restricted setting"
If you installed Gotcha from a downloaded APK, Android blocks the Accessibility toggle until you unlock restricted settings for the app:
- Settings → Apps → See all apps → Gotcha
- Tap the ⋮ three-dot menu in the top-right corner of that app-info screen
- Tap Allow restricted settings
- Confirm with PIN/fingerprint if prompted
- Go back to Settings → Accessibility → Gotcha — the toggle now works
Other controls: Clear (top bar) wipes chat history; Clear LLM cache (Settings) drops cached deterministic responses.
7. Troubleshooting
| Symptom | Fix |
|---|---|
| Gradle sync fails on SDK location | Fix sdk.dir in local.properties, or delete the file and re-sync. |
401 after sending a message |
Wrong API key — re-check it in Settings. |
Network problem / cannot reach API |
Check the Base URL (needs /v1/), device connectivity; for emulator→PC use 10.0.2.2. |
Local http:// endpoint blocked as "cleartext not permitted" |
Add android:usesCleartextTraffic="true" to <application> in AndroidManifest.xml (debug only), or use an https endpoint. |
| Model replies but never calls tools | Use a model that supports function calling. |
| Emulator has no Dialer/Wallpaper | Use a Google APIs/Play system image. |
| Accessibility toggle greyed out, "Controlled by restricted setting" | Settings → Apps → See all apps → Gotcha → ⋮ → Allow restricted settings. See Accessibility toggle says "Controlled by restricted setting". |
8. Where things live
- API key & config: encrypted in
SharedPreferences(gotcha_settings). - Chat history:
filesDir/chat_history.json(survives restarts). - Audit log of every tool run:
filesDir/action_log.txt. - LLM response cache:
cacheDir/llm_cache/.
9. Production release checklist
Before publishing to Google Play or distributing a release APK, complete this checklist.
Signing configuration
- Create a release keystore (do NOT use the debug keystore):
keytool -genkey -v -keystore gotcha-release.jks -keyalg RSA -keysize 2048 -validity 10000 -alias gotcha - Store keystore credentials securely in
local.properties(gitignored):RELEASE_STORE_FILE=/path/to/gotcha-release.jks RELEASE_STORE_PASSWORD=your_strong_password RELEASE_KEY_ALIAS=gotcha RELEASE_KEY_PASSWORD=your_strong_password - Verify signing config loads in
app/build.gradle.kts(lines 36-46) - Backup the release keystore — losing it means you cannot update the app
- Never commit the keystore to git (already in
.gitignore)
Samosa AI / Google OAuth setup
- Register release SHA-1 in Google Cloud Console:
- Get the release keystore fingerprint:
keytool -list -v -keystore gotcha-release.jks -alias gotcha - Copy the SHA-1 fingerprint
- Go to Google Cloud Console → APIs & Services → Credentials
- Edit the Android OAuth client (or create a new one)
- Paste the SHA-1 fingerprint
- Get the release keystore fingerprint:
- Update
WEB_CLIENT_IDinSamosaAuthManager.ktif you created a new OAuth client
Build & verify
- Bump version in
app/build.gradle.kts:versionCode = <increment> // e.g. 2 versionName = "0.2.0" // semantic version - Run static analysis:
./gradlew detekt lintDebug - Run unit tests:
./gradlew testDebugUnitTest - Build release APK:
./gradlew assembleRelease - Verify APK signature:
apksigner verify --print-certs app/build/outputs/apk/release/app-release.apk - Test on physical device — install the release APK and verify:
- Samosa AI sign-in works
- OpenAI-compatible mode works
- Tool permissions function correctly
- No crashes on API 30-34 devices
Security verification
- No secrets in source code: search for hardcoded API keys, passwords, or tokens
grep -rn "sk-\|password\|secret\|token\|api_key" app/src/main/java/ --include="*.kt" | grep -v "EncryptedSharedPreferences\|SettingsRepository\|samosaSession\|SamosaAuthApi\|LLMClient" - Keystore not in git: verify
*.keystoreis in.gitignore
Post-release
- Monitor crash reports for signing-related issues
- Rotate secrets if any credentials are compromised
- Document the release in
CHANGELOG.md