Show a warning when a separate export/backup password is configured

This commit is contained in:
Alexander Bakker 2022-10-26 13:14:54 +02:00
parent 031a11250a
commit 7993142cc5
8 changed files with 56 additions and 30 deletions

View File

@ -26,6 +26,7 @@ public class BackupsPreferencesFragment extends PreferencesFragment {
private Preference _backupsLocationPreference;
private Preference _backupsTriggerPreference;
private Preference _backupsVersionsPreference;
private Preference _backupsPasswordWarningPreference;
private Preference _builtinBackupStatusPreference;
private Preference _androidBackupStatusPreference;
@ -41,6 +42,7 @@ public class BackupsPreferencesFragment extends PreferencesFragment {
super.onCreatePreferences(savedInstanceState, rootKey);
addPreferencesFromResource(R.xml.preferences_backups);
_backupsPasswordWarningPreference = requirePreference("pref_backups_warning_password");
_builtinBackupStatusPreference = requirePreference("pref_status_backup_builtin");
_builtinBackupStatusPreference.setOnPreferenceClickListener(preference -> {
Preferences.BackupResult backupRes = _prefs.getBuiltInBackupResult();
@ -138,6 +140,7 @@ public class BackupsPreferencesFragment extends PreferencesFragment {
boolean encrypted = _vaultManager.getVault().isEncryptionEnabled();
boolean androidBackupEnabled = _prefs.isAndroidBackupsEnabled() && encrypted;
boolean backupEnabled = _prefs.isBackupsEnabled() && encrypted;
_backupsPasswordWarningPreference.setVisible(_vaultManager.getVault().isBackupPasswordSet());
_androidBackupsPreference.setChecked(androidBackupEnabled);
_androidBackupsPreference.setEnabled(encrypted);
_backupsPreference.setChecked(backupEnabled);

View File

@ -9,6 +9,7 @@ import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -147,10 +148,13 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
}
private void startExport() {
boolean isBackupPasswordSet = _vaultManager.getVault().isBackupPasswordSet();
View view = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_export, null);
TextView warningText = view.findViewById(R.id.text_export_warning);
CheckBox checkBoxEncrypt = view.findViewById(R.id.checkbox_export_encrypt);
CheckBox checkBoxAccept = view.findViewById(R.id.checkbox_accept);
TextView passwordInfoText = view.findViewById(R.id.text_separate_password);
passwordInfoText.setVisibility(checkBoxEncrypt.isChecked() && isBackupPasswordSet ? View.VISIBLE : View.GONE);
AutoCompleteTextView dropdown = view.findViewById(R.id.dropdown_export_format);
DropdownHelper.fillDropdown(requireContext(), dropdown, R.array.export_formats);
dropdown.setText(getString(R.string.export_format_aegis), false);
@ -158,6 +162,7 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
checkBoxEncrypt.setChecked(position == 0);
checkBoxEncrypt.setEnabled(position == 0);
warningText.setVisibility(checkBoxEncrypt.isChecked() ? View.GONE : View.VISIBLE);
passwordInfoText.setVisibility(checkBoxEncrypt.isChecked() && isBackupPasswordSet ? View.VISIBLE : View.GONE);
});
AlertDialog dialog = new AlertDialog.Builder(requireContext())
@ -174,6 +179,7 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
checkBoxEncrypt.setOnCheckedChangeListener((buttonView, isChecked) -> {
warningText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordInfoText.setVisibility(isChecked && isBackupPasswordSet ? View.VISIBLE : View.GONE);
checkBoxAccept.setVisibility(isChecked ? View.GONE : View.VISIBLE);
checkBoxAccept.setChecked(false);
btnPos.setEnabled(isChecked);

View File

@ -238,7 +238,7 @@ public class SecurityPreferencesFragment extends PreferencesFragment {
_backupPasswordPreference = requirePreference("pref_backup_password");
_backupPasswordPreference.setOnPreferenceChangeListener((preference, newValue) -> {
if (!isBackupPasswordSet()) {
if (!_vaultManager.getVault().isBackupPasswordSet()) {
Dialogs.showSetPasswordDialog(requireActivity(), new SetBackupPasswordListener());
} else {
VaultFileCredentials creds = _vaultManager.getVault().getCredentials();
@ -264,7 +264,7 @@ public class SecurityPreferencesFragment extends PreferencesFragment {
private void updateEncryptionPreferences() {
boolean encrypted = _vaultManager.getVault().isEncryptionEnabled();
boolean backupPasswordSet = isBackupPasswordSet();
boolean backupPasswordSet = _vaultManager.getVault().isBackupPasswordSet();
_encryptionPreference.setChecked(encrypted, true);
_setPasswordPreference.setVisible(encrypted);
_biometricsPreference.setVisible(encrypted);
@ -294,15 +294,6 @@ public class SecurityPreferencesFragment extends PreferencesFragment {
}
}
private boolean isBackupPasswordSet() {
VaultRepository vault = _vaultManager.getVault();
if (!vault.isEncryptionEnabled()) {
return false;
}
return vault.getCredentials().getSlots().findBackupPasswordSlots().size() > 0;
}
private String getPasswordReminderSummary() {
PassReminderFreq freq = _prefs.getPasswordReminderFrequency();
if (freq == PassReminderFreq.NEVER) {

View File

@ -230,4 +230,12 @@ public class VaultRepository {
public boolean isEncryptionEnabled() {
return _creds != null;
}
public boolean isBackupPasswordSet() {
if (!isEncryptionEnabled()) {
return false;
}
return getCredentials().getSlots().findBackupPasswordSlots().size() > 0;
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M16.61 15.15C16.15 15.15 15.77 14.78 15.77 14.32S16.15 13.5 16.61 13.5H16.61C17.07 13.5 17.45 13.86 17.45 14.32C17.45 14.78 17.07 15.15 16.61 15.15M7.41 15.15C6.95 15.15 6.57 14.78 6.57 14.32C6.57 13.86 6.95 13.5 7.41 13.5H7.41C7.87 13.5 8.24 13.86 8.24 14.32C8.24 14.78 7.87 15.15 7.41 15.15M16.91 10.14L18.58 7.26C18.67 7.09 18.61 6.88 18.45 6.79C18.28 6.69 18.07 6.75 18 6.92L16.29 9.83C14.95 9.22 13.5 8.9 12 8.91C10.47 8.91 9 9.24 7.73 9.82L6.04 6.91C5.95 6.74 5.74 6.68 5.57 6.78C5.4 6.87 5.35 7.08 5.44 7.25L7.1 10.13C4.25 11.69 2.29 14.58 2 18H22C21.72 14.59 19.77 11.7 16.91 10.14H16.91Z" />
</vector>

View File

@ -17,7 +17,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="5dp"
android:layout_marginTop="15dp"
android:hint="@string/export_format_hint"
style="?attr/dropdownStyle">
<AutoCompleteTextView
@ -35,6 +35,15 @@
android:layout_marginTop="5dp"
android:text="@string/export_encrypted"
android:checked="true" />
<TextView
android:id="@+id/text_separate_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="5dp"
android:textStyle="italic"
android:text="@string/export_warning_password" />
<TextView
android:id="@+id/text_export_warning"
android:layout_width="match_parent"

View File

@ -100,6 +100,7 @@
<string name="export_help">This action will export the vault out of Aegis\' internal storage. Select the format you\'d like your export to be in:</string>
<string name="export_warning_unencrypted">You are about to export an unencrypted copy of your Aegis vault. <b>This is not recommended</b>.</string>
<string name="export_warning_accept">I understand the risk</string>
<string name="export_warning_password">Exports are encrypted using a separate password configured in Security settings.</string>
<string name="export_format_aegis">Aegis (.JSON)</string>
<string name="export_format_google_auth_uri">Text file (.TXT)</string>
<string name="export_format_hint">Export format</string>
@ -210,6 +211,7 @@
<string name="backup_status_success">Most recent backup successful: %s</string>
<string name="backup_status_failed">Most recent backup failed: %s</string>
<string name="backup_status_none">No backups have been made yet</string>
<string name="backup_warning_password">Backups are encrypted using a separate password configured in Security settings</string>
<string name="documentsui_error">DocumentsUI appears to be missing from your device. This is an important system component necessary for the selection and creation of documents. If you used a tool to &quot;debloat&quot; your device, you may have accidentally deleted it and will have to reinstall it.</string>
<string name="icon_pack_import_error">An error occurred while trying to import an icon pack</string>
<string name="icon_pack_import_exists_error">The icon pack you\'re trying to import already exists. Do you want to overwrite it?</string>

View File

@ -2,53 +2,52 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/pref_section_backups_title">
<Preference
android:key="pref_backups_warning_password"
android:persistent="false"
android:selectable="false"
android:summary="@string/backup_warning_password"
app:isPreferenceVisible="false"
app:icon="@drawable/ic_info_outline_black_24dp" />
<PreferenceCategory
android:title="@string/pref_cat_backups_auto"
app:iconSpaceReserved="false">
android:title="@string/pref_cat_backups_auto">
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_backups"
android:title="@string/pref_backups_title"
android:summary="@string/pref_backups_summary"
app:iconSpaceReserved="false"/>
app:icon="@drawable/ic_cloud_upload_outline_black_24dp" />
<Preference
android:key="pref_backups_location"
android:title="@string/pref_backups_location_title"
android:summary="@string/pref_backups_location_summary"
app:iconSpaceReserved="false"/>
android:summary="@string/pref_backups_location_summary" />
<Preference
android:key="pref_backups_trigger"
android:title="@string/pref_backups_trigger_title"
android:summary="@string/pref_backups_trigger_summary"
app:iconSpaceReserved="false"/>
android:summary="@string/pref_backups_trigger_summary" />
<Preference
android:key="pref_backups_versions"
android:title="@string/pref_backups_versions_title"
app:iconSpaceReserved="false"/>
android:title="@string/pref_backups_versions_title" />
<Preference
android:key="pref_status_backup_builtin"
android:persistent="false"
android:selectable="false"
app:iconSpaceReserved="false"/>
android:selectable="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_cat_backups_android"
app:iconSpaceReserved="false">
android:title="@string/pref_cat_backups_android">
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_android_backups"
android:title="@string/pref_android_backups_title"
android:summary="@string/pref_android_backups_summary"
app:iconSpaceReserved="false"/>
app:icon="@drawable/ic_android" />
<Preference
android:key="pref_status_backup_android"
android:persistent="false"
android:selectable="false"
app:iconSpaceReserved="false"/>
android:selectable="false" />
<Preference
android:persistent="false"
android:selectable="false"
android:summary="@string/pref_android_backups_hint"
app:iconSpaceReserved="false"/>
android:summary="@string/pref_android_backups_hint" />
</PreferenceCategory>
</PreferenceScreen>