From 92fc22b313eb10f1b88749f42d6ef64c47aaac67 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 9 May 2020 11:14:39 +0200 Subject: [PATCH] show call duration in audio calls. fixes #3708 --- .../conversations/ui/RecordingActivity.java | 2 +- .../conversations/ui/RtpSessionActivity.java | 43 ++++++++++++++++++- .../xmpp/jingle/JingleRtpConnection.java | 12 ++++++ src/main/res/layout/activity_rtp_session.xml | 18 +++++--- src/main/res/values/styles.xml | 5 +++ 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java index e38fb236c..bcd564788 100644 --- a/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RecordingActivity.java @@ -182,7 +182,7 @@ public class RecordingActivity extends Activity implements View.OnClickListener }; mFileObserver.startWatching(); } - + private void tick() { this.binding.timer.setText(TimeFrameUtils.formatTimePassed(mStartTime, true)); } diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 405865734..2a1730c94 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -9,6 +9,7 @@ import android.content.pm.PackageManager; import android.databinding.DataBindingUtil; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.os.PowerManager; import android.os.SystemClock; import android.support.annotation.NonNull; @@ -27,7 +28,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import org.checkerframework.checker.nullness.compatqual.NullableDecl; import org.webrtc.SurfaceViewRenderer; @@ -49,6 +49,7 @@ import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.util.AvatarWorkerTask; import eu.siacs.conversations.ui.util.MainThreadExecutor; import eu.siacs.conversations.utils.PermissionUtils; +import eu.siacs.conversations.utils.TimeFrameUtils; import eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection; import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection; import eu.siacs.conversations.xmpp.jingle.Media; @@ -67,6 +68,9 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe public static final String ACTION_ACCEPT_CALL = "action_accept_call"; public static final String ACTION_MAKE_VOICE_CALL = "action_make_voice_call"; public static final String ACTION_MAKE_VIDEO_CALL = "action_make_video_call"; + + private static final int CALL_DURATION_UPDATE_INTERVAL = 333; + private static final List END_CARD = Arrays.asList( RtpEndUserState.APPLICATION_ERROR, RtpEndUserState.DECLINED_OR_BUSY, @@ -79,6 +83,15 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe private ActivityRtpSessionBinding binding; private PowerManager.WakeLock mProximityWakeLock; + private Handler mHandler = new Handler(); + private Runnable mTickExecutor = new Runnable() { + @Override + public void run() { + updateCallDuration(); + mHandler.postDelayed(mTickExecutor, CALL_DURATION_UPDATE_INTERVAL); + } + }; + private static Set actionToMedia(final String action) { if (ACTION_MAKE_VIDEO_CALL.equals(action)) { return ImmutableSet.of(Media.AUDIO, Media.VIDEO); @@ -308,8 +321,15 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe } } + @Override + public void onStart() { + super.onStart(); + mHandler.postDelayed(mTickExecutor, CALL_DURATION_UPDATE_INTERVAL); + } + @Override public void onStop() { + mHandler.removeCallbacks(mTickExecutor); binding.remoteVideo.release(); binding.localVideo.release(); final WeakReference weakReference = this.rtpConnectionReference; @@ -655,7 +675,7 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe @Override public void onFailure(@NonNull final Throwable throwable) { - Log.d(Config.LOGTAG,"could not switch camera", Throwables.getRootCause(throwable)); + Log.d(Config.LOGTAG, "could not switch camera", Throwables.getRootCause(throwable)); Toast.makeText(RtpSessionActivity.this, R.string.could_not_switch_camera, Toast.LENGTH_LONG).show(); } }, MainThreadExecutor.getInstance()); @@ -684,6 +704,25 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe this.binding.inCallActionLeft.setVisibility(View.VISIBLE); } + private void updateCallDuration() { + Log.d(Config.LOGTAG,"updateCallDuration()"); + final JingleRtpConnection connection = this.rtpConnectionReference != null ? this.rtpConnectionReference.get() : null; + if (connection == null || connection.getMedia().contains(Media.VIDEO)) { + Log.d(Config.LOGTAG,"rtpConnection was null or contained video"); + this.binding.duration.setVisibility(View.GONE); + return; + } + final long rtpConnectionStarted = connection.getRtpConnectionStarted(); + final long rtpConnectionEnded = connection.getRtpConnectionEnded(); + if (rtpConnectionStarted != 0) { + final long ended = rtpConnectionEnded == 0 ? SystemClock.elapsedRealtime() : rtpConnectionEnded; + this.binding.duration.setText(TimeFrameUtils.formatTimePassed(rtpConnectionStarted, ended, false)); + this.binding.duration.setVisibility(View.VISIBLE); + } else { + this.binding.duration.setVisibility(View.GONE); + } + } + private void updateVideoViews(final RtpEndUserState state) { if (END_CARD.contains(state) || state == RtpEndUserState.ENDING_CALL) { binding.localVideo.setVisibility(View.GONE); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index ecf2aff32..af94cbd0b 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -125,6 +125,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web private RtpContentMap initiatorRtpContentMap; private RtpContentMap responderRtpContentMap; private long rtpConnectionStarted = 0; //time of 'connected' + private long rtpConnectionEnded = 0; private ScheduledFuture ringingTimeoutFuture; JingleRtpConnection(JingleConnectionManager jingleConnectionManager, Id id, Jid initiator) { @@ -1006,6 +1007,9 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web if (newState == PeerConnection.PeerConnectionState.CONNECTED && this.rtpConnectionStarted == 0) { this.rtpConnectionStarted = SystemClock.elapsedRealtime(); } + if (newState == PeerConnection.PeerConnectionState.CLOSED && this.rtpConnectionEnded == 0) { + this.rtpConnectionEnded = SystemClock.elapsedRealtime(); + } //TODO 'DISCONNECTED' might be an opportunity to renew the offer and send a transport-replace //TODO exact syntax is yet to be determined but transport-replace sounds like the most reasonable //as there is no content-replace @@ -1031,6 +1035,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web } } + public long getRtpConnectionStarted() { + return this.rtpConnectionStarted; + } + + public long getRtpConnectionEnded() { + return this.rtpConnectionEnded; + } + public AppRTCAudioManager getAudioManager() { return webRTCWrapper.getAudioManager(); } diff --git a/src/main/res/layout/activity_rtp_session.xml b/src/main/res/layout/activity_rtp_session.xml index 13e0e5d2e..cc4ea716e 100644 --- a/src/main/res/layout/activity_rtp_session.xml +++ b/src/main/res/layout/activity_rtp_session.xml @@ -62,21 +62,29 @@ - + android:layout_below="@id/app_bar_layout"> + + - + monospace + +