From df2ef0eeb07c3de9f1d42d24ab3bbc7fa76a7018 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 20 Apr 2020 12:32:56 +0200 Subject: [PATCH] automatically reject/ignore calls from strangers if the setting is set --- .../services/NotificationService.java | 2 +- .../xmpp/jingle/JingleConnectionManager.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index c4a0fe2e4..9f1617b56 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -224,7 +224,7 @@ public class NotificationService { && (!conversation.isWithStranger() || notificationsFromStrangers()); } - private boolean notificationsFromStrangers() { + public boolean notificationsFromStrangers() { return mXmppConnectionService.getBooleanPreference("notifications_from_strangers", R.bool.notifications_from_strangers); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index 468b8d8a2..5fd89aea2 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit; import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; @@ -87,8 +88,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { connection = new JingleFileTransferConnection(this, id, from); } else if (Namespace.JINGLE_APPS_RTP.equals(descriptionNamespace) && !usesTor(account)) { final boolean sessionEnded = this.endedSessions.asMap().containsKey(PersistableSessionId.of(id)); - if (isBusy() || sessionEnded) { - Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": rejected session with " + id.with + " because busy. sessionEnded=" + sessionEnded); + final boolean stranger = isWithStrangerAndStrangerNotificationsAreOff(account, id.with); + if (isBusy() || sessionEnded || stranger) { + Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": rejected session with " + id.with + " because busy. sessionEnded=" + sessionEnded+", stranger="+stranger); mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null); final JinglePacket sessionTermination = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId); sessionTermination.setTo(id.with); @@ -124,6 +126,15 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } + private boolean isWithStrangerAndStrangerNotificationsAreOff(final Account account, Jid with) { + final boolean notifyForStrangers = mXmppConnectionService.getNotificationService().notificationsFromStrangers(); + if (notifyForStrangers) { + return false; + } + final Contact contact = account.getRoster().getContact(with); + return !contact.showInContactList(); + } + public void respondWithJingleError(final Account account, final IqPacket original, String jingleCondition, String condition, String conditionType) { final IqPacket response = original.generateResponse(IqPacket.TYPE.ERROR); final Element error = response.addChild("error"); @@ -205,8 +216,13 @@ public class JingleConnectionManager extends AbstractConnectionManager { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": encountered unknown media in session proposal. " + propose); return; } - if (isBusy()) { + final boolean stranger = isWithStrangerAndStrangerNotificationsAreOff(account, id.with); + if (isBusy() || stranger) { writeLogMissedIncoming(account, id.with.asBareJid(), id.sessionId, serverMsgId, timestamp); + if (stranger) { + Log.d(Config.LOGTAG,id.account.getJid().asBareJid()+": ignoring call proposal from stranger "+id.with); + return; + } final int activeDevices = account.countPresences(); Log.d(Config.LOGTAG, "active devices: " + activeDevices); if (activeDevices == 0) {