Use megaphones for PIN reminders.

This commit is contained in:
Greyson Parrelli
2020-02-07 20:37:35 -05:00
parent 38e4733433
commit ddc01b539f
20 changed files with 496 additions and 244 deletions

View File

@@ -0,0 +1,57 @@
package org.thoughtcrime.securesms.keyvalue;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.lock.SignalPinReminders;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
public final class PinValues {
private static final String TAG = Log.tag(PinValues.class);
private static final String LAST_SUCCESSFUL_ENTRY = "pin.last_successful_entry";
private static final String NEXT_INTERVAL = "pin.interval_index";
private final KeyValueStore store;
PinValues(KeyValueStore store) {
this.store = store;
}
public void onEntrySuccess() {
long nextInterval = SignalPinReminders.getNextInterval(getCurrentInterval());
Log.w(TAG, "onEntrySuccess() nextInterval: " + nextInterval);
store.beginWrite()
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
.putLong(NEXT_INTERVAL, nextInterval)
.apply();
}
public void onEntryFailure() {
long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
Log.w(TAG, "onEntryFailure() nextInterval: " + nextInterval);
store.beginWrite()
.putLong(NEXT_INTERVAL, nextInterval)
.apply();
}
public void onPinChange() {
long nextInterval = SignalPinReminders.INITIAL_INTERVAL;
Log.w(TAG, "onPinChange() nextInterval: " + nextInterval);
store.beginWrite()
.putLong(NEXT_INTERVAL, nextInterval)
.putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
.apply();
}
public long getCurrentInterval() {
return store.getLong(NEXT_INTERVAL, TextSecurePreferences.getRegistrationLockNextReminderInterval(ApplicationDependencies.getApplication()));
}
public long getLastSuccessfulEntryTime() {
return store.getLong(LAST_SUCCESSFUL_ENTRY, TextSecurePreferences.getRegistrationLockLastReminderTime(ApplicationDependencies.getApplication()));
}
}

View File

@@ -17,14 +17,18 @@ public final class SignalStore {
private SignalStore() {}
public static KbsValues kbsValues() {
public static @NonNull KbsValues kbsValues() {
return new KbsValues(getStore());
}
public static RegistrationValues registrationValues() {
public static @NonNull RegistrationValues registrationValues() {
return new RegistrationValues(getStore());
}
public static @NonNull PinValues pinValues() {
return new PinValues(getStore());
}
public static String getRemoteConfig() {
return getStore().getString(REMOTE_CONFIG, null);
}