diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f90c21000..caf6bf117 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -58,9 +58,9 @@
-
-
diff --git a/res/drawable/notify_profile.png b/res/drawable/notify_profile.png
new file mode 100644
index 000000000..10ac41684
Binary files /dev/null and b/res/drawable/notify_profile.png differ
diff --git a/src/com/keepassdroid/Database.java b/src/com/keepassdroid/Database.java
index fa3b8ec26..fa6d413b9 100644
--- a/src/com/keepassdroid/Database.java
+++ b/src/com/keepassdroid/Database.java
@@ -47,7 +47,8 @@
import com.keepassdroid.database.load.ImporterFactory;
import com.keepassdroid.database.save.PwDbOutput;
import com.keepassdroid.icons.DrawableFactory;
-import com.keepassdroid.search.SearchDbHelper;
+import com.keepassdroid.search.InMemorySearchHelper;
+import com.keepassdroid.search.SearchHelper;
/**
* @author bpellin
@@ -59,7 +60,7 @@ public class Database {
public PwGroup root;
public PwDatabase pm;
public String mFilename;
- public SearchDbHelper searchHelper;
+ private SearchHelper searchHelper;
public boolean indexBuilt = false;
public DrawableFactory drawFactory = new DrawableFactory();
@@ -129,7 +130,8 @@ public void LoadData(Context ctx, InputStream is, String password, String keyfil
*/
public void buildSearchIndex(Context ctx) {
- searchHelper = new SearchDbHelper(ctx);
+ searchHelper = new InMemorySearchHelper();
+// searchHelper = new SearchDbHelper(ctx);
initSearch();
@@ -235,5 +237,12 @@ public void markAllGroupsAsDirty() {
}
}
+ public SearchHelper getSearchHelper() {
+ if( searchHelper == null ) {
+ searchHelper = new InMemorySearchHelper();
+ }
+ return searchHelper;
+ }
+
}
diff --git a/src/com/keepassdroid/EntryActivity.java b/src/com/keepassdroid/EntryActivity.java
index 7f8bd4884..712bde751 100644
--- a/src/com/keepassdroid/EntryActivity.java
+++ b/src/com/keepassdroid/EntryActivity.java
@@ -148,15 +148,19 @@ protected void onCreate(Bundle savedInstanceState) {
// Notification Manager
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ String title = mEntry.getTitle();
+ if( title == null ) {
+ title = "";
+ }
if ( mEntry.getPassword().length() > 0 ) {
- // only show notification if password is available
- Notification password = getNotification(Intents.COPY_PASSWORD, R.string.copy_password);
+ // only show notification if password is available
+ Notification password = getNotification(Intents.COPY_PASSWORD, String.format( "%s [%s]", getString(R.string.copy_password), title ), R.drawable.notify);
mNM.notify(NOTIFY_PASSWORD, password);
}
if ( mEntry.getUsername().length() > 0 ) {
// only show notification if username is available
- Notification username = getNotification(Intents.COPY_USERNAME, R.string.copy_username);
+ Notification username = getNotification(Intents.COPY_USERNAME, String.format( "%s [%s]", getString(R.string.copy_username), title ), R.drawable.notify_profile);
mNM.notify(NOTIFY_USERNAME, username);
}
@@ -200,16 +204,32 @@ protected void onDestroy() {
super.onDestroy();
}
+ /**
+ * Get {@link Notification} using custom icon resource
+ * @param intentText
+ * @param desc
+ * @param icon
+ * @return
+ */
+ private Notification getNotification(String intentText, String desc, int icon) {
+ Notification notify = new Notification(icon, desc, System.currentTimeMillis());
+
+ Intent intent = new Intent(intentText);
+ PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
+
+ notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending);
+
+ return notify;
+ }
+
+ /**
+ * Get {@link Notification} using default icon (R.drawable.notify)
+ * @param intentText
+ * @param descResId
+ * @return
+ */
private Notification getNotification(String intentText, int descResId) {
- String desc = getString(descResId);
- Notification notify = new Notification(R.drawable.notify, desc, System.currentTimeMillis());
-
- Intent intent = new Intent(intentText);
- PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
-
- notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending);
-
- return notify;
+ return getNotification(intentText, getString(descResId), R.drawable.notify);
}
private String getDateTime(Date dt) {
diff --git a/src/com/keepassdroid/compat/BackupManagerCompat.java b/src/com/keepassdroid/compat/BackupManagerCompat.java
index f62ed8f83..9470d6302 100644
--- a/src/com/keepassdroid/compat/BackupManagerCompat.java
+++ b/src/com/keepassdroid/compat/BackupManagerCompat.java
@@ -25,10 +25,9 @@
import android.content.Context;
-@SuppressWarnings("unchecked")
public class BackupManagerCompat {
- private static Class classBackupManager;
- private static Constructor constructorBackupManager;
+ private static Class> classBackupManager;
+ private static Constructor> constructorBackupManager;
private static Method dataChanged;
private Object backupManager;
diff --git a/src/com/keepassdroid/database/edit/AddEntry.java b/src/com/keepassdroid/database/edit/AddEntry.java
index 8bb911c8b..3af91dd4e 100644
--- a/src/com/keepassdroid/database/edit/AddEntry.java
+++ b/src/com/keepassdroid/database/edit/AddEntry.java
@@ -22,7 +22,7 @@
import com.keepassdroid.Database;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
-import com.keepassdroid.search.SearchDbHelper;
+import com.keepassdroid.search.SearchHelper;
public class AddEntry extends RunnableOnFinish {
protected Database mDb;
@@ -70,7 +70,7 @@ public void run() {
if ( mDb.indexBuilt ) {
// Add entry to search index
- SearchDbHelper helper = mDb.searchHelper;
+ SearchHelper helper = mDb.getSearchHelper();
helper.open();
helper.insertEntry(mDb.pm, mEntry);
helper.close();
diff --git a/src/com/keepassdroid/database/edit/DeleteEntry.java b/src/com/keepassdroid/database/edit/DeleteEntry.java
index ba0115e00..afc1a19b5 100644
--- a/src/com/keepassdroid/database/edit/DeleteEntry.java
+++ b/src/com/keepassdroid/database/edit/DeleteEntry.java
@@ -22,7 +22,7 @@
import com.keepassdroid.Database;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
-import com.keepassdroid.search.SearchDbHelper;
+import com.keepassdroid.search.SearchHelper;
/** Task to delete entries
* @author bpellin
@@ -88,7 +88,7 @@ public AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry) {
public void run() {
if ( mSuccess ) {
if ( mDb.indexBuilt ) {
- SearchDbHelper dbHelper = mDb.searchHelper;
+ SearchHelper dbHelper = mDb.getSearchHelper();
dbHelper.open();
// Remove from entry global
diff --git a/src/com/keepassdroid/database/edit/UpdateEntry.java b/src/com/keepassdroid/database/edit/UpdateEntry.java
index dfc652f9c..9219592ba 100644
--- a/src/com/keepassdroid/database/edit/UpdateEntry.java
+++ b/src/com/keepassdroid/database/edit/UpdateEntry.java
@@ -22,7 +22,7 @@
import com.keepassdroid.Database;
import com.keepassdroid.database.PwEntry;
import com.keepassdroid.database.PwGroup;
-import com.keepassdroid.search.SearchDbHelper;
+import com.keepassdroid.search.SearchHelper;
public class UpdateEntry extends RunnableOnFinish {
private Database mDb;
@@ -79,7 +79,7 @@ public void run() {
if ( mDb.indexBuilt ) {
// Update search index
- SearchDbHelper helper = mDb.searchHelper;
+ SearchHelper helper = mDb.getSearchHelper();
helper.open();
helper.updateEntry(mDb.pm, mOldE);
helper.close();
diff --git a/src/com/keepassdroid/search/InMemorySearchHelper.java b/src/com/keepassdroid/search/InMemorySearchHelper.java
new file mode 100644
index 000000000..3df568b5f
--- /dev/null
+++ b/src/com/keepassdroid/search/InMemorySearchHelper.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2009-2011 Brian Pellin.
+ * Copyright 2011 riku salkia
+ *
+ * This file is part of KeePassDroid.
+ *
+ * KeePassDroid is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * KeePassDroid is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with KeePassDroid. If not, see .
+ *
+ */
+package com.keepassdroid.search;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import android.util.Log;
+
+import com.keepassdroid.Database;
+import com.keepassdroid.database.PwDatabase;
+import com.keepassdroid.database.PwDatabaseV3;
+import com.keepassdroid.database.PwDatabaseV4;
+import com.keepassdroid.database.PwEntry;
+import com.keepassdroid.database.PwEntryV4;
+import com.keepassdroid.database.PwGroup;
+import com.keepassdroid.database.PwGroupV3;
+import com.keepassdroid.database.PwGroupV4;
+
+public class InMemorySearchHelper implements SearchHelper {
+ private static final String TAG = InMemorySearchHelper.class.getSimpleName();
+ private Map> stringMap = new HashMap>();
+
+ @Override
+ public SearchHelper open(){
+ return this;
+ }
+
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public void clear() {
+ }
+
+ @Override
+ public void insertEntry(PwDatabase db, PwEntry entry) {
+ UUID uuid = entry.getUUID();
+ Collection strings = new ArrayList();
+ strings.add( entry.getTitle().toLowerCase() );
+ strings.add( entry.getUrl().toLowerCase() );
+ strings.add( entry.getUsername().toLowerCase() );
+ strings.add( entry.getNotes().toLowerCase() );
+
+ if( entry instanceof PwEntryV4 ) {
+ // Add Advanced keys&values https://code.google.com/p/keepassdroid/issues/detail?id=162
+ PwEntryV4 v4 = (PwEntryV4) entry;
+ for( String key : v4.strings.keySet() ) {
+ strings.add(key.toLowerCase());
+ strings.add(v4.strings.get(key).toLowerCase());
+ }
+ }
+
+ stringMap.put(uuid, strings);
+ }
+
+ @Override
+ public void insertEntry(PwDatabase db, List extends PwEntry> entries) {
+ for( PwEntry entry : entries ) {
+ insertEntry( db, entry );
+ }
+ }
+
+ @Override
+ public void updateEntry(PwDatabase db, PwEntry entry) {
+ insertEntry(db, entry);
+ }
+
+ @Override
+ public void deleteEntry(PwEntry entry) {
+ stringMap.remove( entry.getUUID() );
+ }
+
+ @Override
+ public PwGroup search(Database db, String qStr) {
+ long start = System.currentTimeMillis();
+
+ final String searchStr = qStr.toLowerCase();
+
+ PwGroup group;
+ if ( db.pm instanceof PwDatabaseV3 ) {
+ group = new PwGroupV3();
+ } else if ( db.pm instanceof PwDatabaseV4 ) {
+ group = new PwGroupV4();
+ } else {
+ Log.d(TAG, "Tried to search with unknown db");
+ return null;
+ }
+ group.name = "Search results";
+ group.childEntries = new ArrayList();
+
+ int entries = 0;
+ int total = 0;
+
+ for( UUID uuid : stringMap.keySet() ) {
+ for( String str : stringMap.get(uuid) ) {
+ if( str.contains( searchStr ) ) {
+ PwEntry entry = (PwEntry) db.entries.get(uuid);
+ group.childEntries.add(entry);
+ }
+
+ total++;
+ }
+ entries++;
+ }
+ Log.d(TAG, String.format("Searched %d entries, %d strings. Search took %dms to complete", entries, total, System.currentTimeMillis()-start) );
+
+ return group;
+ }
+
+}
diff --git a/src/com/keepassdroid/search/SearchDbHelper.java b/src/com/keepassdroid/search/SearchDbHelper.java
index 3285b4110..c905b5f06 100644
--- a/src/com/keepassdroid/search/SearchDbHelper.java
+++ b/src/com/keepassdroid/search/SearchDbHelper.java
@@ -43,7 +43,8 @@
import com.keepassdroid.database.PwGroupV3;
import com.keepassdroid.database.PwGroupV4;
-public class SearchDbHelper {
+@Deprecated
+public class SearchDbHelper implements SearchHelper {
private static final String DATABASE_NAME = "search";
private static final String SEARCH_TABLE = "entries";
private static final int DATABASE_VERSION = 3;
@@ -104,18 +105,30 @@ private void initOmitBackup() {
}
- public SearchDbHelper open() throws SQLException {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#open()
+ */
+ @Override
+ public SearchHelper open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
mDb.execSQL(PRAGMA_NO_SYNCHRONOUS);
return this;
}
- public void close() {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#close()
+ */
+ @Override
+ public void close() {
mDb.close();
}
- public void clear() {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#clear()
+ */
+ @Override
+ public void clear() {
mDb.delete(SEARCH_TABLE, null, null);
initOmitBackup();
}
@@ -135,14 +148,22 @@ private ContentValues buildNewEntryContent(PwDatabase db, PwEntry entry) {
return cv;
}
- public void insertEntry(PwDatabase db, PwEntry entry) {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#insertEntry(com.keepassdroid.database.PwDatabase, com.keepassdroid.database.PwEntry)
+ */
+ @Override
+ public void insertEntry(PwDatabase db, PwEntry entry) {
if (!isOmitBackup || !db.isBackup(entry.getParent())) {
ContentValues cv = buildNewEntryContent(db, entry);
mDb.insert(SEARCH_TABLE, null, cv);
}
}
- public void insertEntry(PwDatabase db, List extends PwEntry> entries) {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#insertEntry(com.keepassdroid.database.PwDatabase, java.util.List)
+ */
+ @Override
+ public void insertEntry(PwDatabase db, List extends PwEntry> entries) {
mDb.beginTransaction();
try {
@@ -155,21 +176,33 @@ public void insertEntry(PwDatabase db, List extends PwEntry> entries) {
}
}
- public void updateEntry(PwDatabase db, PwEntry entry) {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#updateEntry(com.keepassdroid.database.PwDatabase, com.keepassdroid.database.PwEntry)
+ */
+ @Override
+ public void updateEntry(PwDatabase db, PwEntry entry) {
ContentValues cv = buildNewEntryContent(db, entry);
String uuidStr = cv.getAsString(KEY_UUID);
mDb.update(SEARCH_TABLE, cv, KEY_UUID + " = ?", new String[] {uuidStr});
}
- public void deleteEntry(PwEntry entry) {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#deleteEntry(com.keepassdroid.database.PwEntry)
+ */
+ @Override
+ public void deleteEntry(PwEntry entry) {
UUID uuid = entry.getUUID();
String uuidStr = uuid.toString();
mDb.delete(SEARCH_TABLE, KEY_UUID + " = ?", new String[] {uuidStr});
}
- public PwGroup search(Database db, String qStr) {
+ /* (non-Javadoc)
+ * @see com.keepassdroid.search.SearchHelper#search(com.keepassdroid.Database, java.lang.String)
+ */
+ @Override
+ public PwGroup search(Database db, String qStr) {
Cursor cursor;
String queryWithWildCard = addWildCard(qStr);
diff --git a/src/com/keepassdroid/search/SearchHelper.java b/src/com/keepassdroid/search/SearchHelper.java
new file mode 100644
index 000000000..ad41ddc4b
--- /dev/null
+++ b/src/com/keepassdroid/search/SearchHelper.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2009-2011 Brian Pellin.
+ * Copyright 2011 riku salkia
+ *
+ * This file is part of KeePassDroid.
+ *
+ * KeePassDroid is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * KeePassDroid is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with KeePassDroid. If not, see .
+ *
+ */
+package com.keepassdroid.search;
+
+import java.util.List;
+
+import com.keepassdroid.Database;
+import com.keepassdroid.database.PwDatabase;
+import com.keepassdroid.database.PwEntry;
+import com.keepassdroid.database.PwGroup;
+
+public interface SearchHelper {
+
+ /**
+ * Called before insert/update/delete for opening a backing resource (database/file/whatever)
+ * @return this
+ */
+ public abstract SearchHelper open();
+
+ /**
+ * Called after insert/update/delete for closing backing resource (database/file/whatever)
+ * @return this
+ */
+ public abstract void close();
+
+ public abstract void clear();
+
+ public abstract void insertEntry(PwDatabase db, PwEntry entry);
+
+ public abstract void insertEntry(PwDatabase db, List extends PwEntry> entries);
+
+ public abstract void updateEntry(PwDatabase db, PwEntry entry);
+
+ public abstract void deleteEntry(PwEntry entry);
+
+ public abstract PwGroup search(Database db, String qStr);
+
+}
\ No newline at end of file
diff --git a/src/org/bouncycastle/asn1/ASN1OctetString.java b/src/org/bouncycastle/asn1/ASN1OctetString.java
index d235458e1..f4cde8d0f 100644
--- a/src/org/bouncycastle/asn1/ASN1OctetString.java
+++ b/src/org/bouncycastle/asn1/ASN1OctetString.java
@@ -37,7 +37,6 @@ public static ASN1OctetString getInstance(
* @param obj the object we want converted.
* @exception IllegalArgumentException if the object cannot be converted.
*/
- @SuppressWarnings("unchecked")
public static ASN1OctetString getInstance(
Object obj)
{
@@ -53,8 +52,8 @@ public static ASN1OctetString getInstance(
if (obj instanceof ASN1Sequence)
{
- Vector v = new Vector();
- Enumeration e = ((ASN1Sequence)obj).getObjects();
+ Vector v = new Vector();
+ Enumeration e = ((ASN1Sequence)obj).getObjects();
while (e.hasMoreElements())
{
diff --git a/src/org/bouncycastle/asn1/ASN1Sequence.java b/src/org/bouncycastle/asn1/ASN1Sequence.java
index da80adec3..b48a54949 100644
--- a/src/org/bouncycastle/asn1/ASN1Sequence.java
+++ b/src/org/bouncycastle/asn1/ASN1Sequence.java
@@ -4,11 +4,10 @@
import java.util.Enumeration;
import java.util.Vector;
-@SuppressWarnings("unchecked")
public abstract class ASN1Sequence
extends ASN1Object
{
- private Vector seq = new Vector();
+ private Vector seq = new Vector();
/**
* return an ASN1Sequence from the given object.
@@ -86,7 +85,7 @@ public static ASN1Sequence getInstance(
throw new IllegalArgumentException("unknown object in getInstance: " + obj.getClass().getName());
}
- public Enumeration getObjects()
+ public Enumeration getObjects()
{
return seq.elements();
}
@@ -152,7 +151,7 @@ public int size()
public int hashCode()
{
- Enumeration e = this.getObjects();
+ Enumeration e = this.getObjects();
int hashCode = size();
while (e.hasMoreElements())
@@ -183,8 +182,8 @@ boolean asn1Equals(
return false;
}
- Enumeration s1 = this.getObjects();
- Enumeration s2 = other.getObjects();
+ Enumeration s1 = this.getObjects();
+ Enumeration s2 = other.getObjects();
while (s1.hasMoreElements())
{
diff --git a/src/org/bouncycastle/asn1/ASN1Set.java b/src/org/bouncycastle/asn1/ASN1Set.java
index 2eaafe0ec..2f3496b42 100644
--- a/src/org/bouncycastle/asn1/ASN1Set.java
+++ b/src/org/bouncycastle/asn1/ASN1Set.java
@@ -5,11 +5,10 @@
import java.util.Enumeration;
import java.util.Vector;
-@SuppressWarnings("unchecked")
abstract public class ASN1Set
extends ASN1Object
{
- protected Vector set = new Vector();
+ protected Vector