mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Start mirroring to SVR2.
This commit is contained in:
committed by
Clark Chen
parent
dfb7304626
commit
e1570e9512
@@ -96,7 +96,7 @@ public class ApplicationMigrations {
|
||||
static final int JUMBOMOJI_DOWNLOAD = 52;
|
||||
static final int FIX_EMOJI_QUALITY = 53;
|
||||
static final int CHANGE_NUMBER_CAPABILITY_4 = 54;
|
||||
static final int KBS_MIGRATION = 55;
|
||||
//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;
|
||||
@@ -106,7 +106,7 @@ public class ApplicationMigrations {
|
||||
static final int REFRESH_EXPIRING_CREDENTIAL = 62;
|
||||
static final int EMOJI_SEARCH_INDEX_10 = 63;
|
||||
static final int REFRESH_PNI_REGISTRATION_ID = 64;
|
||||
static final int KBS_MIGRATION_2 = 65;
|
||||
//static final int KBS_MIGRATION_2 = 65;
|
||||
static final int PNI_2 = 66;
|
||||
static final int SYSTEM_NAME_SYNC = 67;
|
||||
static final int STORY_VIEWED_STATE = 68;
|
||||
@@ -132,9 +132,10 @@ public class ApplicationMigrations {
|
||||
static final int DEDUPE_DB_MIGRATION = 88;
|
||||
static final int DEDUPE_DB_MIGRATION_2 = 89;
|
||||
static final int EMOJI_VERSION_8 = 90;
|
||||
static final int SVR2_MIRROR = 91;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 90;
|
||||
public static final int CURRENT_VERSION = 91;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
@@ -452,9 +453,9 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.CHANGE_NUMBER_CAPABILITY_4,new AttributesMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.KBS_MIGRATION) {
|
||||
jobs.put(Version.KBS_MIGRATION, new KbsEnclaveMigrationJob());
|
||||
}
|
||||
// if (lastSeenVersion < Version.KBS_MIGRATION) {
|
||||
// jobs.put(Version.KBS_MIGRATION, new KbsEnclaveMigrationJob());
|
||||
// }
|
||||
|
||||
if (lastSeenVersion < Version.PNI_IDENTITY) {
|
||||
jobs.put(Version.PNI_IDENTITY, new PniAccountInitializationMigrationJob());
|
||||
@@ -492,9 +493,9 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.REFRESH_PNI_REGISTRATION_ID, new AttributesMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.KBS_MIGRATION_2) {
|
||||
jobs.put(Version.KBS_MIGRATION_2, new KbsEnclaveMigrationJob());
|
||||
}
|
||||
// if (lastSeenVersion < Version.KBS_MIGRATION_2) {
|
||||
// jobs.put(Version.KBS_MIGRATION_2, new KbsEnclaveMigrationJob());
|
||||
// }
|
||||
|
||||
if (lastSeenVersion < Version.PNI_2) {
|
||||
jobs.put(Version.PNI_2, new PniMigrationJob());
|
||||
@@ -596,6 +597,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.EMOJI_VERSION_8, new EmojiDownloadMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.SVR2_MIRROR) {
|
||||
jobs.put(Version.SVR2_MIRROR, new Svr2MirrorMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobs.KbsEnclaveMigrationWorkerJob;
|
||||
|
||||
/**
|
||||
* A job to be run whenever we add a new KBS enclave. In order to prevent this moderately-expensive
|
||||
* task from blocking the network for too long, this task simply enqueues another non-migration job,
|
||||
* {@link KbsEnclaveMigrationWorkerJob}, to do the heavy lifting.
|
||||
*/
|
||||
public class KbsEnclaveMigrationJob extends MigrationJob {
|
||||
|
||||
public static final String KEY = "KbsEnclaveMigrationJob";
|
||||
|
||||
KbsEnclaveMigrationJob() {
|
||||
this(new Parameters.Builder().build());
|
||||
}
|
||||
|
||||
private KbsEnclaveMigrationJob(@NonNull Parameters parameters) {
|
||||
super(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUiBlocking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getFactoryKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performMigration() {
|
||||
ApplicationDependencies.getJobManager().add(new KbsEnclaveMigrationWorkerJob());
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean shouldRetry(@NonNull Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<KbsEnclaveMigrationJob> {
|
||||
@Override
|
||||
public @NonNull KbsEnclaveMigrationJob create(@NonNull Parameters parameters, @Nullable byte[] serializedData) {
|
||||
return new KbsEnclaveMigrationJob(parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,15 +37,15 @@ public final class PinOptOutMigration extends MigrationJob {
|
||||
|
||||
@Override
|
||||
void performMigration() {
|
||||
if (SignalStore.kbsValues().hasOptedOut() && SignalStore.kbsValues().hasPin()) {
|
||||
if (SignalStore.svr().hasOptedOut() && SignalStore.svr().hasPin()) {
|
||||
Log.w(TAG, "Discovered a legacy opt-out user! Resetting the state.");
|
||||
|
||||
SignalStore.kbsValues().optOut();
|
||||
SignalStore.svr().optOut();
|
||||
ApplicationDependencies.getJobManager().startChain(new RefreshAttributesJob())
|
||||
.then(new RefreshOwnProfileJob())
|
||||
.then(new StorageForcePushJob())
|
||||
.enqueue();
|
||||
} else if (SignalStore.kbsValues().hasOptedOut()) {
|
||||
} else if (SignalStore.svr().hasOptedOut()) {
|
||||
Log.i(TAG, "Discovered an opt-out user, but they're already in a good state. No action required.");
|
||||
} else {
|
||||
Log.i(TAG, "Discovered a normal PIN user. No action required.");
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.protocol.InvalidKeyException;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
|
||||
import org.thoughtcrime.securesms.jobs.BaseJob;
|
||||
import org.thoughtcrime.securesms.pin.PinState;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Migrates an existing V1 registration lock user to a V2 registration lock that is backed by a
|
||||
* Signal PIN.
|
||||
*
|
||||
* Deliberately not a {@link MigrationJob} because it is not something that needs to run at app start.
|
||||
* This migration can run at anytime.
|
||||
*/
|
||||
public final class RegistrationPinV2MigrationJob extends BaseJob {
|
||||
|
||||
private static final String TAG = Log.tag(RegistrationPinV2MigrationJob.class);
|
||||
|
||||
public static final String KEY = "RegistrationPinV2MigrationJob";
|
||||
|
||||
public RegistrationPinV2MigrationJob() {
|
||||
this(new Parameters.Builder()
|
||||
.setQueue(KEY)
|
||||
.setMaxInstancesForFactory(1)
|
||||
.addConstraint(NetworkConstraint.KEY)
|
||||
.setLifespan(Job.Parameters.IMMORTAL)
|
||||
.setMaxAttempts(Job.Parameters.UNLIMITED)
|
||||
.build());
|
||||
}
|
||||
|
||||
private RegistrationPinV2MigrationJob(@NonNull Parameters parameters) {
|
||||
super(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable byte[] serialize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRun() throws IOException, UnauthenticatedResponseException, InvalidKeyException {
|
||||
if (!TextSecurePreferences.isV1RegistrationLockEnabled(context)) {
|
||||
Log.i(TAG, "Registration lock disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
//noinspection deprecation Only acceptable place to read the old pin.
|
||||
String pinValue = TextSecurePreferences.getDeprecatedV1RegistrationLockPin(context);
|
||||
|
||||
if (pinValue == null | TextUtils.isEmpty(pinValue)) {
|
||||
Log.i(TAG, "No old pin to migrate");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Migrating pin to Key Backup Service");
|
||||
PinState.onMigrateToRegistrationLockV2(context, pinValue);
|
||||
Log.i(TAG, "Pin migrated to Key Backup Service");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onShouldRetry(@NonNull Exception e) {
|
||||
return e instanceof IOException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getFactoryKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<RegistrationPinV2MigrationJob> {
|
||||
@Override
|
||||
public @NonNull RegistrationPinV2MigrationJob create(@NonNull Parameters parameters, @Nullable byte[] serializedData) {
|
||||
return new RegistrationPinV2MigrationJob(parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.thoughtcrime.securesms.migrations
|
||||
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.jobs.Svr2MirrorJob
|
||||
|
||||
/**
|
||||
* Mirrors the user's SVR1 data to SVR2.
|
||||
*/
|
||||
internal class Svr2MirrorMigrationJob(
|
||||
parameters: Parameters = Parameters.Builder().build()
|
||||
) : MigrationJob(parameters) {
|
||||
|
||||
companion object {
|
||||
val TAG = Log.tag(Svr2MirrorMigrationJob::class.java)
|
||||
const val KEY = "Svr2MirrorMigrationJob"
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun isUiBlocking(): Boolean = false
|
||||
|
||||
override fun performMigration() {
|
||||
ApplicationDependencies.getJobManager().add(Svr2MirrorJob())
|
||||
}
|
||||
|
||||
override fun shouldRetry(e: Exception): Boolean = false
|
||||
|
||||
class Factory : Job.Factory<Svr2MirrorMigrationJob> {
|
||||
override fun create(parameters: Parameters, serializedData: ByteArray?): Svr2MirrorMigrationJob {
|
||||
return Svr2MirrorMigrationJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user