diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d81e978a8..7938e4fd8 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -34,6 +34,12 @@
+
+
+
+
+
diff --git a/src/com/keepassdroid/Database.java b/src/com/keepassdroid/Database.java
index db576e3a1..6de95e890 100644
--- a/src/com/keepassdroid/Database.java
+++ b/src/com/keepassdroid/Database.java
@@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.HashMap;
+import java.util.List;
import java.util.UUID;
import java.util.Vector;
@@ -47,7 +48,6 @@ import com.keepassdroid.database.exception.Kdb4Exception;
import com.keepassdroid.database.exception.PwDbOutputException;
import com.keepassdroid.database.load.Importer;
import com.keepassdroid.database.load.ImporterFactory;
-import com.keepassdroid.database.load.ImporterV3;
import com.keepassdroid.database.save.PwDbOutput;
import com.keepassdroid.search.SearchDbHelper;
@@ -112,14 +112,17 @@ public class Database {
Importer imp = ImporterFactory.createImporter(bis, debug);
-
+
+ /*
ImporterV3 Importer;
Importer = (ImporterV3) imp; // Remove me when V4 support is in
+ */
bis.reset(); // Return to the start
- pm = Importer.openDatabase(bis, password, keyfile, status);
+ pm = imp.openDatabase(bis, password, keyfile, status);
if ( pm != null ) {
+ root = pm.rootGroup;
populateGlobals(null);
}
@@ -192,7 +195,6 @@ public class Database {
Vector extends PwGroup> rootChildGroups = pm.getGrpRoots();
for (int i = 0; i < rootChildGroups.size(); i++ ){
PwGroup cur = rootChildGroups.elementAt(i);
- root = cur.getParent();
groups.put(cur.getId(), new WeakReference(cur));
populateGlobals(cur);
}
@@ -200,16 +202,16 @@ public class Database {
return;
}
- Vector childGroups = currentGroup.childGroups;
- Vector childEntries = currentGroup.childEntries;
+ List childGroups = currentGroup.childGroups;
+ List childEntries = currentGroup.childEntries;
for (int i = 0; i < childEntries.size(); i++ ) {
- PwEntry cur = childEntries.elementAt(i);
+ PwEntry cur = childEntries.get(i);
entries.put(cur.getUUID(), new WeakReference(cur));
}
for (int i = 0; i < childGroups.size(); i++ ) {
- PwGroup cur = childGroups.elementAt(i);
+ PwGroup cur = childGroups.get(i);
groups.put(cur.getId(), new WeakReference(cur));
populateGlobals(cur);
}
diff --git a/src/com/keepassdroid/GroupActivity.java b/src/com/keepassdroid/GroupActivity.java
index 97308cfd6..33cbd8942 100644
--- a/src/com/keepassdroid/GroupActivity.java
+++ b/src/com/keepassdroid/GroupActivity.java
@@ -44,6 +44,7 @@ import com.keepassdroid.database.PwDatabaseV4;
import com.keepassdroid.database.PwGroup;
import com.keepassdroid.database.PwGroupId;
import com.keepassdroid.database.PwGroupV3;
+import com.keepassdroid.database.PwGroupV4;
import com.keepassdroid.database.edit.AddGroup;
public abstract class GroupActivity extends GroupBaseActivity {
@@ -57,16 +58,22 @@ public abstract class GroupActivity extends GroupBaseActivity {
public static void Launch(Activity act, PwGroup group, int mode) {
Intent i;
- PwDatabase pm = App.getDB().pm;
- if ( pm instanceof PwDatabaseV3 ) {
+ // Need to use PwDatabase since group may be null
+ PwDatabase db = App.getDB().pm;
+ if ( db instanceof PwDatabaseV3 ) {
i = new Intent(act, GroupActivityV3.class);
if ( group != null ) {
PwGroupV3 g = (PwGroupV3) group;
i.putExtra(KEY_ENTRY, g.groupId);
}
- } else if ( pm instanceof PwDatabaseV4 ) {
- throw new RuntimeException("Not yet implemented.");
+ } else if ( db instanceof PwDatabaseV4 ) {
+ i = new Intent(act, GroupActivityV4.class);
+
+ if ( group != null ) {
+ PwGroupV4 g = (PwGroupV4) group;
+ i.putExtra(KEY_ENTRY, g.uuid.toString());
+ }
} else {
assert(true); // Should never be reached
throw new RuntimeException("Should never be reached.");
@@ -78,7 +85,6 @@ public abstract class GroupActivity extends GroupBaseActivity {
}
protected abstract PwGroupId retrieveGroupId(Intent i);
- protected abstract PwGroup getGroup();
@Override
protected void onCreate(Bundle savedInstanceState) {
diff --git a/src/com/keepassdroid/GroupActivityV3.java b/src/com/keepassdroid/GroupActivityV3.java
index 97cc7362e..7c6ba62b4 100644
--- a/src/com/keepassdroid/GroupActivityV3.java
+++ b/src/com/keepassdroid/GroupActivityV3.java
@@ -1,18 +1,30 @@
+/*
+ * Copyright 2010 Brian Pellin.
+ *
+ * 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;
import android.content.Intent;
import com.keepassdroid.database.PwGroupIdV3;
-import com.keepassdroid.database.PwGroupV3;
public class GroupActivityV3 extends GroupActivity {
- @Override
- protected PwGroupV3 getGroup() {
-
- return (PwGroupV3) mGroup;
- }
-
@Override
protected PwGroupIdV3 retrieveGroupId(Intent i) {
int id = i.getIntExtra(KEY_ENTRY, -1);
diff --git a/src/com/keepassdroid/GroupActivityV4.java b/src/com/keepassdroid/GroupActivityV4.java
new file mode 100644
index 000000000..5c295fb71
--- /dev/null
+++ b/src/com/keepassdroid/GroupActivityV4.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010 Brian Pellin.
+ *
+ * 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;
+
+import java.util.UUID;
+
+import android.content.Intent;
+
+import com.keepassdroid.database.PwGroupId;
+import com.keepassdroid.database.PwGroupIdV4;
+
+public class GroupActivityV4 extends GroupActivity {
+
+ @Override
+ protected PwGroupId retrieveGroupId(Intent i) {
+ String uuid = i.getStringExtra(KEY_ENTRY);
+
+ if ( uuid == null || uuid.length() == 0 ) {
+ return null;
+ }
+
+ return new PwGroupIdV4(UUID.fromString(uuid));
+ }
+
+}
diff --git a/src/com/keepassdroid/PwListAdapter.java b/src/com/keepassdroid/PwListAdapter.java
index 8bf0e0152..0520aa0df 100644
--- a/src/com/keepassdroid/PwListAdapter.java
+++ b/src/com/keepassdroid/PwListAdapter.java
@@ -26,9 +26,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.keepassdroid.database.PwEntry;
-import com.keepassdroid.database.PwEntryV3;
import com.keepassdroid.database.PwGroup;
-import com.keepassdroid.database.PwGroupV3;
import com.keepassdroid.view.PwEntryView;
import com.keepassdroid.view.PwGroupView;
@@ -64,7 +62,7 @@ public class PwListAdapter extends BaseAdapter {
filteredEntries = new Vector();
for (int i = 0; i < mGroup.childEntries.size(); i++) {
- PwEntryV3 entry = (PwEntryV3) mGroup.childEntries.elementAt(i);
+ PwEntry entry = mGroup.childEntries.get(i);
if ( ! entry.isMetaStream() ) {
filteredEntries.add(entry);
}
@@ -100,26 +98,18 @@ public class PwListAdapter extends BaseAdapter {
private View createGroupView(int position, View convertView) {
PwGroupView gv;
- //if (convertView == null || ! (convertView instanceof PwGroupView)) {
- PwGroupV3 group = (PwGroupV3) mGroup.childGroups.elementAt(position);
- gv = PwGroupView.getInstance(mAct, group);
- /*
- } else {
- gv = (PwGroupView) convertView;
- gv.setGroup((PwGroupV3) mGroup.childGroups.elementAt(position));
- }
- */
+
+ PwGroup group = mGroup.childGroups.get(position);
+ gv = PwGroupView.getInstance(mAct, group);
+
return gv;
}
private PwEntryView createEntryView(int position, View convertView) {
PwEntryView ev;
-// if (convertView == null || ! (convertView instanceof PwEntryView) ) {
- ev = PwEntryView.getInstance(mAct, filteredEntries.elementAt(position), position);
-// } else {
-// ev = (PwEntryView) convertView;
-// ev.setEntry(filteredEntries.elementAt(position));
-// }
+
+ ev = PwEntryView.getInstance(mAct, filteredEntries.elementAt(position), position);
+
return ev;
}
diff --git a/src/com/keepassdroid/database/PwDatabase.java b/src/com/keepassdroid/database/PwDatabase.java
index 57386e0db..89143b31c 100644
--- a/src/com/keepassdroid/database/PwDatabase.java
+++ b/src/com/keepassdroid/database/PwDatabase.java
@@ -39,6 +39,7 @@ public abstract class PwDatabase {
public byte masterKey[] = new byte[32];
public byte[] finalKey;
public String name = "KeePass database";
+ public PwGroup rootGroup;
public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, int numRounds) throws IOException {
diff --git a/src/com/keepassdroid/database/PwDatabaseV3.java b/src/com/keepassdroid/database/PwDatabaseV3.java
index c144e5d63..886a5c2fb 100644
--- a/src/com/keepassdroid/database/PwDatabaseV3.java
+++ b/src/com/keepassdroid/database/PwDatabaseV3.java
@@ -61,8 +61,6 @@ public class PwDatabaseV3 extends PwDatabase {
// Debugging entries
public PwDbHeaderV3 dbHeader;
- // root group
- public PwGroupV3 rootGroup;
public int getAlgorithm() {
return algorithm;
@@ -159,15 +157,17 @@ public class PwDatabaseV3 extends PwDatabase {
{
// I'm in root
if (currentGroup == null) {
- rootGroup = new PwGroupV3();
+ PwGroupV3 root = new PwGroupV3();
+ rootGroup = root;
+
Vector rootChildGroups = getGrpRoots();
- rootGroup.setGroups(rootChildGroups);
- rootGroup.childEntries = new Vector();
- rootGroup.level = -1;
+ root.setGroups(rootChildGroups);
+ root.childEntries = new Vector();
+ root.level = -1;
for (int i=0; i groups = new Vector();
- public PwGroupV4 rootGroup;
-
@Override
public byte[] getMasterKey(String key, String keyFileName)
throws InvalidKeyFileException, IOException {
@@ -118,15 +113,12 @@ public class PwDatabaseV4 extends PwDatabase {
@Override
public Vector getGroups() {
Vector list = new Vector();
- rootGroup.buildChildGroupsRecursive(list);
+ PwGroupV4 root = (PwGroupV4) rootGroup;
+ root.buildChildGroupsRecursive(list);
return list;
}
- public void parseDB(InputStream in) throws InconsistentDBException {
- //TODO Implement Me
- }
-
@Override
public Vector getGrpRoots() {
return rootGroup.childGroups;
@@ -135,7 +127,8 @@ public class PwDatabaseV4 extends PwDatabase {
@Override
public Vector getEntries() {
Vector list = new Vector();
- rootGroup.buildChildEntriesRecursive(list);
+ PwGroupV4 root = (PwGroupV4) rootGroup;
+ root.buildChildEntriesRecursive(list);
return list;
}
diff --git a/src/com/keepassdroid/database/PwEntry.java b/src/com/keepassdroid/database/PwEntry.java
index 872c18f9e..545f3fadb 100644
--- a/src/com/keepassdroid/database/PwEntry.java
+++ b/src/com/keepassdroid/database/PwEntry.java
@@ -73,4 +73,8 @@ public abstract class PwEntry implements Cloneable {
public abstract String getDisplayTitle();
+ public boolean isMetaStream() {
+ return false;
+ }
+
}
diff --git a/src/com/keepassdroid/database/PwEntryV3.java b/src/com/keepassdroid/database/PwEntryV3.java
index 265ea4065..cd5d9b3e3 100644
--- a/src/com/keepassdroid/database/PwEntryV3.java
+++ b/src/com/keepassdroid/database/PwEntryV3.java
@@ -223,7 +223,8 @@ public class PwEntryV3 extends PwEntry {
System.arraycopy( buf, offset, binaryData, 0, len );
}
- // Determine if this is a MetaStream entrie
+ // Determine if this is a MetaStream entry
+ @Override
public boolean isMetaStream() {
if ( binaryData == null ) return false;
if ( additional == null || additional.length() == 0 ) return false;
diff --git a/src/com/keepassdroid/database/PwGroupV4.java b/src/com/keepassdroid/database/PwGroupV4.java
index 304057d81..a92f6a43f 100644
--- a/src/com/keepassdroid/database/PwGroupV4.java
+++ b/src/com/keepassdroid/database/PwGroupV4.java
@@ -19,9 +19,7 @@
*/
package com.keepassdroid.database;
-import java.util.ArrayList;
import java.util.Date;
-import java.util.List;
import java.util.UUID;
import java.util.Vector;
@@ -46,10 +44,6 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
private boolean expires = false;
private long usageCount = 0;
-
- public List listGroups = new ArrayList();
- public List listEntries = new ArrayList();
-
public PwGroupV4() {
}
@@ -61,7 +55,7 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
public void AddGroup(PwGroupV4 subGroup, boolean takeOwnership, boolean updateLocationChanged) {
if ( subGroup == null ) throw new RuntimeException("subGroup");
- listGroups.add(subGroup);
+ childGroups.add(subGroup);
if ( takeOwnership ) subGroup.parent = this;
@@ -76,7 +70,7 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
public void AddEntry(PwEntryV4 pe, boolean takeOwnership, boolean updateLocationChanged) {
assert(pe != null);
- listEntries.add(pe);
+ childEntries.add(pe);
if ( takeOwnership ) pe.parent = this;
diff --git a/src/com/keepassdroid/database/edit/AddEntry.java b/src/com/keepassdroid/database/edit/AddEntry.java
index c92ce11da..bdca221f7 100644
--- a/src/com/keepassdroid/database/edit/AddEntry.java
+++ b/src/com/keepassdroid/database/edit/AddEntry.java
@@ -86,7 +86,7 @@ public abstract class AddEntry extends RunnableOnFinish {
}
} else {
// Remove from group
- mEntry.getParent().childEntries.removeElement(mEntry);
+ mEntry.getParent().childEntries.remove(mEntry);
// Remove from manager
mDb.pm.getEntries().removeElement(mEntry);
diff --git a/src/com/keepassdroid/database/load/ImporterFactory.java b/src/com/keepassdroid/database/load/ImporterFactory.java
index 4ca83dc7e..897b6eeeb 100644
--- a/src/com/keepassdroid/database/load/ImporterFactory.java
+++ b/src/com/keepassdroid/database/load/ImporterFactory.java
@@ -42,7 +42,8 @@ public class ImporterFactory {
if ( PwDbHeaderV3.matchesHeader(sig1, sig2) ) {
return new ImporterV3(debug);
} else if ( PwDbHeaderV4.matchesHeader(sig1, sig2) ) {
- throw new Kdb4Exception();
+ return new ImporterV4();
+ //throw new Kdb4Exception();
//return new ImporterV4();
}
diff --git a/src/com/keepassdroid/database/load/ImporterV4.java b/src/com/keepassdroid/database/load/ImporterV4.java
index e3598ce1e..56edd4edf 100644
--- a/src/com/keepassdroid/database/load/ImporterV4.java
+++ b/src/com/keepassdroid/database/load/ImporterV4.java
@@ -464,7 +464,7 @@ public class ImporterV4 extends Importer {
if ( ctxGroups.size() != 0 ) throw new IOException("Group list should be empty.");
db.rootGroup = new PwGroupV4();
- ctxGroups.push(db.rootGroup);
+ ctxGroups.push((PwGroupV4)db.rootGroup);
ctxGroup = ctxGroups.peek();
return SwitchContext(ctx, KdbContext.Group, xpp);