Refactor database elements

This commit is contained in:
J-Jamet
2019-04-24 20:38:13 +02:00
parent 5705d367ed
commit 9e79da0efc
15 changed files with 347 additions and 492 deletions

View File

@@ -25,7 +25,6 @@ import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine; import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory; import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.database.EntryHandler; import com.kunzisoft.keepass.database.EntryHandler;
@@ -44,28 +43,23 @@ import com.kunzisoft.keepass.icons.IconDrawableFactory;
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater; import com.kunzisoft.keepass.tasks.ProgressTaskUpdater;
import com.kunzisoft.keepass.utils.EmptyUtils; import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.UriUtil; import com.kunzisoft.keepass.utils.UriUtil;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.io.BufferedInputStream; import javax.annotation.Nullable;
import java.io.File; import java.io.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.SyncFailedException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
public class Database { public class Database {
private static final String TAG = Database.class.getName(); private static final String TAG = Database.class.getName();
private PwDatabase pwDatabase = null; private PwDatabase pwDatabase = null;
private PwDatabaseV3 pwDatabaseV3 = null;
private PwDatabaseV4 pwDatabaseV4 = null;
private PwVersion version = null;
private Uri mUri = null; private Uri mUri = null;
private SearchDbHelper searchHelper = null; private SearchDbHelper searchHelper = null;
private boolean readOnly = false; private boolean readOnly = false;
@@ -80,14 +74,31 @@ public class Database {
public Database(String databasePath) { public Database(String databasePath) {
// TODO Test with kdb extension // TODO Test with kdb extension
if (isKDBExtension(databasePath)) { if (isKDBExtension(databasePath)) {
this.pwDatabase = new PwDatabaseV3(); this.pwDatabaseV3 = new PwDatabaseV3();
this.pwDatabase = pwDatabaseV3;
} else { } else {
PwDatabaseV4 databaseV4 = new PwDatabaseV4(); PwGroupV4 groupV4 = new PwGroupV4();
databaseV4.setRootGroup( this.pwDatabaseV4 = new PwDatabaseV4();
new PwGroupV4(dbNameFromPath(databasePath),
databaseV4.getIconFactory().getFolderIcon()) groupV4.setTitle(dbNameFromPath(databasePath));
); groupV4.setIconStandard(pwDatabaseV4.getIconFactory().getFolderIcon());
this.pwDatabase = databaseV4; this.pwDatabaseV4.setRootGroup(groupV4);
this.pwDatabase = pwDatabaseV4;
}
this.version = pwDatabase.getVersion();
}
private void retrieveDatabaseVersioned(PwDatabase pwDatabase) {
this.version = pwDatabase.getVersion();
switch (version) {
case V3:
pwDatabaseV3 = (PwDatabaseV3) pwDatabase;
break;
case V4:
pwDatabaseV4 = (PwDatabaseV4) pwDatabase;
break;
} }
} }
@@ -187,17 +198,11 @@ public class Database {
bis.reset(); // Return to the start bis.reset(); // Return to the start
pwDatabase = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater); pwDatabase = databaseImporter.openDatabase(bis, password, keyFileInputStream, progressTaskUpdater);
retrieveDatabaseVersioned(pwDatabase);
if ( pwDatabase != null ) { if ( pwDatabase != null ) {
try { try {
passwordEncodingError = !pwDatabase.validatePasswordEncoding(password); passwordEncodingError = !pwDatabase.validatePasswordEncoding(password);
switch (pwDatabase.getVersion()) { searchHelper = new SearchDbHelper(ctx);
case V3:
searchHelper = new SearchDbHelper.SearchDbHelperV3(ctx);
break;
case V4:
searchHelper = new SearchDbHelper.SearchDbHelperV4(ctx);
break;
}
loaded = true; loaded = true;
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Load can't be performed with this Database version", e); Log.e(TAG, "Load can't be performed with this Database version", e);
@@ -211,22 +216,12 @@ public class Database {
} }
public PwGroupInterface search(String str, int max) { public PwGroupInterface search(String str, int max) {
if (searchHelper == null) { return null; } if (searchHelper == null)
try {
switch (pwDatabase.getVersion()) {
case V3:
return ((SearchDbHelper.SearchDbHelperV3) searchHelper).search(((PwDatabaseV3) pwDatabase), str, max);
case V4:
return ((SearchDbHelper.SearchDbHelperV4) searchHelper).search(((PwDatabaseV4) pwDatabase), str, max);
}
} catch (Exception e) {
Log.e(TAG, "Search can't be performed with this SearchHelper", e);
}
return null; return null;
return searchHelper.search(pwDatabase, str, max);
} }
public Cursor searchEntry(String query) { public Cursor searchEntry(String query) {
PwVersion version = pwDatabase.getVersion();
switch (version) { switch (version) {
case V3: case V3:
EntryCursorV3 cursorV3 = new EntryCursorV3(); EntryCursorV3 cursorV3 = new EntryCursorV3();
@@ -262,7 +257,7 @@ public class Database {
PwIconFactory iconFactory = pwDatabase.getIconFactory(); PwIconFactory iconFactory = pwDatabase.getIconFactory();
PwEntryInterface pwEntry = createEntry(); PwEntryInterface pwEntry = createEntry();
try { try {
switch (pwDatabase.getVersion()) { switch (version) {
case V3: case V3:
((EntryCursorV3) cursor).populateEntry((PwEntryV3) pwEntry, iconFactory); ((EntryCursorV3) cursor).populateEntry((PwEntryV3) pwEntry, iconFactory);
break; break;
@@ -339,8 +334,8 @@ public class Database {
public void closeAndClear(Context context) { public void closeAndClear(Context context) {
drawFactory.clearCache(); drawFactory.clearCache();
// Delete the cache of the database if present // Delete the cache of the database if present
if (pwDatabase != null) if (pwDatabaseV4 != null)
pwDatabase.clearCache(); pwDatabaseV4.clearCache();
// In all cases, delete all the files in the temp dir // In all cases, delete all the files in the temp dir
try { try {
FileUtils.cleanDirectory(context.getFilesDir()); FileUtils.cleanDirectory(context.getFilesDir());
@@ -349,17 +344,19 @@ public class Database {
} }
pwDatabase = null; pwDatabase = null;
pwDatabaseV3 = null;
pwDatabaseV4 = null;
mUri = null; mUri = null;
loaded = false; loaded = false;
passwordEncodingError = false; passwordEncodingError = false;
} }
public String getVersion() { public String getVersion() {
return pwDatabase.getVersion().toString(); return version.toString();
} }
public boolean containsName() { public boolean containsName() {
switch (pwDatabase.getVersion()) { switch (version) {
default: default:
return false; return false;
case V4: case V4:
@@ -368,26 +365,25 @@ public class Database {
} }
public String getName() { public String getName() {
switch (pwDatabase.getVersion()) { switch (version) {
default: default:
return ""; return "";
case V4: case V4:
return ((PwDatabaseV4) pwDatabase).getName(); return pwDatabaseV4.getName();
} }
} }
public void assignName(String name) { public void assignName(String name) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
PwDatabaseV4 databaseV4 = ((PwDatabaseV4) pwDatabase); pwDatabaseV4.setName(name);
databaseV4.setName(name); pwDatabaseV4.setNameChanged(new PwDate());
databaseV4.setNameChanged(new PwDate());
break; break;
} }
} }
public boolean containsDescription() { public boolean containsDescription() {
switch (pwDatabase.getVersion()) { switch (version) {
default: default:
return false; return false;
case V4: case V4:
@@ -396,36 +392,36 @@ public class Database {
} }
public String getDescription() { public String getDescription() {
switch (pwDatabase.getVersion()) { switch (version) {
default: default:
return ""; return "";
case V4: case V4:
return ((PwDatabaseV4) pwDatabase).getDescription(); return pwDatabaseV4.getDescription();
} }
} }
public void assignDescription(String description) { public void assignDescription(String description) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwDatabaseV4) pwDatabase).setDescription(description); pwDatabaseV4.setDescription(description);
((PwDatabaseV4) pwDatabase).setDescriptionChanged(new PwDate()); pwDatabaseV4.setDescriptionChanged(new PwDate());
} }
} }
public String getDefaultUsername() { public String getDefaultUsername() {
switch (pwDatabase.getVersion()) { switch (version) {
default: default:
return ""; return "";
case V4: case V4:
return ((PwDatabaseV4) pwDatabase).getDefaultUserName(); return pwDatabaseV4.getDefaultUserName();
} }
} }
public void setDefaultUsername(String username) { public void setDefaultUsername(String username) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwDatabaseV4) pwDatabase).setDefaultUserName(username); pwDatabaseV4.setDefaultUserName(username);
((PwDatabaseV4) pwDatabase).setDefaultUserNameChanged(new PwDate()); pwDatabaseV4.setDefaultUserNameChanged(new PwDate());
} }
} }
@@ -442,11 +438,11 @@ public class Database {
} }
public void assignEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) { public void assignEncryptionAlgorithm(PwEncryptionAlgorithm algorithm) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwDatabaseV4) pwDatabase).setEncryptionAlgorithm(algorithm); pwDatabaseV4.setEncryptionAlgorithm(algorithm);
((PwDatabaseV4) pwDatabase).setDataEngine(algorithm.getCipherEngine()); pwDatabaseV4.setDataEngine(algorithm.getCipherEngine());
((PwDatabaseV4) pwDatabase).setDataCipher(algorithm.getDataCipher()); pwDatabaseV4.setDataCipher(algorithm.getDataCipher());
} }
} }
@@ -455,7 +451,7 @@ public class Database {
} }
public List<KdfEngine> getAvailableKdfEngines() { public List<KdfEngine> getAvailableKdfEngines() {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
return KdfFactory.kdfListV4; return KdfFactory.kdfListV4;
case V3: case V3:
@@ -469,9 +465,9 @@ public class Database {
} }
public KdfEngine getKdfEngine() { public KdfEngine getKdfEngine() {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
KdfEngine kdfEngine = ((PwDatabaseV4) pwDatabase).getKdfEngine(); KdfEngine kdfEngine = pwDatabaseV4.getKdfEngine();
if (kdfEngine == null) if (kdfEngine == null)
return KdfFactory.aesKdf; return KdfFactory.aesKdf;
return kdfEngine; return kdfEngine;
@@ -482,12 +478,11 @@ public class Database {
} }
public void assignKdfEngine(KdfEngine kdfEngine) { public void assignKdfEngine(KdfEngine kdfEngine) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
PwDatabaseV4 db = ((PwDatabaseV4) pwDatabase); if (pwDatabaseV4.getKdfParameters() == null
if (db.getKdfParameters() == null || !pwDatabaseV4.getKdfParameters().getUUID().equals(kdfEngine.getDefaultParameters().getUUID()))
|| !db.getKdfParameters().getUUID().equals(kdfEngine.getDefaultParameters().getUUID())) pwDatabaseV4.setKdfParameters(kdfEngine.getDefaultParameters());
db.setKdfParameters(kdfEngine.getDefaultParameters());
setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds()); setNumberKeyEncryptionRounds(kdfEngine.getDefaultKeyRounds());
setMemoryUsage(kdfEngine.getDefaultMemoryUsage()); setMemoryUsage(kdfEngine.getDefaultMemoryUsage());
setParallelism(kdfEngine.getDefaultParallelism()); setParallelism(kdfEngine.getDefaultParallelism());
@@ -520,17 +515,17 @@ public class Database {
} }
public long getMemoryUsage() { public long getMemoryUsage() {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
return ((PwDatabaseV4) pwDatabase).getMemoryUsage(); return pwDatabaseV4.getMemoryUsage();
} }
return KdfEngine.UNKNOW_VALUE; return KdfEngine.UNKNOW_VALUE;
} }
public void setMemoryUsage(long memory) { public void setMemoryUsage(long memory) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwDatabaseV4) pwDatabase).setMemoryUsage(memory); pwDatabaseV4.setMemoryUsage(memory);
} }
} }
@@ -539,17 +534,17 @@ public class Database {
} }
public int getParallelism() { public int getParallelism() {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
return ((PwDatabaseV4) pwDatabase).getParallelism(); return pwDatabaseV4.getParallelism();
} }
return KdfEngine.UNKNOW_VALUE; return KdfEngine.UNKNOW_VALUE;
} }
public void setParallelism(int parallelism) { public void setParallelism(int parallelism) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwDatabaseV4) pwDatabase).setParallelism(parallelism); pwDatabaseV4.setParallelism(parallelism);
} }
} }
@@ -576,7 +571,7 @@ public class Database {
public PwEntryInterface createEntry() { public PwEntryInterface createEntry() {
try { try {
switch (pwDatabase.getVersion()) { switch (version) {
case V3: case V3:
return new PwEntryV3(); return new PwEntryV3();
case V4: case V4:
@@ -591,7 +586,7 @@ public class Database {
public PwGroupInterface createGroup() { public PwGroupInterface createGroup() {
PwGroupInterface newPwGroup = null; PwGroupInterface newPwGroup = null;
try { try {
switch (pwDatabase.getVersion()) { switch (version) {
case V3: case V3:
newPwGroup = new PwGroupV3(); newPwGroup = new PwGroupV3();
case V4: case V4:
@@ -644,43 +639,9 @@ public class Database {
} }
} }
public boolean canRecycle(PwEntryInterface entry) {
try {
pwDatabase.canRecycle(entry);
} catch (Exception e) {
Log.e(TAG, "This version of PwEntry can't be recycled", e);
}
return false;
}
public boolean canRecycle(PwGroupInterface group) {
try {
pwDatabase.canRecycle(group);
} catch (Exception e) {
Log.e(TAG, "This version of PwGroup can't be recycled", e);
}
return false;
}
public void recycle(PwEntryInterface entry) {
try {
pwDatabase.recycle(entry);
} catch (Exception e) {
Log.e(TAG, "This version of PwEntry can't be recycled", e);
}
}
public void recycle(PwGroupInterface group) {
try {
pwDatabase.recycle(group);
} catch (Exception e) {
Log.e(TAG, "This version of PwGroup can't be recycled", e);
}
}
public void updateEntry(PwEntryInterface oldEntry, PwEntryInterface newEntry) { public void updateEntry(PwEntryInterface oldEntry, PwEntryInterface newEntry) {
try { try {
switch (pwDatabase.getVersion()) { switch (version) {
case V3: case V3:
((PwEntryV3) oldEntry).updateWith((PwEntryV3) newEntry); ((PwEntryV3) oldEntry).updateWith((PwEntryV3) newEntry);
break; break;
@@ -695,7 +656,7 @@ public class Database {
public void updateGroup(PwGroupInterface oldGroup, PwGroupInterface newGroup) { public void updateGroup(PwGroupInterface oldGroup, PwGroupInterface newGroup) {
try { try {
switch (pwDatabase.getVersion()) { switch (version) {
case V3: case V3:
((PwGroupV3) oldGroup).updateWith((PwGroupV3) newGroup); ((PwGroupV3) oldGroup).updateWith((PwGroupV3) newGroup);
break; break;
@@ -716,12 +677,12 @@ public class Database {
public @Nullable PwEntryInterface copyEntry(PwEntryInterface entryToCopy, PwGroupInterface newParent) { public @Nullable PwEntryInterface copyEntry(PwEntryInterface entryToCopy, PwGroupInterface newParent) {
try { try {
PwEntryInterface entryCopied = null; PwEntryInterface entryCopied = null;
switch (pwDatabase.getVersion()) { switch (version) {
case V3: case V3:
entryCopied = ((PwEntryV3) entryToCopy).clone(); entryCopied = entryToCopy.duplicate();
break; break;
case V4: case V4:
entryCopied = ((PwEntryV4) entryToCopy).clone(); entryCopied = entryToCopy.duplicate();
break; break;
} }
entryCopied.setNodeId(new PwNodeIdUUID()); entryCopied.setNodeId(new PwNodeIdUUID());
@@ -745,16 +706,10 @@ public class Database {
} }
public void deleteEntry(PwEntryInterface entry) { public void deleteEntry(PwEntryInterface entry) {
try { removeEntryFrom(entry, entry.getParent());
PwGroupInterface parent = entry.getParent();
removeEntryFrom(entry, parent);
} catch (Exception e) {
Log.e(TAG, "This version of PwEntry can't be deleted", e);
}
} }
public void deleteGroup(PwGroupInterface group) { public void deleteGroup(PwGroupInterface group) {
try {
PwGroupInterface.doForEachChildAndForRoot(group, PwGroupInterface.doForEachChildAndForRoot(group,
new EntryHandler<PwEntryInterface>() { new EntryHandler<PwEntryInterface>() {
@Override @Override
@@ -771,72 +726,123 @@ public class Database {
return true; return true;
} }
}); });
} catch (Exception e) {
Log.e(TAG, "This version of PwGroup can't be deleted", e);
}
} }
public void undoDeleteEntry(PwEntryInterface entry, PwGroupInterface parent) {
pwDatabase.undoDeleteEntryFrom(entry, parent);
}
public void undoDeleteGroup(PwGroupInterface group, PwGroupInterface parent) {
pwDatabase.undoDeleteGroup(group, parent);
}
/**
* Determine if RecycleBin is available or not for this version of database
* @return true if RecycleBin available
*/
public boolean isRecycleBinAvailable() { public boolean isRecycleBinAvailable() {
return pwDatabase.isRecycleBinAvailable(); if (pwDatabaseV4 != null) {
switch (version) {
case V4:
return true;
}
}
return false;
} }
public boolean isRecycleBinEnabled() { public boolean isRecycleBinEnabled() {
return pwDatabase.isRecycleBinEnabled(); if (pwDatabaseV4 != null) {
switch (version) {
case V4:
return pwDatabaseV4.isRecycleBinEnabled();
}
}
return false;
} }
public PwGroupInterface getRecycleBin() { public PwGroupInterface getRecycleBin() {
switch (pwDatabase.getVersion()) { if (pwDatabaseV4 != null) {
switch (version) {
case V4: case V4:
return ((PwDatabaseV4) pwDatabase).getRecycleBin(); return pwDatabaseV4.getRecycleBin();
}
} }
return null; return null;
} }
public boolean canRecycle(PwEntryInterface entry) {
if (pwDatabaseV4 != null) {
switch (version) {
case V4:
return pwDatabaseV4.canRecycle(entry);
}
}
return false;
}
public boolean canRecycle(PwGroupInterface group) {
if (pwDatabaseV4 != null) {
switch (version) {
case V4:
return pwDatabaseV4.canRecycle(group);
}
}
return false;
}
public void recycle(PwEntryInterface entry) {
if (pwDatabaseV4 != null) {
switch (version) {
case V4:
pwDatabaseV4.recycle(entry);
break;
}
}
}
public void recycle(PwGroupInterface group) {
if (pwDatabaseV4 != null) {
switch (version) {
case V4:
pwDatabaseV4.recycle(group);
break;
}
}
}
public void undoRecycle(PwEntryInterface entry, PwGroupInterface parent) { public void undoRecycle(PwEntryInterface entry, PwGroupInterface parent) {
try { if (pwDatabaseV4 != null) {
pwDatabase.undoRecycle(entry, parent); switch (version) {
} catch (Exception e) { case V4:
Log.e(TAG, "This version of database can't undo Recycle of this version of PwEntry", e); pwDatabaseV4.undoRecycle(entry, parent);
break;
}
} }
} }
public void undoRecycle(PwGroupInterface group, PwGroupInterface parent) { public void undoRecycle(PwGroupInterface group, PwGroupInterface parent) {
try { if (pwDatabaseV4 != null) {
pwDatabase.undoRecycle(group, parent); switch (version) {
} catch (Exception e) { case V4:
Log.e(TAG, "This version of database can't undo Recycle of this version of PwGroup", e); pwDatabaseV4.undoRecycle(group, parent);
break;
} }
} }
public void undoDeleteEntry(PwEntryInterface entry, PwGroupInterface parent) {
try {
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);
}
}
public void undoDeleteGroup(PwGroupInterface group, PwGroupInterface parent) {
try {
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) { public void startManageEntry(PwEntryInterface entry) {
if (pwDatabase != null) { if (pwDatabaseV4 != null) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwEntryV4) entry).startToManageFieldReferences((PwDatabaseV4) pwDatabase); ((PwEntryV4) entry).startToManageFieldReferences(pwDatabaseV4);
break; break;
} }
} }
} }
public void stopManageEntry(PwEntryInterface entry) { public void stopManageEntry(PwEntryInterface entry) {
if (pwDatabase != null) { if (pwDatabaseV4 != null) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwEntryV4) entry).stopToManageFieldReferences(); ((PwEntryV4) entry).stopToManageFieldReferences();
break; break;
@@ -845,10 +851,10 @@ public class Database {
} }
public void createBackupOf(PwEntryInterface entry) { public void createBackupOf(PwEntryInterface entry) {
if (pwDatabase != null) { if (pwDatabaseV4 != null) {
switch (pwDatabase.getVersion()) { switch (version) {
case V4: case V4:
((PwEntryV4) entry).createBackup((PwDatabaseV4) pwDatabase); ((PwEntryV4) entry).createBackup(pwDatabaseV4);
break; break;
} }
} }

View File

@@ -355,68 +355,7 @@ public abstract class PwDatabase {
public abstract boolean isBackup(PwGroupInterface group); public abstract boolean isBackup(PwGroupInterface group);
/*
* -------------------------------------
* RecycleBin
* -------------------------------------
*/
/**
* Determine if RecycleBin is available or not for this version of database
* @return true if RecycleBin enable
*/
protected boolean isRecycleBinAvailable() {
return false;
}
/**
* Determine if RecycleBin is enable or not
* @return true if RecycleBin enable, false if is not available or not enable
*/
protected boolean isRecycleBinEnabled() {
return false;
}
/**
* Define if a Group must be delete or recycle
* @param group Group to remove
* @return true if group can be recycle, false elsewhere
*/
protected boolean canRecycle(PwGroupInterface group) {
return false;
}
/**
* Define if an Entry must be delete or recycle
* @param entry Entry to remove
* @return true if entry can be recycle, false elsewhere
*/
protected boolean canRecycle(PwEntryInterface entry) {
return false;
}
protected void recycle(PwGroupInterface group) {
// Assume calls to this are protected by calling inRecyleBin
throw new RuntimeException("Call not valid for .kdb databases.");
}
protected void recycle(PwEntryInterface entry) {
// Assume calls to this are protected by calling inRecyleBin
throw new RuntimeException("Call not valid for .kdb databases.");
}
protected void undoRecycle(PwGroupInterface group, PwGroupInterface origParent) {
throw new RuntimeException("Call not valid for .kdb databases.");
}
protected void undoRecycle(PwEntryInterface entry, PwGroupInterface origParent) {
throw new RuntimeException("Call not valid for .kdb databases.");
}
public boolean isGroupSearchable(PwGroupInterface group, boolean omitBackup) { public boolean isGroupSearchable(PwGroupInterface group, boolean omitBackup) {
return group != null; return group != null;
} }
public abstract void clearCache();
} }

View File

@@ -177,7 +177,6 @@ public class PwDatabaseV3 extends PwDatabase {
} }
group = group.getParent(); group = group.getParent();
} }
return false; return false;
} }
@@ -186,10 +185,6 @@ public class PwDatabaseV3 extends PwDatabase {
if (!super.isGroupSearchable(group, omitBackup)) { if (!super.isGroupSearchable(group, omitBackup)) {
return false; return false;
} }
return !(omitBackup && isBackup(group)); return !(omitBackup && isBackup(group));
} }
@Override
public void clearCache() {}
} }

View File

@@ -20,7 +20,7 @@
package com.kunzisoft.keepass.database.element; package com.kunzisoft.keepass.database.element;
import android.util.Log; import android.util.Log;
import biz.source_code.base64Coder.Base64Coder;
import com.kunzisoft.keepass.collections.VariantDictionary; import com.kunzisoft.keepass.collections.VariantDictionary;
import com.kunzisoft.keepass.crypto.CryptoUtil; import com.kunzisoft.keepass.crypto.CryptoUtil;
import com.kunzisoft.keepass.crypto.engine.AesEngine; import com.kunzisoft.keepass.crypto.engine.AesEngine;
@@ -28,37 +28,19 @@ import com.kunzisoft.keepass.crypto.engine.CipherEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine; import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory; import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory;
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters; import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters;
import com.kunzisoft.keepass.database.BinaryPool; import com.kunzisoft.keepass.database.*;
import com.kunzisoft.keepass.database.EntryHandler;
import com.kunzisoft.keepass.database.GroupHandler;
import com.kunzisoft.keepass.database.MemoryProtectionConfig;
import com.kunzisoft.keepass.database.PwCompressionAlgorithm;
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
import com.kunzisoft.keepass.database.exception.UnknownKDF; import com.kunzisoft.keepass.database.exception.UnknownKDF;
import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException;
import biz.source_code.base64Coder.Base64Coder; import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
public class PwDatabaseV4 extends PwDatabase { public class PwDatabaseV4 extends PwDatabase {
@@ -536,7 +518,9 @@ public class PwDatabaseV4 extends PwDatabase {
if (getRecycleBin() == null) { if (getRecycleBin() == null) {
// Create recycle bin // Create recycle bin
PwGroupV4 recycleBin = new PwGroupV4(RECYCLEBIN_NAME, iconFactory.getTrashIcon()); PwGroupV4 recycleBin = new PwGroupV4();
recycleBin.setTitle(RECYCLEBIN_NAME);
recycleBin.setIconStandard(iconFactory.getTrashIcon());
recycleBin.setEnableAutoType(false); recycleBin.setEnableAutoType(false);
recycleBin.setEnableSearching(false); recycleBin.setEnableSearching(false);
recycleBin.setExpanded(false); recycleBin.setExpanded(false);
@@ -554,12 +538,10 @@ public class PwDatabaseV4 extends PwDatabase {
this.recycleBinUUID = recycleBinUUID; this.recycleBinUUID = recycleBinUUID;
} }
@Override /**
public boolean isRecycleBinAvailable() { * Determine if RecycleBin is enable or not
return true; * @return true if RecycleBin enable, false if is not available or not enable
} */
@Override
public boolean isRecycleBinEnabled() { public boolean isRecycleBinEnabled() {
return recycleBinEnabled; return recycleBinEnabled;
} }
@@ -577,7 +559,11 @@ public class PwDatabaseV4 extends PwDatabase {
this.recycleBinChanged = recycleBinChanged; this.recycleBinChanged = recycleBinChanged;
} }
@Override /**
* Define if a Group must be delete or recycle
* @param group Group to remove
* @return true if group can be recycle, false elsewhere
*/
public boolean canRecycle(PwGroupInterface group) { public boolean canRecycle(PwGroupInterface group) {
if (!recycleBinEnabled) { if (!recycleBinEnabled) {
return false; return false;
@@ -586,7 +572,11 @@ public class PwDatabaseV4 extends PwDatabase {
return (recycle == null) || (!group.isContainedIn(recycle)); return (recycle == null) || (!group.isContainedIn(recycle));
} }
@Override /**
* Define if an Entry must be delete or recycle
* @param entry Entry to remove
* @return true if entry can be recycle, false elsewhere
*/
public boolean canRecycle(PwEntryInterface entry) { public boolean canRecycle(PwEntryInterface entry) {
if (!recycleBinEnabled) { if (!recycleBinEnabled) {
return false; return false;
@@ -595,7 +585,6 @@ public class PwDatabaseV4 extends PwDatabase {
return (parent != null) && canRecycle(parent); return (parent != null) && canRecycle(parent);
} }
@Override
public void recycle(PwGroupInterface group) { public void recycle(PwGroupInterface group) {
ensureRecycleBin(); ensureRecycleBin();
@@ -608,7 +597,6 @@ public class PwDatabaseV4 extends PwDatabase {
// TODO ? group.touchLocation(); // TODO ? group.touchLocation();
} }
@Override
public void recycle(PwEntryInterface entry) { public void recycle(PwEntryInterface entry) {
ensureRecycleBin(); ensureRecycleBin();
@@ -621,7 +609,6 @@ public class PwDatabaseV4 extends PwDatabase {
entry.touchLocation(); entry.touchLocation();
} }
@Override
public void undoRecycle(PwGroupInterface group, PwGroupInterface origParent) { public void undoRecycle(PwGroupInterface group, PwGroupInterface origParent) {
PwGroupInterface recycleBin = getRecycleBin(); PwGroupInterface recycleBin = getRecycleBin();
@@ -630,7 +617,6 @@ public class PwDatabaseV4 extends PwDatabase {
addGroupTo(group, origParent); addGroupTo(group, origParent);
} }
@Override
public void undoRecycle(PwEntryInterface entry, PwGroupInterface origParent) { public void undoRecycle(PwEntryInterface entry, PwGroupInterface origParent) {
PwGroupInterface recycleBin = getRecycleBin(); PwGroupInterface recycleBin = getRecycleBin();
@@ -693,7 +679,6 @@ public class PwDatabaseV4 extends PwDatabase {
if (!super.isGroupSearchable(group, omitBackup)) { if (!super.isGroupSearchable(group, omitBackup)) {
return false; return false;
} }
return group.isSearchingEnabled(); return group.isSearchingEnabled();
} }
@@ -702,7 +687,6 @@ public class PwDatabaseV4 extends PwDatabase {
return true; return true;
} }
@Override
public void clearCache() { public void clearCache() {
binPool.clear(); binPool.clear();
} }

View File

@@ -134,7 +134,7 @@ public class PwEntryV3 extends PwNode<UUID> implements PwEntryInterface {
}; };
public void updateWith(PwEntryV3 source) { public void updateWith(PwEntryV3 source) {
super.assign(source); super.updateWith(source);
title = source.title; title = source.title;
username = source.username; username = source.username;
int passLen = source.password.length; int passLen = source.password.length;

View File

@@ -122,7 +122,7 @@ public class PwEntryV4 extends PwNode<UUID> implements ITimeLogger, PwEntryInte
}; };
public void updateWith(PwEntryV4 source) { public void updateWith(PwEntryV4 source) {
super.assign(source); super.updateWith(source);
customIcon = source.customIcon; customIcon = source.customIcon;
usageCount = source.usageCount; usageCount = source.usageCount;
parentGroupLastMod = source.parentGroupLastMod; parentGroupLastMod = source.parentGroupLastMod;

View File

@@ -0,0 +1,98 @@
package com.kunzisoft.keepass.database.element;
import android.os.Parcel;
import java.util.ArrayList;
import java.util.List;
public abstract class PwGroup<Id> extends PwNode<Id> implements PwGroupInterface {
private String title = "";
transient private List<PwGroupInterface> childGroups = new ArrayList<>();
transient private List<PwEntryInterface> childEntries = new ArrayList<>();
public PwGroup() {
super();
}
public PwGroup(Parcel in) {
super(in);
title = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(title);
}
protected void updateWith(PwGroup source) {
super.updateWith(source);
title = source.title;
}
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String name) {
this.title = name;
}
@Override
public List<PwGroupInterface> getChildGroups() {
return childGroups;
}
@Override
public List<PwEntryInterface> getChildEntries() {
return childEntries;
}
@Override
public void addChildGroup(PwGroupInterface group) {
this.childGroups.add(group);
}
@Override
public void addChildEntry(PwEntryInterface entry) {
this.childEntries.add(entry);
}
@Override
public void removeChildGroup(PwGroupInterface group) {
this.childGroups.remove(group);
}
@Override
public void removeChildEntry(PwEntryInterface entry) {
this.childEntries.remove(entry);
}
@Override
public int getLevel() {
return -1;
}
@Override
public void setLevel(int level) {
// Do nothing here
}
@Override
public List<PwNodeInterface> getChildrenWithoutMetastream() {
List<PwNodeInterface> children = new ArrayList<>(childGroups);
for(PwEntryInterface child : childEntries) {
if (!child.isMetaStream())
children.add(child);
}
return children;
}
@Override
public String toString() {
return getTitle();
}
}

View File

@@ -25,8 +25,6 @@ public interface PwGroupInterface extends PwNodeInterface {
void removeChildEntry(PwEntryInterface entry); void removeChildEntry(PwEntryInterface entry);
boolean containsParent();
/** /**
* Filter MetaStream entries and return children * Filter MetaStream entries and return children
* @return List of direct children (one level below) as PwNode * @return List of direct children (one level below) as PwNode

View File

@@ -22,17 +22,8 @@ package com.kunzisoft.keepass.database.element;
import android.os.Parcel; import android.os.Parcel;
import java.util.ArrayList; public class PwGroupV3 extends PwGroup<Integer> {
import java.util.List;
public class PwGroupV3 extends PwNode<Integer> implements PwGroupInterface {
// TODO verify children not needed
transient private List<PwGroupInterface> childGroups = new ArrayList<>();
transient private List<PwEntryInterface> childEntries = new ArrayList<>();
// for tree traversing
private String title = "";
private int level = 0; // short private int level = 0; // short
/** Used by KeePass internally, don't use */ /** Used by KeePass internally, don't use */
private int flags; private int flags;
@@ -48,7 +39,6 @@ public class PwGroupV3 extends PwNode<Integer> implements PwGroupInterface {
public PwGroupV3(Parcel in) { public PwGroupV3(Parcel in) {
super(in); super(in);
title = in.readString();
level = in.readInt(); level = in.readInt();
flags = in.readInt(); flags = in.readInt();
} }
@@ -56,7 +46,6 @@ public class PwGroupV3 extends PwNode<Integer> implements PwGroupInterface {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags); super.writeToParcel(dest, flags);
dest.writeString(title);
dest.writeInt(level); dest.writeInt(level);
dest.writeInt(flags); dest.writeInt(flags);
} }
@@ -74,8 +63,7 @@ public class PwGroupV3 extends PwNode<Integer> implements PwGroupInterface {
}; };
protected void updateWith(PwGroupV3 source) { protected void updateWith(PwGroupV3 source) {
super.assign(source); super.updateWith(source);
title = source.title;
level = source.level; level = source.level;
flags = source.flags; flags = source.flags;
} }
@@ -137,61 +125,6 @@ public class PwGroupV3 extends PwNode<Integer> implements PwGroupInterface {
this.flags = flags; this.flags = flags;
} }
@Override
public String toString() {
return getTitle();
}
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@Override
public List<PwGroupInterface> getChildGroups() {
return childGroups;
}
@Override
public List<PwEntryInterface> getChildEntries() {
return childEntries;
}
@Override
public void addChildGroup(PwGroupInterface group) {
this.childGroups.add(group);
}
@Override
public void addChildEntry(PwEntryInterface entry) {
this.childEntries.add(entry);
}
@Override
public void removeChildGroup(PwGroupInterface group) {
this.childGroups.remove(group);
}
@Override
public void removeChildEntry(PwEntryInterface entry) {
this.childEntries.remove(entry);
}
@Override
public List<PwNodeInterface> getChildrenWithoutMetastream() {
List<PwNodeInterface> children = new ArrayList<>(childGroups);
for(PwEntryInterface child : childEntries) {
if (!child.isMetaStream())
children.add(child);
}
return children;
}
@Override @Override
public boolean allowAddEntryIfIsRoot() { public boolean allowAddEntryIfIsRoot() {
return false; return false;

View File

@@ -20,24 +20,16 @@
package com.kunzisoft.keepass.database.element; package com.kunzisoft.keepass.database.element;
import android.os.Parcel; import android.os.Parcel;
import com.kunzisoft.keepass.database.ITimeLogger; import com.kunzisoft.keepass.database.ITimeLogger;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class PwGroupV4 extends PwNode<UUID> implements ITimeLogger, PwGroupInterface { public class PwGroupV4 extends PwGroup<UUID> implements ITimeLogger {
public static final boolean DEFAULT_SEARCHING_ENABLED = true; public static final boolean DEFAULT_SEARCHING_ENABLED = true;
// TODO verify children not needed
transient private List<PwGroupInterface> childGroups = new ArrayList<>();
transient private List<PwEntryInterface> childEntries = new ArrayList<>();
private String title = "";
private PwIconCustom customIcon = PwIconCustom.ZERO; private PwIconCustom customIcon = PwIconCustom.ZERO;
private long usageCount = 0; private long usageCount = 0;
private PwDate locationChangeDate = new PwDate(); private PwDate locationChangeDate = new PwDate();
@@ -59,15 +51,8 @@ public class PwGroupV4 extends PwNode<UUID> implements ITimeLogger, PwGroupInter
super(); super();
} }
public PwGroupV4(String title, PwIconStandard icon) {
super();
this.title = title;
this.icon = icon;
}
public PwGroupV4(Parcel in) { public PwGroupV4(Parcel in) {
super(in); super(in);
title = in.readString();
customIcon = in.readParcelable(PwIconCustom.class.getClassLoader()); customIcon = in.readParcelable(PwIconCustom.class.getClassLoader());
usageCount = in.readLong(); usageCount = in.readLong();
locationChangeDate = in.readParcelable(PwDate.class.getClassLoader()); locationChangeDate = in.readParcelable(PwDate.class.getClassLoader());
@@ -86,7 +71,6 @@ public class PwGroupV4 extends PwNode<UUID> implements ITimeLogger, PwGroupInter
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags); super.writeToParcel(dest, flags);
dest.writeString(title);
dest.writeParcelable(customIcon, flags); dest.writeParcelable(customIcon, flags);
dest.writeLong(usageCount); dest.writeLong(usageCount);
dest.writeParcelable(locationChangeDate, flags); dest.writeParcelable(locationChangeDate, flags);
@@ -113,8 +97,7 @@ public class PwGroupV4 extends PwNode<UUID> implements ITimeLogger, PwGroupInter
}; };
protected void updateWith(PwGroupV4 source) { protected void updateWith(PwGroupV4 source) {
super.assign(source); super.updateWith(source);
title = source.title;
customIcon = source.customIcon; customIcon = source.customIcon;
usageCount = source.usageCount; usageCount = source.usageCount;
locationChangeDate = source.locationChangeDate; locationChangeDate = source.locationChangeDate;
@@ -297,66 +280,6 @@ public class PwGroupV4 extends PwNode<UUID> implements ITimeLogger, PwGroupInter
return true; return true;
} }
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String name) {
this.title = name;
}
@Override
public List<PwGroupInterface> getChildGroups() {
return childGroups;
}
@Override
public List<PwEntryInterface> getChildEntries() {
return childEntries;
}
@Override
public int getLevel() {
return -1; // TODO Level
}
@Override
public void setLevel(int level) {
// Do nothing here
}
@Override
public void addChildGroup(PwGroupInterface group) {
this.childGroups.add(group);
}
@Override
public void addChildEntry(PwEntryInterface entry) {
this.childEntries.add(entry);
}
@Override
public void removeChildGroup(PwGroupInterface group) {
this.childGroups.remove(group);
}
@Override
public void removeChildEntry(PwEntryInterface entry) {
this.childEntries.remove(entry);
}
@Override
public List<PwNodeInterface> getChildrenWithoutMetastream() {
List<PwNodeInterface> children = new ArrayList<>(childGroups);
for(PwEntryInterface child : childEntries) {
if (!child.isMetaStream())
children.add(child);
}
return children;
}
@Override @Override
public boolean allowAddEntryIfIsRoot() { public boolean allowAddEntryIfIsRoot() {
return true; return true;

View File

@@ -82,7 +82,7 @@ public abstract class PwNode<IdType> implements PwNodeInterface, Parcelable, Clo
return 0; return 0;
} }
protected void assign(PwNode source) { protected void updateWith(PwNode source) {
this.nodeId = source.nodeId; this.nodeId = source.nodeId;
this.parent = source.parent; this.parent = source.parent;
this.icon = source.icon; this.icon = source.icon;

View File

@@ -37,6 +37,8 @@ public interface PwNodeInterface extends SmallTimeInterface, Parcelable {
*/ */
void setParent(PwGroupInterface prt); void setParent(PwGroupInterface prt);
boolean containsParent();
void touch(boolean modified, boolean touchParents); void touch(boolean modified, boolean touchParents);
boolean isContainedIn(PwGroupInterface container); boolean isContainedIn(PwGroupInterface container);

View File

@@ -29,9 +29,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class ImporterFactory { public class ImporterFactory {
public static Importer createImporter(InputStream is, File streamDir) throws InvalidDBSignatureException, IOException {
return createImporter(is, streamDir,false);
}
public static Importer createImporter(InputStream is, File streamDir, boolean debug) throws InvalidDBSignatureException, IOException { public static Importer createImporter(InputStream is, File streamDir, boolean debug) throws InvalidDBSignatureException, IOException {
int sig1 = LEDataInputStream.readInt(is); int sig1 = LEDataInputStream.readInt(is);
@@ -41,7 +38,6 @@ public class ImporterFactory {
if (debug) { if (debug) {
return new ImporterV3Debug(); return new ImporterV3Debug();
} }
return new ImporterV3(); return new ImporterV3();
} else if ( PwDbHeaderV4.matchesHeader(sig1, sig2) ) { } else if ( PwDbHeaderV4.matchesHeader(sig1, sig2) ) {
return new ImporterV4(streamDir); return new ImporterV4(streamDir);

View File

@@ -22,13 +22,10 @@ package com.kunzisoft.keepass.database.search;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.EntryHandler; import com.kunzisoft.keepass.database.EntryHandler;
import com.kunzisoft.keepass.database.GroupHandler; import com.kunzisoft.keepass.database.GroupHandler;
import com.kunzisoft.keepass.database.element.PwDatabase; import com.kunzisoft.keepass.database.element.PwDatabase;
import com.kunzisoft.keepass.database.element.PwDatabaseV3;
import com.kunzisoft.keepass.database.element.PwDatabaseV4;
import com.kunzisoft.keepass.database.element.PwEntryInterface; import com.kunzisoft.keepass.database.element.PwEntryInterface;
import com.kunzisoft.keepass.database.element.PwGroupInterface; import com.kunzisoft.keepass.database.element.PwGroupInterface;
import com.kunzisoft.keepass.database.iterator.EntrySearchStringIterator; import com.kunzisoft.keepass.database.iterator.EntrySearchStringIterator;
@@ -36,21 +33,21 @@ import com.kunzisoft.keepass.database.iterator.EntrySearchStringIterator;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
public class SearchDbHelper<PwDatabaseVersion extends PwDatabase> { public class SearchDbHelper {
private final Context mCtx; private final Context mContext;
private int incrementEntry = 0; private int incrementEntry = 0;
public SearchDbHelper(Context ctx) { public SearchDbHelper(Context context) {
this.mCtx = ctx; this.mContext = context;
} }
private boolean omitBackup() { private boolean omitBackup() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mCtx); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
return prefs.getBoolean(mCtx.getString(R.string.omitbackup_key), mCtx.getResources().getBoolean(R.bool.omitbackup_default)); return prefs.getBoolean(mContext.getString(R.string.omitbackup_key), mContext.getResources().getBoolean(R.bool.omitbackup_default));
} }
public PwGroupInterface search(PwDatabaseVersion pm, String qStr, int max) { public PwGroupInterface search(PwDatabase pm, String qStr, int max) {
PwGroupInterface searchGroup = pm.createGroup(); PwGroupInterface searchGroup = pm.createGroup();
searchGroup.setTitle("\"" + qStr + "\""); searchGroup.setTitle("\"" + qStr + "\"");
@@ -101,19 +98,4 @@ public class SearchDbHelper<PwDatabaseVersion extends PwDatabase> {
} }
return false; return false;
} }
public static class SearchDbHelperV3 extends SearchDbHelper<PwDatabaseV3>{
public SearchDbHelperV3(Context ctx) {
super(ctx);
}
}
public static class SearchDbHelperV4 extends SearchDbHelper<PwDatabaseV4>{
public SearchDbHelperV4(Context ctx) {
super(ctx);
}
}
} }

View File

@@ -347,7 +347,6 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
// TODO Recycle // TODO Recycle
dbGeneralPrefCategory.removePreference(recycleBinPref); // To delete dbGeneralPrefCategory.removePreference(recycleBinPref); // To delete
if (database.isRecycleBinAvailable()) { if (database.isRecycleBinAvailable()) {
recycleBinPref.setChecked(database.isRecycleBinEnabled()); recycleBinPref.setChecked(database.isRecycleBinEnabled());
recycleBinPref.setEnabled(false); recycleBinPref.setEnabled(false);
} else { } else {