diff --git a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java
index 94c6b79b9..747189ff7 100644
--- a/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java
+++ b/src/main/java/eu/siacs/conversations/services/AbstractConnectionManager.java
@@ -1,6 +1,10 @@
package eu.siacs.conversations.services;
import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.Network;
+import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.Log;
@@ -121,6 +125,33 @@ public class AbstractConnectionManager {
public long getAutoAcceptFileSize() {
final long autoAcceptFileSize = this.mXmppConnectionService.getLongPreference("auto_accept_file_size", R.integer.auto_accept_filesize);
+ final boolean acceptAllOnWifi = this.mXmppConnectionService.getBooleanPreference("accept_all_files_if_wifi", R.bool.accept_all_files_if_wifi);
+
+ if (acceptAllOnWifi) {
+ boolean connectedToUnmeteredWifi = false;
+ ConnectivityManager manager = (ConnectivityManager) mXmppConnectionService.getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ NetworkCapabilities capabilities = null;
+ NetworkInfo networkInfo = null;
+ Network network = manager.getActiveNetwork();
+ if (network != null) {
+ capabilities = manager.getNetworkCapabilities(network);
+ networkInfo = manager.getNetworkInfo(network);
+ } else {
+ networkInfo = manager.getActiveNetworkInfo();
+ }
+
+ if (capabilities != null) {
+ connectedToUnmeteredWifi = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
+ } else if (networkInfo != null) {
+ connectedToUnmeteredWifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI && !manager.isActiveNetworkMetered();
+ }
+
+ if (connectedToUnmeteredWifi) {
+ return Long.MAX_VALUE;
+ }
+ }
+
return autoAcceptFileSize <= 0 ? -1 : autoAcceptFileSize;
}
diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml
index 55a8feb29..8c7c6ec88 100644
--- a/src/main/res/values/defaults.xml
+++ b/src/main/res/values/defaults.xml
@@ -43,6 +43,7 @@
default_off
small
false
+ false
false
360
JABBER_NETWORK
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index aef093a96..27bc5b5e5 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -114,6 +114,8 @@
General
Accept files
Automatically accept files smaller than…
+ Accept all files
+ Automatically accept all files when connected to Wi-Fi
Attachments
Notification
Vibrate
diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml
index cff63c834..fcf2fbb0c 100644
--- a/src/main/res/xml/preferences.xml
+++ b/src/main/res/xml/preferences.xml
@@ -164,6 +164,11 @@
android:key="auto_accept_file_size"
android:summary="@string/pref_accept_files_summary"
android:title="@string/pref_accept_files" />
+