From 70eecb754ed14994c65083ce06203bee8118d73b Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Fri, 7 Sep 2018 16:18:26 -0700 Subject: [PATCH] Address bugs in notification channel backup restore. --- .../securesms/RecipientPreferenceActivity.java | 16 ++-------------- .../securesms/notifications/MessageNotifier.java | 5 ++++- .../notifications/NotificationChannels.java | 8 ++++++-- .../notifications/NotificationState.java | 3 ++- .../securesms/recipients/Recipient.java | 6 +----- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java index 90ff3faf29..3ea79f1b4a 100644 --- a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java +++ b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java @@ -364,7 +364,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi mutePreference.setChecked(recipient.isMuted()); - ringtoneMessagePreference.setSummary(ringtoneMessagePreference.isEnabled() ? getRingtoneSummary(getContext(), recipient.getMessageRingtone(getContext())) : ""); + ringtoneMessagePreference.setSummary(ringtoneMessagePreference.isEnabled() ? getRingtoneSummary(getContext(), recipient.getMessageRingtone()) : ""); ringtoneCallPreference.setSummary(getRingtoneSummary(getContext(), recipient.getCallRingtone())); Pair vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate()); @@ -512,7 +512,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi current = recipient.getCallRingtone(); defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext()); } else { - current = recipient.getMessageRingtone(getContext()); + current = recipient.getMessageRingtone(); defaultUri = TextSecurePreferences.getNotificationRingtone(getContext()); } @@ -754,17 +754,5 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi return true; } } - - private class NotificationSettingsClickedListener implements Preference.OnPreferenceClickListener { - - @Override - public boolean onPreferenceClick(Preference preference) { - String channel = recipient.getNotificationChannel(); - if (channel != null) { - NotificationChannels.openChannelSettings(getActivity(), channel); - } - return true; - } - } } } diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index 6cd281077a..7316e011a9 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -381,7 +381,10 @@ public class MessageNotifier { return; } - Uri uri = recipient != null ? recipient.resolve().getMessageRingtone(context) : null; + Uri uri = null; + if (recipient != null) { + uri = NotificationChannels.supported() ? NotificationChannels.getMessageRingtone(context, recipient) : recipient.getMessageRingtone(); + } if (uri == null) { uri = NotificationChannels.supported() ? NotificationChannels.getMessageRingtone(context) : TextSecurePreferences.getNotificationRingtone(context); diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java b/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java index e5940ee7f5..2e43329565 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationChannels.java @@ -82,7 +82,11 @@ public class NotificationChannels { try (RecipientDatabase.RecipientReader reader = db.getRecipientsWithNotificationChannels()) { Recipient recipient; while ((recipient = reader.getNext()) != null) { - NotificationChannels.createChannelFor(context, recipient); + NotificationManager notificationManager = getNotificationManager(context); + if (!channelExists(notificationManager.getNotificationChannel(recipient.getNotificationChannel()))) { + String id = createChannelFor(context, recipient); + db.setNotificationChannel(recipient, id); + } } } } @@ -123,7 +127,7 @@ public class NotificationChannels { public static String createChannelFor(@NonNull Context context, @NonNull Recipient recipient) { VibrateState vibrateState = recipient.getMessageVibrate(); boolean vibrationEnabled = vibrateState == VibrateState.DEFAULT ? TextSecurePreferences.isNotificationVibrateEnabled(context) : vibrateState == VibrateState.ENABLED; - Uri messageRingtone = recipient.getMessageRingtone(context) != null ? recipient.getMessageRingtone(context) : getMessageRingtone(context); + Uri messageRingtone = recipient.getMessageRingtone() != null ? recipient.getMessageRingtone() : getMessageRingtone(context); String displayName = getChannelDisplayNameFor(context, recipient.getName(), recipient.getProfileName(), recipient.getAddress()); return createChannelFor(context, recipient.getAddress(), displayName, messageRingtone, vibrationEnabled); diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationState.java b/src/org/thoughtcrime/securesms/notifications/NotificationState.java index 3e3e282b37..ea1b4f30fa 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationState.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationState.java @@ -50,7 +50,8 @@ public class NotificationState { Recipient recipient = notifications.getFirst().getRecipient(); if (recipient != null) { - return recipient.resolve().getMessageRingtone(context); + return NotificationChannels.supported() ? NotificationChannels.getMessageRingtone(context, recipient) + : recipient.resolve().getMessageRingtone(); } } diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index 90ad56c8f1..41b8638e35 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -463,15 +463,11 @@ public class Recipient implements RecipientModifiedListener { if (notify) notifyListeners(); } - public synchronized @Nullable Uri getMessageRingtone(@NonNull Context context) { + public synchronized @Nullable Uri getMessageRingtone() { if (messageRingtone != null && messageRingtone.getScheme() != null && messageRingtone.getScheme().startsWith("file")) { return null; } - if (NotificationChannels.supported()) { - return NotificationChannels.getMessageRingtone(context, this); - } - return messageRingtone; }