From bb422743dd4216861b6faa2be3978d7739873ac1 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 11 May 2020 15:21:24 -0400 Subject: [PATCH] Supporting more network transports (fixes miui) (again) --- .../tachiyomi/util/system/ContextExtensions.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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 498cedf7df..fb6fc3769d 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 @@ -14,6 +14,7 @@ import android.graphics.drawable.Drawable import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.net.Uri +import android.os.Build import android.os.PowerManager import android.view.View import android.widget.Toast @@ -243,15 +244,13 @@ fun Context.isOnline(): Boolean { var result = false connectivityManager?.let { val networkCapabilities = connectivityManager.activeNetwork ?: return false - val actNw = - connectivityManager.getNetworkCapabilities(networkCapabilities) ?: return false - result = when { - actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true - actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true - actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true - else -> false + val actNw = connectivityManager.getNetworkCapabilities(networkCapabilities) ?: return false + val maxTransport = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -> NetworkCapabilities.TRANSPORT_LOWPAN + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> NetworkCapabilities.TRANSPORT_WIFI_AWARE + else -> NetworkCapabilities.TRANSPORT_VPN } + result = (NetworkCapabilities.TRANSPORT_CELLULAR..maxTransport).any(actNw::hasTransport) } - return result }