[Android] NetworkMonitor: Sanity check
Geoffrey Métais
git at videolan.org
Fri Feb 21 14:34:20 CET 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 20 15:32:53 2020 +0100| [330bc747236b0db972ddbbba195aa9d9ac9efb9e] | committer: Geoffrey Métais
NetworkMonitor: Sanity check
> https://code.videolan.org/videolan/vlc-android/commit/330bc747236b0db972ddbbba195aa9d9ac9efb9e
---
.../tools/src/main/java/org/videolan/tools/NetworkMonitor.kt | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/application/tools/src/main/java/org/videolan/tools/NetworkMonitor.kt b/application/tools/src/main/java/org/videolan/tools/NetworkMonitor.kt
index 532b80638..3ad31a61a 100644
--- a/application/tools/src/main/java/org/videolan/tools/NetworkMonitor.kt
+++ b/application/tools/src/main/java/org/videolan/tools/NetworkMonitor.kt
@@ -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 {
More information about the Android
mailing list