[Android] Proper fix for NetworkMonitor.stop

Nicolas Pomepuy git at videolan.org
Thu May 7 12:17:01 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon May  4 14:00:00 2020 +0200| [1b3bcce1581f7aa2ea95ac44d7f2a449fd98ecb8] | committer: Nicolas Pomepuy

Proper fix for NetworkMonitor.stop

> https://code.videolan.org/videolan/vlc-android/commit/1b3bcce1581f7aa2ea95ac44d7f2a449fd98ecb8
---

 .../main/java/org/videolan/tools/NetworkMonitor.kt | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 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 8505cff2d..9d9071102 100644
--- a/application/tools/src/main/java/org/videolan/tools/NetworkMonitor.kt
+++ b/application/tools/src/main/java/org/videolan/tools/NetworkMonitor.kt
@@ -31,6 +31,22 @@ class NetworkMonitor(private val context: Context) : LifecycleObserver {
         get() = connection.value.run { connected && !mobile }
     val lanAllowed : Boolean
         get() = connection.value.run { connected && (!mobile || vpn) }
+    val receiver = object : BroadcastReceiver() {
+        @SuppressLint("MissingPermission")
+        override fun onReceive(context: Context?, intent: Intent?) {
+            when (intent?.action) {
+                ConnectivityManager.CONNECTIVITY_ACTION -> {
+                    val networkInfo = cm.activeNetworkInfo
+                    val isConnected = networkInfo != null && networkInfo.isConnected
+                    val isMobile = isConnected && networkInfo!!.type == ConnectivityManager.TYPE_MOBILE
+                    val isVPN = isConnected && updateVPNStatus()
+                    val conn = Connection(isConnected, isMobile, isVPN)
+                    if (connection.value != conn) connection.offer(conn)
+                }
+
+            }
+        }
+    }
 
     init {
         ProcessLifecycleOwner.get().lifecycle.addObserver(this at NetworkMonitor)
@@ -78,22 +94,6 @@ class NetworkMonitor(private val context: Context) : LifecycleObserver {
         }
     }
 
-    val receiver = object : BroadcastReceiver() {
-        @SuppressLint("MissingPermission")
-        override fun onReceive(context: Context?, intent: Intent?) {
-            when (intent?.action) {
-                ConnectivityManager.CONNECTIVITY_ACTION -> {
-                    val networkInfo = cm.activeNetworkInfo
-                    val isConnected = networkInfo != null && networkInfo.isConnected
-                    val isMobile = isConnected && networkInfo!!.type == ConnectivityManager.TYPE_MOBILE
-                    val isVPN = isConnected && updateVPNStatus()
-                    val conn = Connection(isConnected, isMobile, isVPN)
-                    if (connection.value != conn) connection.offer(conn)
-                }
-
-            }
-        }
-    }
     companion object : SingletonHolder<NetworkMonitor, Context>({ NetworkMonitor(it.applicationContext) })
 }
 



More information about the Android mailing list