Improve robustness of PNI migration job.

This commit is contained in:
Greyson Parrelli
2022-02-20 23:57:19 -05:00
parent 97f8b5988d
commit 1f0c56546e
2 changed files with 20 additions and 10 deletions
@@ -99,9 +99,10 @@ public class ApplicationMigrations {
static final int KBS_MIGRATION = 55; static final int KBS_MIGRATION = 55;
static final int PNI_IDENTITY = 56; static final int PNI_IDENTITY = 56;
static final int PNI_IDENTITY_2 = 57; static final int PNI_IDENTITY_2 = 57;
static final int PNI_IDENTITY_3 = 58;
} }
public static final int CURRENT_VERSION = 57; public static final int CURRENT_VERSION = 58;
/** /**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call * This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@@ -431,6 +432,10 @@ public class ApplicationMigrations {
jobs.put(Version.PNI_IDENTITY_2, new PniAccountInitializationMigrationJob()); jobs.put(Version.PNI_IDENTITY_2, new PniAccountInitializationMigrationJob());
} }
if (lastSeenVersion < Version.PNI_IDENTITY_3) {
jobs.put(Version.PNI_IDENTITY_3, new PniAccountInitializationMigrationJob());
}
return jobs; return jobs;
} }
@@ -63,22 +63,27 @@ public class PniAccountInitializationMigrationJob extends MigrationJob {
return; return;
} }
if (SignalStore.account().hasPniIdentityKey()) { if (!SignalStore.account().hasPniIdentityKey()) {
Log.w(TAG, "Already generated the PNI identity. Skipping."); Log.i(TAG, "Generating PNI identity.");
return; SignalStore.account().generatePniIdentityKey();
} else {
Log.w(TAG, "Already generated the PNI identity. Skipping this step.");
} }
SignalStore.account().generatePniIdentityKey();
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager(); SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
SignalProtocolStore protocolStore = ApplicationDependencies.getProtocolStore().pni(); SignalProtocolStore protocolStore = ApplicationDependencies.getProtocolStore().pni();
PreKeyMetadataStore metadataStore = SignalStore.account().pniPreKeys(); PreKeyMetadataStore metadataStore = SignalStore.account().pniPreKeys();
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateAndStoreSignedPreKey(protocolStore, metadataStore, true); if (!metadataStore.isSignedPreKeyRegistered()) {
List<PreKeyRecord> oneTimePreKeys = PreKeyUtil.generateAndStoreOneTimePreKeys(protocolStore, metadataStore); Log.i(TAG, "Uploading signed prekey for PNI.");
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateAndStoreSignedPreKey(protocolStore, metadataStore, true);
List<PreKeyRecord> oneTimePreKeys = PreKeyUtil.generateAndStoreOneTimePreKeys(protocolStore, metadataStore);
accountManager.setPreKeys(ServiceIdType.PNI, protocolStore.getIdentityKeyPair().getPublicKey(), signedPreKey, oneTimePreKeys); accountManager.setPreKeys(ServiceIdType.PNI, protocolStore.getIdentityKeyPair().getPublicKey(), signedPreKey, oneTimePreKeys);
metadataStore.setSignedPreKeyRegistered(true); metadataStore.setSignedPreKeyRegistered(true);
} else {
Log.w(TAG, "Already uploaded signed prekey for PNI. Skipping this step.");
}
} }
@Override @Override