Add the ability to disable PIN reminders.
This commit is contained in:
parent
bb6ca80d5a
commit
5cb1201903
6 changed files with 205 additions and 2 deletions
|
@ -1,6 +1,5 @@
|
|||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.CheckResult;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
@ -21,6 +20,7 @@ public final class PinValues {
|
|||
private static final String NEXT_INTERVAL = "pin.interval_index";
|
||||
private static final String KEYBOARD_TYPE = "kbs.keyboard_type";
|
||||
private static final String PIN_STATE = "pin.pin_state";
|
||||
public static final String PIN_REMINDERS_ENABLED = "pin.pin_reminders_enabled";
|
||||
|
||||
private final KeyValueStore store;
|
||||
|
||||
|
@ -81,6 +81,14 @@ public final class PinValues {
|
|||
.commit();
|
||||
}
|
||||
|
||||
public void setPinRemindersEnabled(boolean enabled) {
|
||||
store.beginWrite().putBoolean(PIN_REMINDERS_ENABLED, enabled).apply();
|
||||
}
|
||||
|
||||
public boolean arePinRemindersEnabled() {
|
||||
return store.getBoolean(PIN_REMINDERS_ENABLED, true);
|
||||
}
|
||||
|
||||
public @NonNull PinKeyboardType getKeyboardType() {
|
||||
return PinKeyboardType.fromCode(store.getString(KEYBOARD_TYPE, null));
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@ final class SignalPinReminderSchedule implements MegaphoneSchedule {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!SignalStore.pinValues().arePinRemindersEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long lastSuccessTime = SignalStore.pinValues().getLastSuccessfulEntryTime();
|
||||
long interval = SignalStore.pinValues().getCurrentInterval();
|
||||
|
||||
|
|
|
@ -3,11 +3,26 @@ package org.thoughtcrime.securesms.preferences;
|
|||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.autofill.HintConstants;
|
||||
import androidx.core.app.DialogCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.preference.CheckBoxPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
|
@ -19,15 +34,20 @@ import org.thoughtcrime.securesms.BlockedContactsActivity;
|
|||
import org.thoughtcrime.securesms.PassphraseChangeActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
||||
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.KbsValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.PinValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.lock.PinHashing;
|
||||
import org.thoughtcrime.securesms.lock.RegistrationLockV1Dialog;
|
||||
import org.thoughtcrime.securesms.lock.SignalPinReminderDialog;
|
||||
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
||||
import org.thoughtcrime.securesms.lock.v2.KbsConstants;
|
||||
import org.thoughtcrime.securesms.lock.v2.RegistrationLockUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.pin.PinState;
|
||||
|
@ -37,13 +57,17 @@ import org.thoughtcrime.securesms.service.KeyCachingService;
|
|||
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SignalExecutors;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import mobi.upod.timedurationpicker.TimeDurationPickerDialog;
|
||||
|
@ -62,10 +86,15 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||
super.onCreate(paramBundle);
|
||||
|
||||
disablePassphrase = (CheckBoxPreference) this.findPreference("pref_enable_passphrase_temporary");
|
||||
|
||||
this.findPreference(KbsValues.V2_LOCK_ENABLED).setPreferenceDataStore(SignalStore.getPreferenceDataStore());
|
||||
((SwitchPreferenceCompat) this.findPreference(KbsValues.V2_LOCK_ENABLED)).setChecked(SignalStore.kbsValues().isV2RegistrationLockEnabled());
|
||||
this.findPreference(KbsValues.V2_LOCK_ENABLED).setOnPreferenceChangeListener(new RegistrationLockV2ChangedListener());
|
||||
|
||||
this.findPreference(PinValues.PIN_REMINDERS_ENABLED).setPreferenceDataStore(SignalStore.getPreferenceDataStore());
|
||||
((SwitchPreferenceCompat) this.findPreference(PinValues.PIN_REMINDERS_ENABLED)).setChecked(SignalStore.pinValues().arePinRemindersEnabled());
|
||||
this.findPreference(PinValues.PIN_REMINDERS_ENABLED).setOnPreferenceChangeListener(new PinRemindersChangedListener());
|
||||
|
||||
this.findPreference(TextSecurePreferences.SCREEN_LOCK).setOnPreferenceChangeListener(new ScreenLockListener());
|
||||
this.findPreference(TextSecurePreferences.SCREEN_LOCK_TIMEOUT).setOnPreferenceClickListener(new ScreenLockTimeoutListener());
|
||||
|
||||
|
@ -102,6 +131,7 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||
SwitchPreferenceCompat registrationLockV1 = (SwitchPreferenceCompat) this.findPreference(TextSecurePreferences.REGISTRATION_LOCK_PREF_V1);
|
||||
Preference signalPinGroup = this.findPreference("prefs_signal_pin");
|
||||
Preference signalPinCreateChange = this.findPreference(TextSecurePreferences.SIGNAL_PIN_CHANGE);
|
||||
SwitchPreferenceCompat signalPinReminders = (SwitchPreferenceCompat) this.findPreference(PinValues.PIN_REMINDERS_ENABLED);
|
||||
SwitchPreferenceCompat registrationLockV2 = (SwitchPreferenceCompat) this.findPreference(KbsValues.V2_LOCK_ENABLED);
|
||||
|
||||
|
||||
|
@ -115,6 +145,7 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||
} else {
|
||||
signalPinCreateChange.setOnPreferenceClickListener(new KbsPinCreateListener());
|
||||
signalPinCreateChange.setTitle(R.string.preferences_app_protection__create_a_pin);
|
||||
signalPinReminders.setEnabled(false);
|
||||
registrationLockV2.setEnabled(false);
|
||||
}
|
||||
} else {
|
||||
|
@ -430,4 +461,75 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class PinRemindersChangedListener implements Preference.OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean value = (boolean) newValue;
|
||||
|
||||
if (!value) {
|
||||
Context context = preference.getContext();
|
||||
DisplayMetrics metrics = preference.getContext().getResources().getDisplayMetrics();
|
||||
AlertDialog dialog = new AlertDialog.Builder(context, ThemeUtil.isDarkTheme(context) ? R.style.Theme_Signal_AlertDialog_Dark_Cornered_ColoredAccent : R.style.Theme_Signal_AlertDialog_Light_Cornered_ColoredAccent)
|
||||
.setView(R.layout.pin_disable_reminders_dialog)
|
||||
.create();
|
||||
|
||||
|
||||
dialog.show();
|
||||
dialog.getWindow().setLayout((int)(metrics.widthPixels * .80), ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
EditText pinEditText = (EditText) DialogCompat.requireViewById(dialog, R.id.reminder_disable_pin);
|
||||
TextView statusText = (TextView) DialogCompat.requireViewById(dialog, R.id.reminder_disable_status);
|
||||
View cancelButton = DialogCompat.requireViewById(dialog, R.id.reminder_disable_cancel);
|
||||
View turnOffButton = DialogCompat.requireViewById(dialog, R.id.reminder_disable_turn_off);
|
||||
|
||||
pinEditText.post(() -> {
|
||||
if (pinEditText.requestFocus()) {
|
||||
ServiceUtil.getInputMethodManager(pinEditText.getContext()).showSoftInput(pinEditText, 0);
|
||||
}
|
||||
});
|
||||
|
||||
ViewCompat.setAutofillHints(pinEditText, HintConstants.AUTOFILL_HINT_PASSWORD);
|
||||
|
||||
switch (SignalStore.pinValues().getKeyboardType()) {
|
||||
case NUMERIC:
|
||||
pinEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||
break;
|
||||
case ALPHA_NUMERIC:
|
||||
pinEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Unexpected type!");
|
||||
}
|
||||
|
||||
pinEditText.addTextChangedListener(new SimpleTextWatcher() {
|
||||
@Override
|
||||
public void onTextChanged(String text) {
|
||||
turnOffButton.setEnabled(text.length() >= KbsConstants.MINIMUM_PIN_LENGTH);
|
||||
}
|
||||
});
|
||||
|
||||
pinEditText.setTypeface(Typeface.DEFAULT);
|
||||
|
||||
turnOffButton.setOnClickListener(v -> {
|
||||
String pin = pinEditText.getText().toString();
|
||||
boolean correct = PinHashing.verifyLocalPinHash(Objects.requireNonNull(SignalStore.kbsValues().getLocalPinHash()), pin);
|
||||
|
||||
if (correct) {
|
||||
SignalStore.pinValues().setPinRemindersEnabled(false);
|
||||
((SwitchPreferenceCompat) findPreference(PinValues.PIN_REMINDERS_ENABLED)).setChecked(false);
|
||||
dialog.dismiss();
|
||||
} else {
|
||||
statusText.setText(R.string.preferences_app_protection__incorrect_pin_try_again);
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
77
app/src/main/res/layout/pin_disable_reminders_dialog.xml
Normal file
77
app/src/main/res/layout/pin_disable_reminders_dialog.xml
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_disable_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/preferences_app_protection__confirm_your_signal_pin"
|
||||
style="@style/Signal.Text.Body"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_disable_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/preferences_app_protection__make_sure_you_memorize_or_securely_store_your_pin"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="center"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/reminder_disable_title"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/reminder_disable_pin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="105sp"
|
||||
android:paddingTop="36dp"
|
||||
android:gravity="center"
|
||||
android:hint="@string/preferences_app_protection__confirm_pin"
|
||||
android:fontFamily="sans-serif"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/reminder_disable_description" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_disable_status"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/core_red"
|
||||
app:layout_constraintTop_toBottomOf="@id/reminder_disable_pin"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:text="@string/preferences_app_protection__incorrect_pin_try_again" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/reminder_disable_cancel"
|
||||
style="@style/Button.Borderless"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@android:string/cancel"
|
||||
app:layout_constraintTop_toTopOf="@id/reminder_disable_turn_off"
|
||||
app:layout_constraintEnd_toStartOf="@id/reminder_disable_turn_off"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/reminder_disable_turn_off"
|
||||
style="@style/Button.Primary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/preferences_app_protection__turn_off"
|
||||
android:layout_marginTop="8dp"
|
||||
android:enabled="false"
|
||||
app:layout_constraintTop_toBottomOf="@id/reminder_disable_status"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -2195,8 +2195,15 @@
|
|||
<string name="preferences_app_protection__signal_pin">Signal PIN</string>
|
||||
<string name="preferences_app_protection__create_a_pin">Create a PIN</string>
|
||||
<string name="preferences_app_protection__change_your_pin">Change your PIN</string>
|
||||
<string name="preferences_app_protection__pin_reminders">PIN reminders</string>
|
||||
<string name="preferences_app_protection__pins_keep_information_stored_with_signal_encrypted">PINs keep information stored with Signal encrypted so only you can access it. Your profile, settings, and contacts will restore when you reinstall Signal.</string>
|
||||
<string name="preferences_app_protection__add_extra_security_by_requiring_your_signal_pin_to_register">Add extra security by requiring your Signal PIN to register your phone number with Signal again.</string>
|
||||
<string name="preferences_app_protection__reminders_help_you_remember_your_pin">Reminders help you remember your PIN since it can\'t be recovered. You\'ll be asked less frequently over time.</string>
|
||||
<string name="preferences_app_protection__turn_off">Turn off</string>
|
||||
<string name="preferences_app_protection__confirm_pin">Confirm PIN</string>
|
||||
<string name="preferences_app_protection__confirm_your_signal_pin">Confirm your Signal PIN</string>
|
||||
<string name="preferences_app_protection__make_sure_you_memorize_or_securely_store_your_pin">Make sure you memorize or securely store your PIN as it can\'t be recovered. If you forget your PIN, you may lose data when re-registering your Signal account.</string>
|
||||
<string name="preferences_app_protection__incorrect_pin_try_again">Incorrect PIN. Try again.</string>
|
||||
<string name="preferences_app_protection__failed_to_enable_registration_lock">Failed to enable registration lock.</string>
|
||||
<string name="preferences_app_protection__failed_to_disable_registration_lock">Failed to disable registration lock.</string>
|
||||
<string name="AppProtectionPreferenceFragment_none">None</string>
|
||||
|
@ -2226,7 +2233,7 @@
|
|||
<string name="RegistrationLockDialog_i_forgot_my_pin">I forgot my PIN.</string>
|
||||
<string name="RegistrationLockDialog_forgotten_pin">Forgotten PIN?</string>
|
||||
<string name="RegistrationLockDialog_registration_lock_helps_protect_your_phone_number_from_unauthorized_registration_attempts">Registration Lock helps protect your phone number from unauthorized registration attempts. This feature can be disabled at any time in your Signal privacy settings</string>
|
||||
<string name="RegistrationLockDialog_registration_lock">Registration Lock</string>
|
||||
<string name="RegistrationLockDialog_registration_lock">Registration lock</string>
|
||||
<string name="RegistrationLockDialog_enable">Enable</string>
|
||||
<string name="RegistrationLockDialog_the_registration_lock_pin_must_be_at_least_d_digits">The Registration Lock PIN must be at least %d digits.</string>
|
||||
<string name="RegistrationLockDialog_the_two_pins_you_entered_do_not_match">The two PINs you entered do not match.</string>
|
||||
|
|
|
@ -115,6 +115,11 @@
|
|||
android:summary="@string/preferences_app_protection__pins_keep_information_stored_with_signal_encrypted"
|
||||
android:title="@string/preferences_app_protection__change_your_pin" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:key="pin.pin_reminders_enabled"
|
||||
android:summary="@string/preferences_app_protection__reminders_help_you_remember_your_pin"
|
||||
android:title="@string/preferences_app_protection__pin_reminders" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:enabled="false"
|
||||
|
|
Loading…
Add table
Reference in a new issue