Skip to content

feat(android): opt-in LAN web host for phone library sharing - #10

Merged
involvex merged 1 commit into
mainfrom
cursor/android-lan-web-host
Nov 16, 2026
Merged

involvex merged 1 commit into
mainfrom
cursor/android-lan-web-host

Conversation

@involvex

@involvex involvex commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Android Local mode can opt into hosting the existing Axum LAN web UI/API on Wi-Fi (0.0.0.0), with token auth always required and a one-shot migration so old loopback lan_enabled flags do not suddenly expose the network.
  • Adds LanShareForegroundService (separate from download keep-alive) plus Settings UI/docs so phones can share a copy-link/QR web UI while a notification keeps the process alive.

Test plan

  • Desktop: LAN hosting still works; auth toggle still available
  • Android Local: Settings → LAN → Share library on Wi-Fi starts notification and serves http://<phone-ip>:8787/?token=...
  • Another device on same Wi-Fi opens the copied link and can browse/play library
  • Turning share off restores loopback media and stops the LAN notification
  • Fresh/upgraded Android install does not auto-enable network hosting
  • bun run lint, bun run format:check, and cargo check / cargo test as available

Summary by Sourcery

Enable opt-in, authenticated LAN library sharing from Android Local mode while preserving secure defaults and loopback playback when sharing is disabled.

New Features:

  • Enable Android Local mode to host the LAN web UI and API over Wi-Fi for browsing and media sharing from other devices.
  • Add Android LAN sharing controls with tokenized copy links, QR sharing, and a persistent foreground notification to keep hosting available.

Bug Fixes:

  • Prevent legacy Android loopback settings from unintentionally enabling network-wide hosting after upgrades.
  • Restore the loopback media server when Android LAN sharing is disabled.

Enhancements:

  • Require token authentication for Android-hosted LAN access while preserving configurable authentication on desktop.
  • Keep Android LAN-sharing lifecycle separate from download foreground-service notifications.

Documentation:

  • Document Android phones as optional LAN hosts, including setup, authentication, notifications, battery impact, and network limitations.

Tests:

  • Extend Android build validation to require the LAN sharing foreground service and manifest registration.
  • Add coverage confirming the LAN settings tab remains visible on phones.

Allow Android Local mode to bind the existing Axum server on 0.0.0.0 with required token auth and a dedicated foreground service, so other devices can open the same LAN web UI on Wi-Fi.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add the persisted Android migration flag and expose it in the TypeScript settings type so older loopback settings can be distinguished from an explicit LAN-sharing opt-in.

  • src-tauri/src/models.rs L540-543, L796
  • src/lib/types.ts L245-246

API

Allow the Tauri stop-LAN command to await shutdown and make the frontend LAN commands available to mobile runtimes as well as desktop.

  • src-tauri/src/commands.rs L609-610
  • src/lib/api/client.ts L1125-1127, L1133-1134, L1139-1141

Uses of the API

Expose LAN hosting capability for Android Local or standalone mode, and update settings consumers and coverage to reflect that capability.

  • src/lib/runtime.ts L1, L35-40
  • src/lib/settings/capabilities.test.ts L26-29

Implementation

Make Android startup select LAN or loopback hosting based on the opt-in setting, and clear stale Android LAN flags once during migration.

  • src-tauri/src/lib.rs L134-142, L255-271

Implement LAN-host switching, Android token enforcement, foreground-service lifecycle, and restoration of the loopback media server when sharing stops.

  • src-tauri/src/state.rs L1251-1277, L1293-1307, L1346-1356 (+10 small edits)

Add the Android foreground service and plugin commands that keep LAN sharing alive independently of download notifications, with Rust bridge helpers to invoke them.

  • src-tauri/android-overlays/LanShareForegroundService.kt L1-99
  • src-tauri/android-overlays/YtDlpPlugin.kt L462-497
  • src-tauri/src/mobile/lan_share.rs L1-14
  • src-tauri/src/mobile/mod.rs L3-4
  • src-tauri/src/mobile/ytdlp_bridge.rs L408-444

UI

Present Android LAN sharing instructions, required-token messaging, and host-specific controls in Settings while retaining desktop behavior.

  • src/routes/settings/index.tsx L2629-2643, L2659-2663, L2701-2706 (+6 small edits)

Configuration

Install and validate the Android LAN foreground service and register it in the generated Android manifest.

  • scripts/patch-android-lan.ps1 L87-101
  • scripts/patch-android-ytdlp.ps1 L27, L47-50
  • scripts/validate-android-build.ps1 L40, L67-69, L152-154

Documentation

Document Android hosting, setup, URLs, authentication, client use, and platform-specific constraints alongside the existing LAN guide.

  • docs/lan-web.md L3-28, L33-47, L74
  • docs/mobile-android.md L148-179

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@involvex
involvex marked this pull request as ready for review November 16, 2026 06:43
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Sorry @involvex, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

}

private fun buildNotification(title: String, text: String): Notification {
val launch = packageManager.getLaunchIntentForPackage(packageName)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: getLaunchIntentForPackage can return null

packageManager.getLaunchIntentForPackage(packageName) returns null if the app doesn't have a launchable activity (e.g., if the manifest lacks a MAIN/LAUNCHER intent filter). This would make pending null, causing the notification's setContentIntent(pending) to crash or produce a notification that doesn't open the app when tapped.

Suggested change
val launch = packageManager.getLaunchIntentForPackage(packageName)
val launch = packageManager.getLaunchIntentForPackage(packageName) ?: return buildNotification(title, text)

Comment thread src/lib/runtime.ts
lanServer:
runtime === "desktop-tauri" ||
(runtime === "mobile-tauri" &&
isAndroidTauri() &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: lanServer capability includes retired standalone engine mode

The lanServer capability check at lines 36-40 includes settings.engine_mode === "standalone". However, the PR description and bootstrap_mobile_settings in lib.rs (lines 102-107) state that "Standalone" is retired and migrated to "local". Keeping this check could incorrectly enable LAN hosting for users who have stale standalone values in their settings before migration runs.

Suggested change
isAndroidTauri() &&
(runtime === "mobile-tauri" &&
isAndroidTauri() &&
settings.engine_mode === "local"),

#[cfg(target_os = "android")]
{
use serde_json::json;
let _ = with_plugin_state(app, |state| {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Silent error suppression in LAN share keep-alive functions

Both start_lan_share_keep_alive (lines 410-426) and stop_lan_share_keep_alive (lines 428-443) use let _ = with_plugin_state(...) which silently discards any errors from the Kotlin plugin. If the foreground service fails to start/stop (e.g., due to missing manifest registration, permission issues, or plugin not initialized), the Rust side has no visibility and the UI shows no feedback.

Comment thread src-tauri/src/state.rs
*self.lan_server.lock() = Some(server);
settings.lan_enabled = true;
settings.lan_port = port;
if force_auth {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Force-enabling lan_auth_enabled on Android without ensuring a valid token exists

When force_auth is true (Android), the code sets settings.lan_auth_enabled = true at line 1338. However, the token is generated at lines 1320-1323 and could theoretically be empty if generate_token() fails or returns empty. At lines 1340-1344, if the token is empty, settings.lan_token is set to None. This creates an inconsistent state: lan_auth_enabled = true but lan_token = None. The Axum server would then require auth but have no token to validate against, causing all requests to fail.

Suggested change
if force_auth {
if force_auth {
settings.lan_auth_enabled = true;
// Ensure token is never empty when auth is forced
if token.is_empty() {
token = crate::server::generate_token();
}
}

Comment thread src-tauri/src/state.rs
/// Site adapters need this to append `?token=` to the proxy URLs they hand
/// to the WebView.
/// to the WebView (which still hits 127.0.0.1).
pub fn loopback_token(&self) -> Option<String> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Misleading function name loopback_token now returns token for LAN host too

The function loopback_token() at lines 1388-1393 was changed to return the token regardless of whether the server is loopback or LAN (the old code had server.is_loopback().then(...)). The comment says "Token of the RUNNING on-device media server (loopback or Android LAN host)" but the name loopback_token suggests it only returns loopback tokens. Consider renaming to device_server_token() or active_media_token() for clarity.

@kilo-code-bot

kilo-code-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 3
SUGGESTION 1
Issue Details (click to expand)

CRITICAL

File Line Issue
src-tauri/src/state.rs 1337 Force-enabling lan_auth_enabled on Android without ensuring a valid token exists

WARNING

File Line Issue
src-tauri/android-overlays/LanShareForegroundService.kt 59 getLaunchIntentForPackage can return null
src/lib/runtime.ts 39 lanServer capability includes retired standalone engine mode
src-tauri/src/mobile/ytdlp_bridge.rs 414 Silent error suppression in LAN share keep-alive functions

SUGGESTION

File Line Issue
src-tauri/src/state.rs 1388 Misleading function name loopback_token now returns token for LAN host too
Files Reviewed (19 files)
  • src-tauri/src/state.rs - 2 issues
  • src-tauri/android-overlays/LanShareForegroundService.kt - 1 issue
  • src/lib/runtime.ts - 1 issue
  • src-tauri/src/mobile/ytdlp_bridge.rs - 1 issue
  • src-tauri/src/lib.rs - No issues
  • src-tauri/src/commands.rs - No issues
  • src-tauri/src/models.rs - No issues
  • src-tauri/src/mobile/lan_share.rs - No issues
  • src-tauri/src/mobile/mod.rs - No issues
  • src-tauri/android-overlays/YtDlpPlugin.kt - No issues
  • src/lib/api/client.ts - No issues
  • src/lib/types.ts - No issues
  • src/lib/settings/capabilities.test.ts - No issues
  • src/routes/settings/index.tsx - No issues
  • docs/lan-web.md - No issues
  • docs/mobile-android.md - No issues
  • scripts/patch-android-lan.ps1 - No issues
  • scripts/patch-android-ytdlp.ps1 - No issues
  • scripts/validate-android-build.ps1 - No issues

Fix these issues in Kilo Cloud


Reviewed by free · Input: 237.3K · Output: 11.2K · Cached: 1.4M

@involvex
involvex merged commit b698e0c into main Nov 16, 2026
12 checks passed
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