mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
Start mirroring to SVR2.
This commit is contained in:
committed by
Clark Chen
parent
dfb7304626
commit
e1570e9512
@@ -31,8 +31,8 @@ import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
||||
import org.thoughtcrime.securesms.lock.v2.KbsConstants;
|
||||
import org.thoughtcrime.securesms.lock.v2.CreateSvrPinActivity;
|
||||
import org.thoughtcrime.securesms.lock.v2.SvrConstants;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.whispersystems.signalservice.api.kbs.PinHashUtil;
|
||||
@@ -44,7 +44,7 @@ public final class SignalPinReminderDialog {
|
||||
private static final String TAG = Log.tag(SignalPinReminderDialog.class);
|
||||
|
||||
public static void show(@NonNull Context context, @NonNull Launcher launcher, @NonNull Callback mainCallback) {
|
||||
if (!SignalStore.kbsValues().hasPin()) {
|
||||
if (!SignalStore.svr().hasPin()) {
|
||||
throw new AssertionError("Must have a PIN!");
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public final class SignalPinReminderDialog {
|
||||
@Override
|
||||
public void onClick(@NonNull View widget) {
|
||||
dialog.dismiss();
|
||||
launcher.launch(CreateKbsPinActivity.getIntentForPinChangeFromForgotPin(context), CreateKbsPinActivity.REQUEST_NEW_PIN);
|
||||
launcher.launch(CreateSvrPinActivity.getIntentForPinChangeFromForgotPin(context), CreateSvrPinActivity.REQUEST_NEW_PIN);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -115,11 +115,11 @@ public final class SignalPinReminderDialog {
|
||||
|
||||
pinEditText.addTextChangedListener(new SimpleTextWatcher() {
|
||||
|
||||
private final String localHash = Objects.requireNonNull(SignalStore.kbsValues().getLocalPinHash());
|
||||
private final String localHash = Objects.requireNonNull(SignalStore.svr().getLocalPinHash());
|
||||
|
||||
@Override
|
||||
public void onTextChanged(String text) {
|
||||
if (text.length() >= KbsConstants.MINIMUM_PIN_LENGTH) {
|
||||
if (text.length() >= SvrConstants.MINIMUM_PIN_LENGTH) {
|
||||
submit.setEnabled(true);
|
||||
|
||||
if (PinHashUtil.verifyLocalPinHash(localHash, text)) {
|
||||
@@ -169,7 +169,7 @@ public final class SignalPinReminderDialog {
|
||||
private final String localPinHash;
|
||||
|
||||
V2PinVerifier() {
|
||||
localPinHash = SignalStore.kbsValues().getLocalPinHash();
|
||||
localPinHash = SignalStore.svr().getLocalPinHash();
|
||||
|
||||
if (localPinHash == null) throw new AssertionError("No local pin hash set at time of reminder");
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public final class SignalPinReminderDialog {
|
||||
if (pin == null) return;
|
||||
if (TextUtils.isEmpty(pin)) return;
|
||||
|
||||
if (pin.length() < KbsConstants.MINIMUM_PIN_LENGTH) return;
|
||||
if (pin.length() < SvrConstants.MINIMUM_PIN_LENGTH) return;
|
||||
|
||||
if (PinHashUtil.verifyLocalPinHash(localPinHash, pin)) {
|
||||
callback.onPinCorrect(pin);
|
||||
|
||||
@@ -14,7 +14,6 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
@@ -33,7 +32,7 @@ import org.thoughtcrime.securesms.util.text.AfterTextChanged;
|
||||
import org.thoughtcrime.securesms.util.views.CircularProgressMaterialButton;
|
||||
import org.thoughtcrime.securesms.util.views.LearnMoreTextView;
|
||||
|
||||
public abstract class BaseKbsPinFragment<ViewModel extends BaseKbsPinViewModel> extends LoggingFragment {
|
||||
public abstract class BaseSvrPinFragment<ViewModel extends BaseSvrPinViewModel> extends LoggingFragment {
|
||||
|
||||
private TextView title;
|
||||
private LearnMoreTextView description;
|
||||
@@ -62,8 +61,8 @@ public abstract class BaseKbsPinFragment<ViewModel extends BaseKbsPinViewModel>
|
||||
initializeViews(view);
|
||||
|
||||
viewModel = initializeViewModel();
|
||||
viewModel.getUserEntry().observe(getViewLifecycleOwner(), kbsPin -> {
|
||||
boolean isEntryValid = kbsPin.length() >= KbsConstants.MINIMUM_PIN_LENGTH;
|
||||
viewModel.getUserEntry().observe(getViewLifecycleOwner(), svrPin -> {
|
||||
boolean isEntryValid = svrPin.length() >= SvrConstants.MINIMUM_PIN_LENGTH;
|
||||
|
||||
confirm.setEnabled(isEntryValid);
|
||||
confirm.setAlpha(isEntryValid ? 1f : 0.5f);
|
||||
@@ -100,9 +99,9 @@ public abstract class BaseKbsPinFragment<ViewModel extends BaseKbsPinViewModel>
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
if (RegistrationLockUtil.userHasRegistrationLock(requireContext()) ||
|
||||
SignalStore.kbsValues().hasPin() ||
|
||||
SignalStore.kbsValues().hasOptedOut())
|
||||
if (SignalStore.svr().isRegistrationLockEnabled() ||
|
||||
SignalStore.svr().hasPin() ||
|
||||
SignalStore.svr().hasOptedOut())
|
||||
{
|
||||
menu.clear();
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package org.thoughtcrime.securesms.lock.v2;
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
interface BaseKbsPinViewModel {
|
||||
LiveData<KbsPin> getUserEntry();
|
||||
interface BaseSvrPinViewModel {
|
||||
LiveData<SvrPin> getUserEntry();
|
||||
|
||||
LiveData<PinKeyboardType> getKeyboard();
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package org.thoughtcrime.securesms.lock.v2;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.util.Consumer;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.protocol.InvalidKeyException;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.pin.PinState;
|
||||
import org.signal.core.util.concurrent.SimpleTask;
|
||||
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
final class ConfirmKbsPinRepository {
|
||||
|
||||
private static final String TAG = Log.tag(ConfirmKbsPinRepository.class);
|
||||
|
||||
void setPin(@NonNull KbsPin kbsPin, @NonNull PinKeyboardType keyboard, @NonNull Consumer<PinSetResult> resultConsumer) {
|
||||
|
||||
Context context = ApplicationDependencies.getApplication();
|
||||
String pinValue = kbsPin.toString();
|
||||
|
||||
SimpleTask.run(() -> {
|
||||
try {
|
||||
Log.i(TAG, "Setting pin on KBS");
|
||||
PinState.onPinChangedOrCreated(context, pinValue, keyboard);
|
||||
Log.i(TAG, "Pin set on KBS");
|
||||
|
||||
return PinSetResult.SUCCESS;
|
||||
} catch (IOException | UnauthenticatedResponseException | InvalidKeyException e) {
|
||||
Log.w(TAG, e);
|
||||
PinState.onPinCreateFailure();
|
||||
return PinSetResult.FAILURE;
|
||||
}
|
||||
}, resultConsumer::accept);
|
||||
}
|
||||
|
||||
enum PinSetResult {
|
||||
SUCCESS,
|
||||
FAILURE
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package org.thoughtcrime.securesms.lock.v2;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Transformations;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import org.thoughtcrime.securesms.lock.v2.ConfirmKbsPinRepository.PinSetResult;
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
|
||||
|
||||
final class ConfirmKbsPinViewModel extends ViewModel implements BaseKbsPinViewModel {
|
||||
|
||||
private final ConfirmKbsPinRepository repository;
|
||||
|
||||
private final DefaultValueLiveData<KbsPin> userEntry = new DefaultValueLiveData<>(KbsPin.EMPTY);
|
||||
private final DefaultValueLiveData<PinKeyboardType> keyboard = new DefaultValueLiveData<>(PinKeyboardType.NUMERIC);
|
||||
private final DefaultValueLiveData<SaveAnimation> saveAnimation = new DefaultValueLiveData<>(SaveAnimation.NONE);
|
||||
private final DefaultValueLiveData<LabelState> label = new DefaultValueLiveData<>(LabelState.EMPTY);
|
||||
|
||||
private final KbsPin pinToConfirm;
|
||||
|
||||
private ConfirmKbsPinViewModel(@NonNull KbsPin pinToConfirm,
|
||||
@NonNull PinKeyboardType keyboard,
|
||||
@NonNull ConfirmKbsPinRepository repository)
|
||||
{
|
||||
this.keyboard.setValue(keyboard);
|
||||
|
||||
this.pinToConfirm = pinToConfirm;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
LiveData<SaveAnimation> getSaveAnimation() {
|
||||
return Transformations.distinctUntilChanged(saveAnimation);
|
||||
}
|
||||
|
||||
LiveData<LabelState> getLabel() {
|
||||
return Transformations.distinctUntilChanged(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirm() {
|
||||
KbsPin userEntry = this.userEntry.getValue();
|
||||
|
||||
if (pinToConfirm.toString().equals(userEntry.toString())) {
|
||||
this.label.setValue(LabelState.CREATING_PIN);
|
||||
this.saveAnimation.setValue(SaveAnimation.LOADING);
|
||||
|
||||
repository.setPin(pinToConfirm, this.keyboard.getValue(), this::handleResult);
|
||||
} else {
|
||||
this.userEntry.setValue(KbsPin.EMPTY);
|
||||
this.label.setValue(LabelState.PIN_DOES_NOT_MATCH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<KbsPin> getUserEntry() {
|
||||
return userEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<PinKeyboardType> getKeyboard() {
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public void setUserEntry(String userEntry) {
|
||||
this.userEntry.setValue(KbsPin.from(userEntry));
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public void toggleAlphaNumeric() {
|
||||
this.keyboard.setValue(this.keyboard.getValue().getOther());
|
||||
}
|
||||
|
||||
private void handleResult(PinSetResult result) {
|
||||
switch (result) {
|
||||
case SUCCESS:
|
||||
this.saveAnimation.setValue(SaveAnimation.SUCCESS);
|
||||
break;
|
||||
case FAILURE:
|
||||
this.saveAnimation.setValue(SaveAnimation.FAILURE);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown state: " + result.name());
|
||||
}
|
||||
}
|
||||
|
||||
enum LabelState {
|
||||
RE_ENTER_PIN,
|
||||
PIN_DOES_NOT_MATCH,
|
||||
CREATING_PIN,
|
||||
EMPTY
|
||||
}
|
||||
|
||||
enum SaveAnimation {
|
||||
NONE,
|
||||
LOADING,
|
||||
SUCCESS,
|
||||
FAILURE
|
||||
}
|
||||
|
||||
static final class Factory implements ViewModelProvider.Factory {
|
||||
|
||||
private final KbsPin pinToConfirm;
|
||||
private final PinKeyboardType keyboard;
|
||||
private final ConfirmKbsPinRepository repository;
|
||||
|
||||
Factory(@NonNull KbsPin pinToConfirm,
|
||||
@NonNull PinKeyboardType keyboard,
|
||||
@NonNull ConfirmKbsPinRepository repository)
|
||||
{
|
||||
this.pinToConfirm = pinToConfirm;
|
||||
this.keyboard = keyboard;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new ConfirmKbsPinViewModel(pinToConfirm, keyboard, repository);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,16 +10,16 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.thoughtcrime.securesms.lock.v2.ConfirmKbsPinViewModel.SaveAnimation
|
||||
import org.thoughtcrime.securesms.lock.v2.ConfirmSvrPinViewModel.SaveAnimation
|
||||
import org.thoughtcrime.securesms.megaphone.Megaphones
|
||||
import org.thoughtcrime.securesms.registration.RegistrationUtil
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
import org.thoughtcrime.securesms.util.SpanUtil
|
||||
|
||||
internal class ConfirmKbsPinFragment : BaseKbsPinFragment<ConfirmKbsPinViewModel>() {
|
||||
internal class ConfirmSvrPinFragment : BaseSvrPinFragment<ConfirmSvrPinViewModel>() {
|
||||
|
||||
override fun initializeViewStates() {
|
||||
val args = ConfirmKbsPinFragmentArgs.fromBundle(requireArguments())
|
||||
val args = ConfirmSvrPinFragmentArgs.fromBundle(requireArguments())
|
||||
if (args.isPinChange) {
|
||||
initializeViewStatesForPinChange()
|
||||
} else {
|
||||
@@ -28,14 +28,13 @@ internal class ConfirmKbsPinFragment : BaseKbsPinFragment<ConfirmKbsPinViewModel
|
||||
ViewCompat.setAutofillHints(input, HintConstants.AUTOFILL_HINT_NEW_PASSWORD)
|
||||
}
|
||||
|
||||
override fun initializeViewModel(): ConfirmKbsPinViewModel {
|
||||
val args = ConfirmKbsPinFragmentArgs.fromBundle(requireArguments())
|
||||
override fun initializeViewModel(): ConfirmSvrPinViewModel {
|
||||
val args = ConfirmSvrPinFragmentArgs.fromBundle(requireArguments())
|
||||
val userEntry = args.userEntry!!
|
||||
val keyboard = args.keyboard
|
||||
val repository = ConfirmKbsPinRepository()
|
||||
val factory = ConfirmKbsPinViewModel.Factory(userEntry, keyboard, repository)
|
||||
val viewModel = ViewModelProvider(this, factory)[ConfirmKbsPinViewModel::class.java]
|
||||
viewModel.label.observe(viewLifecycleOwner) { label: ConfirmKbsPinViewModel.LabelState -> updateLabel(label) }
|
||||
val factory = ConfirmSvrPinViewModel.Factory(userEntry, keyboard)
|
||||
val viewModel = ViewModelProvider(this, factory)[ConfirmSvrPinViewModel::class.java]
|
||||
viewModel.label.observe(viewLifecycleOwner) { label: ConfirmSvrPinViewModel.LabelState -> updateLabel(label) }
|
||||
viewModel.saveAnimation.observe(viewLifecycleOwner) { animation: SaveAnimation -> updateSaveAnimation(animation) }
|
||||
return viewModel
|
||||
}
|
||||
@@ -58,15 +57,15 @@ internal class ConfirmKbsPinFragment : BaseKbsPinFragment<ConfirmKbsPinViewModel
|
||||
confirm.isEnabled = true
|
||||
}
|
||||
|
||||
private fun updateLabel(labelState: ConfirmKbsPinViewModel.LabelState) {
|
||||
private fun updateLabel(labelState: ConfirmSvrPinViewModel.LabelState) {
|
||||
when (labelState) {
|
||||
ConfirmKbsPinViewModel.LabelState.EMPTY -> label.text = ""
|
||||
ConfirmKbsPinViewModel.LabelState.CREATING_PIN -> {
|
||||
ConfirmSvrPinViewModel.LabelState.EMPTY -> label.text = ""
|
||||
ConfirmSvrPinViewModel.LabelState.CREATING_PIN -> {
|
||||
label.setText(R.string.ConfirmKbsPinFragment__creating_pin)
|
||||
input.isEnabled = false
|
||||
}
|
||||
ConfirmKbsPinViewModel.LabelState.RE_ENTER_PIN -> label.setText(R.string.ConfirmKbsPinFragment__re_enter_your_pin)
|
||||
ConfirmKbsPinViewModel.LabelState.PIN_DOES_NOT_MATCH -> {
|
||||
ConfirmSvrPinViewModel.LabelState.RE_ENTER_PIN -> label.setText(R.string.ConfirmKbsPinFragment__re_enter_your_pin)
|
||||
ConfirmSvrPinViewModel.LabelState.PIN_DOES_NOT_MATCH -> {
|
||||
label.text = SpanUtil.color(
|
||||
ContextCompat.getColor(requireContext(), R.color.red_500),
|
||||
getString(R.string.ConfirmKbsPinFragment__pins_dont_match)
|
||||
@@ -0,0 +1,125 @@
|
||||
package org.thoughtcrime.securesms.lock.v2;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Transformations;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import org.thoughtcrime.securesms.pin.SvrRepository;
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
|
||||
import org.whispersystems.signalservice.api.svr.SecureValueRecovery;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.core.Scheduler;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
final class ConfirmSvrPinViewModel extends ViewModel implements BaseSvrPinViewModel {
|
||||
|
||||
private final DefaultValueLiveData<SvrPin> userEntry = new DefaultValueLiveData<>(SvrPin.EMPTY);
|
||||
private final DefaultValueLiveData<PinKeyboardType> keyboard = new DefaultValueLiveData<>(PinKeyboardType.NUMERIC);
|
||||
private final DefaultValueLiveData<SaveAnimation> saveAnimation = new DefaultValueLiveData<>(SaveAnimation.NONE);
|
||||
private final DefaultValueLiveData<LabelState> label = new DefaultValueLiveData<>(LabelState.EMPTY);
|
||||
|
||||
private final SvrPin pinToConfirm;
|
||||
|
||||
private final CompositeDisposable disposables = new CompositeDisposable();
|
||||
|
||||
private ConfirmSvrPinViewModel(@NonNull SvrPin pinToConfirm, @NonNull PinKeyboardType keyboard) {
|
||||
this.keyboard.setValue(keyboard);
|
||||
this.pinToConfirm = pinToConfirm;
|
||||
}
|
||||
|
||||
LiveData<SaveAnimation> getSaveAnimation() {
|
||||
return Transformations.distinctUntilChanged(saveAnimation);
|
||||
}
|
||||
|
||||
LiveData<LabelState> getLabel() {
|
||||
return Transformations.distinctUntilChanged(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirm() {
|
||||
SvrPin userEntry = this.userEntry.getValue();
|
||||
|
||||
if (pinToConfirm.toString().equals(userEntry.toString())) {
|
||||
this.label.setValue(LabelState.CREATING_PIN);
|
||||
this.saveAnimation.setValue(SaveAnimation.LOADING);
|
||||
|
||||
disposables.add(
|
||||
Single.fromCallable(() -> SvrRepository.setPin(pinToConfirm.toString(), this.keyboard.getValue()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(result -> {
|
||||
if (result instanceof SecureValueRecovery.BackupResponse.Success) {
|
||||
this.saveAnimation.setValue(SaveAnimation.SUCCESS);
|
||||
} else {
|
||||
this.saveAnimation.setValue(SaveAnimation.FAILURE);
|
||||
}
|
||||
})
|
||||
);
|
||||
} else {
|
||||
this.userEntry.setValue(SvrPin.EMPTY);
|
||||
this.label.setValue(LabelState.PIN_DOES_NOT_MATCH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<SvrPin> getUserEntry() {
|
||||
return userEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<PinKeyboardType> getKeyboard() {
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public void setUserEntry(String userEntry) {
|
||||
this.userEntry.setValue(SvrPin.from(userEntry));
|
||||
}
|
||||
|
||||
@MainThread
|
||||
public void toggleAlphaNumeric() {
|
||||
this.keyboard.setValue(this.keyboard.getValue().getOther());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
disposables.clear();
|
||||
}
|
||||
|
||||
enum LabelState {
|
||||
RE_ENTER_PIN,
|
||||
PIN_DOES_NOT_MATCH,
|
||||
CREATING_PIN,
|
||||
EMPTY
|
||||
}
|
||||
|
||||
enum SaveAnimation {
|
||||
NONE,
|
||||
LOADING,
|
||||
SUCCESS,
|
||||
FAILURE
|
||||
}
|
||||
|
||||
static final class Factory implements ViewModelProvider.Factory {
|
||||
|
||||
private final SvrPin pinToConfirm;
|
||||
private final PinKeyboardType keyboard;
|
||||
|
||||
Factory(@NonNull SvrPin pinToConfirm, @NonNull PinKeyboardType keyboard) {
|
||||
this.pinToConfirm = pinToConfirm;
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||
//noinspection unchecked
|
||||
return (T) new ConfirmSvrPinViewModel(pinToConfirm, keyboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,14 @@ import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.DynamicRegistrationTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
|
||||
public class CreateKbsPinActivity extends BaseActivity {
|
||||
public class CreateSvrPinActivity extends BaseActivity {
|
||||
|
||||
public static final int REQUEST_NEW_PIN = 27698;
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicRegistrationTheme();
|
||||
|
||||
public static @NonNull Intent getIntentForPinCreate(@NonNull Context context) {
|
||||
CreateKbsPinFragmentArgs args = new CreateKbsPinFragmentArgs.Builder()
|
||||
CreateSvrPinFragmentArgs args = new CreateSvrPinFragmentArgs.Builder()
|
||||
.setIsForgotPin(false)
|
||||
.setIsPinChange(false)
|
||||
.build();
|
||||
@@ -33,7 +33,7 @@ public class CreateKbsPinActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
public static @NonNull Intent getIntentForPinChangeFromForgotPin(@NonNull Context context) {
|
||||
CreateKbsPinFragmentArgs args = new CreateKbsPinFragmentArgs.Builder()
|
||||
CreateSvrPinFragmentArgs args = new CreateSvrPinFragmentArgs.Builder()
|
||||
.setIsForgotPin(true)
|
||||
.setIsPinChange(true)
|
||||
.build();
|
||||
@@ -42,7 +42,7 @@ public class CreateKbsPinActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
public static @NonNull Intent getIntentForPinChangeFromSettings(@NonNull Context context) {
|
||||
CreateKbsPinFragmentArgs args = new CreateKbsPinFragmentArgs.Builder()
|
||||
CreateSvrPinFragmentArgs args = new CreateSvrPinFragmentArgs.Builder()
|
||||
.setIsForgotPin(false)
|
||||
.setIsPinChange(true)
|
||||
.build();
|
||||
@@ -50,8 +50,8 @@ public class CreateKbsPinActivity extends BaseActivity {
|
||||
return getIntentWithArgs(context, args);
|
||||
}
|
||||
|
||||
private static @NonNull Intent getIntentWithArgs(@NonNull Context context, @NonNull CreateKbsPinFragmentArgs args) {
|
||||
return new Intent(context, CreateKbsPinActivity.class).putExtras(args.toBundle());
|
||||
private static @NonNull Intent getIntentWithArgs(@NonNull Context context, @NonNull CreateSvrPinFragmentArgs args) {
|
||||
return new Intent(context, CreateSvrPinActivity.class).putExtras(args.toBundle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,7 +68,7 @@ public class CreateKbsPinActivity extends BaseActivity {
|
||||
|
||||
setContentView(R.layout.create_kbs_pin_activity);
|
||||
|
||||
CreateKbsPinFragmentArgs arguments = CreateKbsPinFragmentArgs.fromBundle(getIntent().getExtras());
|
||||
CreateSvrPinFragmentArgs arguments = CreateSvrPinFragmentArgs.fromBundle(getIntent().getExtras());
|
||||
|
||||
NavGraph graph = Navigation.findNavController(this, R.id.nav_host_fragment).getGraph();
|
||||
Navigation.findNavController(this, R.id.nav_host_fragment).setGraph(graph, arguments.toBundle());
|
||||
@@ -10,14 +10,14 @@ import androidx.core.view.ViewCompat
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.Navigation.findNavController
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinViewModel.NavigationEvent
|
||||
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinViewModel.PinErrorEvent
|
||||
import org.thoughtcrime.securesms.lock.v2.CreateSvrPinViewModel.NavigationEvent
|
||||
import org.thoughtcrime.securesms.lock.v2.CreateSvrPinViewModel.PinErrorEvent
|
||||
import org.thoughtcrime.securesms.util.SpanUtil
|
||||
import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||
|
||||
class CreateKbsPinFragment : BaseKbsPinFragment<CreateKbsPinViewModel?>() {
|
||||
class CreateSvrPinFragment : BaseSvrPinFragment<CreateSvrPinViewModel?>() {
|
||||
override fun initializeViewStates() {
|
||||
val args = CreateKbsPinFragmentArgs.fromBundle(requireArguments())
|
||||
val args = CreateSvrPinFragmentArgs.fromBundle(requireArguments())
|
||||
if (args.isPinChange) {
|
||||
initializeViewStatesForPinChange(args.isForgotPin)
|
||||
} else {
|
||||
@@ -40,9 +40,9 @@ class CreateKbsPinFragment : BaseKbsPinFragment<CreateKbsPinViewModel?>() {
|
||||
description.setLearnMoreVisible(true)
|
||||
}
|
||||
|
||||
override fun initializeViewModel(): CreateKbsPinViewModel {
|
||||
val viewModel = ViewModelProvider(this)[CreateKbsPinViewModel::class.java]
|
||||
val args = CreateKbsPinFragmentArgs.fromBundle(requireArguments())
|
||||
override fun initializeViewModel(): CreateSvrPinViewModel {
|
||||
val viewModel = ViewModelProvider(this)[CreateSvrPinViewModel::class.java]
|
||||
val args = CreateSvrPinFragmentArgs.fromBundle(requireArguments())
|
||||
viewModel.navigationEvents.observe(viewLifecycleOwner) { e: NavigationEvent -> onConfirmPin(e.userEntry, e.keyboard, args.isPinChange) }
|
||||
viewModel.errorEvents.observe(viewLifecycleOwner) { e: PinErrorEvent ->
|
||||
if (e == PinErrorEvent.WEAK_PIN) {
|
||||
@@ -62,8 +62,8 @@ class CreateKbsPinFragment : BaseKbsPinFragment<CreateKbsPinViewModel?>() {
|
||||
return viewModel
|
||||
}
|
||||
|
||||
private fun onConfirmPin(userEntry: KbsPin, keyboard: PinKeyboardType, isPinChange: Boolean) {
|
||||
val action = CreateKbsPinFragmentDirections.actionConfirmPin()
|
||||
private fun onConfirmPin(userEntry: SvrPin, keyboard: PinKeyboardType, isPinChange: Boolean) {
|
||||
val action = CreateSvrPinFragmentDirections.actionConfirmPin()
|
||||
action.userEntry = userEntry
|
||||
action.keyboard = keyboard
|
||||
action.isPinChange = isPinChange
|
||||
@@ -79,7 +79,7 @@ class CreateKbsPinFragment : BaseKbsPinFragment<CreateKbsPinViewModel?>() {
|
||||
}
|
||||
|
||||
private fun getPinLengthRestrictionText(@PluralsRes plurals: Int): String {
|
||||
return resources.getQuantityString(plurals, KbsConstants.MINIMUM_PIN_LENGTH, KbsConstants.MINIMUM_PIN_LENGTH)
|
||||
return resources.getQuantityString(plurals, SvrConstants.MINIMUM_PIN_LENGTH, SvrConstants.MINIMUM_PIN_LENGTH)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -2,23 +2,23 @@ package org.thoughtcrime.securesms.lock.v2;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.util.Preconditions;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import org.thoughtcrime.securesms.util.SingleLiveEvent;
|
||||
import org.whispersystems.signalservice.api.kbs.PinValidityChecker;
|
||||
import org.whispersystems.signalservice.api.util.Preconditions;
|
||||
|
||||
public final class CreateKbsPinViewModel extends ViewModel implements BaseKbsPinViewModel {
|
||||
public final class CreateSvrPinViewModel extends ViewModel implements BaseSvrPinViewModel {
|
||||
|
||||
private final MutableLiveData<KbsPin> userEntry = new MutableLiveData<>(KbsPin.EMPTY);
|
||||
private final MutableLiveData<SvrPin> userEntry = new MutableLiveData<>(SvrPin.EMPTY);
|
||||
private final MutableLiveData<PinKeyboardType> keyboard = new MutableLiveData<>(PinKeyboardType.NUMERIC);
|
||||
private final SingleLiveEvent<NavigationEvent> events = new SingleLiveEvent<>();
|
||||
private final SingleLiveEvent<PinErrorEvent> errors = new SingleLiveEvent<>();
|
||||
|
||||
@Override
|
||||
public LiveData<KbsPin> getUserEntry() {
|
||||
public LiveData<SvrPin> getUserEntry() {
|
||||
return userEntry;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class CreateKbsPinViewModel extends ViewModel implements BaseKbsPin
|
||||
@Override
|
||||
@MainThread
|
||||
public void setUserEntry(String userEntry) {
|
||||
this.userEntry.setValue(KbsPin.from(userEntry));
|
||||
this.userEntry.setValue(SvrPin.from(userEntry));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +46,7 @@ public final class CreateKbsPinViewModel extends ViewModel implements BaseKbsPin
|
||||
@Override
|
||||
@MainThread
|
||||
public void confirm() {
|
||||
KbsPin pin = Preconditions.checkNotNull(this.getUserEntry().getValue());
|
||||
SvrPin pin = Preconditions.checkNotNull(this.getUserEntry().getValue());
|
||||
PinKeyboardType keyboard = Preconditions.checkNotNull(this.getKeyboard().getValue());
|
||||
|
||||
if (PinValidityChecker.valid(pin.toString())) {
|
||||
@@ -57,15 +57,15 @@ public final class CreateKbsPinViewModel extends ViewModel implements BaseKbsPin
|
||||
}
|
||||
|
||||
static final class NavigationEvent {
|
||||
private final KbsPin userEntry;
|
||||
private final SvrPin userEntry;
|
||||
private final PinKeyboardType keyboard;
|
||||
|
||||
NavigationEvent(@NonNull KbsPin userEntry, @NonNull PinKeyboardType keyboard) {
|
||||
NavigationEvent(@NonNull SvrPin userEntry, @NonNull PinKeyboardType keyboard) {
|
||||
this.userEntry = userEntry;
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
|
||||
KbsPin getUserEntry() {
|
||||
SvrPin getUserEntry() {
|
||||
return userEntry;
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.thoughtcrime.securesms.lock.v2;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
public final class RegistrationLockUtil {
|
||||
|
||||
private RegistrationLockUtil() {}
|
||||
|
||||
public static boolean userHasRegistrationLock(@NonNull Context context) {
|
||||
return TextSecurePreferences.isV1RegistrationLockEnabled(context) || SignalStore.kbsValues().isV2RegistrationLockEnabled();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.thoughtcrime.securesms.lock.v2;
|
||||
|
||||
public final class KbsConstants {
|
||||
public final class SvrConstants {
|
||||
|
||||
public static final int MINIMUM_PIN_LENGTH = 4;
|
||||
|
||||
private KbsConstants() { }
|
||||
private SvrConstants() { }
|
||||
}
|
||||
@@ -13,14 +13,14 @@ import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.DynamicRegistrationTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
|
||||
public class KbsMigrationActivity extends BaseActivity {
|
||||
public class SvrMigrationActivity extends BaseActivity {
|
||||
|
||||
public static final int REQUEST_NEW_PIN = CreateKbsPinActivity.REQUEST_NEW_PIN;
|
||||
public static final int REQUEST_NEW_PIN = CreateSvrPinActivity.REQUEST_NEW_PIN;
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicRegistrationTheme();
|
||||
|
||||
public static Intent createIntent() {
|
||||
return new Intent(ApplicationDependencies.getApplication(), KbsMigrationActivity.class);
|
||||
return new Intent(ApplicationDependencies.getApplication(), SvrMigrationActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -6,17 +6,17 @@ import android.os.Parcelable;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public final class KbsPin implements Parcelable {
|
||||
public final class SvrPin implements Parcelable {
|
||||
|
||||
public static KbsPin EMPTY = new KbsPin("");
|
||||
public static SvrPin EMPTY = new SvrPin("");
|
||||
|
||||
private final String pin;
|
||||
|
||||
private KbsPin(String pin) {
|
||||
private SvrPin(String pin) {
|
||||
this.pin = pin;
|
||||
}
|
||||
|
||||
private KbsPin(Parcel in) {
|
||||
private SvrPin(Parcel in) {
|
||||
pin = in.readString();
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ public final class KbsPin implements Parcelable {
|
||||
return pin;
|
||||
}
|
||||
|
||||
public static KbsPin from(@Nullable String pin) {
|
||||
public static SvrPin from(@Nullable String pin) {
|
||||
if (pin == null) return EMPTY;
|
||||
|
||||
pin = pin.trim();
|
||||
|
||||
if (pin.length() == 0) return EMPTY;
|
||||
|
||||
return new KbsPin(pin);
|
||||
return new SvrPin(pin);
|
||||
}
|
||||
|
||||
public int length() {
|
||||
@@ -49,15 +49,15 @@ public final class KbsPin implements Parcelable {
|
||||
dest.writeString(pin);
|
||||
}
|
||||
|
||||
public static final Creator<KbsPin> CREATOR = new Creator<KbsPin>() {
|
||||
public static final Creator<SvrPin> CREATOR = new Creator<SvrPin>() {
|
||||
@Override
|
||||
public KbsPin createFromParcel(Parcel in) {
|
||||
return new KbsPin(in);
|
||||
public SvrPin createFromParcel(Parcel in) {
|
||||
return new SvrPin(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KbsPin[] newArray(int size) {
|
||||
return new KbsPin[size];
|
||||
public SvrPin[] newArray(int size) {
|
||||
return new SvrPin[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.thoughtcrime.securesms.pin.PinOptOutDialog;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.navigation.SafeNavigation;
|
||||
|
||||
public final class KbsSplashFragment extends Fragment {
|
||||
public final class SvrSplashFragment extends Fragment {
|
||||
|
||||
private TextView title;
|
||||
private TextView description;
|
||||
@@ -55,7 +55,7 @@ public final class KbsSplashFragment extends Fragment {
|
||||
primaryAction.setOnClickListener(v -> onCreatePin());
|
||||
secondaryAction.setOnClickListener(v -> onLearnMore());
|
||||
|
||||
if (RegistrationLockUtil.userHasRegistrationLock(requireContext())) {
|
||||
if (SignalStore.svr().isRegistrationLockEnabled()) {
|
||||
setUpRegLockEnabled();
|
||||
} else {
|
||||
setUpRegLockDisabled();
|
||||
@@ -80,7 +80,7 @@ public final class KbsSplashFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
if (RegistrationLockUtil.userHasRegistrationLock(requireContext())) {
|
||||
if (SignalStore.svr().isRegistrationLockEnabled()) {
|
||||
menu.clear();
|
||||
}
|
||||
}
|
||||
@@ -113,9 +113,9 @@ public final class KbsSplashFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void onCreatePin() {
|
||||
KbsSplashFragmentDirections.ActionCreateKbsPin action = KbsSplashFragmentDirections.actionCreateKbsPin();
|
||||
SvrSplashFragmentDirections.ActionCreateKbsPin action = SvrSplashFragmentDirections.actionCreateKbsPin();
|
||||
|
||||
action.setIsPinChange(SignalStore.kbsValues().hasPin());
|
||||
action.setIsPinChange(SignalStore.svr().hasPin());
|
||||
|
||||
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), action);
|
||||
}
|
||||
Reference in New Issue
Block a user