mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Add migration to cleanup some inconsistent DB state.
This commit is contained in:
committed by
Clark Chen
parent
1b63bdec12
commit
6ca9cb6da1
@@ -135,9 +135,10 @@ public class ApplicationMigrations {
|
||||
static final int SVR2_MIRROR = 91;
|
||||
static final int ATTACHMENT_CLEANUP_3 = 92;
|
||||
static final int EMOJI_SEARCH_INDEX_CHECK = 93;
|
||||
static final int IDENTITY_FIX = 94;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 93;
|
||||
public static final int CURRENT_VERSION = 94;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
@@ -611,6 +612,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.EMOJI_SEARCH_INDEX_CHECK, new EmojiSearchIndexCheckMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.IDENTITY_FIX) {
|
||||
jobs.put(Version.IDENTITY_FIX, new IdentityTableCleanupMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.thoughtcrime.securesms.migrations
|
||||
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.database.IdentityTable
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.jobs.AccountConsistencyWorkerJob
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
|
||||
/**
|
||||
* Migration to help cleanup some inconsistent state for ourself in the identity table.
|
||||
*/
|
||||
internal class IdentityTableCleanupMigrationJob(
|
||||
parameters: Parameters = Parameters.Builder().build()
|
||||
) : MigrationJob(parameters) {
|
||||
|
||||
companion object {
|
||||
const val KEY = "IdentityTableCleanupMigrationJob"
|
||||
|
||||
val TAG = Log.tag(IdentityTableCleanupMigrationJob::class.java)
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun isUiBlocking(): Boolean = false
|
||||
|
||||
override fun performMigration() {
|
||||
if (SignalStore.account().aci == null || SignalStore.account().pni == null) {
|
||||
Log.i(TAG, "ACI/PNI are unset, skipping.")
|
||||
return
|
||||
}
|
||||
|
||||
if (!SignalStore.account().hasAciIdentityKey()) {
|
||||
Log.i(TAG, "No ACI identity set yet, skipping.")
|
||||
return
|
||||
}
|
||||
|
||||
if (!SignalStore.account().hasPniIdentityKey()) {
|
||||
Log.i(TAG, "No PNI identity set yet, skipping.")
|
||||
return
|
||||
}
|
||||
|
||||
ApplicationDependencies.getProtocolStore().aci().identities().saveIdentityWithoutSideEffects(
|
||||
Recipient.self().id,
|
||||
SignalStore.account().aci!!,
|
||||
SignalStore.account().aciIdentityKey.publicKey,
|
||||
IdentityTable.VerifiedStatus.VERIFIED,
|
||||
true,
|
||||
System.currentTimeMillis(),
|
||||
true
|
||||
)
|
||||
|
||||
ApplicationDependencies.getProtocolStore().pni().identities().saveIdentityWithoutSideEffects(
|
||||
Recipient.self().id,
|
||||
SignalStore.account().pni!!,
|
||||
SignalStore.account().pniIdentityKey.publicKey,
|
||||
IdentityTable.VerifiedStatus.VERIFIED,
|
||||
true,
|
||||
System.currentTimeMillis(),
|
||||
true
|
||||
)
|
||||
|
||||
ApplicationDependencies.getJobManager().add(AccountConsistencyWorkerJob())
|
||||
}
|
||||
|
||||
override fun shouldRetry(e: Exception): Boolean = false
|
||||
|
||||
class Factory : Job.Factory<IdentityTableCleanupMigrationJob> {
|
||||
override fun create(parameters: Parameters, serializedData: ByteArray?): IdentityTableCleanupMigrationJob {
|
||||
return IdentityTableCleanupMigrationJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user