play dial tones on STREAM_MUSIC when phone is silent

when the phone is silent only the first ~three tones are played when
attempting to play out the tone over STREAM_VOICE_CALL

it’s unclear exactly why this is the case (in the past we went back and forth
between STREAM_VOICE_CALL and STREAM_MUSIC) exactly to fix issues around silent
mode.
Apparently we failed to test this past three sounds.

This commit changes the stream back to music - but not generally as this was in
the past - but only for when the phone is on silent
This commit is contained in:
Daniel Gultsch 2023-04-03 16:00:02 +02:00
parent d38c264e7d
commit 9187739450
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2

View file

@ -14,9 +14,11 @@ import eu.siacs.conversations.Config;
import static java.util.Arrays.asList;
import androidx.core.content.ContextCompat;
class ToneManager {
private final ToneGenerator toneGenerator;
private ToneGenerator toneGenerator;
private final Context context;
private ToneState state = null;
@ -26,14 +28,6 @@ class ToneManager {
private boolean appRtcAudioManagerHasControl = false;
ToneManager(final Context context) {
ToneGenerator toneGenerator;
try {
toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 60);
} catch (final RuntimeException e) {
Log.e(Config.LOGTAG, "unable to instantiate ToneGenerator", e);
toneGenerator = null;
}
this.toneGenerator = toneGenerator;
this.context = context;
}
@ -172,10 +166,28 @@ class ToneManager {
}
private void startTone(final int toneType, final int durationMs) {
if (this.toneGenerator != null) {
this.toneGenerator.release();;
}
final AudioManager audioManager = ContextCompat.getSystemService(context, AudioManager.class);
final boolean ringerModeNormal = audioManager == null || audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL;
this.toneGenerator = getToneGenerator(ringerModeNormal);
if (toneGenerator != null) {
this.toneGenerator.startTone(toneType, durationMs);
} else {
Log.e(Config.LOGTAG, "failed to start tone. ToneGenerator doesn't exist");
}
}
private static ToneGenerator getToneGenerator(final boolean ringerModeNormal) {
try {
if (ringerModeNormal) {
return new ToneGenerator(AudioManager.STREAM_VOICE_CALL,60);
} else {
return new ToneGenerator(AudioManager.STREAM_MUSIC,100);
}
} catch (final Exception e) {
Log.d(Config.LOGTAG,"could not create tone generator",e);
return null;
}
}