Skip to content
Snippets Groups Projects
Commit 330bc747 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

NetworkMonitor: Sanity check

parent d650c5d9
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment