summaryrefslogtreecommitdiff
path: root/core/src/main/java
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2021-10-30 18:23:20 +0200
committerByteHamster <info@bytehamster.com>2021-10-30 18:23:20 +0200
commitb1c4a89f9b19fd141ddcff003e146d45e00a5170 (patch)
treecaae16d74e13c1d64d34bbcff4ad1c5a168ba2a3 /core/src/main/java
parent345aad4148f133477e40c232a8e855dfd28e0654 (diff)
downloadAntennaPod-b1c4a89f9b19fd141ddcff003e146d45e00a5170.zip
Don't connect to metered wifi networks
Diffstat (limited to 'core/src/main/java')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java65
2 files changed, 20 insertions, 47 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java
index b5202d79c..0dc57e0af 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java
@@ -35,7 +35,7 @@ public class AutomaticDownloadAlgorithm {
return () -> {
// true if we should auto download based on network status
- boolean networkShouldAutoDl = NetworkUtils.autodownloadNetworkAvailable()
+ boolean networkShouldAutoDl = NetworkUtils.isAutoDownloadAllowed()
&& UserPreferences.isEnableAutodownload();
// true if we should auto download based on power status
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java
index 12f1e98f9..06d5d67a3 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java
@@ -40,56 +40,23 @@ public class NetworkUtils {
NetworkUtils.context = context;
}
- /**
- * Returns true if the device is connected to Wi-Fi and the Wi-Fi filter for
- * automatic downloads is disabled or the device is connected to a Wi-Fi
- * network that is on the 'selected networks' list of the Wi-Fi filter for
- * automatic downloads and false otherwise.
- * */
- public static boolean autodownloadNetworkAvailable() {
- ConnectivityManager cm = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
+ public static boolean isAutoDownloadAllowed() {
+ ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
- if (networkInfo != null) {
- if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
- Log.d(TAG, "Device is connected to Wi-Fi");
- if (networkInfo.isConnected()) {
- if (!UserPreferences.isEnableAutodownloadWifiFilter()) {
- Log.d(TAG, "Auto-dl filter is disabled");
- return true;
- } else {
- WifiManager wm = (WifiManager) context.getApplicationContext()
- .getSystemService(Context.WIFI_SERVICE);
- WifiInfo wifiInfo = wm.getConnectionInfo();
- List<String> selectedNetworks = Arrays
- .asList(UserPreferences
- .getAutodownloadSelectedNetworks());
- if (selectedNetworks.contains(Integer.toString(wifiInfo
- .getNetworkId()))) {
- Log.d(TAG, "Current network is on the selected networks list");
- return true;
- }
- }
- }
- } else if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
- Log.d(TAG, "Device is connected to Ethernet");
- if (networkInfo.isConnected()) {
- return true;
- }
+ if (networkInfo == null) {
+ return false;
+ }
+ if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
+ if (UserPreferences.isEnableAutodownloadWifiFilter()) {
+ return isInAllowedWifiNetwork();
} else {
- if (!UserPreferences.isAllowMobileAutoDownload()) {
- Log.d(TAG, "Auto Download not enabled on Mobile");
- return false;
- }
- if (networkInfo.isRoaming()) {
- Log.d(TAG, "Roaming on foreign network");
- return false;
- }
- return true;
+ return !isNetworkMetered();
}
+ } else if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
+ return true;
+ } else {
+ return UserPreferences.isAllowMobileAutoDownload() || !NetworkUtils.isNetworkRestricted();
}
- Log.d(TAG, "Network for auto-dl is not available");
- return false;
}
public static boolean networkAvailable() {
@@ -157,6 +124,12 @@ public class NetworkUtils {
}
}
+ private static boolean isInAllowedWifiNetwork() {
+ WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+ List<String> selectedNetworks = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
+ return selectedNetworks.contains(Integer.toString(wm.getConnectionInfo().getNetworkId()));
+ }
+
/**
* Returns the SSID of the wifi connection, or <code>null</code> if there is no wifi.
*/