add safeguards to ringtone playing twice

This commit is contained in:
Daniel Gultsch 2024-03-25 08:50:44 +01:00 committed by Arne
parent 56433c5ef8
commit 50a5951873
3 changed files with 16 additions and 2 deletions

View file

@ -775,7 +775,7 @@ public class NotificationService {
}
showIncomingCallNotification(id, media, toString());
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
final NotificationManager notificationManager = mXmppConnectionService.getSystemService(NotificationManager.class);
final int currentInterruptionFilter;
if (notificationManager != null) {
currentInterruptionFilter = notificationManager.getCurrentInterruptionFilter();
@ -787,7 +787,7 @@ public class NotificationService {
return;
}
final ScheduledFuture<?> currentVibrationFuture = this.vibrationFuture;
this.vibrationFuture = SCHEDULED_EXECUTOR_SERVICE.scheduleAtFixedRate(
this.vibrationFuture = SCHEDULED_EXECUTOR_SERVICE.scheduleWithFixedDelay(
new VibrationRunnable(),
0,
3,
@ -796,6 +796,10 @@ public class NotificationService {
if (currentVibrationFuture != null) {
currentVibrationFuture.cancel(true);
}
final var preexistingRingtone = this.currentlyPlayingRingtone;
if (preexistingRingtone != null) {
preexistingRingtone.stop();
}
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
final Resources resources = mXmppConnectionService.getResources();
final String ringtonePreference = preferences.getString("call_ringtone", resources.getString(R.string.incoming_call_ringtone));

View file

@ -504,6 +504,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
final RtpSessionProposal proposal =
getRtpSessionProposal(account, from.asBareJid(), sessionId);
synchronized (rtpSessionProposals) {
// TODO remove the remove()!= null check to ensure we always call busy()
if (proposal != null && rtpSessionProposals.remove(proposal) != null) {
proposal.callIntegration.busy();
writeLogMissedOutgoing(

View file

@ -2695,6 +2695,15 @@ public class JingleRtpConnection extends AbstractJingleConnection
@Override
public void onCallIntegrationShowIncomingCallUi() {
if (isTerminated()) {
// there might be race conditions with the call integration service invoking this
// callback when the rtp session has already ended. It should be enough to just return
// instead of throwing an exception. however throwing an exception gives us a sense of
// if and how frequently this happens
throw new IllegalStateException(
"CallIntegration requested incoming call UI but session was already terminated");
}
// TODO apparently this can be called too early as well?
xmppConnectionService.getNotificationService().startRinging(id, getMedia());
}