Skip to content

fix(android): app splitting ONLY mode don't mix allowed/disallowed apps - #143

Merged
therealaleph merged 1 commit into
therealaleph:mainfrom
dazzling-no-more:fix/split_tunneling_android
Apr 24, 2026
Merged

therealaleph merged 1 commit into
therealaleph:mainfrom
dazzling-no-more:fix/split_tunneling_android

Conversation

@dazzling-no-more

Copy link
Copy Markdown
Contributor

Problem

VpnService.Builder treats addAllowedApplication() and addDisallowedApplication() as mutually exclusive — calling both on one Builder makes establish() throw IllegalArgumentException. The existing code unconditionally calls addDisallowedApplication(packageName) (the mandatory self-exclude) before the split-mode when block, then calls addAllowedApplication() for each selected package in ONLY mode. Result: establish() fails silently, the TUN never comes up, and the app either fails to start or regresses to an unrouted state — which manifests to the user as "ONLY mode doesn't work, everything still tunnels (or nothing does)".

The existing code comment at MhrvVpnService.kt:176-180 already acknowledges the mutual exclusivity — but the implementation doesn't respect it.

Fix

Move the mandatory self-exclude inside the when (cfg.splitMode) block:

  • ALL / EXCEPT: keep calling addDisallowedApplication(packageName) — no conflict with other disallowed entries.
  • ONLY: skip the explicit self-exclude entirely. Self-exclusion is implicit, since our own package is not in the allow-list. Also skip our own packageName inside the allow-list loop as a defensive guard against a user selecting mhrv-rs itself.
  • ONLY with empty list: fall back to the self-exclude so establish() still succeeds instead of creating a zero-app VPN.

@therealaleph

Copy link
Copy Markdown
Owner

Reviewed carefully — this is a real bug and the fix is correct.

The underlying issue verified: VpnService.Builder.addAllowedApplication() and addDisallowedApplication() are explicitly documented as mutually exclusive on the same Builder — calling both throws IllegalArgumentException at establish() time. The existing code unconditionally added addDisallowedApplication(packageName) before the split-mode switch, which poisoned ONLY mode regardless of what the user selected. The code comment already admitted this in the body but the implementation didn't enforce it.

Your fix matches the documented intent:

  • ALL / EXCEPT: self-exclude via addDisallowedApplication — correct, these modes can stack disallows.
  • ONLY (non-empty list): skip the self-exclude entirely; we're not in the allow-list so exclusion is implicit. Defensive if (pkg == packageName) continue in the allow-list loop is a nice touch — handles the edge case where a user accidentally selects mhrv-rs itself.
  • ONLY (empty list): fall back to self-exclude so establish() creates a working (if useless) VPN rather than failing with a zero-app allow-list. Correct — the warning log already tells the user what happened.

Verified locally:

Merging. Thanks for catching this — the "ONLY mode silently fails" behaviour would have been painful to diagnose from user reports, and it was baked into the current code since splitting was added.


[reply via Anthropic Claude | reviewed by @therealaleph]

@therealaleph
therealaleph merged commit 8817b0a into therealaleph:main Apr 24, 2026
therealaleph added a commit that referenced this pull request Apr 24, 2026
Rolls up the four post-v1.2.14 commits on main into a single tagged
release. Highlights:

- Per-deployment concurrency (#142): each deployment ID gets its own
  30-permit semaphore, so setups with deployments across multiple
  Google accounts get a genuine 30×N throughput ceiling. Single-account
  setups still cap at Google's per-account 30-simultaneous limit —
  docs (EN + FA) updated to call that out.
- Android app-splitting ONLY-mode bug fix (#143): the previous code
  called both addAllowedApplication and addDisallowedApplication,
  which Android documents as mutually exclusive. ONLY mode was
  silently failing establish(). Now fixed.
- Per-ABI Android APKs (#136): ships four split APKs (arm64-v8a ~21 MB,
  armeabi-v7a ~18 MB, x86_64 ~23 MB, x86 ~22 MB) alongside the ~53 MB
  universal. Huge distribution win for users on unreliable
  censorship-tunnel paths — the 21 MB arm64-v8a download succeeds
  where the universal doesn't.
- Honest IP-exposure note in Security Posture (#148): clarified that
  v1.2.9's forwarded-header stripping only covers the client-side leg;
  what Google's own infrastructure may add on the UrlFetchApp.fetch()
  second leg is outside this client's control. Full Tunnel mode is
  the recommendation for threat models where that matters.
- Telegram release-post format: added Persian preambles above both
  links (GitHub repo + full Persian guide; release page + desktop/
  router builds) so channel readers see the intent at a glance.

82 tests pass. Desktop + Android builds both verified clean locally
across the v1.2.15+ commit series.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@dazzling-no-more
dazzling-no-more deleted the fix/split_tunneling_android branch April 24, 2026 20:19
therealaleph added a commit that referenced this pull request Apr 24, 2026
Rolls up #150 + #151 + #153 (all merged on main) into a tagged release.

Highlights:

- Full Tunnel mode opens new HTTPS connections ~500-2000 ms faster
  (#153). The new connect_data tunnel op bundles the client's first
  bytes (typically TLS ClientHello) with the CONNECT call, eliminating
  one full Apps Script round trip per new flow. Backward compat is
  handled via UNSUPPORTED_OP detection + sticky AtomicBool fallback +
  pending_client_data replay so older deployments keep working without
  byte loss. New `connect_data preread: X win / Y loss / Z skip`
  metric in logs lets us measure the win ratio empirically.
- Android ONLY-mode split fix (#150): when the allow-list contained
  only mhrv-rs or stale uninstalled packages, every
  addAllowedApplication call silently failed and Android applied the
  TUN to every app — looping our own proxy traffic. Now we count
  successful adds; if zero, we fall back to ALL-mode self-exclusion.
  Complements PR #143 which fixed the empty-list case.
- Memory-safety cap on relay range stitching (#151): a hostile or
  buggy origin could advertise an absurd Content-Range total
  (e.g. 10 GiB) and force range-parallel to plan millions of chunks
  and preallocate a huge stitched buffer. Now capped at 64 MiB; larger
  totals fall back to a normal single GET.

Tests: 91 lib tests pass (was 82; +1 from #151, +8 from #153).
Tunnel-node: 6 tests pass (all new from #153).

Local Android build verified — universal + four per-ABI APKs all
produced at expected sizes (universal 53 MB, arm64-v8a 21 MB,
armeabi-v7a 18 MB, x86_64 23 MB, x86 22 MB). Installed on mhrv_test
emulator, app launches and renders correctly with v1.4.0 in title.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
therealaleph added a commit that referenced this pull request Apr 25, 2026
…roid

fix(android): app splitting ONLY mode don't mix allowed/disallowed apps
therealaleph added a commit that referenced this pull request Apr 25, 2026
Rolls up the four post-v1.2.14 commits on main into a single tagged
release. Highlights:

- Per-deployment concurrency (#142): each deployment ID gets its own
  30-permit semaphore, so setups with deployments across multiple
  Google accounts get a genuine 30×N throughput ceiling. Single-account
  setups still cap at Google's per-account 30-simultaneous limit —
  docs (EN + FA) updated to call that out.
- Android app-splitting ONLY-mode bug fix (#143): the previous code
  called both addAllowedApplication and addDisallowedApplication,
  which Android documents as mutually exclusive. ONLY mode was
  silently failing establish(). Now fixed.
- Per-ABI Android APKs (#136): ships four split APKs (arm64-v8a ~21 MB,
  armeabi-v7a ~18 MB, x86_64 ~23 MB, x86 ~22 MB) alongside the ~53 MB
  universal. Huge distribution win for users on unreliable
  censorship-tunnel paths — the 21 MB arm64-v8a download succeeds
  where the universal doesn't.
- Honest IP-exposure note in Security Posture (#148): clarified that
  v1.2.9's forwarded-header stripping only covers the client-side leg;
  what Google's own infrastructure may add on the UrlFetchApp.fetch()
  second leg is outside this client's control. Full Tunnel mode is
  the recommendation for threat models where that matters.
- Telegram release-post format: added Persian preambles above both
  links (GitHub repo + full Persian guide; release page + desktop/
  router builds) so channel readers see the intent at a glance.

82 tests pass. Desktop + Android builds both verified clean locally
across the v1.2.15+ commit series.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
therealaleph added a commit that referenced this pull request Apr 25, 2026
Rolls up #150 + #151 + #153 (all merged on main) into a tagged release.

Highlights:

- Full Tunnel mode opens new HTTPS connections ~500-2000 ms faster
  (#153). The new connect_data tunnel op bundles the client's first
  bytes (typically TLS ClientHello) with the CONNECT call, eliminating
  one full Apps Script round trip per new flow. Backward compat is
  handled via UNSUPPORTED_OP detection + sticky AtomicBool fallback +
  pending_client_data replay so older deployments keep working without
  byte loss. New `connect_data preread: X win / Y loss / Z skip`
  metric in logs lets us measure the win ratio empirically.
- Android ONLY-mode split fix (#150): when the allow-list contained
  only mhrv-rs or stale uninstalled packages, every
  addAllowedApplication call silently failed and Android applied the
  TUN to every app — looping our own proxy traffic. Now we count
  successful adds; if zero, we fall back to ALL-mode self-exclusion.
  Complements PR #143 which fixed the empty-list case.
- Memory-safety cap on relay range stitching (#151): a hostile or
  buggy origin could advertise an absurd Content-Range total
  (e.g. 10 GiB) and force range-parallel to plan millions of chunks
  and preallocate a huge stitched buffer. Now capped at 64 MiB; larger
  totals fall back to a normal single GET.

Tests: 91 lib tests pass (was 82; +1 from #151, +8 from #153).
Tunnel-node: 6 tests pass (all new from #153).

Local Android build verified — universal + four per-ABI APKs all
produced at expected sizes (universal 53 MB, arm64-v8a 21 MB,
armeabi-v7a 18 MB, x86_64 23 MB, x86 22 MB). Installed on mhrv_test
emulator, app launches and renders correctly with v1.4.0 in title.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.

2 participants