Add the ability to opt out of PINs.

This commit is contained in:
Greyson Parrelli
2020-07-09 16:04:30 -07:00
parent c26dcc2618
commit 04a8996348
24 changed files with 550 additions and 101 deletions

View File

@@ -20,6 +20,7 @@ public final class KbsValues extends SignalStoreValues {
private static final String PIN = "kbs.pin";
private static final String LOCK_LOCAL_PIN_HASH = "kbs.registration_lock_local_pin_hash";
private static final String LAST_CREATE_FAILED_TIMESTAMP = "kbs.last_create_failed_timestamp";
public static final String OPTED_OUT = "kbs.opted_out";
KbsValues(KeyValueStore store) {
super(store);
@@ -41,6 +42,7 @@ public final class KbsValues extends SignalStoreValues {
.remove(LOCK_LOCAL_PIN_HASH)
.remove(PIN)
.remove(LAST_CREATE_FAILED_TIMESTAMP)
.remove(OPTED_OUT)
.commit();
}
@@ -142,6 +144,33 @@ public final class KbsValues extends SignalStoreValues {
return getLocalPinHash() != null;
}
/**
* Should only be called by {@link org.thoughtcrime.securesms.pin.PinState}.
*/
public synchronized void optIn() {
putBoolean(OPTED_OUT, false);
}
/**
* Should only be called by {@link org.thoughtcrime.securesms.pin.PinState}.
*/
public synchronized void optOut() {
putBoolean(OPTED_OUT, true);
}
/**
* Should only be called by {@link org.thoughtcrime.securesms.pin.PinState}.
*/
public synchronized void resetMasterKey() {
getStore().beginWrite()
.remove(MASTER_KEY)
.apply();
}
public synchronized boolean hasOptedOut() {
return getBoolean(OPTED_OUT, false);
}
public synchronized @Nullable TokenResponse getRegistrationLockTokenResponse() {
String token = getStore().getString(TOKEN_RESPONSE, null);