mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 18:30:20 +01:00
Implement new PIN UX.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.lock.v2.KbsKeyboardType;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.whispersystems.signalservice.api.RegistrationLockData;
|
||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||
@@ -17,6 +19,7 @@ public final class KbsValues {
|
||||
private static final String MASTER_KEY = "kbs.registration_lock_master_key";
|
||||
private static final String TOKEN_RESPONSE = "kbs.token_response";
|
||||
private static final String LOCK_LOCAL_PIN_HASH = "kbs.registration_lock_local_pin_hash";
|
||||
private static final String KEYBOARD_TYPE = "kbs.keyboard_type";
|
||||
|
||||
private final KeyValueStore store;
|
||||
|
||||
@@ -32,6 +35,7 @@ public final class KbsValues {
|
||||
.remove(V2_LOCK_ENABLED)
|
||||
.remove(TOKEN_RESPONSE)
|
||||
.remove(LOCK_LOCAL_PIN_HASH)
|
||||
.remove(KEYBOARD_TYPE)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@@ -112,4 +116,15 @@ public final class KbsValues {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setKeyboardType(@NonNull KbsKeyboardType keyboardType) {
|
||||
store.beginWrite()
|
||||
.putString(KEYBOARD_TYPE, keyboardType.getCode())
|
||||
.commit();
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
public @NonNull KbsKeyboardType getKeyboardType() {
|
||||
return KbsKeyboardType.fromCode(store.getString(KEYBOARD_TYPE, null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,10 @@ public class KeyValueDataSet implements KeyValueReader {
|
||||
}
|
||||
}
|
||||
|
||||
boolean containsKey(@NonNull String key) {
|
||||
return values.containsKey(key);
|
||||
}
|
||||
|
||||
public @NonNull Map<String, Object> getValues() {
|
||||
return values;
|
||||
}
|
||||
@@ -114,10 +118,6 @@ public class KeyValueDataSet implements KeyValueReader {
|
||||
return types.get(key);
|
||||
}
|
||||
|
||||
public boolean containsKey(@NonNull String key) {
|
||||
return values.containsKey(key);
|
||||
}
|
||||
|
||||
private <E> E readValueAsType(@NonNull String key, Class<E> type, boolean nullable) {
|
||||
Object value = values.get(key);
|
||||
if ((value == null && nullable) || (value != null && value.getClass() == type)) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public final class RegistrationValues {
|
||||
|
||||
private static final String REGISTRATION_COMPLETE = "registration.complete";
|
||||
private static final String PIN_REQUIRED = "registration.pin_required";
|
||||
|
||||
private final KeyValueStore store;
|
||||
|
||||
RegistrationValues(@NonNull KeyValueStore store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
public synchronized void onNewInstall() {
|
||||
store.beginWrite()
|
||||
.putBoolean(REGISTRATION_COMPLETE, false)
|
||||
.putBoolean(PIN_REQUIRED, true)
|
||||
.commit();
|
||||
}
|
||||
|
||||
public synchronized void clearRegistrationComplete() {
|
||||
onNewInstall();
|
||||
}
|
||||
|
||||
public synchronized void setRegistrationComplete() {
|
||||
store.beginWrite()
|
||||
.putBoolean(REGISTRATION_COMPLETE, true)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
public synchronized boolean isPinRequired() {
|
||||
return store.getBoolean(PIN_REQUIRED, false);
|
||||
}
|
||||
|
||||
@CheckResult
|
||||
public synchronized boolean isRegistrationComplete() {
|
||||
return store.getBoolean(REGISTRATION_COMPLETE, true);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,10 @@ public final class SignalStore {
|
||||
return new KbsValues(getStore());
|
||||
}
|
||||
|
||||
public static RegistrationValues registrationValues() {
|
||||
return new RegistrationValues(getStore());
|
||||
}
|
||||
|
||||
public static String getRemoteConfig() {
|
||||
return getStore().getString(REMOTE_CONFIG, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user