From caafd0313027fc81b7cf529e84df33461a7f9a90 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 27 Aug 2016 13:35:52 +0200 Subject: [PATCH] don't automatically download files and avatars when datasaver is on --- .../conversations/http/HttpDownloadConnection.java | 4 +++- .../eu/siacs/conversations/parser/MessageParser.java | 2 +- .../eu/siacs/conversations/parser/PresenceParser.java | 4 ++-- .../conversations/services/XmppConnectionService.java | 10 ++++++++++ .../conversations/xmpp/jingle/JingleConnection.java | 3 ++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index 3e2b1cad7..741ea98df 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -183,7 +183,9 @@ public class HttpDownloadConnection implements Transferable { return; } file.setExpectedSize(size); - if (mHttpConnectionManager.hasStoragePermission() && size <= mHttpConnectionManager.getAutoAcceptFileSize()) { + if (mHttpConnectionManager.hasStoragePermission() + && size <= mHttpConnectionManager.getAutoAcceptFileSize() + && mXmppConnectionService.isDataSaverDisabled()) { HttpDownloadConnection.this.acceptedAutomatically = true; new Thread(new FileDownloader(interactive)).start(); } else { diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index f3958621c..f4fe80b51 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -238,7 +238,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateRosterUi(); } - } else { + } else if (mXmppConnectionService.isDataSaverDisabled()) { mXmppConnectionService.fetchAvatar(account, avatar); } } diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index b11a6effd..d812b85de 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -105,7 +105,7 @@ public class PresenceParser extends AbstractParser implements if (user.setAvatar(avatar)) { mXmppConnectionService.getAvatarService().clear(user); } - } else { + } else if (mXmppConnectionService.isDataSaverDisabled()) { mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar); } } @@ -192,7 +192,7 @@ public class PresenceParser extends AbstractParser implements mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateRosterUi(); } - } else { + } else if (mXmppConnectionService.isDataSaverDisabled()){ mXmppConnectionService.fetchAvatar(account, avatar); } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 96965d039..83a1af235 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -697,6 +697,16 @@ public class XmppConnectionService extends Service { return START_STICKY; } + public boolean isDataSaverDisabled() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); + return !connectivityManager.isActiveNetworkMetered() + || connectivityManager.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED; + } else { + return true; + } + } + private void directReply(Conversation conversation, String body) { Message message = new Message(conversation,body,conversation.getNextEncryption()); message.markUnread(); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 89ab30cd3..3099b570f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -389,7 +389,8 @@ public class JingleConnection implements Transferable { conversation.add(message); mXmppConnectionService.updateConversationUi(); if (mJingleConnectionManager.hasStoragePermission() - && size < this.mJingleConnectionManager.getAutoAcceptFileSize()) { + && size < this.mJingleConnectionManager.getAutoAcceptFileSize() + && mXmppConnectionService.isDataSaverDisabled()) { Log.d(Config.LOGTAG, "auto accepting file from "+ packet.getFrom()); this.acceptedAutomatically = true; this.sendAccept();