reset tone manager after reaching NULL status

This commit is contained in:
Daniel Gultsch 2020-05-22 16:25:29 +02:00
parent 550fbc6d2c
commit ed4d7bff92
1 changed files with 14 additions and 2 deletions

View File

@ -20,6 +20,7 @@ class ToneManager {
private ToneState state = null; private ToneState state = null;
private ScheduledFuture<?> currentTone; private ScheduledFuture<?> currentTone;
private ScheduledFuture<?> currentResetFuture;
private boolean appRtcAudioManagerHasControl = false; private boolean appRtcAudioManagerHasControl = false;
ToneManager(final Context context) { ToneManager(final Context context) {
@ -93,6 +94,13 @@ class ToneManager {
case ENDING_CALL: case ENDING_CALL:
scheduleEnding(); scheduleEnding();
break; break;
case NULL:
if (noResetScheduled()) {
resetAudioManager();
}
break;
default:
throw new IllegalStateException("Unable to handle transition to "+state);
} }
this.state = state; this.state = state;
} }
@ -111,14 +119,14 @@ class ToneManager {
this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> { this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375); startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
}, 0, TimeUnit.SECONDS); }, 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() { private void scheduleBusy() {
this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> { this.currentTone = JingleConnectionManager.SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
startTone(ToneGenerator.TONE_CDMA_NETWORK_BUSY, 2500); startTone(ToneGenerator.TONE_CDMA_NETWORK_BUSY, 2500);
}, 0, TimeUnit.SECONDS); }, 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() { private void scheduleWaitingTone() {
@ -127,6 +135,10 @@ class ToneManager {
}, 0, 3, TimeUnit.SECONDS); }, 0, 3, TimeUnit.SECONDS);
} }
private boolean noResetScheduled() {
return this.currentResetFuture == null || this.currentResetFuture.isDone();
}
private void cancelCurrentTone() { private void cancelCurrentTone() {
if (currentTone != null) { if (currentTone != null) {
currentTone.cancel(true); currentTone.cancel(true);