Never start the intro if the database file exists

This commit is contained in:
Alexander Bakker 2017-12-25 00:16:24 +01:00
parent ff214eaa4a
commit 0427164529
2 changed files with 14 additions and 6 deletions

View file

@ -91,21 +91,23 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
touchHelper.attachToRecyclerView(rvKeyProfiles);
rvKeyProfiles.setAdapter(_keyProfileAdapter);
// skip this part if this is the not initial startup and the database has been unlocked
if (!_app.isRunning() && _db.isLocked()) {
if (!_app.getPreferences().getBoolean("pref_intro", false)) {
if (!_db.fileExists()) {
// the db doesn't exist, start the intro
if (_app.getPreferences().getBoolean("pref_intro", false)) {
Toast.makeText(this, "Database file not found, starting over...", Toast.LENGTH_SHORT).show();
}
Intent intro = new Intent(this, IntroActivity.class);
startActivityForResult(intro, CODE_DO_INTRO);
} else {
// the db exists, load the database
// if the database is still encrypted, start the auth activity
try {
_db.load();
if (_db.isLocked()) {
startAuthActivity();
}
} catch (FileNotFoundException e) {
// start the intro if the db file was not found
Toast.makeText(this, "Database file not found, starting over...", Toast.LENGTH_SHORT).show();
Intent intro = new Intent(this, IntroActivity.class);
startActivityForResult(intro, CODE_DO_INTRO);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "An error occurred while trying to deserialize the database", Toast.LENGTH_LONG).show();
@ -114,6 +116,7 @@ public class MainActivity extends AegisActivity implements KeyProfileAdapter.Lis
}
}
// if the database has been decrypted at this point, we can load the key profiles
if (!_db.isLocked()) {
loadKeyProfiles();
}

View file

@ -29,6 +29,11 @@ public class DatabaseManager {
_context = context;
}
public boolean fileExists() {
File file = new File(_context.getFilesDir(), FILENAME);
return file.exists() && file.isFile();
}
public void load() throws Exception {
assertState(true, false);