mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 10:17:56 +00:00
Improve robustness of PNI migration job.
This commit is contained in:
@@ -99,9 +99,10 @@ public class ApplicationMigrations {
|
||||
static final int KBS_MIGRATION = 55;
|
||||
static final int PNI_IDENTITY = 56;
|
||||
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
|
||||
@@ -431,6 +432,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.PNI_IDENTITY_2, new PniAccountInitializationMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.PNI_IDENTITY_3) {
|
||||
jobs.put(Version.PNI_IDENTITY_3, new PniAccountInitializationMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,22 +63,27 @@ public class PniAccountInitializationMigrationJob extends MigrationJob {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SignalStore.account().hasPniIdentityKey()) {
|
||||
Log.w(TAG, "Already generated the PNI identity. Skipping.");
|
||||
return;
|
||||
if (!SignalStore.account().hasPniIdentityKey()) {
|
||||
Log.i(TAG, "Generating PNI identity.");
|
||||
SignalStore.account().generatePniIdentityKey();
|
||||
} else {
|
||||
Log.w(TAG, "Already generated the PNI identity. Skipping this step.");
|
||||
}
|
||||
|
||||
SignalStore.account().generatePniIdentityKey();
|
||||
|
||||
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
|
||||
SignalProtocolStore protocolStore = ApplicationDependencies.getProtocolStore().pni();
|
||||
PreKeyMetadataStore metadataStore = SignalStore.account().pniPreKeys();
|
||||
|
||||
SignedPreKeyRecord signedPreKey = PreKeyUtil.generateAndStoreSignedPreKey(protocolStore, metadataStore, true);
|
||||
List<PreKeyRecord> oneTimePreKeys = PreKeyUtil.generateAndStoreOneTimePreKeys(protocolStore, metadataStore);
|
||||
if (!metadataStore.isSignedPreKeyRegistered()) {
|
||||
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);
|
||||
metadataStore.setSignedPreKeyRegistered(true);
|
||||
accountManager.setPreKeys(ServiceIdType.PNI, protocolStore.getIdentityKeyPair().getPublicKey(), signedPreKey, oneTimePreKeys);
|
||||
metadataStore.setSignedPreKeyRegistered(true);
|
||||
} else {
|
||||
Log.w(TAG, "Already uploaded signed prekey for PNI. Skipping this step.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user