Insert a state sanity check at the end of the intro

This is a temporary 'fix' for a rare issue where the intro could end up in a bad state
This commit is contained in:
Alexander Bakker 2020-07-10 20:55:36 +02:00
parent 6e54497492
commit 0f439506bd
3 changed files with 29 additions and 5 deletions

View file

@ -31,6 +31,11 @@
</head> </head>
<body> <body>
<div></div> <div></div>
<h3>Version 1.2.1</h3>
<h4>Fixes</h4>
<ul>
<li>Fix a rare issue where the intro could end up in a bad state</li>
</ul>
<h3>Version 1.2</h3> <h3>Version 1.2</h3>
<h4>New</h4> <h4>New</h4>
<ul> <ul>

View file

@ -8,20 +8,27 @@ import androidx.fragment.app.Fragment;
import com.beemdevelopment.aegis.AegisApplication; import com.beemdevelopment.aegis.AegisApplication;
import com.beemdevelopment.aegis.Preferences; import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.R; import com.beemdevelopment.aegis.R;
import com.beemdevelopment.aegis.ui.slides.SecuritySetupSlide;
import com.beemdevelopment.aegis.ui.slides.SecurityPickerSlide; import com.beemdevelopment.aegis.ui.slides.SecurityPickerSlide;
import com.beemdevelopment.aegis.ui.slides.SecuritySetupSlide;
import com.beemdevelopment.aegis.vault.Vault; import com.beemdevelopment.aegis.vault.Vault;
import com.beemdevelopment.aegis.vault.VaultFile; import com.beemdevelopment.aegis.vault.VaultFile;
import com.beemdevelopment.aegis.vault.VaultFileCredentials; import com.beemdevelopment.aegis.vault.VaultFileCredentials;
import com.beemdevelopment.aegis.vault.VaultFileException; import com.beemdevelopment.aegis.vault.VaultFileException;
import com.beemdevelopment.aegis.vault.VaultManager; import com.beemdevelopment.aegis.vault.VaultManager;
import com.beemdevelopment.aegis.vault.VaultManagerException; import com.beemdevelopment.aegis.vault.VaultManagerException;
import com.beemdevelopment.aegis.vault.slots.BiometricSlot;
import com.beemdevelopment.aegis.vault.slots.PasswordSlot;
import com.github.appintro.AppIntro2; import com.github.appintro.AppIntro2;
import com.github.appintro.AppIntroFragment; import com.github.appintro.AppIntroFragment;
import com.github.appintro.model.SliderPage; import com.github.appintro.model.SliderPage;
import org.json.JSONObject; import org.json.JSONObject;
import static com.beemdevelopment.aegis.ui.slides.SecurityPickerSlide.CRYPT_TYPE_BIOMETRIC;
import static com.beemdevelopment.aegis.ui.slides.SecurityPickerSlide.CRYPT_TYPE_INVALID;
import static com.beemdevelopment.aegis.ui.slides.SecurityPickerSlide.CRYPT_TYPE_NONE;
import static com.beemdevelopment.aegis.ui.slides.SecurityPickerSlide.CRYPT_TYPE_PASS;
public class IntroActivity extends AppIntro2 { public class IntroActivity extends AppIntro2 {
private SecuritySetupSlide securitySetupSlide; private SecuritySetupSlide securitySetupSlide;
private SecurityPickerSlide _securityPickerSlide; private SecurityPickerSlide _securityPickerSlide;
@ -76,8 +83,8 @@ public class IntroActivity extends AppIntro2 {
public void onSlideChanged(Fragment oldFragment, Fragment newFragment) { public void onSlideChanged(Fragment oldFragment, Fragment newFragment) {
if (oldFragment == _securityPickerSlide && newFragment != _endSlide) { if (oldFragment == _securityPickerSlide && newFragment != _endSlide) {
// skip to the last slide if no encryption will be used // skip to the last slide if no encryption will be used
int cryptType = getIntent().getIntExtra("cryptType", SecurityPickerSlide.CRYPT_TYPE_INVALID); int cryptType = getIntent().getIntExtra("cryptType", CRYPT_TYPE_INVALID);
if (cryptType == SecurityPickerSlide.CRYPT_TYPE_NONE) { if (cryptType == CRYPT_TYPE_NONE) {
// TODO: no magic indices // TODO: no magic indices
goToNextSlide(false); goToNextSlide(false);
} }
@ -96,12 +103,23 @@ public class IntroActivity extends AppIntro2 {
int cryptType = securitySetupSlide.getCryptType(); int cryptType = securitySetupSlide.getCryptType();
VaultFileCredentials creds = securitySetupSlide.getCredentials(); VaultFileCredentials creds = securitySetupSlide.getCredentials();
if (cryptType == CRYPT_TYPE_INVALID
|| (cryptType == CRYPT_TYPE_NONE && creds != null)
|| (cryptType == CRYPT_TYPE_PASS && (creds == null || !creds.getSlots().has(PasswordSlot.class)))
|| (cryptType == CRYPT_TYPE_BIOMETRIC && (creds == null || !creds.getSlots().has(PasswordSlot.class) || !creds.getSlots().has(BiometricSlot.class)))) {
Dialogs.showErrorDialog(this, R.string.intro_crypto_error, String.format("State of SecuritySetupSlide not properly propagated, cryptType: %d, creds: %s", cryptType, creds), (dialog, which) -> finishIntro(CRYPT_TYPE_NONE, null));
return;
}
finishIntro(cryptType, creds);
}
private void finishIntro(int cryptType, VaultFileCredentials creds) {
Vault vault = new Vault(); Vault vault = new Vault();
VaultFile vaultFile = new VaultFile(); VaultFile vaultFile = new VaultFile();
try { try {
JSONObject obj = vault.toJson(); JSONObject obj = vault.toJson();
if (cryptType == SecurityPickerSlide.CRYPT_TYPE_NONE) { if (cryptType == CRYPT_TYPE_NONE) {
vaultFile.setContent(obj); vaultFile.setContent(obj);
} else { } else {
vaultFile.setContent(obj, creds); vaultFile.setContent(obj, creds);
@ -114,7 +132,7 @@ public class IntroActivity extends AppIntro2 {
return; return;
} }
if (cryptType == SecurityPickerSlide.CRYPT_TYPE_NONE) { if (cryptType == CRYPT_TYPE_NONE) {
_app.initVaultManager(vault, null); _app.initVaultManager(vault, null);
} else { } else {
_app.initVaultManager(vault, creds); _app.initVaultManager(vault, creds);

View file

@ -154,6 +154,7 @@
<string name="choose_application">Select the application you\'d like to import from</string> <string name="choose_application">Select the application you\'d like to import from</string>
<string name="choose_theme">Select your desired theme</string> <string name="choose_theme">Select your desired theme</string>
<string name="choose_view_mode">Select your desired view mode</string> <string name="choose_view_mode">Select your desired view mode</string>
<string name="intro_crypto_error">An error occurred while trying to set up encryption for your vault. Please try setting up encryption manually in the settings menu of Aegis.</string>
<string name="parsing_file_error">An error occurred while trying to parse the file</string> <string name="parsing_file_error">An error occurred while trying to parse the file</string>
<string name="file_not_found">Error: File not found</string> <string name="file_not_found">Error: File not found</string>
<string name="reading_file_error">An error occurred while trying to read the file</string> <string name="reading_file_error">An error occurred while trying to read the file</string>