From f5203b082b89d2f72ae7bfc541adf24cfa80556b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 23 Feb 2023 09:40:20 +0100 Subject: [PATCH] calculate switch to video cap on jingle connection startup --- .../xmpp/jingle/JingleRtpConnection.java | 11 +++++++--- .../android/util/BooleanFutures.java | 20 +++++++++++++++++++ .../xmpp/manager/ExternalDiscoManager.java | 6 ++---- .../res/drawable/ic_assured_workload_24dp.xml | 10 ++++++++++ .../drawable/ic_private_connectivity_24dp.xml | 5 +++++ 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/im/conversations/android/util/BooleanFutures.java create mode 100644 app/src/main/res/drawable/ic_assured_workload_24dp.xml create mode 100644 app/src/main/res/drawable/ic_private_connectivity_24dp.xml diff --git a/app/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/app/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 1130469a0..1c1910ab7 100644 --- a/app/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/app/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -32,6 +32,7 @@ import im.conversations.android.axolotl.AxolotlService; import im.conversations.android.dns.IP; import im.conversations.android.notification.RtpSessionNotification; import im.conversations.android.transformer.CallLogEntry; +import im.conversations.android.util.BooleanFutures; import im.conversations.android.xml.Element; import im.conversations.android.xml.Namespace; import im.conversations.android.xmpp.Entity; @@ -179,6 +180,7 @@ public class JingleRtpConnection extends AbstractJingleConnection private final RtpSessionNotification rtpSessionNotification; private ScheduledFuture ringingTimeoutFuture; private CallLogEntry message = null; + private final ListenableFuture remoteHasVideoFeature; public JingleRtpConnection( final Context context, @@ -186,7 +188,11 @@ public class JingleRtpConnection extends AbstractJingleConnection final Id id, final Jid initiator) { super(context, connection, id, initiator); - this.rtpSessionNotification = new RtpSessionNotification(context); + this.rtpSessionNotification = + getManager(JingleConnectionManager.class).getNotificationService(); + this.remoteHasVideoFeature = + getManager(DiscoManager.class) + .hasFeatureAsync(Entity.presence(id.with), Namespace.JINGLE_FEATURE_VIDEO); } private static State reasonToState(Reason reason) { @@ -2662,8 +2668,7 @@ public class JingleRtpConnection extends AbstractJingleConnection } private boolean remoteHasVideoFeature() { - return getManager(DiscoManager.class) - .hasFeature(Entity.presence(id.with), Namespace.JINGLE_FEATURE_VIDEO); + return BooleanFutures.isDoneAndTrue(this.remoteHasVideoFeature); } private interface OnIceServersDiscovered { diff --git a/app/src/main/java/im/conversations/android/util/BooleanFutures.java b/app/src/main/java/im/conversations/android/util/BooleanFutures.java new file mode 100644 index 000000000..0f0b8190f --- /dev/null +++ b/app/src/main/java/im/conversations/android/util/BooleanFutures.java @@ -0,0 +1,20 @@ +package im.conversations.android.util; + +import com.google.common.util.concurrent.ListenableFuture; + +public final class BooleanFutures { + + private BooleanFutures() {} + + public static boolean isDoneAndTrue(final ListenableFuture future) { + if (future.isDone()) { + try { + return Boolean.TRUE.equals(future.get()); + } catch (final Exception e) { + return false; + } + } else { + return false; + } + } +} diff --git a/app/src/main/java/im/conversations/android/xmpp/manager/ExternalDiscoManager.java b/app/src/main/java/im/conversations/android/xmpp/manager/ExternalDiscoManager.java index ffccad68f..1c28f926c 100644 --- a/app/src/main/java/im/conversations/android/xmpp/manager/ExternalDiscoManager.java +++ b/app/src/main/java/im/conversations/android/xmpp/manager/ExternalDiscoManager.java @@ -4,16 +4,14 @@ import android.content.Context; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import im.conversations.android.xml.Namespace; import im.conversations.android.xmpp.XmppConnection; import im.conversations.android.xmpp.model.disco.external.Service; import im.conversations.android.xmpp.model.disco.external.Services; import im.conversations.android.xmpp.model.stanza.Iq; import java.util.Collection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ExternalDiscoManager extends AbstractManager { diff --git a/app/src/main/res/drawable/ic_assured_workload_24dp.xml b/app/src/main/res/drawable/ic_assured_workload_24dp.xml new file mode 100644 index 000000000..ea7c30902 --- /dev/null +++ b/app/src/main/res/drawable/ic_assured_workload_24dp.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/ic_private_connectivity_24dp.xml b/app/src/main/res/drawable/ic_private_connectivity_24dp.xml new file mode 100644 index 000000000..a78de42fb --- /dev/null +++ b/app/src/main/res/drawable/ic_private_connectivity_24dp.xml @@ -0,0 +1,5 @@ + + +