Skills von pixel: autonomous-ai-agents/hermes-a2a software-development/android-debugging-from-termux software-development/termux-go-builds

This commit is contained in:
2026-10-27 01:23:20 +01:00
parent 3b03f4f525
commit 82ab91b0ef
7 changed files with 590 additions and 0 deletions
@@ -0,0 +1,136 @@
---
name: android-debugging-from-termux
description: Debug an Android device from Termux running on the device.
version: 1
author: hermes
license: MIT
metadata:
hermes:
tags: [android, termux, adb, grapheneos, debugging, sync, contacts, tailscale, networking]
related_skills: [systematic-debugging]
---
# Android debugging from Termux (on-device terminal)
## When to Use
- The user asks to debug, sync-fix, or inspect an Android phone, AND the agent's terminal already runs ON that same phone (Termux, non-root).
- The agent needs to reach a peer Android device over LAN (adb over WLAN / wireless debugging from a non-root context).
- Permission denial patterns are blocking diagnosis from Termux: `Permission Denial … DUMP`, `/bin/sh: cannot execute`, empty `dumpsys`/`settings`/`cmd account` output.
Skip this skill when: the terminal is on a separate host and the phone is already attached via USB (plain `adb shell` flow), or the device is rooted (most of §1 does not apply).
Key context that is easy to get wrong:
- The shell is a normal app uid (e.g. `u0_a227`), NOT root.
- GrapheneOS hardening blocks the privileged CLI subset even where stock Android would allow it.
- Termux symlinks `/system/bin/sh` to `/bin/sh` in its PATH, and `/bin/sh` doesn't
exist — any tool that needs `sh` (most Java-based `app_process` wrappers: `content`,
`cmd` on some builds) silently fails with "cannot execute: required file not found".
- `logcat` works fine via absolute path.
## Tailscale / tailnet connectivity
- Non-root Termux tailscaled usually runs `--tun=userspace-networking` → proxy-only (SOCKS5/HTTP on localhost); stock Android browsers don't use local proxies, so browser access to tailnet names needs the official Tailscale app (real VpnService) or a TUN-capable proxy client.
- Full playbook (daemon cmdline, CLI socket trap, MagicDNS name verification, probe-by-name-vs-IP ladder, peer-vs-public reachability): `references/tailscale-termux.md`.
## 1. Which /system/bin tools actually work from a non-root app
| Tool | Status on GrapheneOS (no root) | Notes |
| --- | --- | --- |
| `/system/bin/logcat` | ✅ works | use `-v time`, `-b events\|crash\|system` for coverage |
| `/system/bin/pm list packages` | ✅ works | package inventory only |
| `/system/bin/input` | ✅ works | tap/swipe for UI automation |
| `/system/bin/cmd account list` | ⚠️ often empty | AccountManager refuses listing to unprivileged callers |
| `/system/bin/dumpsys` | ❌ DENIED | `Permission Denial … missing android.permission.DUMP` |
| `/system/bin/settings list` | ❌ often empty | secure/global/system reads require perms |
| `/system/bin/content query` | ❌ broken via `/bin/sh` | fix: call `app_process /system/bin com.android.commands.content.Content …` with `CLASSPATH=/system/framework/content.jar`, but READ_CONTACTS still required |
| `adb` (client) | ✅ works | client is fine; target server is what you connect to |
Rule: use ABSOLUTE paths for any /system/bin tool. The Termux PATH is a lie.
## 2. Live log-capture recipe that actually works
```bash
LOG=$HOME/sync_capture.log # $HOME, never /root (blocked)
/system/bin/logcat -c # clear old noise
# then background:
/system/bin/logcat -v time > "$LOG" 2>&1 &
```
- Start BEFORE the user triggers the action you want to observe
(manual sync, opening Contacts, dialing) — logcat ring buffer is small
(≈512 KiB/main) and rotates fast on a busy phone.
- **SELinux audit lines from Termux itself will dominate** (`avc: denied … app=com.termux
…`). Filter with `grep -ivE 'avc:|audit'`.
- Third-party app classes (DAVx5 `at.bitfire.davdroid`, Nextcloud, etc.) are
loggable, but only for a few seconds before rotation; combine a narrow
`grep -i "davx5\|carddav"` filter with a fast post-hoc pass.
- If an "expected sync" produces **zero** matching lines in a capture that spans
the user's action, the app either wasn't running (`ps -A | grep -i bitfire`) or
its log level is below the buffer window — that's data, act on it.
## 3. Contacts/phone/sms inconsistency — diagnosis ladder
**Symptom:** same person shows different name/number in Phone vs SMS vs Contacts app,
or a newly created contact won't "stick."
**Common root cause (verify, don't assume):** after a GrapheneOS-Backup-Tool restore
into a device that also syncs via DAVx5/Nextcloud, the restored contacts live
**outside** the DAV account (Storage = "local" / none), while
newly-created ones enter DAVx5's provider. Two records for one number → the
Phone/SMS apps pick one record for display, Contacts shows both → apparent "not
synced."
Ladder of checks, cheapest first:
1. **Nextcloud web UI** (user's browser, NOT the phone):
- Is there exactly ONE record for the person?
- What number format does it show (E.164 `+49…` vs local `0…`)?
- Does the record have a storage/label marker for "DAVx5"?
2. **On the device** (once we have a privileged path — see §4):
```
content query --uri content://com.android.contacts/raw_contacts \
--projection raw_id:account_type:account_name
content query --uri content://com.android.contacts/data \
--projection data1:data2:mimetype --where "mimetype='vnd.android.cursor.item/phone_v2'"
```
Look for two `raw_contacts` rows whose `data1` values are numerically equal
after stripping `+`/`0`.
3. **Merge fix** (once identified):
- In Nextcloud web **or** the Contacts app: merge the local dup into the DAV one.
- Force a reindex: Settings → Apps → Contacts → Storage → "Clear cache" (safe — it
just rebuilds the lookup table, does NOT delete contacts).
- Confirm with `adb shell dumpsys contacts | grep -A2 "lookup"` that the
target number now maps to the DAV-owned row id.
Do NOT do: "wipe the Contacts app data" as a first fix. That destroys the
local-side dup (usually your pre-migration contacts) — only do it after you've
confirmed the dup is recoverable from Nextcloud.
## 4. Reaching the phone from your terminal — adb-over-WLAN vs local ADB
**Prefer local ADB when the terminal is on the same device (try FIRST — not verified in the originating session, so treat as a best-effort option):**
1. Phone UI: Settings → System → Developer options → **Local ADB** ON.
2. Termux: `adb devices` → device may appear as `emulator-…` or `localhost:…`.
3. This sidesteps the entire wireless-pairing dance (codes, expiring ports, TLS).
If it doesn't appear, fall back to wireless debugging (§4b) or give the user
the Nextcloud-web diagnosis path (§3.1) instead of burning more pairing attempts.
**Wireless debugging (Settings → Developer options → Wireless debugging):**
- GUI shows a PAIR port (one-time, ephemeral) and a SESSION port (persistent).
- Flow: `adb pair HOST:PAIRPORT <6-digit-code>` then `adb connect HOST:SESSIONPORT`.
- Codes are **one-shot and short-lived** (~1 min). A second attempt with the same
code fails even if the first "failed" — user must open the GUI to regenerate.
- Termux's `adb` (android-tools build) accepts the pairing code as an argument —
`adb pair 192.168.x.y:42805 290347` (see `strings $(which adb)` → `pair HOST[:PORT] [PAIRING CODE]`) —
this avoids the PTY/expect fragility, BUT note that in the originating session BOTH
interactive-PTY and arg-based pairing hit the same `protocol fault` error, so the
code was the likely culprit, not the input method.
- Failure mode we hit: `error: protocol fault (couldn't read status message): Success`
with the pair port closing after code entry and the session port staying open
but `adb connect` failing → root cause is most likely a stale/already-used code
(codes are one-shot, ~1 min TTL) or server-side rate limiting after failed attempts.
**Get a FRESH code+port from the phone GUI, re-pair within ~30 s, then connect.
A fresh code has not been verified as working in the originating session.**
- Sanity checks before suspecting the client:
- `nc -z -w2 HOST PAIRPORT` — closed = code was consumed (good sign), open = GUI still showing (expected)
- `nc -z -w2 HOST SESSIONPORT` — must stay open
- `adb version` — verify android-tools build ≥ 35; older versions had TLS issues with Android 13+ pairing
@@ -0,0 +1,51 @@
# Tailscale / tailnet debugging from Termux (non-root)
Use when the user can't reach a tailnet service (browser, curl, ssh) from the phone and tailscaled runs as a Termux app rather than the official Android app.
## 0. Establish how tailscaled actually runs (before any fix)
```bash
ps -ef | grep tailscaled
cat /proc/<pid>/cmdline | tr '\0' ' '
```
- `--tun=userspace-networking` means the daemon can only offer a local SOCKS5/HTTP proxy (address in `--socks5-server=…`); there is NO device-wide VPN and NO system-DNS interception. Expect stock App-level tailnet access to fail in this mode — the fix is a real VPN path (official Tailscale app) or a TUN-capable proxy client, not curl flags.
- `--socket=<path>` in the cmdline is the source of truth for where the daemon listens; it is often NOT the path the CLI dials by default.
## 1. Wire the CLI to the running daemon (socket-mismatch trap)
CLI keeps erroring `dial unix $PREFIX/tmp/tailscaled.sock: no such file or directory` even though tailscaled is running → it is dialing its default path, not the daemon's socket. Some Termux CLI builds ignore `TS_SOCKET`/`TAILSCALE_SOCKET` and keep using the default; stop chasing env vars and use the symlink, which verified works:
```bash
ln -sF <daemon-sock-from-cmdline> /data/data/com.termux/files/usr/tmp/tailscaled.sock
tailscale status # must now list peers
```
## 2. Verify the NAME before blaming the tunnel
```bash
tailscale status # peer hostnames + 100.64/10 IPs + live state
tailscale status --json | python3 -c 'import sys,json; d=json.load(sys.stdin); print(d["Self"]["DNSName"]; [ (k,v["Hostname"]) for k,v in d["Peers"].items() ]')
```
- MagicDNS peer name form is `<hostname>.ts.<tailnet-domain>` — `Self.DNSName` shows the exact form, don't guess it.
- If the user's typed name isn't a peer (e.g. missing the `.ts.` part), it is very likely a PUBLIC DNS name that just shares the domain. Cross-check with the system resolver (`getent hosts X`, plain `ping X`): if it lands on a non-100.x IP, the traffic was never tailnet traffic — diagnose it as an ordinary web service (redirects, TLS, auth) instead of tunneling.
## 3. Probe reachability through the daemon (works even in userspace mode, no TUN needed)
```bash
# remote-DNS variant (socks5h) makes tailscaled resolve AND route the name;
# -sv to capture the discriminating line
curl --socks5-hostname 127.0.0.1:<socks-port> -sv -o /dev/null --max-time 6 \
http://<target>:<port>/ 2>&1 | grep -iE 'trying|opened|socks|refused|timed|connect'
```
Isolation ladder, cheapest first:
1. **Baseline control**: any public host/IP (e.g. `socks5h://1.1.1.1:443`). FAILs → the proxy itself is down (check the socks port from cmdline is listening) — stop, this is not a peer problem.
2. **Peer by name**: `cannot complete SOCKS5 connection … (1)` while control passed → name or peer path.
3. **Peer by raw 100.x IP** at the same port AND at ports that are usually open (22):
- still failing → the peer/tunnel path itself is broken (wireguard or user-space forwarding), not DNS and not port choice. Do NOT keep guessing ports. Check the peer's live state in `tailscale status` (active vs idle, tx/rx), re-`up`/re-auth, or fall back to the official app for app-level access.
- passing, name failing → DNS record/naming problem, or the service genuinely isn't listening on the guessed port.
4. **Refused vs timeout**: `connection refused` = peer reachable, no listener on that port (harmless — try another port). Timeout or SOCKS-level failure = no route.
## 4. Browser access (stock Chrome on Android)
- Stock Chrome on Android cannot be pointed at a local SOCKS5/HTTP proxy. In userspace-daemon mode, "open <tailnet-name> in Chrome" fails by design — say so directly instead of re-probing.
- Clean fix: install the official Tailscale app (Play Store / F-Droid), log into the same tailnet → device-wide VPN + DNS. Then the correct `<name>.ts.<domain>:<port>` opens in Chrome with no extra config.
- Proxy-only fallback: a SOCKS-capable browser (e.g. Kiwi) or a TUN-mode proxy client (NekoBox/KitsuneBI) importing `socks5 127.0.0.1:<socks-port>`.
## Anti-patterns
- Don't conclude "Tailscale is broken" from a single failed name: verify name validity (§2) and baseline control (§3.1) first — the name may simply not be tailnet traffic.
- Don't blame DNS when the raw-100.x-IP probe also fails — that's a routing/peer problem.
- Don't present a proxy-only (userspace) setup as an app-level workaround: it cannot intercept stock browser traffic, ever.