Add a migration for users of the previous PIN opt-out flow.
parent
8f0f600b6b
commit
e27fc512b4
|
@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.migrations.DatabaseMigrationJob;
|
|||
import org.thoughtcrime.securesms.migrations.LegacyMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.MigrationCompleteJob;
|
||||
import org.thoughtcrime.securesms.migrations.PassingMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.PinOptOutMigration;
|
||||
import org.thoughtcrime.securesms.migrations.PinReminderMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.ProfileMigrationJob;
|
||||
import org.thoughtcrime.securesms.migrations.RecipientSearchMigrationJob;
|
||||
|
@ -128,7 +129,9 @@ public final class JobManagerFactories {
|
|||
put(DatabaseMigrationJob.KEY, new DatabaseMigrationJob.Factory());
|
||||
put(LegacyMigrationJob.KEY, new LegacyMigrationJob.Factory());
|
||||
put(MigrationCompleteJob.KEY, new MigrationCompleteJob.Factory());
|
||||
put(PinOptOutMigration.KEY, new PinOptOutMigration.Factory());
|
||||
put(PinReminderMigrationJob.KEY, new PinReminderMigrationJob.Factory());
|
||||
put(ProfileMigrationJob.KEY, new ProfileMigrationJob.Factory());
|
||||
put(RecipientSearchMigrationJob.KEY, new RecipientSearchMigrationJob.Factory());
|
||||
put(RegistrationPinV2MigrationJob.KEY, new RegistrationPinV2MigrationJob.Factory());
|
||||
put(StickerLaunchMigrationJob.KEY, new StickerLaunchMigrationJob.Factory());
|
||||
|
@ -136,7 +139,6 @@ public final class JobManagerFactories {
|
|||
put(StorageCapabilityMigrationJob.KEY, new StorageCapabilityMigrationJob.Factory());
|
||||
put(StorageServiceMigrationJob.KEY, new StorageServiceMigrationJob.Factory());
|
||||
put(UuidMigrationJob.KEY, new UuidMigrationJob.Factory());
|
||||
put(ProfileMigrationJob.KEY, new ProfileMigrationJob.Factory());
|
||||
|
||||
// Dead jobs
|
||||
put(FailingJob.KEY, new FailingJob.Factory());
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ApplicationMigrations {
|
|||
|
||||
private static final int LEGACY_CANONICAL_VERSION = 455;
|
||||
|
||||
public static final int CURRENT_VERSION = 16;
|
||||
public static final int CURRENT_VERSION = 17;
|
||||
|
||||
private static final class Version {
|
||||
static final int LEGACY = 1;
|
||||
|
@ -58,6 +58,7 @@ public class ApplicationMigrations {
|
|||
static final int STORAGE_CAPABILITY = 14;
|
||||
static final int PIN_REMINDER = 15;
|
||||
static final int VERSIONED_PROFILE = 16;
|
||||
static final int PIN_OPT_OUT = 17;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,6 +237,10 @@ public class ApplicationMigrations {
|
|||
jobs.put(Version.VERSIONED_PROFILE, new ProfileMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.PIN_OPT_OUT) {
|
||||
jobs.put(Version.PIN_OPT_OUT, new PinOptOutMigration());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
||||
import org.thoughtcrime.securesms.jobs.StorageForcePushJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
|
||||
/**
|
||||
* We changed some details of what it means to opt-out of a PIN. This ensures that users who went
|
||||
* through the previous opt-out flow are now in the same state as users who went through the new
|
||||
* opt-out flow.
|
||||
*/
|
||||
public final class PinOptOutMigration extends MigrationJob {
|
||||
|
||||
private static final String TAG = Log.tag(PinOptOutMigration.class);
|
||||
|
||||
public static final String KEY = "PinOptOutMigration";
|
||||
|
||||
PinOptOutMigration() {
|
||||
this(new Parameters.Builder().build());
|
||||
}
|
||||
|
||||
private PinOptOutMigration(@NonNull Parameters parameters) {
|
||||
super(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isUiBlocking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
void performMigration() {
|
||||
if (SignalStore.kbsValues().hasOptedOut() && SignalStore.kbsValues().hasPin()) {
|
||||
Log.w(TAG, "Discovered a legacy opt-out user! Resetting the state.");
|
||||
|
||||
SignalStore.kbsValues().optOut();
|
||||
ApplicationDependencies.getJobManager().add(new RefreshAttributesJob());
|
||||
ApplicationDependencies.getJobManager().add(new StorageForcePushJob());
|
||||
} else if (SignalStore.kbsValues().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.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean shouldRetry(@NonNull Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getFactoryKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<PinOptOutMigration> {
|
||||
@Override
|
||||
public @NonNull PinOptOutMigration create(@NonNull Parameters parameters, @NonNull Data data) {
|
||||
return new PinOptOutMigration(parameters);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue