@@ -392,9 +392,7 @@ public class CallIntegration extends Connection {
public void success() {
Log.d(Config.LOGTAG, "CallIntegration.success()");
- final var toneGenerator =
- new ToneGenerator(AudioManager.STREAM_VOICE_CALL, DEFAULT_TONE_VOLUME);
- toneGenerator.startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
+ startTone(DEFAULT_TONE_VOLUME, ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
this.destroyWithDelay(new DisconnectCause(DisconnectCause.LOCAL, null), 375);
}
@@ -409,9 +407,7 @@ public class CallIntegration extends Connection {
public void error() {
Log.d(Config.LOGTAG, "CallIntegration.error()");
- final var toneGenerator =
- new ToneGenerator(AudioManager.STREAM_VOICE_CALL, DEFAULT_TONE_VOLUME);
- toneGenerator.startTone(ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
+ startTone(DEFAULT_TONE_VOLUME, ToneGenerator.TONE_CDMA_CALLDROP_LITE, 375);
this.destroyWithDelay(new DisconnectCause(DisconnectCause.ERROR, null), 375);
}
@@ -428,8 +424,7 @@ public class CallIntegration extends Connection {
public void busy() {
Log.d(Config.LOGTAG, "CallIntegration.busy()");
- final var toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 80);
- toneGenerator.startTone(ToneGenerator.TONE_CDMA_NETWORK_BUSY, 2500);
+ startTone(80, ToneGenerator.TONE_CDMA_NETWORK_BUSY, 2500);
this.destroyWithDelay(new DisconnectCause(DisconnectCause.BUSY, null), 2500);
}
@@ -457,6 +452,17 @@ public class CallIntegration extends Connection {
Log.d(Config.LOGTAG, "destroyed!");
}
+ private void startTone(final int volume, final int toneType, final int durationMs) {
+ final ToneGenerator toneGenerator;
+ try {
+ toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, volume);
+ } catch (final RuntimeException e) {
+ Log.e(Config.LOGTAG, "could not initialize tone generator", e);
+ return;
+ }
+ toneGenerator.startTone(toneType, durationMs);
+ }
+
public static Uri address(final Jid contact) {
return Uri.parse(String.format("xmpp:%s", contact.toEscapedString()));
}