@Override protected void onResume() { super.onResume(); // If the application was shutdown make sure to clear the password field, if it // was saved in the instance state if (App.isShutdown()) { TextView password = (TextView) findViewById(R.id.password); password.setText(""); } // Clear the shutdown flag App.clearShutdown(); }
@Override public void run() { // Create new database record Database db = new Database(); App.setDB(db); // Create the PwDatabaseV3 PwDatabaseV3 pm = new PwDatabaseV3(); pm.algorithm = PwEncryptionAlgorithm.Rjindal; pm.numKeyEncRounds = DEFAULT_ENCRYPTION_ROUNDS; pm.name = "KeePass Password Manager"; // Build the root group pm.constructTree(null); // Set Database state db.root = pm.rootGroup; db.pm = pm; db.mFilename = mFilename; db.setLoaded(); // Add a couple default groups AddGroup internet = AddGroup.getInstance(db, "Internet", pm.rootGroup, null, true); internet.run(); AddGroup email = AddGroup.getInstance(db, "eMail", pm.rootGroup, null, true); email.run(); // Commit changes SaveDB save = new SaveDB(db, mFinish, mDontSave); mFinish = null; save.run(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case KeePass.EXIT_NORMAL: setEditText(R.id.password, ""); App.getDB().clear(); break; case KeePass.EXIT_LOCK: setResult(KeePass.EXIT_LOCK); setEditText(R.id.password, ""); finish(); App.getDB().clear(); break; case FILE_BROWSE: if (resultCode == RESULT_OK) { String filename = data.getDataString(); if (filename != null) { if (filename.startsWith("file://")) { filename = filename.substring(7); } filename = URLDecoder.decode(filename); EditText fn = (EditText) findViewById(R.id.pass_keyfile); fn.setText(filename); } } break; case GET_CONTENT: if (resultCode == RESULT_OK) { if (data != null) { Uri uri = data.getData(); if (uri != null) { String path = uri.getPath(); if (path != null) { EditText fn = (EditText) findViewById(R.id.pass_keyfile); fn.setText(path); } } } } break; } }
private String getKeyFile(String filename) { if (mRememberKeyfile) { String keyfile = App.getFileHistory().getFileByName(filename); return keyfile; } else { return ""; } }
private void loadDatabase(String pass, String keyfile) { if (pass.length() == 0 && keyfile.length() == 0) { errorMessage(R.string.error_nopass); return; } String fileName = getEditText(R.id.filename); // Clear before we load Database db = App.getDB(); db.clear(); // Clear the shutdown flag App.clearShutdown(); Handler handler = new Handler(); LoadDB task = new LoadDB(db, PasswordActivity.this, fileName, pass, keyfile, new AfterLoad(handler)); ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database); pt.run(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); Preference keyFile = findPreference(getString(R.string.keyfile_key)); keyFile.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { Boolean value = (Boolean) newValue; if (!value.booleanValue()) { App.getFileHistory().deleteAllKeys(); } return true; } }); Preference recentHistory = findPreference(getString(R.string.recentfile_key)); recentHistory.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { Boolean value = (Boolean) newValue; if (value == null) { value = true; } if (!value) { App.getFileHistory().deleteAll(); } return true; } }); Database db = App.getDB(); if (db.Loaded() && db.pm.appSettingsEnabled()) { Preference rounds = findPreference(getString(R.string.rounds_key)); rounds.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { setRounds(App.getDB(), preference); return true; } }); setRounds(db, rounds); Preference algorithm = findPreference(getString(R.string.algorithm_key)); setAlgorithm(db, algorithm); } else { Preference dbSettings = findPreference(getString(R.string.db_key)); dbSettings.setEnabled(false); } backupManager = new BackupManagerCompat(this); }