From 53da64b7e2af6349c0796acefae0cbcaf7371e53 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 19 Feb 2021 15:30:55 +0100 Subject: [PATCH] do not attempt to play 'none' ringtone trying to play 'none' ringtone resulted in the default ring tone being played --- .../services/NotificationService.java | 23 ++++++++++++------- src/main/res/values/strings.xml | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 755895961..c7384b5fb 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -34,6 +34,8 @@ import androidx.core.app.RemoteInput; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.IconCompat; +import com.google.common.base.Strings; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -397,20 +399,25 @@ public class NotificationService { public void startRinging(final AbstractJingleConnection.Id id, final Set media) { showIncomingCallNotification(id, media); - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService); - final Resources resources = mXmppConnectionService.getResources(); - final Uri uri = Uri.parse(preferences.getString("call_ringtone", resources.getString(R.string.incoming_call_ringtone))); - this.currentlyPlayingRingtone = RingtoneManager.getRingtone(mXmppConnectionService, uri); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - this.currentlyPlayingRingtone.setLooping(true); - } - this.currentlyPlayingRingtone.play(); this.vibrationFuture = SCHEDULED_EXECUTOR_SERVICE.scheduleAtFixedRate( new VibrationRunnable(), 0, 3, TimeUnit.SECONDS ); + 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)); + if (Strings.isNullOrEmpty(ringtonePreference)) { + Log.d(Config.LOGTAG,"ringtone has been set to none"); + return; + } + final Uri uri = Uri.parse(ringtonePreference); + this.currentlyPlayingRingtone = RingtoneManager.getRingtone(mXmppConnectionService, uri); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + this.currentlyPlayingRingtone.setLooping(true); + } + this.currentlyPlayingRingtone.play(); } private void showIncomingCallNotification(final AbstractJingleConnection.Id id, final Set media) { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 05c6237e4..d1d803688 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -122,7 +122,7 @@ Ringtone Notification sound Notification sound for new messages - Ringtone for incoming call + Ringtone for incoming calls Grace Period The length of time notifications are silenced after detecting activity on one of your other devices. Advanced