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

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

View File

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

View File

@ -67,6 +67,26 @@ public class NotificationChannels {
onCreate(context, notificationManager); 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. * @return The channel ID for the default messages channel.
*/ */