mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 11:08:31 +00:00
Only show connection warning if not actively connected.
This commit is contained in:
@@ -2,12 +2,11 @@ package org.thoughtcrime.securesms.dependencies
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import io.reactivex.rxjava3.core.Observable
|
|
||||||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||||
import io.reactivex.rxjava3.subjects.Subject
|
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import org.signal.core.util.billing.BillingApi
|
import org.signal.core.util.billing.BillingApi
|
||||||
import org.signal.core.util.concurrent.DeadlockDetector
|
import org.signal.core.util.concurrent.DeadlockDetector
|
||||||
|
import org.signal.core.util.concurrent.LatestValueObservable
|
||||||
import org.signal.core.util.resettableLazy
|
import org.signal.core.util.resettableLazy
|
||||||
import org.signal.libsignal.net.Network
|
import org.signal.libsignal.net.Network
|
||||||
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations
|
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations
|
||||||
@@ -209,14 +208,14 @@ object AppDependencies {
|
|||||||
provider.provideBillingApi()
|
provider.provideBillingApi()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _webSocketObserver: Subject<WebSocketConnectionState> = BehaviorSubject.create()
|
private val _webSocketObserver: BehaviorSubject<WebSocketConnectionState> = BehaviorSubject.create()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An observable that emits the current state of the WebSocket connection across the various lifecycles
|
* An observable that emits the current state of the WebSocket connection across the various lifecycles
|
||||||
* of the [signalWebSocket].
|
* of the [signalWebSocket].
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val webSocketObserver: Observable<WebSocketConnectionState> = _webSocketObserver
|
val webSocketObserver: LatestValueObservable<WebSocketConnectionState> = LatestValueObservable(_webSocketObserver)
|
||||||
|
|
||||||
private val _networkModule = resettableLazy {
|
private val _networkModule = resettableLazy {
|
||||||
NetworkDependenciesModule(application, provider, _webSocketObserver)
|
NetworkDependenciesModule(application, provider, _webSocketObserver)
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ import io.reactivex.rxjava3.schedulers.Schedulers
|
|||||||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||||
import org.thoughtcrime.securesms.crash.CrashConfig
|
import org.thoughtcrime.securesms.crash.CrashConfig
|
||||||
import org.thoughtcrime.securesms.database.LogDatabase
|
import org.thoughtcrime.securesms.database.LogDatabase
|
||||||
|
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||||
import org.thoughtcrime.securesms.notifications.DeviceSpecificNotificationConfig.ShowCondition
|
import org.thoughtcrime.securesms.notifications.DeviceSpecificNotificationConfig.ShowCondition
|
||||||
import org.thoughtcrime.securesms.util.ConnectivityWarning
|
import org.thoughtcrime.securesms.util.ConnectivityWarning
|
||||||
import org.thoughtcrime.securesms.util.NetworkUtil
|
import org.thoughtcrime.securesms.util.NetworkUtil
|
||||||
|
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.time.Duration.Companion.days
|
import kotlin.time.Duration.Companion.days
|
||||||
|
|
||||||
@@ -72,8 +74,9 @@ class VitalsViewModel(private val context: Application) : AndroidViewModel(conte
|
|||||||
|
|
||||||
val timeSinceLastConnection = System.currentTimeMillis() - SignalStore.misc.lastWebSocketConnectTime
|
val timeSinceLastConnection = System.currentTimeMillis() - SignalStore.misc.lastWebSocketConnectTime
|
||||||
val timeSinceLastConnectionWarning = System.currentTimeMillis() - SignalStore.misc.lastConnectivityWarningTime
|
val timeSinceLastConnectionWarning = System.currentTimeMillis() - SignalStore.misc.lastConnectivityWarningTime
|
||||||
|
val connectedToWebSocket = AppDependencies.webSocketObserver.value == WebSocketConnectionState.CONNECTED
|
||||||
|
|
||||||
if (ConnectivityWarning.isEnabled && timeSinceLastConnection > ConnectivityWarning.threshold && timeSinceLastConnectionWarning > 14.days.inWholeMilliseconds && NetworkUtil.isConnected(context) && SignalStore.account.isRegistered) {
|
if (ConnectivityWarning.isEnabled && timeSinceLastConnection > ConnectivityWarning.threshold && timeSinceLastConnectionWarning > 14.days.inWholeMilliseconds && NetworkUtil.isConnected(context) && SignalStore.account.isRegistered && !connectedToWebSocket) {
|
||||||
return@fromCallable if (ConnectivityWarning.isDebugPromptEnabled) {
|
return@fromCallable if (ConnectivityWarning.isDebugPromptEnabled) {
|
||||||
State.PROMPT_DEBUGLOGS_FOR_CONNECTIVITY_WARNING
|
State.PROMPT_DEBUGLOGS_FOR_CONNECTIVITY_WARNING
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 Signal Messenger, LLC
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.signal.core.util.concurrent
|
||||||
|
|
||||||
|
import io.reactivex.rxjava3.core.Observable
|
||||||
|
import io.reactivex.rxjava3.core.Observer
|
||||||
|
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Observer that provides instant access to the latest emitted value.
|
||||||
|
* Basically a read-only version of [BehaviorSubject].
|
||||||
|
*/
|
||||||
|
class LatestValueObservable<T : Any>(private val subject: BehaviorSubject<T>) : Observable<T>() {
|
||||||
|
val value: T?
|
||||||
|
get() = subject.value
|
||||||
|
|
||||||
|
override fun subscribeActual(observer: Observer<in T>) {
|
||||||
|
subject.subscribe(observer)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user