From e863e8c64b7b815cde53c28e17bd143f9eda9072 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 4 Oct 2021 17:06:24 -0400 Subject: [PATCH] Adjust Wi-Fi connection check (related to #6038) --- .../tachiyomi/data/download/DownloadService.kt | 4 +++- .../tachiyomi/util/system/ContextExtensions.kt | 13 ++++++------- 2 files changed, 9 insertions(+), 8 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 952b792f7..b1f7c6463 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 @@ -29,6 +29,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import ru.beryukhov.reactivenetwork.ReactiveNetwork import rx.subscriptions.CompositeSubscription +import timber.log.Timber import uy.kohesive.injekt.injectLazy /** @@ -140,8 +141,9 @@ class DownloadService : Service() { onNetworkStateChanged() } } - .catch { + .catch { error -> withUIContext { + Timber.e(error) toast(R.string.download_queue_error) stopSelf() } 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 05aedd1ec..86416cea6 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 @@ -17,7 +17,6 @@ import android.graphics.Color import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.net.Uri -import android.net.wifi.WifiInfo import android.net.wifi.WifiManager import android.os.Build import android.os.PowerManager @@ -381,21 +380,21 @@ fun Context.isOnline(): Boolean { } /** - * Returns true if device is connected to wifi. + * Returns true if device is connected to Wifi. */ fun Context.isConnectedToWifi(): Boolean { if (!wifiManager.isWifiEnabled) return false - val wifiInfo: WifiInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { val activeNetwork = connectivityManager.activeNetwork ?: return false val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false - networkCapabilities.transportInfo as WifiInfo + + networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) && + networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) } else { @Suppress("DEPRECATION") - wifiManager.connectionInfo + wifiManager.connectionInfo.bssid != null } - - return wifiInfo.bssid != null } /**