Fix NotificationChannel backup import.

We were recreating the channels before the database upgrade. We
have to do it after.

Fixes #8174
This commit is contained in:
Greyson Parrelli
2018-09-04 10:57:33 -07:00
parent d9ba6962c7
commit 73b18fc1dd
3 changed files with 22 additions and 15 deletions

View File

@@ -67,6 +67,26 @@ public class NotificationChannels {
onCreate(context, notificationManager);
}
/**
* Recreates all notification channels for contacts with custom notifications enabled. Should be
* safe to call repeatedly. Needs to be executed on a background thread.
*/
@WorkerThread
public static void restoreContactNotificationChannels(@NonNull Context context) {
if (!NotificationChannels.supported()) {
return;
}
RecipientDatabase db = DatabaseFactory.getRecipientDatabase(context);
try (RecipientDatabase.RecipientReader reader = db.getRecipientsWithNotificationChannels()) {
Recipient recipient;
while ((recipient = reader.getNext()) != null) {
NotificationChannels.createChannelFor(context, recipient);
}
}
}
/**
* @return The channel ID for the default messages channel.
*/