Skip to content

Commit 7fcef1a

Browse files
committed
fix: re-verify connectivity when cached state is false before blocking 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.
1 parent 32e9b77 commit 7fcef1a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

lib/features/call/controllers/call_controller.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ class CallController {
3636
/// don't get confused with signaling connectivity (SIP registration)
3737
/// this is needed to determine what notification to show
3838
Future<bool> get isNetworkConnected async {
39-
// If we already have a connectivity status from the stream, return it immediately.
40-
// For cases if app was initialized and we know our connectivity status, we can avoid the overhead of an additional checkConnection call.
41-
if (_netConnected != null) return _netConnected!;
39+
// Only trust the cached value when it says connected. A cached false may be
40+
// stale — OEMs (e.g. Xiaomi) can signal ConnectivityResult.none while the
41+
// app is backgrounded even when the network interface stays up, and the
42+
// stream may not re-emit after the app returns to the foreground.
43+
if (_netConnected == true) return true;
4244

43-
// But if its null its means app was just launched and we haven't received any connectivity updates yet,
44-
// so we should perform an active check to determine our connectivity status before proceeding with the call.
4545
_netConnected = await connectivityService.checkConnection().timeout(
4646
const Duration(seconds: 5),
4747
onTimeout: () {

0 commit comments

Comments
 (0)