From ed4d7bff922e0aa1c5451f8851162f17a24e7d54 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 22 May 2020 16:25:29 +0200 Subject: [PATCH] reset tone manager after reaching NULL status --- .../conversations/xmpp/jingle/ToneManager.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/ToneManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/ToneManager.java index 3cdc083c0..60ac67f14 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/ToneManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/ToneManager.java @@ -20,6 +20,7 @@ class ToneManager { private ToneState state = null; private ScheduledFuture currentTone; + private ScheduledFuture currentResetFuture; private boolean appRtcAudioManagerHasControl = false; ToneManager(final Context context) { @@ -93,6 +94,13 @@ class ToneManager { case ENDING_CALL: scheduleEnding(); break; + case NULL: + if (noResetScheduled()) { + resetAudioManager(); + } + break; + default: + throw new IllegalStateException("Unable to handle transition to "+state); } this.state = state; } @@ -111,14 +119,14 @@ class ToneManager { this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> { startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375); }, 0, TimeUnit.SECONDS); - JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 375, TimeUnit.MILLISECONDS); + this.currentResetFuture = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 375, TimeUnit.MILLISECONDS); } private void scheduleBusy() { this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> { startTone(ToneGenerator.TONE_CDMA_NETWORK_BUSY, 2500); }, 0, TimeUnit.SECONDS); - JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 2500, TimeUnit.MILLISECONDS); + this.currentResetFuture = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(this::resetAudioManager, 2500, TimeUnit.MILLISECONDS); } private void scheduleWaitingTone() { @@ -127,6 +135,10 @@ class ToneManager { }, 0, 3, TimeUnit.SECONDS); } + private boolean noResetScheduled() { + return this.currentResetFuture == null || this.currentResetFuture.isDone(); + } + private void cancelCurrentTone() { if (currentTone != null) { currentTone.cancel(true);