checkbox for auto downloading all files when connected to wifi
This commit is contained in:
parent
cf889b3450
commit
42a57ca532
|
@ -1,6 +1,10 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
import android.content.Context;
|
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.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -121,6 +125,33 @@ public class AbstractConnectionManager {
|
||||||
|
|
||||||
public long getAutoAcceptFileSize() {
|
public long getAutoAcceptFileSize() {
|
||||||
final long autoAcceptFileSize = this.mXmppConnectionService.getLongPreference("auto_accept_file_size", R.integer.auto_accept_filesize);
|
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;
|
return autoAcceptFileSize <= 0 ? -1 : autoAcceptFileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<string name="omemo_setting_default">default_off</string>
|
<string name="omemo_setting_default">default_off</string>
|
||||||
<string name="default_font_size">small</string>
|
<string name="default_font_size">small</string>
|
||||||
<bool name="use_share_location_plugin">false</bool>
|
<bool name="use_share_location_plugin">false</bool>
|
||||||
|
<bool name="accept_all_files_if_wifi">false</bool>
|
||||||
<bool name="start_searching">false</bool>
|
<bool name="start_searching">false</bool>
|
||||||
<string name="video_compression">360</string>
|
<string name="video_compression">360</string>
|
||||||
<string name="default_channel_discovery">JABBER_NETWORK</string>
|
<string name="default_channel_discovery">JABBER_NETWORK</string>
|
||||||
|
|
|
@ -114,6 +114,8 @@
|
||||||
<string name="pref_general">General</string>
|
<string name="pref_general">General</string>
|
||||||
<string name="pref_accept_files">Accept files</string>
|
<string name="pref_accept_files">Accept files</string>
|
||||||
<string name="pref_accept_files_summary">Automatically accept files smaller than…</string>
|
<string name="pref_accept_files_summary">Automatically accept files smaller than…</string>
|
||||||
|
<string name="pref_accept_all_files_if_wifi">Accept all files</string>
|
||||||
|
<string name="pref_accept_all_files_if_wifi_summary">Automatically accept all files when connected to Wi-Fi</string>
|
||||||
<string name="pref_attachments">Attachments</string>
|
<string name="pref_attachments">Attachments</string>
|
||||||
<string name="pref_notification_settings">Notification</string>
|
<string name="pref_notification_settings">Notification</string>
|
||||||
<string name="pref_vibrate">Vibrate</string>
|
<string name="pref_vibrate">Vibrate</string>
|
||||||
|
|
|
@ -164,6 +164,11 @@
|
||||||
android:key="auto_accept_file_size"
|
android:key="auto_accept_file_size"
|
||||||
android:summary="@string/pref_accept_files_summary"
|
android:summary="@string/pref_accept_files_summary"
|
||||||
android:title="@string/pref_accept_files" />
|
android:title="@string/pref_accept_files" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="@bool/use_share_location_plugin"
|
||||||
|
android:key="accept_all_files_if_wifi"
|
||||||
|
android:summary="@string/pref_accept_all_files_if_wifi_summary"
|
||||||
|
android:title="@string/pref_accept_all_files_if_wifi" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/pref_ui_options">
|
<PreferenceCategory android:title="@string/pref_ui_options">
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
|
|
Loading…
Reference in a new issue