pull/1710/head
SessionHero01 4 weeks ago
parent 84d775cd06
commit 54ec9e5d10
No known key found for this signature in database

@ -44,7 +44,7 @@ import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.Namespace
import org.session.libsignal.utilities.Snode
import org.session.libsignal.utilities.retryWithUniformInterval
import org.thoughtcrime.securesms.util.InternetConnectivity
import org.thoughtcrime.securesms.util.NetworkConnectivity
import javax.inject.Inject
private const val TAG = "ConfigUploader"
@ -64,7 +64,7 @@ class ConfigUploader @Inject constructor(
private val configFactory: ConfigFactoryProtocol,
private val storageProtocol: StorageProtocol,
private val clock: SnodeClock,
private val internetConnectivity: InternetConnectivity,
private val networkConnectivity: NetworkConnectivity,
private val textSecurePreferences: TextSecurePreferences,
) {
private var job: Job? = null
@ -77,7 +77,7 @@ class ConfigUploader @Inject constructor(
* The value pushed doesn't matter as nothing is emitted when the conditions are not met.
*/
@OptIn(ExperimentalCoroutinesApi::class)
private fun pathBecomesAvailable(): Flow<*> = internetConnectivity.networkAvailable
private fun pathBecomesAvailable(): Flow<*> = networkConnectivity.networkAvailable
.flatMapLatest { hasNetwork ->
if (hasNetwork) {
OnionRequestAPI.hasPath.filter { it }

@ -1,6 +1,5 @@
package org.thoughtcrime.securesms.groups
import dagger.Lazy
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
@ -25,8 +24,6 @@ import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.scan
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.supervisorScope
import org.session.libsession.database.StorageProtocol
import org.session.libsession.messaging.groups.GroupManagerV2
import org.session.libsession.snode.SnodeClock
import org.session.libsession.utilities.ConfigUpdateNotification
import org.session.libsession.utilities.TextSecurePreferences
@ -35,7 +32,7 @@ import org.session.libsignal.utilities.AccountId
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.dependencies.ConfigFactory
import org.thoughtcrime.securesms.util.AppVisibilityManager
import org.thoughtcrime.securesms.util.InternetConnectivity
import org.thoughtcrime.securesms.util.NetworkConnectivity
import javax.inject.Inject
import javax.inject.Singleton
@ -59,7 +56,7 @@ class GroupPollerManager @Inject constructor(
clock: SnodeClock,
preferences: TextSecurePreferences,
appVisibilityManager: AppVisibilityManager,
connectivity: InternetConnectivity,
connectivity: NetworkConnectivity,
groupRevokedMessageHandler: GroupRevokedMessageHandler,
) {
@Suppress("OPT_IN_USAGE")

@ -2,10 +2,8 @@
import android.Manifest
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Bundle
@ -53,18 +51,10 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.canhub.cropper.CropImageContract
import com.squareup.phrase.Phrase
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import network.loki.messenger.BuildConfig
import network.loki.messenger.R
import network.loki.messenger.databinding.ActivitySettingsBinding
@ -103,7 +93,6 @@ import org.thoughtcrime.securesms.ui.theme.PreviewTheme
import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.theme.ThemeColors
import org.thoughtcrime.securesms.ui.theme.dangerButtonColors
import org.thoughtcrime.securesms.util.InternetConnectivity
import org.thoughtcrime.securesms.util.push
import java.io.File
import javax.inject.Inject

@ -36,7 +36,7 @@ import org.thoughtcrime.securesms.preferences.SettingsViewModel.AvatarDialogStat
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints
import org.thoughtcrime.securesms.util.BitmapDecodingException
import org.thoughtcrime.securesms.util.BitmapUtil
import org.thoughtcrime.securesms.util.InternetConnectivity
import org.thoughtcrime.securesms.util.NetworkConnectivity
import java.io.File
import java.io.IOException
import javax.inject.Inject
@ -46,7 +46,7 @@ class SettingsViewModel @Inject constructor(
@ApplicationContext private val context: Context,
private val prefs: TextSecurePreferences,
private val configFactory: ConfigFactory,
private val connectivity: InternetConnectivity,
private val connectivity: NetworkConnectivity,
) : ViewModel() {
private val TAG = "SettingsViewModel"

@ -43,7 +43,7 @@ import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.TYPE_IN
import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.TYPE_INCOMING_RINGING
import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.TYPE_OUTGOING_RINGING
import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.WEBRTC_NOTIFICATION
import org.thoughtcrime.securesms.util.InternetConnectivity
import org.thoughtcrime.securesms.util.NetworkConnectivity
import org.thoughtcrime.securesms.webrtc.AudioManagerCommand
import org.thoughtcrime.securesms.webrtc.CallManager
import org.thoughtcrime.securesms.webrtc.CallViewModel
@ -219,7 +219,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener {
lateinit var callManager: CallManager
@Inject
lateinit var internetConnectivity: InternetConnectivity
lateinit var networkConnectivity: NetworkConnectivity
private var wantsToAnswer = false
private var currentTimeouts = 0
@ -335,7 +335,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener {
registerUncaughtExceptionHandler()
GlobalScope.launch {
internetConnectivity.networkAvailable.collectLatest(::networkChange)
networkConnectivity.networkAvailable.collectLatest(::networkChange)
}
}

@ -17,10 +17,12 @@ import javax.inject.Inject
import javax.inject.Singleton
/**
* Provides a flow that emits `true` when the device has internet connectivity and `false` otherwise.
* Provides a flow that emits `true` when the device has network connectivity. We won't be sure
* if there's internet or not, it's by designed so that we don't get false negatives in censorship
* countries.
*/
@Singleton
class InternetConnectivity @Inject constructor(application: Application) {
class NetworkConnectivity @Inject constructor(application: Application) {
val networkAvailable = callbackFlow {
val connectivityManager = application.getSystemService(ConnectivityManager::class.java)
Loading…
Cancel
Save