From ce44b8869e046a76ca7eca5c0de16662910312cb Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 24 Sep 2016 00:21:23 +0200 Subject: set different auto download filesizes for wifi, mobile, roaming defaults: * wifi = 10 MiB * mobile = 256 KiB * roaming = 1 Byte --- .../services/AbstractConnectionManager.java | 16 +++++++-- .../messenger/services/XmppConnectionService.java | 40 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/pixart') diff --git a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java index 9228d0055..f888d8fd0 100644 --- a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java +++ b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java @@ -3,6 +3,7 @@ package de.pixart.messenger.services; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; +import android.net.ConnectivityManager; import android.os.Build; import android.os.PowerManager; import android.util.Log; @@ -45,9 +46,18 @@ public class AbstractConnectionManager { } public long getAutoAcceptFileSize() { - String config = this.mXmppConnectionService.getPreferences().getString( - "auto_accept_file_size", "1048576"); - try { + String config = "0"; + if (mXmppConnectionService.isWIFI()) { + config = this.mXmppConnectionService.getPreferences().getString( + "auto_accept_file_size_wifi", "10485760"); + } else if (mXmppConnectionService.isMobile()) { + config = this.mXmppConnectionService.getPreferences().getString( + "auto_accept_file_size_mobile", "262144"); + } else if (mXmppConnectionService.isMobileRoaming()) { + config = this.mXmppConnectionService.getPreferences().getString( + "auto_accept_file_size_roaming", "1"); + } + try { return Long.parseLong(config); } catch (NumberFormatException e) { return 1048576; diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 153c1c269..16ebd8c11 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -896,6 +896,46 @@ public class XmppConnectionService extends Service { return activeNetwork != null && activeNetwork.isConnected(); } + public boolean isWIFI() { + ConnectivityManager cm = (ConnectivityManager) getApplicationContext() + .getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + if (activeNetwork != null) { // connected to the internet + if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { + return true; + } + } + return false; + } + + public boolean isMobile() { + ConnectivityManager cm = (ConnectivityManager) getApplicationContext() + .getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + if (activeNetwork != null) { // connected to the internet + if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { + if (!activeNetwork.isRoaming()) { + return true; + } + } + } + return false; + } + + public boolean isMobileRoaming() { + ConnectivityManager cm = (ConnectivityManager) getApplicationContext() + .getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + if (activeNetwork != null) { // connected to the internet + if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { + if (activeNetwork.isRoaming()) { + return true; + } + } + } + return false; + } + @SuppressLint("TrulyRandom") @Override public void onCreate() { -- cgit v1.2.3