From 3155829994348af8325691b1b86f9e89e5eec249 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 27 Aug 2021 15:41:47 -0400 Subject: [PATCH] Replace Wi-Fi connection check with WifiManager Previous implementation couldn't detect Wi-Fi connection while using a VPN. --- .../eu/kanade/tachiyomi/data/download/DownloadService.kt | 7 ++----- .../eu/kanade/tachiyomi/util/system/ContextExtensions.kt | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt index 0690169c7..2e6ba0ee1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadService.kt +++ b/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. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 130e29074..bf77644ff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/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()!!