That fuck shit the fascists are using
1package org.tm.archive.migrations;
2
3import android.content.Context;
4
5import androidx.annotation.NonNull;
6import androidx.annotation.VisibleForTesting;
7import androidx.lifecycle.LiveData;
8import androidx.lifecycle.MutableLiveData;
9
10import org.greenrobot.eventbus.EventBus;
11import org.greenrobot.eventbus.Subscribe;
12import org.greenrobot.eventbus.ThreadMode;
13import org.signal.core.util.logging.Log;
14import org.tm.archive.jobmanager.JobManager;
15import org.tm.archive.keyvalue.SignalStore;
16import org.tm.archive.stickers.BlessedPacks;
17import org.tm.archive.util.TextSecurePreferences;
18import org.tm.archive.util.Util;
19import org.tm.archive.util.VersionTracker;
20
21import java.util.LinkedHashMap;
22import java.util.Map;
23
24/**
25 * Manages application-level migrations.
26 *
27 * Migrations can be slotted to occur based on changes in the canonical version code
28 * (see {@link Util#getCanonicalVersionCode()}).
29 *
30 * Migrations are performed via {@link MigrationJob}s. These jobs are durable and are run before any
31 * other job, allowing you to schedule safe migrations. Furthermore, you may specify that a
32 * migration is UI-blocking, at which point we will show a spinner via
33 * {@link ApplicationMigrationActivity} if the user opens the app while the migration is in
34 * progress.
35 */
36public class ApplicationMigrations {
37
38 private static final String TAG = Log.tag(ApplicationMigrations.class);
39
40 private static final MutableLiveData<Boolean> UI_BLOCKING_MIGRATION_RUNNING = new MutableLiveData<>();
41
42 private static final int LEGACY_CANONICAL_VERSION = 455;
43
44 @VisibleForTesting
45 static final class Version {
46 static final int LEGACY = 1;
47 static final int RECIPIENT_ID = 2;
48 static final int RECIPIENT_SEARCH = 3;
49 static final int RECIPIENT_CLEANUP = 4;
50 static final int AVATAR_MIGRATION = 5;
51 static final int UUIDS = 6;
52 static final int CACHED_ATTACHMENTS = 7;
53 static final int STICKERS_LAUNCH = 8;
54 //static final int TEST_ARGON2 = 9;
55 static final int SWOON_STICKERS = 10;
56 static final int STORAGE_SERVICE = 11;
57 //static final int STORAGE_KEY_ROTATE = 12;
58 static final int REMOVE_AVATAR_ID = 13;
59 static final int STORAGE_CAPABILITY = 14;
60 static final int PIN_REMINDER = 15;
61 static final int VERSIONED_PROFILE = 16;
62 static final int PIN_OPT_OUT = 17;
63 static final int TRIM_SETTINGS = 18;
64 static final int THUMBNAIL_CLEANUP = 19;
65 static final int GV2 = 20;
66 static final int GV2_2 = 21;
67 static final int CDS = 22;
68 static final int BACKUP_NOTIFICATION = 23;
69 static final int GV1_MIGRATION = 24;
70 static final int USER_NOTIFICATION = 25;
71 static final int DAY_BY_DAY_STICKERS = 26;
72 static final int BLOB_LOCATION = 27;
73 static final int SYSTEM_NAME_SPLIT = 28;
74 // Versions 29, 30 accidentally skipped
75 static final int MUTE_SYNC = 31;
76 static final int PROFILE_SHARING_UPDATE = 32;
77 static final int SMS_STORAGE_SYNC = 33;
78 static final int APPLY_UNIVERSAL_EXPIRE = 34;
79 static final int SENDER_KEY = 35;
80 static final int SENDER_KEY_2 = 36;
81 static final int DB_AUTOINCREMENT = 37;
82 static final int ATTACHMENT_CLEANUP = 38;
83 static final int LOG_CLEANUP = 39;
84 static final int ATTACHMENT_CLEANUP_2 = 40;
85 static final int ANNOUNCEMENT_GROUP_CAPABILITY = 41;
86 static final int STICKER_MY_DAILY_LIFE = 42;
87 static final int SENDER_KEY_3 = 43;
88 static final int CHANGE_NUMBER_SYNC = 44;
89 static final int CHANGE_NUMBER_CAPABILITY = 45;
90 static final int CHANGE_NUMBER_CAPABILITY_2 = 46;
91 static final int DEFAULT_REACTIONS_SYNC = 47;
92 static final int DB_REACTIONS_MIGRATION = 48;
93 //static final int CHANGE_NUMBER_CAPABILITY_3 = 49;
94 static final int PNI = 50;
95 static final int FIX_DEPRECATION = 51; // Only used to trigger clearing the 'client deprecated' flag
96 static final int JUMBOMOJI_DOWNLOAD = 52;
97 static final int FIX_EMOJI_QUALITY = 53;
98 static final int CHANGE_NUMBER_CAPABILITY_4 = 54;
99 //static final int KBS_MIGRATION = 55;
100 static final int PNI_IDENTITY = 56;
101 static final int PNI_IDENTITY_2 = 57;
102 static final int PNI_IDENTITY_3 = 58;
103 static final int STORY_DISTRIBUTION_LIST_SYNC = 59;
104 static final int EMOJI_VERSION_7 = 60;
105 static final int MY_STORY_PRIVACY_MODE = 61;
106 static final int REFRESH_EXPIRING_CREDENTIAL = 62;
107 static final int EMOJI_SEARCH_INDEX_10 = 63;
108 static final int REFRESH_PNI_REGISTRATION_ID = 64;
109 //static final int KBS_MIGRATION_2 = 65;
110 static final int PNI_2 = 66;
111 static final int SYSTEM_NAME_SYNC = 67;
112 static final int STORY_VIEWED_STATE = 68;
113// static final int STORY_READ_STATE = 69;
114 static final int THREAD_MESSAGE_SCHEMA_CHANGE = 70;
115 static final int SMS_MMS_MERGE = 71;
116 static final int REBUILD_MESSAGE_FTS_INDEX = 72;
117 static final int UPDATE_SMS_JOBS = 73;
118 static final int OPTIMIZE_MESSAGE_FTS_INDEX = 74;
119 static final int REACTION_DATABASE_MIGRATION = 75;
120 static final int REBUILD_MESSAGE_FTS_INDEX_2 = 76;
121 static final int GLIDE_CACHE_CLEAR = 77;
122 static final int SYSTEM_NAME_RESYNC = 78;
123 static final int RECOVERY_PASSWORD_SYNC = 79;
124// static final int DECRYPTIONS_DRAINED = 80;
125 static final int REBUILD_MESSAGE_FTS_INDEX_3 = 81;
126 static final int TO_FROM_RECIPIENTS = 82;
127 static final int REBUILD_MESSAGE_FTS_INDEX_4 = 83;
128 static final int INDEX_DATABASE_MIGRATION = 84;
129 static final int ACCOUNT_CONSISTENCY_CHECK = 85;
130 static final int BACKUP_JITTER = 86;
131 static final int PREKEY_SYNC = 87;
132 static final int DEDUPE_DB_MIGRATION = 88;
133 static final int DEDUPE_DB_MIGRATION_2 = 89;
134 static final int EMOJI_VERSION_8 = 90;
135 static final int SVR2_MIRROR = 91;
136 static final int ATTACHMENT_CLEANUP_3 = 92;
137 static final int EMOJI_SEARCH_INDEX_CHECK = 93;
138 static final int IDENTITY_FIX = 94;
139 static final int COPY_USERNAME_TO_SIGNAL_STORE = 95;
140 static final int RECHECK_PAYMENTS = 96;
141 static final int THREAD_COUNT_DB_MIGRATION = 97;
142 static final int SYNC_KEYS_MIGRATION = 98;
143 static final int SELF_REGISTERTED_STATE = 99;
144 static final int SVR2_ENCLAVE_UPDATE = 100;
145 static final int STORAGE_LOCAL_UNKNOWNS_FIX = 101;
146 static final int PNP_LAUNCH = 102;
147 static final int EMOJI_VERSION_10 = 103;
148 static final int ATTACHMENT_HASH_BACKFILL = 104;
149 }
150
151 public static final int CURRENT_VERSION = 104;
152
153 /**
154 * This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
155 * to {@link JobManager#beginJobLoop()}. Otherwise, other non-migration jobs may have started
156 * executing before we add the migration jobs.
157 */
158 public static void onApplicationCreate(@NonNull Context context, @NonNull JobManager jobManager) {
159 if (isLegacyUpdate(context)) {
160 Log.i(TAG, "Detected the need for a legacy update. Last seen canonical version: " + VersionTracker.getLastSeenVersion(context));
161 TextSecurePreferences.setAppMigrationVersion(context, 0);
162 }
163
164 if (!isUpdate(context)) {
165 Log.d(TAG, "Not an update. Skipping.");
166 VersionTracker.updateLastSeenVersion(context);
167 return;
168 } else {
169 Log.d(TAG, "About to update. Clearing deprecation flag.");
170 SignalStore.misc().setClientDeprecated(false);
171 }
172
173 final int lastSeenVersion = TextSecurePreferences.getAppMigrationVersion(context);
174 Log.d(TAG, "currentVersion: " + CURRENT_VERSION + ", lastSeenVersion: " + lastSeenVersion);
175
176 LinkedHashMap<Integer, MigrationJob> migrationJobs = getMigrationJobs(context, lastSeenVersion);
177
178 if (migrationJobs.size() > 0) {
179 Log.i(TAG, "About to enqueue " + migrationJobs.size() + " migration(s).");
180
181 boolean uiBlocking = true;
182 int uiBlockingVersion = lastSeenVersion;
183
184 for (Map.Entry<Integer, MigrationJob> entry : migrationJobs.entrySet()) {
185 int version = entry.getKey();
186 MigrationJob job = entry.getValue();
187
188 uiBlocking &= job.isUiBlocking();
189 if (uiBlocking) {
190 uiBlockingVersion = version;
191 }
192
193 jobManager.add(job);
194 jobManager.add(new MigrationCompleteJob(version));
195 }
196
197 if (uiBlockingVersion > lastSeenVersion) {
198 Log.i(TAG, "Migration set is UI-blocking through version " + uiBlockingVersion + ".");
199 UI_BLOCKING_MIGRATION_RUNNING.setValue(true);
200 } else {
201 Log.i(TAG, "Migration set is non-UI-blocking.");
202 UI_BLOCKING_MIGRATION_RUNNING.setValue(false);
203 }
204
205 final long startTime = System.currentTimeMillis();
206 final int uiVersion = uiBlockingVersion;
207
208 EventBus.getDefault().register(new Object() {
209 @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
210 public void onMigrationComplete(MigrationCompleteEvent event) {
211 Log.i(TAG, "Received MigrationCompleteEvent for version " + event.getVersion() + ". (Current: " + CURRENT_VERSION + ")");
212
213 if (event.getVersion() > CURRENT_VERSION) {
214 throw new AssertionError("Received a higher version than the current version? App downgrades are not supported. (received: " + event.getVersion() + ", current: " + CURRENT_VERSION + ")");
215 }
216
217 Log.i(TAG, "Updating last migration version to " + event.getVersion());
218 TextSecurePreferences.setAppMigrationVersion(context, event.getVersion());
219
220 if (event.getVersion() == CURRENT_VERSION) {
221 Log.i(TAG, "Migration complete. Took " + (System.currentTimeMillis() - startTime) + " ms.");
222 EventBus.getDefault().unregister(this);
223
224 VersionTracker.updateLastSeenVersion(context);
225 UI_BLOCKING_MIGRATION_RUNNING.setValue(false);
226 } else if (event.getVersion() >= uiVersion) {
227 Log.i(TAG, "Version is >= the UI-blocking version. Posting 'false'.");
228 UI_BLOCKING_MIGRATION_RUNNING.setValue(false);
229 }
230 }
231 });
232 } else {
233 Log.d(TAG, "No migrations.");
234 TextSecurePreferences.setAppMigrationVersion(context, CURRENT_VERSION);
235 VersionTracker.updateLastSeenVersion(context);
236 UI_BLOCKING_MIGRATION_RUNNING.setValue(false);
237 }
238 }
239
240 /**
241 * @return A {@link LiveData} object that will update with whether or not a UI blocking migration
242 * is in progress.
243 */
244 public static LiveData<Boolean> getUiBlockingMigrationStatus() {
245 return UI_BLOCKING_MIGRATION_RUNNING;
246 }
247
248 /**
249 * @return True if a UI blocking migration is running.
250 */
251 public static boolean isUiBlockingMigrationRunning() {
252 Boolean value = UI_BLOCKING_MIGRATION_RUNNING.getValue();
253 return value != null && value;
254 }
255
256 /**
257 * @return Whether or not we're in the middle of an update, as determined by the last seen and
258 * current version.
259 */
260 public static boolean isUpdate(@NonNull Context context) {
261 return isLegacyUpdate(context) || TextSecurePreferences.getAppMigrationVersion(context) < CURRENT_VERSION;
262 }
263
264 private static LinkedHashMap<Integer, MigrationJob> getMigrationJobs(@NonNull Context context, int lastSeenVersion) {
265 LinkedHashMap<Integer, MigrationJob> jobs = new LinkedHashMap<>();
266
267 if (lastSeenVersion < Version.LEGACY) {
268 jobs.put(Version.LEGACY, new LegacyMigrationJob());
269 }
270
271 if (lastSeenVersion < Version.RECIPIENT_ID) {
272 jobs.put(Version.RECIPIENT_ID, new DatabaseMigrationJob());
273 }
274
275 if (lastSeenVersion < Version.RECIPIENT_SEARCH) {
276 jobs.put(Version.RECIPIENT_SEARCH, new RecipientSearchMigrationJob());
277 }
278
279 if (lastSeenVersion < Version.RECIPIENT_CLEANUP) {
280 jobs.put(Version.RECIPIENT_CLEANUP, new DatabaseMigrationJob());
281 }
282
283 if (lastSeenVersion < Version.AVATAR_MIGRATION) {
284 jobs.put(Version.AVATAR_MIGRATION, new AvatarMigrationJob());
285 }
286
287 if (lastSeenVersion < Version.UUIDS) {
288 jobs.put(Version.UUIDS, new UuidMigrationJob());
289 }
290
291 if (lastSeenVersion < Version.CACHED_ATTACHMENTS) {
292 jobs.put(Version.CACHED_ATTACHMENTS, new CachedAttachmentsMigrationJob());
293 }
294
295 if (lastSeenVersion < Version.STICKERS_LAUNCH) {
296 jobs.put(Version.STICKERS_LAUNCH, new StickerLaunchMigrationJob());
297 }
298
299 // This migration only triggered a test we aren't interested in any more.
300 // if (lastSeenVersion < Version.TEST_ARGON2) {
301 // jobs.put(Version.TEST_ARGON2, new Argon2TestMigrationJob());
302 // }
303
304 if (lastSeenVersion < Version.SWOON_STICKERS) {
305 jobs.put(Version.SWOON_STICKERS, new StickerAdditionMigrationJob(BlessedPacks.SWOON_HANDS, BlessedPacks.SWOON_FACES));
306 }
307
308 if (lastSeenVersion < Version.STORAGE_SERVICE) {
309 jobs.put(Version.STORAGE_SERVICE, new StorageServiceMigrationJob());
310 }
311
312 // Superceded by StorageCapabilityMigrationJob
313// if (lastSeenVersion < Version.STORAGE_KEY_ROTATE) {
314// jobs.put(Version.STORAGE_KEY_ROTATE, new StorageKeyRotationMigrationJob());
315// }
316
317 if (lastSeenVersion < Version.REMOVE_AVATAR_ID) {
318 jobs.put(Version.REMOVE_AVATAR_ID, new AvatarIdRemovalMigrationJob());
319 }
320
321 if (lastSeenVersion < Version.STORAGE_CAPABILITY) {
322 jobs.put(Version.STORAGE_CAPABILITY, new StorageCapabilityMigrationJob());
323 }
324
325 if (lastSeenVersion < Version.PIN_REMINDER) {
326 jobs.put(Version.PIN_REMINDER, new PinReminderMigrationJob());
327 }
328
329 if (lastSeenVersion < Version.VERSIONED_PROFILE) {
330 jobs.put(Version.VERSIONED_PROFILE, new ProfileMigrationJob());
331 }
332
333 if (lastSeenVersion < Version.PIN_OPT_OUT) {
334 jobs.put(Version.PIN_OPT_OUT, new PinOptOutMigration());
335 }
336
337 if (lastSeenVersion < Version.TRIM_SETTINGS) {
338 jobs.put(Version.TRIM_SETTINGS, new TrimByLengthSettingsMigrationJob());
339 }
340
341 if (lastSeenVersion < Version.THUMBNAIL_CLEANUP) {
342 jobs.put(Version.THUMBNAIL_CLEANUP, new DatabaseMigrationJob());
343 }
344
345 if (lastSeenVersion < Version.GV2) {
346 jobs.put(Version.GV2, new AttributesMigrationJob());
347 }
348
349 if (lastSeenVersion < Version.GV2_2) {
350 jobs.put(Version.GV2_2, new AttributesMigrationJob());
351 }
352
353 if (lastSeenVersion < Version.CDS) {
354 jobs.put(Version.CDS, new DirectoryRefreshMigrationJob());
355 }
356
357 if (lastSeenVersion < Version.BACKUP_NOTIFICATION) {
358 jobs.put(Version.BACKUP_NOTIFICATION, new BackupNotificationMigrationJob());
359 }
360
361 if (lastSeenVersion < Version.GV1_MIGRATION) {
362 jobs.put(Version.GV1_MIGRATION, new AttributesMigrationJob());
363 }
364
365 if (lastSeenVersion < Version.USER_NOTIFICATION) {
366 jobs.put(Version.USER_NOTIFICATION, new UserNotificationMigrationJob());
367 }
368
369 if (lastSeenVersion < Version.DAY_BY_DAY_STICKERS) {
370 jobs.put(Version.DAY_BY_DAY_STICKERS, new StickerDayByDayMigrationJob());
371 }
372
373 if (lastSeenVersion < Version.BLOB_LOCATION) {
374 jobs.put(Version.BLOB_LOCATION, new BlobStorageLocationMigrationJob());
375 }
376
377 if (lastSeenVersion < Version.SYSTEM_NAME_SPLIT) {
378 jobs.put(Version.SYSTEM_NAME_SPLIT, new DirectoryRefreshMigrationJob());
379 }
380
381 if (lastSeenVersion < Version.MUTE_SYNC) {
382 jobs.put(Version.MUTE_SYNC, new StorageServiceMigrationJob());
383 }
384
385 if (lastSeenVersion < Version.PROFILE_SHARING_UPDATE) {
386 jobs.put(Version.PROFILE_SHARING_UPDATE, new ProfileSharingUpdateMigrationJob());
387 }
388
389 if (lastSeenVersion < Version.SMS_STORAGE_SYNC) {
390 jobs.put(Version.SMS_STORAGE_SYNC, new AccountRecordMigrationJob());
391 }
392
393 if (lastSeenVersion < Version.APPLY_UNIVERSAL_EXPIRE) {
394 jobs.put(Version.APPLY_UNIVERSAL_EXPIRE, new ApplyUnknownFieldsToSelfMigrationJob());
395 }
396
397 if (lastSeenVersion < Version.SENDER_KEY) {
398 jobs.put(Version.SENDER_KEY, new AttributesMigrationJob());
399 }
400
401 if (lastSeenVersion < Version.SENDER_KEY_2) {
402 jobs.put(Version.SENDER_KEY_2, new AttributesMigrationJob());
403 }
404
405 if (lastSeenVersion < Version.DB_AUTOINCREMENT) {
406 jobs.put(Version.DB_AUTOINCREMENT, new DatabaseMigrationJob());
407 }
408
409 if (lastSeenVersion < Version.ATTACHMENT_CLEANUP) {
410 jobs.put(Version.ATTACHMENT_CLEANUP, new AttachmentCleanupMigrationJob());
411 }
412
413 if (lastSeenVersion < Version.LOG_CLEANUP) {
414 jobs.put(Version.LOG_CLEANUP, new DeleteDeprecatedLogsMigrationJob());
415 }
416
417 if (lastSeenVersion < Version.ATTACHMENT_CLEANUP_2) {
418 jobs.put(Version.ATTACHMENT_CLEANUP_2, new AttachmentCleanupMigrationJob());
419 }
420
421 if (lastSeenVersion < Version.ANNOUNCEMENT_GROUP_CAPABILITY) {
422 jobs.put(Version.ANNOUNCEMENT_GROUP_CAPABILITY, new AttributesMigrationJob());
423 }
424
425 if (lastSeenVersion < Version.STICKER_MY_DAILY_LIFE) {
426 jobs.put(Version.STICKER_MY_DAILY_LIFE, new StickerMyDailyLifeMigrationJob());
427 }
428
429 if (lastSeenVersion < Version.SENDER_KEY_3) {
430 jobs.put(Version.SENDER_KEY_3, new AttributesMigrationJob());
431 }
432
433 if (lastSeenVersion < Version.CHANGE_NUMBER_SYNC) {
434 jobs.put(Version.CHANGE_NUMBER_SYNC, new AccountRecordMigrationJob());
435 }
436
437 if (lastSeenVersion < Version.CHANGE_NUMBER_CAPABILITY) {
438 jobs.put(Version.CHANGE_NUMBER_CAPABILITY, new AttributesMigrationJob());
439 }
440
441 if (lastSeenVersion < Version.CHANGE_NUMBER_CAPABILITY_2) {
442 jobs.put(Version.CHANGE_NUMBER_CAPABILITY_2, new AttributesMigrationJob());
443 }
444
445 if (lastSeenVersion < Version.DEFAULT_REACTIONS_SYNC) {
446 jobs.put(Version.DEFAULT_REACTIONS_SYNC, new StorageServiceMigrationJob());
447 }
448
449 if (lastSeenVersion < Version.DB_REACTIONS_MIGRATION) {
450 jobs.put(Version.DB_REACTIONS_MIGRATION, new DatabaseMigrationJob());
451 }
452
453 if (lastSeenVersion < Version.PNI) {
454 jobs.put(Version.PNI, new PniMigrationJob());
455 }
456
457 if (lastSeenVersion < Version.JUMBOMOJI_DOWNLOAD) {
458 jobs.put(Version.JUMBOMOJI_DOWNLOAD, new EmojiDownloadMigrationJob());
459 }
460
461 if (lastSeenVersion < Version.FIX_EMOJI_QUALITY) {
462 jobs.put(Version.FIX_EMOJI_QUALITY, new EmojiDownloadMigrationJob());
463 }
464
465 if (lastSeenVersion < Version.CHANGE_NUMBER_CAPABILITY_4) {
466 jobs.put(Version.CHANGE_NUMBER_CAPABILITY_4,new AttributesMigrationJob());
467 }
468
469 // if (lastSeenVersion < Version.KBS_MIGRATION) {
470 // jobs.put(Version.KBS_MIGRATION, new KbsEnclaveMigrationJob());
471 // }
472
473 if (lastSeenVersion < Version.PNI_IDENTITY) {
474 jobs.put(Version.PNI_IDENTITY, new PniAccountInitializationMigrationJob());
475 }
476
477 if (lastSeenVersion < Version.PNI_IDENTITY_2) {
478 jobs.put(Version.PNI_IDENTITY_2, new PniAccountInitializationMigrationJob());
479 }
480
481 if (lastSeenVersion < Version.PNI_IDENTITY_3) {
482 jobs.put(Version.PNI_IDENTITY_3, new PniAccountInitializationMigrationJob());
483 }
484
485 if (lastSeenVersion < Version.STORY_DISTRIBUTION_LIST_SYNC) {
486 jobs.put(Version.STORY_DISTRIBUTION_LIST_SYNC, new StorageServiceMigrationJob());
487 }
488
489 if (lastSeenVersion < Version.EMOJI_VERSION_7) {
490 jobs.put(Version.EMOJI_VERSION_7, new EmojiDownloadMigrationJob());
491 }
492
493 if (lastSeenVersion < Version.MY_STORY_PRIVACY_MODE) {
494 jobs.put(Version.MY_STORY_PRIVACY_MODE, new SyncDistributionListsMigrationJob());
495 }
496
497 if (lastSeenVersion < Version.REFRESH_EXPIRING_CREDENTIAL) {
498 jobs.put(Version.REFRESH_EXPIRING_CREDENTIAL, new AttributesMigrationJob());
499 }
500
501 if (lastSeenVersion < Version.EMOJI_SEARCH_INDEX_10) {
502 jobs.put(Version.EMOJI_SEARCH_INDEX_10, new EmojiDownloadMigrationJob());
503 }
504
505 if (lastSeenVersion < Version.REFRESH_PNI_REGISTRATION_ID) {
506 jobs.put(Version.REFRESH_PNI_REGISTRATION_ID, new AttributesMigrationJob());
507 }
508
509 // if (lastSeenVersion < Version.KBS_MIGRATION_2) {
510 // jobs.put(Version.KBS_MIGRATION_2, new KbsEnclaveMigrationJob());
511 // }
512
513 if (lastSeenVersion < Version.PNI_2) {
514 jobs.put(Version.PNI_2, new PniMigrationJob());
515 }
516
517 if (lastSeenVersion < Version.SYSTEM_NAME_SYNC) {
518 jobs.put(Version.SYSTEM_NAME_SYNC, new StorageServiceSystemNameMigrationJob());
519 }
520
521 if (lastSeenVersion < Version.STORY_VIEWED_STATE) {
522 jobs.put(Version.STORY_VIEWED_STATE, new StoryViewedReceiptsStateMigrationJob());
523 }
524
525// if (lastSeenVersion < Version.STORY_READ_STATE) {
526// jobs.put(Version.STORY_READ_STATE, new StoryReadStateMigrationJob());
527// }
528
529 if (lastSeenVersion < Version.THREAD_MESSAGE_SCHEMA_CHANGE) {
530 jobs.put(Version.THREAD_MESSAGE_SCHEMA_CHANGE, new DatabaseMigrationJob());
531 }
532
533 if (lastSeenVersion < Version.SMS_MMS_MERGE) {
534 jobs.put(Version.SMS_MMS_MERGE, new DatabaseMigrationJob());
535 }
536
537 if (lastSeenVersion < Version.REBUILD_MESSAGE_FTS_INDEX) {
538 jobs.put(Version.REBUILD_MESSAGE_FTS_INDEX, new RebuildMessageSearchIndexMigrationJob());
539 }
540
541 if (lastSeenVersion < Version.UPDATE_SMS_JOBS) {
542 jobs.put(Version.UPDATE_SMS_JOBS, new UpdateSmsJobsMigrationJob());
543 }
544
545 if (lastSeenVersion < Version.OPTIMIZE_MESSAGE_FTS_INDEX) {
546 jobs.put(Version.OPTIMIZE_MESSAGE_FTS_INDEX, new OptimizeMessageSearchIndexMigrationJob());
547 }
548
549 if (lastSeenVersion < Version.REACTION_DATABASE_MIGRATION) {
550 jobs.put(Version.REACTION_DATABASE_MIGRATION, new DatabaseMigrationJob());
551 }
552
553 if (lastSeenVersion < Version.REBUILD_MESSAGE_FTS_INDEX_2) {
554 jobs.put(Version.REBUILD_MESSAGE_FTS_INDEX_2, new RebuildMessageSearchIndexMigrationJob());
555 }
556
557 if (lastSeenVersion < Version.GLIDE_CACHE_CLEAR) {
558 jobs.put(Version.GLIDE_CACHE_CLEAR, new ClearGlideCacheMigrationJob());
559 }
560
561 if (lastSeenVersion < Version.SYSTEM_NAME_RESYNC) {
562 jobs.put(Version.SYSTEM_NAME_RESYNC, new StorageServiceSystemNameMigrationJob());
563 }
564
565 if (lastSeenVersion < Version.RECOVERY_PASSWORD_SYNC) {
566 jobs.put(Version.RECOVERY_PASSWORD_SYNC, new AttributesMigrationJob());
567 }
568
569 // Needed for the conversion to inline decryptions and is no longer necessary
570 // if (lastSeenVersion < Version.DECRYPTIONS_DRAINED) {
571 // jobs.put(Version.DECRYPTIONS_DRAINED, new DecryptionsDrainedMigrationJob());
572 // }
573
574 if (lastSeenVersion < Version.REBUILD_MESSAGE_FTS_INDEX_3) {
575 jobs.put(Version.REBUILD_MESSAGE_FTS_INDEX_3, new RebuildMessageSearchIndexMigrationJob());
576 }
577
578 if (lastSeenVersion < Version.TO_FROM_RECIPIENTS) {
579 jobs.put(Version.TO_FROM_RECIPIENTS, new DatabaseMigrationJob());
580 }
581
582 if (lastSeenVersion < Version.REBUILD_MESSAGE_FTS_INDEX_4) {
583 jobs.put(Version.REBUILD_MESSAGE_FTS_INDEX_4, new RebuildMessageSearchIndexMigrationJob());
584 }
585
586 if (lastSeenVersion < Version.INDEX_DATABASE_MIGRATION) {
587 jobs.put(Version.INDEX_DATABASE_MIGRATION, new DatabaseMigrationJob());
588 }
589
590 if (lastSeenVersion < Version.ACCOUNT_CONSISTENCY_CHECK) {
591 jobs.put(Version.ACCOUNT_CONSISTENCY_CHECK, new AccountConsistencyMigrationJob());
592 }
593
594 if (lastSeenVersion < Version.BACKUP_JITTER) {
595 jobs.put(Version.BACKUP_JITTER, new BackupJitterMigrationJob());
596 }
597
598 if (lastSeenVersion < Version.PREKEY_SYNC) {
599 jobs.put(Version.PREKEY_SYNC, new PreKeysSyncMigrationJob());
600 }
601
602 if (lastSeenVersion < Version.DEDUPE_DB_MIGRATION) {
603 jobs.put(Version.DEDUPE_DB_MIGRATION, new DatabaseMigrationJob());
604 }
605
606 if (lastSeenVersion < Version.DEDUPE_DB_MIGRATION_2) {
607 jobs.put(Version.DEDUPE_DB_MIGRATION_2, new DatabaseMigrationJob());
608 }
609
610 if (lastSeenVersion < Version.EMOJI_VERSION_8) {
611 jobs.put(Version.EMOJI_VERSION_8, new EmojiDownloadMigrationJob());
612 }
613
614 if (lastSeenVersion < Version.SVR2_MIRROR) {
615 jobs.put(Version.SVR2_MIRROR, new Svr2MirrorMigrationJob());
616 }
617
618 if (lastSeenVersion < Version.ATTACHMENT_CLEANUP_3) {
619 jobs.put(Version.ATTACHMENT_CLEANUP_3, new AttachmentCleanupMigrationJob());
620 }
621
622 if (lastSeenVersion < Version.EMOJI_SEARCH_INDEX_CHECK) {
623 jobs.put(Version.EMOJI_SEARCH_INDEX_CHECK, new EmojiSearchIndexCheckMigrationJob());
624 }
625
626 if (lastSeenVersion < Version.IDENTITY_FIX) {
627 jobs.put(Version.IDENTITY_FIX, new IdentityTableCleanupMigrationJob());
628 }
629
630 if (lastSeenVersion < Version.COPY_USERNAME_TO_SIGNAL_STORE) {
631 jobs.put(Version.COPY_USERNAME_TO_SIGNAL_STORE, new CopyUsernameToSignalStoreMigrationJob());
632 }
633
634 if (lastSeenVersion < Version.RECHECK_PAYMENTS) {
635 jobs.put(Version.RECHECK_PAYMENTS, new RecheckPaymentsMigrationJob());
636 }
637
638 if (lastSeenVersion < Version.THREAD_COUNT_DB_MIGRATION) {
639 jobs.put(Version.THREAD_COUNT_DB_MIGRATION, new DatabaseMigrationJob());
640 }
641
642 if (lastSeenVersion < Version.SYNC_KEYS_MIGRATION) {
643 jobs.put(Version.SYNC_KEYS_MIGRATION, new SyncKeysMigrationJob());
644 }
645
646 if (lastSeenVersion < Version.SELF_REGISTERTED_STATE) {
647 jobs.put(Version.SELF_REGISTERTED_STATE, new SelfRegisteredStateMigrationJob());
648 }
649
650 if (lastSeenVersion < Version.SVR2_ENCLAVE_UPDATE) {
651 jobs.put(Version.SVR2_ENCLAVE_UPDATE, new Svr2MirrorMigrationJob());
652 }
653
654 if (lastSeenVersion < Version.STORAGE_LOCAL_UNKNOWNS_FIX) {
655 jobs.put(Version.STORAGE_LOCAL_UNKNOWNS_FIX, new StorageFixLocalUnknownMigrationJob());
656 }
657
658 if (lastSeenVersion < Version.PNP_LAUNCH) {
659 jobs.put(Version.PNP_LAUNCH, new PnpLaunchMigrationJob());
660 }
661
662 if (lastSeenVersion < Version.EMOJI_VERSION_10) {
663 jobs.put(Version.EMOJI_VERSION_10, new EmojiDownloadMigrationJob());
664 }
665
666 if (lastSeenVersion < Version.ATTACHMENT_HASH_BACKFILL) {
667 jobs.put(Version.ATTACHMENT_HASH_BACKFILL, new AttachmentHashBackfillMigrationJob());
668 }
669
670 return jobs;
671 }
672
673 private static boolean isLegacyUpdate(@NonNull Context context) {
674 return VersionTracker.getLastSeenVersion(context) < LEGACY_CANONICAL_VERSION;
675 }
676}