Fix NotificationChannel backup import.

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

Fixes #8174
pull/1/head
Greyson Parrelli 6 years ago
parent d9ba6962c7
commit 73b18fc1dd

@ -69,6 +69,7 @@ import org.thoughtcrime.securesms.database.NoExternalStorageException;
import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob;
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
import org.thoughtcrime.securesms.lock.RegistrationLockReminders;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.push.AccountManagerFactory;
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
@ -378,6 +379,7 @@ public class RegistrationActivity extends BaseActionBarActivity implements Verif
database, backup.getFile(), passphrase);
DatabaseFactory.upgradeRestored(context, database);
NotificationChannels.restoreContactNotificationChannels(context);
TextSecurePreferences.setBackupEnabled(context, true);
TextSecurePreferences.setBackupPassphrase(context, passphrase);

@ -89,7 +89,6 @@ public class FullBackupImporter extends FullBackupBase {
}
trimEntriesForExpiredMessages(context, db);
restoreNotificationChannels(context);
db.setTransactionSuccessful();
} finally {
@ -190,20 +189,6 @@ public class FullBackupImporter extends FullBackupBase {
}
}
private static void restoreNotificationChannels(@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);
}
}
}
private static class BackupRecordInputStream extends BackupStream {

@ -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.
*/

Loading…
Cancel
Save