mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 18:30:20 +01:00
Use megaphones for PIN reminders.
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user