mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-03 09:01:50 +01:00
Check if wifi is connected rather than enabled while downloading. (#5967)
* Fixxy Wixxy * Downgrade check from Android S to Android Q
This commit is contained in:
parent
e2da6259e7
commit
e22825d818
@ -15,11 +15,11 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|||||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||||
import eu.kanade.tachiyomi.util.system.acquireWakeLock
|
import eu.kanade.tachiyomi.util.system.acquireWakeLock
|
||||||
|
import eu.kanade.tachiyomi.util.system.isConnectedToWifi
|
||||||
import eu.kanade.tachiyomi.util.system.isOnline
|
import eu.kanade.tachiyomi.util.system.isOnline
|
||||||
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
||||||
import eu.kanade.tachiyomi.util.system.notification
|
import eu.kanade.tachiyomi.util.system.notification
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.system.wifiManager
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
@ -154,7 +154,7 @@ class DownloadService : Service() {
|
|||||||
*/
|
*/
|
||||||
private fun onNetworkStateChanged() {
|
private fun onNetworkStateChanged() {
|
||||||
if (isOnline()) {
|
if (isOnline()) {
|
||||||
if (preferences.downloadOnlyOverWifi() && !wifiManager.isWifiEnabled) {
|
if (preferences.downloadOnlyOverWifi() && !isConnectedToWifi()) {
|
||||||
stopDownloads(R.string.download_notifier_text_only_wifi)
|
stopDownloads(R.string.download_notifier_text_only_wifi)
|
||||||
} else {
|
} else {
|
||||||
val started = downloadManager.startDownloads()
|
val started = downloadManager.startDownloads()
|
||||||
|
@ -17,6 +17,7 @@ import android.graphics.Color
|
|||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.NetworkCapabilities
|
import android.net.NetworkCapabilities
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.net.wifi.WifiInfo
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
@ -379,6 +380,24 @@ fun Context.isOnline(): Boolean {
|
|||||||
return (NetworkCapabilities.TRANSPORT_CELLULAR..maxTransport).any(networkCapabilities::hasTransport)
|
return (NetworkCapabilities.TRANSPORT_CELLULAR..maxTransport).any(networkCapabilities::hasTransport)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
val activeNetwork = connectivityManager.activeNetwork ?: return false
|
||||||
|
val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false
|
||||||
|
networkCapabilities.transportInfo as WifiInfo
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
wifiManager.connectionInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
return wifiInfo.bssid != null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets document size of provided [Uri]
|
* Gets document size of provided [Uri]
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user