don't automatically download files and avatars when datasaver is on

This commit is contained in:
Daniel Gultsch 2016-08-27 13:35:52 +02:00
parent 3d5940cb76
commit caafd03130
5 changed files with 18 additions and 5 deletions

View File

@ -183,7 +183,9 @@ public class HttpDownloadConnection implements Transferable {
return; return;
} }
file.setExpectedSize(size); file.setExpectedSize(size);
if (mHttpConnectionManager.hasStoragePermission() && size <= mHttpConnectionManager.getAutoAcceptFileSize()) { if (mHttpConnectionManager.hasStoragePermission()
&& size <= mHttpConnectionManager.getAutoAcceptFileSize()
&& mXmppConnectionService.isDataSaverDisabled()) {
HttpDownloadConnection.this.acceptedAutomatically = true; HttpDownloadConnection.this.acceptedAutomatically = true;
new Thread(new FileDownloader(interactive)).start(); new Thread(new FileDownloader(interactive)).start();
} else { } else {

View File

@ -238,7 +238,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi(); mXmppConnectionService.updateRosterUi();
} }
} else { } else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(account, avatar); mXmppConnectionService.fetchAvatar(account, avatar);
} }
} }

View File

@ -105,7 +105,7 @@ public class PresenceParser extends AbstractParser implements
if (user.setAvatar(avatar)) { if (user.setAvatar(avatar)) {
mXmppConnectionService.getAvatarService().clear(user); mXmppConnectionService.getAvatarService().clear(user);
} }
} else { } else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar); mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar);
} }
} }
@ -192,7 +192,7 @@ public class PresenceParser extends AbstractParser implements
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi(); mXmppConnectionService.updateRosterUi();
} }
} else { } else if (mXmppConnectionService.isDataSaverDisabled()){
mXmppConnectionService.fetchAvatar(account, avatar); mXmppConnectionService.fetchAvatar(account, avatar);
} }
} }

View File

@ -697,6 +697,16 @@ public class XmppConnectionService extends Service {
return START_STICKY; 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) { private void directReply(Conversation conversation, String body) {
Message message = new Message(conversation,body,conversation.getNextEncryption()); Message message = new Message(conversation,body,conversation.getNextEncryption());
message.markUnread(); message.markUnread();

View File

@ -389,7 +389,8 @@ public class JingleConnection implements Transferable {
conversation.add(message); conversation.add(message);
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
if (mJingleConnectionManager.hasStoragePermission() if (mJingleConnectionManager.hasStoragePermission()
&& size < this.mJingleConnectionManager.getAutoAcceptFileSize()) { && size < this.mJingleConnectionManager.getAutoAcceptFileSize()
&& mXmppConnectionService.isDataSaverDisabled()) {
Log.d(Config.LOGTAG, "auto accepting file from "+ packet.getFrom()); Log.d(Config.LOGTAG, "auto accepting file from "+ packet.getFrom());
this.acceptedAutomatically = true; this.acceptedAutomatically = true;
this.sendAccept(); this.sendAccept();