Address bugs in notification channel backup restore.

This commit is contained in:
Greyson Parrelli 2018-09-07 16:18:26 -07:00
parent ad036b0d6a
commit 70eecb754e
5 changed files with 15 additions and 23 deletions

View File

@ -364,7 +364,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
mutePreference.setChecked(recipient.isMuted()); 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())); ringtoneCallPreference.setSummary(getRingtoneSummary(getContext(), recipient.getCallRingtone()));
Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate()); Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate());
@ -512,7 +512,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
current = recipient.getCallRingtone(); current = recipient.getCallRingtone();
defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext()); defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext());
} else { } else {
current = recipient.getMessageRingtone(getContext()); current = recipient.getMessageRingtone();
defaultUri = TextSecurePreferences.getNotificationRingtone(getContext()); defaultUri = TextSecurePreferences.getNotificationRingtone(getContext());
} }
@ -754,17 +754,5 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
return true; 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;
}
}
} }
} }

View File

@ -381,7 +381,10 @@ public class MessageNotifier {
return; 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) { if (uri == null) {
uri = NotificationChannels.supported() ? NotificationChannels.getMessageRingtone(context) : TextSecurePreferences.getNotificationRingtone(context); uri = NotificationChannels.supported() ? NotificationChannels.getMessageRingtone(context) : TextSecurePreferences.getNotificationRingtone(context);

View File

@ -82,7 +82,11 @@ public class NotificationChannels {
try (RecipientDatabase.RecipientReader reader = db.getRecipientsWithNotificationChannels()) { try (RecipientDatabase.RecipientReader reader = db.getRecipientsWithNotificationChannels()) {
Recipient recipient; Recipient recipient;
while ((recipient = reader.getNext()) != null) { 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) { public static String createChannelFor(@NonNull Context context, @NonNull Recipient recipient) {
VibrateState vibrateState = recipient.getMessageVibrate(); VibrateState vibrateState = recipient.getMessageVibrate();
boolean vibrationEnabled = vibrateState == VibrateState.DEFAULT ? TextSecurePreferences.isNotificationVibrateEnabled(context) : vibrateState == VibrateState.ENABLED; 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()); String displayName = getChannelDisplayNameFor(context, recipient.getName(), recipient.getProfileName(), recipient.getAddress());
return createChannelFor(context, recipient.getAddress(), displayName, messageRingtone, vibrationEnabled); return createChannelFor(context, recipient.getAddress(), displayName, messageRingtone, vibrationEnabled);

View File

@ -50,7 +50,8 @@ public class NotificationState {
Recipient recipient = notifications.getFirst().getRecipient(); Recipient recipient = notifications.getFirst().getRecipient();
if (recipient != null) { if (recipient != null) {
return recipient.resolve().getMessageRingtone(context); return NotificationChannels.supported() ? NotificationChannels.getMessageRingtone(context, recipient)
: recipient.resolve().getMessageRingtone();
} }
} }

View File

@ -463,15 +463,11 @@ public class Recipient implements RecipientModifiedListener {
if (notify) notifyListeners(); 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")) { if (messageRingtone != null && messageRingtone.getScheme() != null && messageRingtone.getScheme().startsWith("file")) {
return null; return null;
} }
if (NotificationChannels.supported()) {
return NotificationChannels.getMessageRingtone(context, this);
}
return messageRingtone; return messageRingtone;
} }