From bc24c7804d4cf7119dbeb96220c81412d7d9127d Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Wed, 28 Jul 2021 19:37:47 +0200 Subject: [PATCH] Don't backup on metered networks * We better not overuse metered networks as such connections * are usually sensitive to heavy data usage due to monetary costs and/or data limitations. --- .../com/stevesoltys/seedvault/settings/SettingsManager.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt index 727f7d83..bb28b149 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsManager.kt @@ -175,13 +175,14 @@ data class Storage( * but it isn't available right now. */ 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 isMetered = cm.isActiveNetworkMetered() val capabilities = cm.getNetworkCapabilities(cm.activeNetwork) ?: return false - return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) + return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) && !isMetered } }