Merge pull request #291 from luca020400/patch-1

Don't backup on metered networks
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 727f7d8..bb28b14 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 @@
      * 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
     }
 }