Skip to content

fix: re-verify connectivity when cached state is false before blocking call#1236

Merged
SERDUN merged 1 commit intodevelopfrom
fix/stale-connectivity-blocks-call-after-background
Apr 30, 2026
Merged

fix: re-verify connectivity when cached state is false before blocking call#1236
SERDUN merged 1 commit intodevelopfrom
fix/stale-connectivity-blocks-call-after-background

Conversation

@SERDUN
Copy link
Copy Markdown
Member

@SERDUN SERDUN commented Apr 30, 2026

Problem

On Xiaomi (Android 15 / HyperOS), after restoring the app from background:

  • Signaling shows connected in the UI
  • Attempting to make a call shows: "It seems you are not connected to the internet"
  • Actual network IS connected

Logcat shows the socket opens at ~11:16:36, yet six seconds later the call is blocked with "Cannot create call: no network connectivity" — while the network hardware reports inetCondition = 1.

Root Cause

CallController caches connectivity state in _netConnected: bool?, updated only via connectivityService.connectionStream events.

While the app is in background, Xiaomi (OEM aggressive battery/network management) signals ConnectivityResult.none even when the network interface stays up — setting _netConnected = false. When the app returns to foreground the stream does not immediately re-emit, leaving the cache stale. The call attempt reads the stale false and blocks without re-checking actual network state.

The signaling layer is unaffected because SignalingReconnectController already handles AppLifecycleState.resumed proactively.

Fix

Only trust the cached value when it says true. When the cached value is false or null, always perform a fresh checkConnection() before blocking the call.

// Before
if (_netConnected != null) return _netConnected!;

// After
if (_netConnected == true) return true;

When genuinely offline, checkConnectivity() (native OS call) returns ConnectivityResult.none and short-circuits before the HTTP health check — no meaningful latency added for the truly-offline case.

…g call

OEMs like Xiaomi signal ConnectivityResult.none to backgrounded apps even
when the network interface stays active, setting the cached _netConnected to
false. When the app returns to foreground the stream may not re-emit, leaving
the cache stale. Trusting a cached true is safe (fast path); trusting a cached
false is not — always re-check so a genuine connectivity event can clear it.
@SERDUN SERDUN marked this pull request as ready for review April 30, 2026 08:49
@WebTrit WebTrit deleted a comment from claude Bot Apr 30, 2026
@SERDUN SERDUN requested a review from digiboridev April 30, 2026 08:58
@SERDUN SERDUN merged commit 90f4a63 into develop Apr 30, 2026
2 checks passed
@SERDUN SERDUN deleted the fix/stale-connectivity-blocks-call-after-background branch April 30, 2026 09:04
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