From e27fc512b4cf57bb9e889150f4d25ce6acb252fc Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 13 Jul 2020 08:46:03 -0400 Subject: [PATCH] Add a migration for users of the previous PIN opt-out flow. --- .../securesms/jobs/JobManagerFactories.java | 4 +- .../migrations/ApplicationMigrations.java | 7 +- .../migrations/PinOptOutMigration.java | 68 +++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/migrations/PinOptOutMigration.java diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java index bef6117662..0c7e5d6b77 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/JobManagerFactories.java @@ -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()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java b/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java index 1ce47b72ed..685881fc2b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java +++ b/app/src/main/java/org/thoughtcrime/securesms/migrations/ApplicationMigrations.java @@ -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; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/migrations/PinOptOutMigration.java b/app/src/main/java/org/thoughtcrime/securesms/migrations/PinOptOutMigration.java new file mode 100644 index 0000000000..8bcf00e1b2 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/migrations/PinOptOutMigration.java @@ -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 { + @Override + public @NonNull PinOptOutMigration create(@NonNull Parameters parameters, @NonNull Data data) { + return new PinOptOutMigration(parameters); + } + } +}