Commit 330bc747 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

NetworkMonitor: Sanity check

parent d650c5d9
Pipeline #13939 passed with stage
in 4 minutes and 19 seconds
......@@ -9,11 +9,13 @@ import android.content.IntentFilter
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import androidx.lifecycle.*
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.ProcessLifecycleOwner
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.consumeAsFlow
import java.lang.ref.WeakReference
import java.net.NetworkInterface
import java.net.SocketException
......@@ -44,10 +46,15 @@ class NetworkMonitor(private val context: Context) : LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun stop() {
if (!registered) return
registered = false
context.unregisterReceiver(receiver)
}
protected fun finalize() {
stop()
}
@SuppressLint("MissingPermission")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private fun updateVPNStatus(): Boolean {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment