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:
parent
d38c264e7d
commit
9187739450
|
@ -14,9 +14,11 @@ import eu.siacs.conversations.Config;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
class ToneManager {
|
class ToneManager {
|
||||||
|
|
||||||
private final ToneGenerator toneGenerator;
|
private ToneGenerator toneGenerator;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
private ToneState state = null;
|
private ToneState state = null;
|
||||||
|
@ -26,14 +28,6 @@ class ToneManager {
|
||||||
private boolean appRtcAudioManagerHasControl = false;
|
private boolean appRtcAudioManagerHasControl = false;
|
||||||
|
|
||||||
ToneManager(final Context context) {
|
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;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,10 +166,28 @@ class ToneManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTone(final int toneType, final int durationMs) {
|
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) {
|
if (toneGenerator != null) {
|
||||||
this.toneGenerator.startTone(toneType, durationMs);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue