Skip to content

fix(android): restore UI after task removal and clarify rejected pairings - #4

Merged
twlite merged 1 commit into
mainfrom
fix/android-activity-recreation
Nov 26, 2026
Merged

twlite merged 1 commit into
mainfrom
fix/android-activity-recreation

Conversation

@twlite

@twlite twlite commented Nov 26, 2026

Copy link
Copy Markdown
Member

Summary

Fixes two Android issues found while the foreground agent was running, plus a small UX addition.

Blank screen after closing from Recents

When the task is swiped away, the foreground service keeps the process alive, but Tauri (2.11 / tao 0.35) drops the main window along with the destroyed activity. Setup never runs again, so the reopened activity stayed blank.

  • MainActivity.onCreate notifies the plugin (OppaActivityHost.onActivityCreated), and the mobile event loop recreates the main window when it's missing (restore_main_window).
  • The plugin tracks the newest live activity (AgentBridge.activity) for intents, notification permission prompts, and the APK installer, instead of Tauri's stale first activity.

Notification stuck on "Connecting…"

The agent could rewrite the status file between the service's first read and the moment FileObserver started. The service now re-reads the file once after it starts watching.

Rejected pairings looked like "unpaired"

A gateway rejection of credential_not_found (for example, the in-memory example server restarted) was shown as a generic "Authentication failed".

  • New credential_not_found connection state with an explanatory message on the setup screen.
  • New Forget connection action (with confirmation) on the pairing recovery screen.

Local credentials were verified to persist across notification Stop, force-stop, and reinstall; the server accepted the same agent ID each time.

Testing

  • cargo test -p oppa (adds a rejection_state mapping test), cargo clippy -p oppa --all-targets -D warnings, pnpm --filter oppa typecheck, pnpm format:check
  • Android arm64 debug APK on the API 33 emulator:
    • swipe from Recents, then reopen: same process, UI restored, agent stays connected
    • Stop from the notification, then cold start: reconnects with the same agent ID
    • three cold starts: notification shows "Connected"
    • restarted example server: new message shown, and Forget connection returns to the unpaired state and stops the service
  • Not verified on a physical device.

🤖 Generated with Claude Code

…ings

- Recreate the main webview window when Android starts a new activity in a
  process the foreground service kept alive; Tauri drops the window with the
  destroyed activity, which left the reopened app blank.
- Track the newest live activity for intents, permission prompts, and the
  APK installer instead of the destroyed first activity.
- Re-read the agent status after the foreground service starts observing it
  so the notification cannot stay on a stale "Connecting" state.
- Add a credential_not_found connection state so a server that no longer
  knows the device is explained instead of shown as a generic failure.
- Offer "Forget connection" on the pairing recovery screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
oppa Skipped Skipped Nov 26, 2026 9:56am UTC

@twlite
twlite merged commit a6e7905 into main Nov 26, 2026
12 checks passed
@twlite
twlite deleted the fix/android-activity-recreation branch November 26, 2026 10:30
twlite added a commit that referenced this pull request Nov 30, 2026
Removing OPPA from Recents while the foreground agent runs destroys the
activity but keeps the process and agent alive. Android may destroy the
replaced activity only after its successor was created, and PR #4's
restore keyed on `get_webview_window("main")` existing, so physical
devices could reopen to a blank screen.

Root causes:
- the stale activity's window still existed when the new activity
  appeared, so no window was created; its late destroy then removed it;
- Wry keys IPC and asset handlers by webview label, so a late destroy
  of the old "main" web view removed the new one's handlers;
- Tauri's process-wide plugin onDestroy reported "activity destroyed"
  for the stale activity and detached native calls for the live one;
- Wry falls back to activity id 0 for launch intents with extras.

Fix:
- Kotlin activity registry: process-unique Wry ids, generation-tagged
  activityCreated/activityDestroyed events with a live count, replay on
  channel attach, and intents and permission prompts on the live activity;
- `ui_lifecycle.rs`: a tested state machine that gives each activity
  generation its own window, ignores duplicate and stale events, keeps
  the window across configuration changes, waits for the frontend's
  `report_interface_ready`, and replaces a window that never reports
  ready (at most three attempts), with concise logcat diagnostics;
- vendored tao 0.35.3 and wry 0.55.1 with documented fixes for a lost
  event-loop wake-up that left new web views uncreated, a main-thread
  self-deadlock (ANR) and unwrap panics in Wry's main pipe, and IPC
  rejected as `about:blank` during recreation.

Verified on Android 13 (release) and Android 15 (debug) emulators: 25-40
consecutive recreations with late destroys, notification reopen, config
changes, lock, stop, force-stop and background-disabled flows. The process,
agent identity and gateway session stay unchanged and every job prints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
Preview — da82c890 Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant