File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
features/networkmonitor/impl/src/main/kotlin/io/element/android/features/networkmonitor/impl Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ class DefaultNetworkMonitor(
4747) : NetworkMonitor {
4848 private val connectivityManager: ConnectivityManager = context.getSystemService(ConnectivityManager ::class .java)
4949
50- override val isNetworkBlocked = MutableStateFlow (false )
50+ override val isNetworkBlocked = MutableStateFlow (NetworkBlockedChecker (connectivityManager).isNetworkBlocked() )
5151 override val isInAirGappedEnvironment = MutableStateFlow (false )
5252
5353 override val connectivity: StateFlow <NetworkStatus > = callbackFlow {
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2026 Element Creations Ltd.
3+ *
4+ * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
5+ * Please see LICENSE files in the repository root for full details.
6+ */
7+
8+ @file:Suppress(" DEPRECATION" )
9+
10+ package io.element.android.features.networkmonitor.impl
11+
12+ import android.annotation.SuppressLint
13+ import android.net.ConnectivityManager
14+ import android.net.NetworkInfo
15+
16+ /* *
17+ * Helper to synchronously check if the active network in [ConnectivityManager] is blocked.
18+ *
19+ * This is extracted to its own class because it uses deprecated APIs (but the only ones that are reliable)
20+ * and we don't want to suppress deprecations everywhere in the file this would be called.
21+ */
22+ class NetworkBlockedChecker (
23+ private val connectivityManager : ConnectivityManager ,
24+ ) {
25+ // The permission is granted by the manifest, false positive
26+ @SuppressLint(" MissingPermission" )
27+ fun isNetworkBlocked (): Boolean {
28+ // This call is deprecated, but it seems like it's the only reliable way to tell if doze has blocked network access
29+ return connectivityManager.activeNetworkInfo?.detailedState == NetworkInfo .DetailedState .BLOCKED
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments