mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Finish database encapsulation
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.tests.database;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.net.Uri;
|
||||
@@ -30,6 +28,8 @@ import com.kunzisoft.keepass.database.element.PwDatabaseV3Debug;
|
||||
import com.kunzisoft.keepass.database.load.Importer;
|
||||
import com.kunzisoft.keepass.tests.TestUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class TestData {
|
||||
private static final String TEST1_KEYFILE = "";
|
||||
private static final String TEST1_KDB = "test1.kdb";
|
||||
@@ -72,6 +72,7 @@ public class TestData {
|
||||
GetDb1(ctx);
|
||||
}
|
||||
|
||||
return (PwDatabaseV3Debug) mDb1.getPwDatabase();
|
||||
//return (PwDatabaseV3Debug) mDb1.getPwDatabase();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class EntryActivity extends LockingHideActivity {
|
||||
PwNodeId keyEntry;
|
||||
try {
|
||||
keyEntry = i.getParcelableExtra(KEY_ENTRY);
|
||||
mEntry = db.getPwDatabase().getEntryById(keyEntry);
|
||||
mEntry = db.getEntryById(keyEntry);
|
||||
} catch (ClassCastException e) {
|
||||
Log.e(TAG, "Unable to retrieve the entry key");
|
||||
}
|
||||
@@ -157,7 +157,6 @@ public class EntryActivity extends LockingHideActivity {
|
||||
|
||||
Database database = App.getDB();
|
||||
// Start to manage field reference to copy a value from ref
|
||||
if (database != null)
|
||||
database.startManageEntry(mEntry);
|
||||
|
||||
boolean containsUsernameToCopy =
|
||||
@@ -234,7 +233,6 @@ public class EntryActivity extends LockingHideActivity {
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
if (database != null)
|
||||
database.stopManageEntry(mEntry);
|
||||
}
|
||||
firstLaunchOfActivity = false;
|
||||
@@ -315,11 +313,9 @@ public class EntryActivity extends LockingHideActivity {
|
||||
|
||||
protected void fillData() {
|
||||
Database database = App.getDB();
|
||||
if (database != null) {
|
||||
database.startManageEntry(mEntry);
|
||||
// Assign title icon
|
||||
database.getDrawFactory().assignDatabaseIconTo(this, titleIconView, mEntry.getIcon(), iconColor);
|
||||
}
|
||||
|
||||
// Assign title text
|
||||
titleView.setText(PwEntryInterface.getVisualTitle(mEntry));
|
||||
@@ -397,7 +393,6 @@ public class EntryActivity extends LockingHideActivity {
|
||||
entryContentsView.assignExpiresDate(getString(R.string.never));
|
||||
}
|
||||
|
||||
if (database != null)
|
||||
database.stopManageEntry(mEntry);
|
||||
}
|
||||
|
||||
|
||||
@@ -420,10 +420,8 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
|
||||
PwEntryInterface newEntry = mEntry.duplicate();
|
||||
|
||||
if (database != null) {
|
||||
database.startManageEntry(newEntry);
|
||||
database.createBackupOf(newEntry);
|
||||
}
|
||||
|
||||
newEntry.setLastAccessTime(new PwDate());
|
||||
newEntry.setLastModificationTime(new PwDate());
|
||||
@@ -449,7 +447,6 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
}
|
||||
}
|
||||
|
||||
if (database != null)
|
||||
database.stopManageEntry(newEntry);
|
||||
|
||||
return newEntry;
|
||||
|
||||
@@ -72,11 +72,10 @@ import com.kunzisoft.keepass.database.action.node.MoveEntryRunnable;
|
||||
import com.kunzisoft.keepass.database.action.node.MoveGroupRunnable;
|
||||
import com.kunzisoft.keepass.database.action.node.UpdateGroupRunnable;
|
||||
import com.kunzisoft.keepass.database.element.Database;
|
||||
import com.kunzisoft.keepass.database.element.PwDatabase;
|
||||
import com.kunzisoft.keepass.database.element.PwEntryInterface;
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId;
|
||||
import com.kunzisoft.keepass.database.element.PwGroupInterface;
|
||||
import com.kunzisoft.keepass.database.element.PwIcon;
|
||||
import com.kunzisoft.keepass.database.element.PwNodeId;
|
||||
import com.kunzisoft.keepass.database.element.PwNodeInterface;
|
||||
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
||||
import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
|
||||
@@ -242,7 +241,7 @@ public class GroupActivity extends LockingActivity
|
||||
}
|
||||
|
||||
try {
|
||||
rootGroup = database.getPwDatabase().getRootGroup();
|
||||
rootGroup = database.getRootGroup();
|
||||
} catch (NullPointerException e) {
|
||||
Log.e(TAG, "Unable to get rootGroup");
|
||||
}
|
||||
@@ -400,7 +399,7 @@ public class GroupActivity extends LockingActivity
|
||||
if (pwGroupId == null) {
|
||||
currentGroup = rootGroup;
|
||||
} else {
|
||||
currentGroup = database.getPwDatabase().getGroupById(pwGroupId);
|
||||
currentGroup = database.getGroupById(pwGroupId);
|
||||
}
|
||||
|
||||
return currentGroup;
|
||||
@@ -1058,10 +1057,9 @@ public class GroupActivity extends LockingActivity
|
||||
|
||||
if (actionNodeValues.getOldNode() != null) {
|
||||
PwGroupInterface parent = actionNodeValues.getOldNode().getParent();
|
||||
Database db = App.getDB();
|
||||
PwDatabase database = db.getPwDatabase();
|
||||
if (db.isRecycleBinAvailable() &&
|
||||
db.isRecycleBinEnabled()) {
|
||||
Database database = App.getDB();
|
||||
if (database.isRecycleBinAvailable() &&
|
||||
database.isRecycleBinEnabled()) {
|
||||
PwGroupInterface recycleBin = database.getRecycleBin();
|
||||
// Add trash if it doesn't exists
|
||||
if (parent.equals(recycleBin)
|
||||
@@ -1126,7 +1124,7 @@ public class GroupActivity extends LockingActivity
|
||||
}
|
||||
));
|
||||
// Show the progress dialog now or after dialog confirmation
|
||||
if (database.getPwDatabase().validatePasswordEncoding(masterPassword)) {
|
||||
if (database.validatePasswordEncoding(masterPassword)) {
|
||||
taskThread.start();
|
||||
} else {
|
||||
new PasswordEncodingDialogHelper()
|
||||
|
||||
@@ -19,9 +19,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.adapters.NodeAdapter;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum;
|
||||
import com.kunzisoft.keepass.database.element.PwDatabase;
|
||||
import com.kunzisoft.keepass.database.element.PwGroupInterface;
|
||||
import com.kunzisoft.keepass.database.element.PwNodeInterface;
|
||||
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
||||
@@ -213,7 +211,6 @@ public class ListNodesFragment extends StylishFragment implements
|
||||
case R.id.menu_sort:
|
||||
SortDialogFragment sortDialogFragment;
|
||||
|
||||
PwDatabase database = App.getDB().getPwDatabase();
|
||||
/*
|
||||
// TODO Recycle bin bottom
|
||||
if (database.isRecycleBinAvailable() && database.isRecycleBinEnabled()) {
|
||||
|
||||
@@ -251,7 +251,6 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
if (subNode.getType().equals(PwNodeInterface.Type.ENTRY)) {
|
||||
PwEntryInterface entry = (PwEntryInterface) subNode;
|
||||
|
||||
if (database != null)
|
||||
database.startManageEntry(entry);
|
||||
|
||||
holder.text.setText(PwEntryInterface.getVisualTitle(entry));
|
||||
@@ -262,7 +261,6 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
holder.subText.setText(username);
|
||||
}
|
||||
|
||||
if (database != null)
|
||||
database.stopManageEntry(entry);
|
||||
}
|
||||
|
||||
@@ -351,8 +349,10 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
MenuItem menuItem = contextMenu.findItem(R.id.menu_open);
|
||||
menuItem.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||
|
||||
Database database = App.getDB();
|
||||
|
||||
// Edition
|
||||
if (readOnly || node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||
if (readOnly || node.equals(database.getRecycleBin())) {
|
||||
contextMenu.removeItem(R.id.menu_edit);
|
||||
} else {
|
||||
menuItem = contextMenu.findItem(R.id.menu_edit);
|
||||
@@ -362,7 +362,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
// Copy (not for group)
|
||||
if (readOnly
|
||||
|| isASearchResult
|
||||
|| node.equals(App.getDB().getPwDatabase().getRecycleBin())
|
||||
|| node.equals(database.getRecycleBin())
|
||||
|| node.getType().equals(PwNodeInterface.Type.GROUP)) {
|
||||
// TODO COPY For Group
|
||||
contextMenu.removeItem(R.id.menu_copy);
|
||||
@@ -374,7 +374,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
// Move
|
||||
if (readOnly
|
||||
|| isASearchResult
|
||||
|| node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||
|| node.equals(database.getRecycleBin())) {
|
||||
contextMenu.removeItem(R.id.menu_move);
|
||||
} else {
|
||||
menuItem = contextMenu.findItem(R.id.menu_move);
|
||||
@@ -382,7 +382,7 @@ public class NodeAdapter extends RecyclerView.Adapter<BasicViewHolder> {
|
||||
}
|
||||
|
||||
// Deletion
|
||||
if (readOnly || node.equals(App.getDB().getPwDatabase().getRecycleBin())) {
|
||||
if (readOnly || node.equals(database.getRecycleBin())) {
|
||||
contextMenu.removeItem(R.id.menu_delete);
|
||||
} else {
|
||||
menuItem = contextMenu.findItem(R.id.menu_delete);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class SearchEntryCursorAdapter extends CursorAdapter {
|
||||
// Retrieve elements from cursor
|
||||
UUID uuid = new UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_MOST_SIGNIFICANT_BITS)),
|
||||
cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_UUID_LEAST_SIGNIFICANT_BITS)));
|
||||
PwIconFactory iconFactory = database.getPwDatabase().getIconFactory();
|
||||
PwIconFactory iconFactory = database.getIconFactory();
|
||||
PwIcon icon = iconFactory.getIcon(
|
||||
new UUID(cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_MOST_SIGNIFICANT_BITS)),
|
||||
cursor.getLong(cursor.getColumnIndex(EntryCursor.COLUMN_INDEX_ICON_CUSTOM_UUID_LEAST_SIGNIFICANT_BITS))));
|
||||
|
||||
@@ -33,13 +33,13 @@ class AssignPasswordInDatabaseRunnable @JvmOverloads constructor(
|
||||
withMasterPassword: Boolean,
|
||||
masterPassword: String?,
|
||||
withKeyFile: Boolean,
|
||||
keyfile: Uri?,
|
||||
keyFile: Uri?,
|
||||
actionRunnable: ActionRunnable? = null,
|
||||
save: Boolean)
|
||||
: SaveDatabaseRunnable(ctx, db, actionRunnable, save) {
|
||||
|
||||
private var mMasterPassword: String? = null
|
||||
private var mKeyfile: Uri? = null
|
||||
private var mKeyFile: Uri? = null
|
||||
|
||||
private var mBackupKey: ByteArray? = null
|
||||
|
||||
@@ -47,19 +47,18 @@ class AssignPasswordInDatabaseRunnable @JvmOverloads constructor(
|
||||
if (withMasterPassword)
|
||||
this.mMasterPassword = masterPassword
|
||||
if (withKeyFile)
|
||||
this.mKeyfile = keyfile
|
||||
this.mKeyFile = keyFile
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
// Set key
|
||||
try {
|
||||
val pm = database.pwDatabase
|
||||
// TODO move master key methods
|
||||
mBackupKey = ByteArray(pm.getMasterKey().size)
|
||||
System.arraycopy(pm.getMasterKey(), 0, mBackupKey!!, 0, mBackupKey!!.size)
|
||||
mBackupKey = ByteArray(database.masterKey.size)
|
||||
System.arraycopy(database.masterKey, 0, mBackupKey!!, 0, mBackupKey!!.size)
|
||||
|
||||
val uriInputStream = UriUtil.getUriInputStream(context, mKeyfile)
|
||||
pm.retrieveMasterKey(mMasterPassword, uriInputStream)
|
||||
val uriInputStream = UriUtil.getUriInputStream(context, mKeyFile)
|
||||
database.retrieveMasterKey(mMasterPassword, uriInputStream)
|
||||
// To save the database
|
||||
super.run()
|
||||
finishRun(true)
|
||||
@@ -75,8 +74,8 @@ class AssignPasswordInDatabaseRunnable @JvmOverloads constructor(
|
||||
override fun onFinishRun(isSuccess: Boolean, message: String?) {
|
||||
if (!isSuccess) {
|
||||
// Erase the current master key
|
||||
erase(database.pwDatabase.getMasterKey())
|
||||
database.pwDatabase.setMasterKey(mBackupKey)
|
||||
erase(database.masterKey)
|
||||
database.masterKey = mBackupKey
|
||||
}
|
||||
|
||||
super.onFinishRun(isSuccess, message)
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.kunzisoft.keepass.database.cursor.EntryCursorV3;
|
||||
import com.kunzisoft.keepass.database.cursor.EntryCursorV4;
|
||||
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidDBException;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
||||
import com.kunzisoft.keepass.database.exception.PwDbOutputException;
|
||||
import com.kunzisoft.keepass.database.load.Importer;
|
||||
import com.kunzisoft.keepass.database.load.ImporterFactory;
|
||||
@@ -109,10 +110,6 @@ public class Database {
|
||||
return filename.substring(0, lastExtDot);
|
||||
}
|
||||
|
||||
public PwDatabase getPwDatabase() {
|
||||
return pwDatabase;
|
||||
}
|
||||
|
||||
public void setUri(Uri mUri) {
|
||||
this.mUri = mUri;
|
||||
}
|
||||
@@ -229,7 +226,7 @@ public class Database {
|
||||
}
|
||||
|
||||
public Cursor searchEntry(String query) {
|
||||
PwVersion version = getPwDatabase().getVersion();
|
||||
PwVersion version = pwDatabase.getVersion();
|
||||
switch (version) {
|
||||
case V3:
|
||||
EntryCursorV3 cursorV3 = new EntryCursorV3();
|
||||
@@ -262,10 +259,10 @@ public class Database {
|
||||
}
|
||||
|
||||
public PwEntryInterface getEntryFrom(Cursor cursor) {
|
||||
PwIconFactory iconFactory = getPwDatabase().getIconFactory();
|
||||
PwIconFactory iconFactory = pwDatabase.getIconFactory();
|
||||
PwEntryInterface pwEntry = createEntry();
|
||||
try {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V3:
|
||||
((EntryCursorV3) cursor).populateEntry((PwEntryV3) pwEntry, iconFactory);
|
||||
break;
|
||||
@@ -358,11 +355,11 @@ public class Database {
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return getPwDatabase().getVersion().toString();
|
||||
return pwDatabase.getVersion().toString();
|
||||
}
|
||||
|
||||
public boolean containsName() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
default:
|
||||
return false;
|
||||
case V4:
|
||||
@@ -371,18 +368,18 @@ public class Database {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
default:
|
||||
return "";
|
||||
case V4:
|
||||
return ((PwDatabaseV4) getPwDatabase()).getName();
|
||||
return ((PwDatabaseV4) pwDatabase).getName();
|
||||
}
|
||||
}
|
||||
|
||||
public void assignName(String name) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
PwDatabaseV4 databaseV4 = ((PwDatabaseV4) getPwDatabase());
|
||||
PwDatabaseV4 databaseV4 = ((PwDatabaseV4) pwDatabase);
|
||||
databaseV4.setName(name);
|
||||
databaseV4.setNameChanged(new PwDate());
|
||||
break;
|
||||
@@ -390,7 +387,7 @@ public class Database {
|
||||
}
|
||||
|
||||
public boolean containsDescription() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
default:
|
||||
return false;
|
||||
case V4:
|
||||
@@ -399,45 +396,45 @@ public class Database {
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
default:
|
||||
return "";
|
||||
case V4:
|
||||
return ((PwDatabaseV4) getPwDatabase()).getDescription();
|
||||
return ((PwDatabaseV4) pwDatabase).getDescription();
|
||||
}
|
||||
}
|
||||
|
||||
public void assignDescription(String description) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwDatabaseV4) getPwDatabase()).setDescription(description);
|
||||
((PwDatabaseV4) getPwDatabase()).setDescriptionChanged(new PwDate());
|
||||
((PwDatabaseV4) pwDatabase).setDescription(description);
|
||||
((PwDatabaseV4) pwDatabase).setDescriptionChanged(new PwDate());
|
||||
}
|
||||
}
|
||||
|
||||
public String getDefaultUsername() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
default:
|
||||
return "";
|
||||
case V4:
|
||||
return ((PwDatabaseV4) getPwDatabase()).getDefaultUserName();
|
||||
return ((PwDatabaseV4) pwDatabase).getDefaultUserName();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultUsername(String username) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwDatabaseV4) getPwDatabase()).setDefaultUserName(username);
|
||||
((PwDatabaseV4) getPwDatabase()).setDefaultUserNameChanged(new PwDate());
|
||||
((PwDatabaseV4) pwDatabase).setDefaultUserName(username);
|
||||
((PwDatabaseV4) pwDatabase).setDefaultUserNameChanged(new PwDate());
|
||||
}
|
||||
}
|
||||
|
||||
public PwEncryptionAlgorithm getEncryptionAlgorithm() {
|
||||
return getPwDatabase().getEncryptionAlgorithm();
|
||||
return pwDatabase.getEncryptionAlgorithm();
|
||||
}
|
||||
|
||||
public List<PwEncryptionAlgorithm> getAvailableEncryptionAlgorithms() {
|
||||
return getPwDatabase().getAvailableEncryptionAlgorithms();
|
||||
return pwDatabase.getAvailableEncryptionAlgorithms();
|
||||
}
|
||||
|
||||
public boolean allowEncryptionAlgorithmModification() {
|
||||
@@ -445,20 +442,20 @@ public class Database {
|
||||
}
|
||||
|
||||
public void assignEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwDatabaseV4) getPwDatabase()).setEncryptionAlgorithm(algorithm);
|
||||
((PwDatabaseV4) getPwDatabase()).setDataEngine(algorithm.getCipherEngine());
|
||||
((PwDatabaseV4) getPwDatabase()).setDataCipher(algorithm.getDataCipher());
|
||||
((PwDatabaseV4) pwDatabase).setEncryptionAlgorithm(algorithm);
|
||||
((PwDatabaseV4) pwDatabase).setDataEngine(algorithm.getCipherEngine());
|
||||
((PwDatabaseV4) pwDatabase).setDataCipher(algorithm.getDataCipher());
|
||||
}
|
||||
}
|
||||
|
||||
public String getEncryptionAlgorithmName(Resources resources) {
|
||||
return getPwDatabase().getEncryptionAlgorithm().getName(resources);
|
||||
return pwDatabase.getEncryptionAlgorithm().getName(resources);
|
||||
}
|
||||
|
||||
public List<KdfEngine> getAvailableKdfEngines() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
return KdfFactory.kdfListV4;
|
||||
case V3:
|
||||
@@ -472,9 +469,9 @@ public class Database {
|
||||
}
|
||||
|
||||
public KdfEngine getKdfEngine() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
KdfEngine kdfEngine = ((PwDatabaseV4) getPwDatabase()).getKdfEngine();
|
||||
KdfEngine kdfEngine = ((PwDatabaseV4) pwDatabase).getKdfEngine();
|
||||
if (kdfEngine == null)
|
||||
return KdfFactory.aesKdf;
|
||||
return kdfEngine;
|
||||
@@ -485,9 +482,9 @@ public class Database {
|
||||
}
|
||||
|
||||
public void assignKdfEngine(KdfEngine kdfEngine) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
PwDatabaseV4 db = ((PwDatabaseV4) getPwDatabase());
|
||||
PwDatabaseV4 db = ((PwDatabaseV4) pwDatabase);
|
||||
if (db.getKdfParameters() == null
|
||||
|| !db.getKdfParameters().getUUID().equals(kdfEngine.getDefaultParameters().getUUID()))
|
||||
db.setKdfParameters(kdfEngine.getDefaultParameters());
|
||||
@@ -511,11 +508,11 @@ public class Database {
|
||||
}
|
||||
|
||||
public long getNumberKeyEncryptionRounds() {
|
||||
return getPwDatabase().getNumberKeyEncryptionRounds();
|
||||
return pwDatabase.getNumberKeyEncryptionRounds();
|
||||
}
|
||||
|
||||
public void setNumberKeyEncryptionRounds(long numberRounds) throws NumberFormatException {
|
||||
getPwDatabase().setNumberKeyEncryptionRounds(numberRounds);
|
||||
pwDatabase.setNumberKeyEncryptionRounds(numberRounds);
|
||||
}
|
||||
|
||||
public String getMemoryUsageAsString() {
|
||||
@@ -523,17 +520,17 @@ public class Database {
|
||||
}
|
||||
|
||||
public long getMemoryUsage() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
return ((PwDatabaseV4) getPwDatabase()).getMemoryUsage();
|
||||
return ((PwDatabaseV4) pwDatabase).getMemoryUsage();
|
||||
}
|
||||
return KdfEngine.UNKNOW_VALUE;
|
||||
}
|
||||
|
||||
public void setMemoryUsage(long memory) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwDatabaseV4) getPwDatabase()).setMemoryUsage(memory);
|
||||
((PwDatabaseV4) pwDatabase).setMemoryUsage(memory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,23 +539,44 @@ public class Database {
|
||||
}
|
||||
|
||||
public int getParallelism() {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
return ((PwDatabaseV4) getPwDatabase()).getParallelism();
|
||||
return ((PwDatabaseV4) pwDatabase).getParallelism();
|
||||
}
|
||||
return KdfEngine.UNKNOW_VALUE;
|
||||
}
|
||||
|
||||
public void setParallelism(int parallelism) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwDatabaseV4) getPwDatabase()).setParallelism(parallelism);
|
||||
((PwDatabaseV4) pwDatabase).setParallelism(parallelism);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validatePasswordEncoding(String key) {
|
||||
return pwDatabase.validatePasswordEncoding(key);
|
||||
}
|
||||
|
||||
public byte[] getMasterKey() {
|
||||
return pwDatabase.getMasterKey();
|
||||
}
|
||||
|
||||
public void setMasterKey(byte[] masterKey) {
|
||||
pwDatabase.masterKey = masterKey;
|
||||
}
|
||||
|
||||
public void retrieveMasterKey(String key, InputStream keyInputStream)
|
||||
throws InvalidKeyFileException, IOException {
|
||||
pwDatabase.retrieveMasterKey(key, keyInputStream);
|
||||
}
|
||||
|
||||
public PwGroupInterface getRootGroup() {
|
||||
return pwDatabase.getRootGroup();
|
||||
}
|
||||
|
||||
public PwEntryInterface createEntry() {
|
||||
try {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V3:
|
||||
return new PwEntryV3();
|
||||
case V4:
|
||||
@@ -573,7 +591,7 @@ public class Database {
|
||||
public PwGroupInterface createGroup() {
|
||||
PwGroupInterface newPwGroup = null;
|
||||
try {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V3:
|
||||
newPwGroup = new PwGroupV3();
|
||||
case V4:
|
||||
@@ -587,16 +605,16 @@ public class Database {
|
||||
}
|
||||
|
||||
public PwEntryInterface getEntryById(PwNodeId id) {
|
||||
return pwDatabase.entryIndexes.get(id);
|
||||
return pwDatabase.getEntryById(id);
|
||||
}
|
||||
|
||||
public PwGroupInterface getGroupById(PwNodeId id) {
|
||||
return pwDatabase.groupIndexes.get(id);
|
||||
return pwDatabase.getGroupById(id);
|
||||
}
|
||||
|
||||
public void addEntryTo(PwEntryInterface entry, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().addEntryTo(entry, parent);
|
||||
pwDatabase.addEntryTo(entry, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwEntry can't be added from this version of PwGroup", e);
|
||||
}
|
||||
@@ -604,7 +622,7 @@ public class Database {
|
||||
|
||||
public void removeEntryFrom(PwEntryInterface entry, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().removeEntryFrom(entry, parent);
|
||||
pwDatabase.removeEntryFrom(entry, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwEntry can't be removed from this version of PwGroup", e);
|
||||
}
|
||||
@@ -612,7 +630,7 @@ public class Database {
|
||||
|
||||
public void addGroupTo(PwGroupInterface group, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().addGroupTo(group, parent);
|
||||
pwDatabase.addGroupTo(group, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwGroup can't be added in this version of PwGroup", e);
|
||||
}
|
||||
@@ -620,7 +638,7 @@ public class Database {
|
||||
|
||||
public void removeGroupFrom(PwGroupInterface group, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().removeGroupFrom(group, parent);
|
||||
pwDatabase.removeGroupFrom(group, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwGroup can't be removed from this version of PwGroup", e);
|
||||
}
|
||||
@@ -628,7 +646,7 @@ public class Database {
|
||||
|
||||
public boolean canRecycle(PwEntryInterface entry) {
|
||||
try {
|
||||
getPwDatabase().canRecycle(entry);
|
||||
pwDatabase.canRecycle(entry);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwEntry can't be recycled", e);
|
||||
}
|
||||
@@ -637,7 +655,7 @@ public class Database {
|
||||
|
||||
public boolean canRecycle(PwGroupInterface group) {
|
||||
try {
|
||||
getPwDatabase().canRecycle(group);
|
||||
pwDatabase.canRecycle(group);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwGroup can't be recycled", e);
|
||||
}
|
||||
@@ -646,7 +664,7 @@ public class Database {
|
||||
|
||||
public void recycle(PwEntryInterface entry) {
|
||||
try {
|
||||
getPwDatabase().recycle(entry);
|
||||
pwDatabase.recycle(entry);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwEntry can't be recycled", e);
|
||||
}
|
||||
@@ -654,7 +672,7 @@ public class Database {
|
||||
|
||||
public void recycle(PwGroupInterface group) {
|
||||
try {
|
||||
getPwDatabase().recycle(group);
|
||||
pwDatabase.recycle(group);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of PwGroup can't be recycled", e);
|
||||
}
|
||||
@@ -662,7 +680,7 @@ public class Database {
|
||||
|
||||
public void updateEntry(PwEntryInterface oldEntry, PwEntryInterface newEntry) {
|
||||
try {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V3:
|
||||
((PwEntryV3) oldEntry).updateWith((PwEntryV3) newEntry);
|
||||
break;
|
||||
@@ -677,7 +695,7 @@ public class Database {
|
||||
|
||||
public void updateGroup(PwGroupInterface oldGroup, PwGroupInterface newGroup) {
|
||||
try {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V3:
|
||||
((PwGroupV3) oldGroup).updateWith((PwGroupV3) newGroup);
|
||||
break;
|
||||
@@ -698,7 +716,7 @@ public class Database {
|
||||
public @Nullable PwEntryInterface copyEntry(PwEntryInterface entryToCopy, PwGroupInterface newParent) {
|
||||
try {
|
||||
PwEntryInterface entryCopied = null;
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V3:
|
||||
entryCopied = ((PwEntryV3) entryToCopy).clone();
|
||||
break;
|
||||
@@ -759,16 +777,24 @@ public class Database {
|
||||
}
|
||||
|
||||
public boolean isRecycleBinAvailable() {
|
||||
return getPwDatabase().isRecycleBinAvailable();
|
||||
return pwDatabase.isRecycleBinAvailable();
|
||||
}
|
||||
|
||||
public boolean isRecycleBinEnabled() {
|
||||
return getPwDatabase().isRecycleBinEnabled();
|
||||
return pwDatabase.isRecycleBinEnabled();
|
||||
}
|
||||
|
||||
public PwGroupInterface getRecycleBin() {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
return ((PwDatabaseV4) pwDatabase).getRecycleBin();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void undoRecycle(PwEntryInterface entry, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().undoRecycle(entry, parent);
|
||||
pwDatabase.undoRecycle(entry, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of database can't undo Recycle of this version of PwEntry", e);
|
||||
}
|
||||
@@ -776,7 +802,7 @@ public class Database {
|
||||
|
||||
public void undoRecycle(PwGroupInterface group, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().undoRecycle(group, parent);
|
||||
pwDatabase.undoRecycle(group, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of database can't undo Recycle of this version of PwGroup", e);
|
||||
}
|
||||
@@ -784,7 +810,7 @@ public class Database {
|
||||
|
||||
public void undoDeleteEntry(PwEntryInterface entry, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().undoDeleteEntryFrom(entry, parent);
|
||||
pwDatabase.undoDeleteEntryFrom(entry, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of database can't undo the deletion of this version of PwEntry", e);
|
||||
}
|
||||
@@ -792,33 +818,39 @@ public class Database {
|
||||
|
||||
public void undoDeleteGroup(PwGroupInterface group, PwGroupInterface parent) {
|
||||
try {
|
||||
getPwDatabase().undoDeleteGroup(group, parent);
|
||||
pwDatabase.undoDeleteGroup(group, parent);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "This version of database can't undo the deletion of this version of PwGroup", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startManageEntry(PwEntryInterface entry) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
if (pwDatabase != null) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwEntryV4) entry).startToManageFieldReferences((PwDatabaseV4) getPwDatabase());
|
||||
((PwEntryV4) entry).startToManageFieldReferences((PwDatabaseV4) pwDatabase);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopManageEntry(PwEntryInterface entry) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
if (pwDatabase != null) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwEntryV4) entry).stopToManageFieldReferences();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createBackupOf(PwEntryInterface entry) {
|
||||
switch (getPwDatabase().getVersion()) {
|
||||
if (pwDatabase != null) {
|
||||
switch (pwDatabase.getVersion()) {
|
||||
case V4:
|
||||
((PwEntryV4) entry).createBackup((PwDatabaseV4) getPwDatabase());
|
||||
((PwEntryV4) entry).createBackup((PwDatabaseV4) pwDatabase);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,8 @@ public abstract class PwDatabase {
|
||||
return finalKey;
|
||||
}
|
||||
|
||||
public abstract byte[] getMasterKey(String key, InputStream keyInputStream) throws InvalidKeyFileException, IOException;
|
||||
protected abstract byte[] getMasterKey(String key, InputStream keyInputStream)
|
||||
throws InvalidKeyFileException, IOException;
|
||||
|
||||
public void retrieveMasterKey(String key, InputStream keyInputStream)
|
||||
throws InvalidKeyFileException, IOException {
|
||||
@@ -412,10 +413,6 @@ public abstract class PwDatabase {
|
||||
throw new RuntimeException("Call not valid for .kdb databases.");
|
||||
}
|
||||
|
||||
public PwGroupInterface getRecycleBin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isGroupSearchable(PwGroupInterface group, boolean omitBackup) {
|
||||
return group != null;
|
||||
}
|
||||
|
||||
@@ -659,7 +659,6 @@ public class PwDatabaseV4 extends PwDatabase {
|
||||
deletedObjects.remove(new PwDeletedObject((UUID) entry.getNodeId().getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PwGroupInterface getRecycleBin() { // TODO delete recycle bin preference
|
||||
if (recycleBinUUID == null) {
|
||||
return null;
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class PwNode<IdType> implements PwNodeInterface, Parcelable, Clo
|
||||
// TODO better technique ?
|
||||
try {
|
||||
PwNodeId pwGroupId = in.readParcelable(PwNodeId.class.getClassLoader());
|
||||
parent = App.getDB().getPwDatabase().getGroupById(pwGroupId);
|
||||
parent = App.getDB().getGroupById(pwGroupId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class GroupEditDialogFragment extends DialogFragment
|
||||
database = App.getDB();
|
||||
editGroupDialogAction = EditGroupDialogAction.NONE;
|
||||
nameGroup = "";
|
||||
iconGroup = database.getPwDatabase().getIconFactory().getFolderIcon();
|
||||
iconGroup = database.getIconFactory().getFolderIcon();
|
||||
|
||||
if (savedInstanceState != null
|
||||
&& savedInstanceState.containsKey(KEY_ACTION_ID)
|
||||
|
||||
Reference in New Issue
Block a user