Преглед на файлове

Replace Wi-Fi connection check with WifiManager

Previous implementation couldn't detect Wi-Fi connection while using a VPN.
arkon преди 3 години
родител
ревизия
3155829994

+ 2 - 5
app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt

@@ -21,6 +21,7 @@ import eu.kanade.tachiyomi.util.system.connectivityManager
 import eu.kanade.tachiyomi.util.system.isServiceRunning
 import eu.kanade.tachiyomi.util.system.notification
 import eu.kanade.tachiyomi.util.system.toast
+import eu.kanade.tachiyomi.util.system.wifiManager
 import rx.android.schedulers.AndroidSchedulers
 import rx.schedulers.Schedulers
 import rx.subscriptions.CompositeSubscription
@@ -153,7 +154,7 @@ class DownloadService : Service() {
             return stopDownloads(R.string.download_notifier_no_network)
         }
 
-        if (preferences.downloadOnlyOverWifi() && !networkCapabilities.connectedToWifi()) {
+        if (preferences.downloadOnlyOverWifi() && !wifiManager.isWifiEnabled) {
             stopDownloads(R.string.download_notifier_text_only_wifi)
         } else {
             val started = downloadManager.startDownloads()
@@ -170,10 +171,6 @@ class DownloadService : Service() {
             this.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
     }
 
-    private fun NetworkCapabilities.connectedToWifi(): Boolean {
-        return this.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
-    }
-
     /**
      * Listens to downloader status. Enables or disables the wake lock depending on the status.
      */

+ 4 - 0
app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt

@@ -16,6 +16,7 @@ import android.content.res.Resources
 import android.graphics.Color
 import android.net.ConnectivityManager
 import android.net.Uri
+import android.net.wifi.WifiManager
 import android.os.Build
 import android.os.PowerManager
 import android.provider.Settings
@@ -190,6 +191,9 @@ val Context.notificationManager: NotificationManager
 val Context.connectivityManager: ConnectivityManager
     get() = getSystemService()!!
 
+val Context.wifiManager: WifiManager
+    get() = getSystemService()!!
+
 val Context.powerManager: PowerManager
     get() = getSystemService()!!