Merge pull request #291 from luca020400/patch-1

Don't backup on metered networks
This commit is contained in:
Torsten Grote 2021-08-25 10:21:54 -03:00 committed by GitHub
commit b29a50fdb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -175,13 +175,14 @@ data class Storage(
* but it isn't available right now. * but it isn't available right now.
*/ */
fun isUnavailableNetwork(context: Context): Boolean { fun isUnavailableNetwork(context: Context): Boolean {
return requiresNetwork && !hasInternet(context) return requiresNetwork && !hasUnmeteredInternet(context)
} }
private fun hasInternet(context: Context): Boolean { private fun hasUnmeteredInternet(context: Context): Boolean {
val cm = context.getSystemService(ConnectivityManager::class.java) val cm = context.getSystemService(ConnectivityManager::class.java)
val isMetered = cm.isActiveNetworkMetered()
val capabilities = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false val capabilities = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) && !isMetered
} }
} }