That fuck shit the fascists are using
1package org.tm.archive.keyvalue;
2
3import androidx.annotation.NonNull;
4
5import org.signal.core.util.logging.Log;
6import org.tm.archive.dependencies.ApplicationDependencies;
7import org.tm.archive.lock.SignalPinReminders;
8import org.tm.archive.lock.v2.PinKeyboardType;
9import org.tm.archive.util.TextSecurePreferences;
10
11import java.util.Arrays;
12import java.util.List;
13
14/**
15 * Specifically handles just the UI/UX state around PINs. For actual keys, see {@link SvrValues}.
16 */
17public final class PinValues extends SignalStoreValues {
18
19 private static final String TAG = Log.tag(PinValues.class);
20
21 private static final String LAST_SUCCESSFUL_ENTRY = "pin.last_successful_entry";
22 private static final String NEXT_INTERVAL = "pin.interval_index";
23 private static final String KEYBOARD_TYPE = "kbs.keyboard_type";
24 public static final String PIN_REMINDERS_ENABLED = "pin.pin_reminders_enabled";
25
26 PinValues(KeyValueStore store) {
27 super(store);
28 }
29
30 @Override
31 void onFirstEverAppLaunch() {
32 }
33
34 @Override
35 @NonNull List<String> getKeysToIncludeInBackup() {
36 return Arrays.asList(PIN_REMINDERS_ENABLED, KEYBOARD_TYPE);
37 }
38
39 public void onEntrySuccess(@NonNull String pin) {
40 long nextInterval = SignalPinReminders.getNextInterval(getCurrentInterval());
41 Log.i(TAG, "onEntrySuccess() nextInterval: " + nextInterval);
42
43 getStore().beginWrite()
44 .putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
45 .putLong(NEXT_INTERVAL, nextInterval)
46 .apply();
47
48 SignalStore.svr().setPinIfNotPresent(pin);
49 }
50
51 public void onEntrySuccessWithWrongGuess(@NonNull String pin) {
52 long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
53 Log.i(TAG, "onEntrySuccessWithWrongGuess() nextInterval: " + nextInterval);
54
55 getStore().beginWrite()
56 .putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
57 .putLong(NEXT_INTERVAL, nextInterval)
58 .apply();
59
60 SignalStore.svr().setPinIfNotPresent(pin);
61 }
62
63 public void onEntrySkipWithWrongGuess() {
64 long nextInterval = SignalPinReminders.getPreviousInterval(getCurrentInterval());
65 Log.i(TAG, "onEntrySkipWithWrongGuess() nextInterval: " + nextInterval);
66
67 putLong(NEXT_INTERVAL, nextInterval);
68 }
69
70 public void resetPinReminders() {
71 long nextInterval = SignalPinReminders.INITIAL_INTERVAL;
72 Log.i(TAG, "resetPinReminders() nextInterval: " + nextInterval, new Throwable());
73
74 getStore().beginWrite()
75 .putLong(NEXT_INTERVAL, nextInterval)
76 .putLong(LAST_SUCCESSFUL_ENTRY, System.currentTimeMillis())
77 .apply();
78 }
79
80 public long getCurrentInterval() {
81 return getLong(NEXT_INTERVAL, TextSecurePreferences.getRegistrationLockNextReminderInterval(ApplicationDependencies.getApplication()));
82 }
83
84 public long getLastSuccessfulEntryTime() {
85 return getLong(LAST_SUCCESSFUL_ENTRY, TextSecurePreferences.getRegistrationLockLastReminderTime(ApplicationDependencies.getApplication()));
86 }
87
88 public void setKeyboardType(@NonNull PinKeyboardType keyboardType) {
89 putString(KEYBOARD_TYPE, keyboardType.getCode());
90 }
91
92 public void setPinRemindersEnabled(boolean enabled) {
93 putBoolean(PIN_REMINDERS_ENABLED, enabled);
94 }
95
96 public boolean arePinRemindersEnabled() {
97 return getBoolean(PIN_REMINDERS_ENABLED, true);
98 }
99
100 public @NonNull PinKeyboardType getKeyboardType() {
101 String pin = SignalStore.svr().getPin();
102
103 if (pin == null) {
104 return PinKeyboardType.fromCode(getStore().getString(KEYBOARD_TYPE, null));
105 }
106
107 for (char c : pin.toCharArray()) {
108 if (!Character.isDigit(c)) {
109 return PinKeyboardType.ALPHA_NUMERIC;
110 }
111 }
112
113 return PinKeyboardType.NUMERIC;
114 }
115
116 public void setNextReminderIntervalToAtMost(long maxInterval) {
117 if (getStore().getLong(NEXT_INTERVAL, 0) > maxInterval) {
118 putLong(NEXT_INTERVAL, maxInterval);
119 }
120 }
121}