diff --git a/src/com/android/keepass/Database.java b/src/com/android/keepass/Database.java index 37294a615..148873bcf 100644 --- a/src/com/android/keepass/Database.java +++ b/src/com/android/keepass/Database.java @@ -48,15 +48,15 @@ import com.android.keepass.search.SearchDbHelper; * */ public class Database { - public static HashMap> gGroups = new HashMap>(); - public static HashMap> gEntries = new HashMap>(); - public static HashMap> gDirty = new HashMap>(); - public static PwGroup gRoot; - public static PwManager mPM; - public static String mFilename; - public static SearchDbHelper searchHelper; + public HashMap> gGroups = new HashMap>(); + public HashMap> gEntries = new HashMap>(); + public HashMap> gDirty = new HashMap>(); + public PwGroup gRoot; + public PwManager mPM; + public String mFilename; + public SearchDbHelper searchHelper; - public static void LoadData(Context ctx, String filename, String password, String keyfile) throws InvalidCipherTextException, IOException, InvalidKeyFileException, FileNotFoundException { + public void LoadData(Context ctx, String filename, String password, String keyfile) throws InvalidCipherTextException, IOException, InvalidKeyFileException, FileNotFoundException { FileInputStream fis; fis = new FileInputStream(filename); @@ -79,7 +79,7 @@ public class Database { /** Build the search index from the current database * @param ctx */ - private static void buildSearchIndex(Context ctx) { + private void buildSearchIndex(Context ctx) { for ( int i = 0; i < mPM.entries.size(); i++) { @@ -88,7 +88,7 @@ public class Database { } } - public static void NewEntry(PwEntry entry) throws IOException, PwManagerOutputException { + public void NewEntry(PwEntry entry) throws IOException, PwManagerOutputException { PwGroup parent = entry.parent; // Add entry to group @@ -118,7 +118,7 @@ public class Database { searchHelper.insertEntry(entry); } - public static void UndoNewEntry(PwEntry entry) { + public void UndoNewEntry(PwEntry entry) { // Remove from group entry.parent.childEntries.removeElement(entry); @@ -126,7 +126,7 @@ public class Database { mPM.entries.removeElement(entry); } - public static void UpdateEntry(PwEntry oldE, PwEntry newE) throws IOException, PwManagerOutputException { + public void UpdateEntry(PwEntry oldE, PwEntry newE) throws IOException, PwManagerOutputException { // Keep backup of original values in case save fails PwEntry backup = new PwEntry(oldE); @@ -158,16 +158,16 @@ public class Database { } - public static void UndoUpdateEntry(PwEntry old, PwEntry backup) { + public void UndoUpdateEntry(PwEntry old, PwEntry backup) { // If we fail to save, back out changes to global structure old.assign(backup); } - public static void SaveData() throws IOException, PwManagerOutputException { + public void SaveData() throws IOException, PwManagerOutputException { SaveData(mFilename); } - public static void SaveData(String filename) throws IOException, PwManagerOutputException { + public void SaveData(String filename) throws IOException, PwManagerOutputException { File tempFile = new File(filename + ".tmp"); FileOutputStream fos = new FileOutputStream(tempFile); PwManagerOutput pmo = new PwManagerOutput(mPM, fos); @@ -185,7 +185,7 @@ public class Database { } - private static void populateGlobals(PwGroup currentGroup) { + private void populateGlobals(PwGroup currentGroup) { if (currentGroup == null) { Vector rootChildGroups = mPM.getGrpRoots(); for (int i = 0; i < rootChildGroups.size(); i++ ){ @@ -213,7 +213,7 @@ public class Database { } } - public static void clear() { + public void clear() { if ( searchHelper != null ) { searchHelper.close(); searchHelper = null; diff --git a/src/com/android/keepass/EntryActivity.java b/src/com/android/keepass/EntryActivity.java index bb7a468a6..f82b5a6d3 100644 --- a/src/com/android/keepass/EntryActivity.java +++ b/src/com/android/keepass/EntryActivity.java @@ -77,7 +77,7 @@ public class EntryActivity extends LockingActivity { mPos = i.getIntExtra(KEY_REFRESH_POS, -1); assert(uuid != null); - mEntry = Database.gEntries.get(uuid).get(); + mEntry = KeePass.db.gEntries.get(uuid).get(); // Update last access time. Calendar cal = Calendar.getInstance(); diff --git a/src/com/android/keepass/EntryEditActivity.java b/src/com/android/keepass/EntryEditActivity.java index 149660da6..1ad13ea6d 100644 --- a/src/com/android/keepass/EntryEditActivity.java +++ b/src/com/android/keepass/EntryEditActivity.java @@ -81,14 +81,14 @@ public class EntryEditActivity extends LockingActivity { if ( uuidBytes == null ) { int groupId = i.getIntExtra(KEY_PARENT, -1); - mEntry = new PwEntry(groupId); + mEntry = new PwEntry(KeePass.db, groupId); mIsNew = true; } else { UUID uuid = Types.bytestoUUID(uuidBytes); assert(uuid != null); - mEntry = Database.gEntries.get(uuid).get(); + mEntry = KeePass.db.gEntries.get(uuid).get(); mIsNew = false; fillData(); @@ -264,9 +264,9 @@ public class EntryEditActivity extends LockingActivity { public void run() { try { if ( mIsNew ) { - Database.NewEntry(mNew); + KeePass.db.NewEntry(mNew); } else { - Database.UpdateEntry(mOld, mNew); + KeePass.db.UpdateEntry(mOld, mNew); } uiHandler.post(new AfterSave()); diff --git a/src/com/android/keepass/GroupActivity.java b/src/com/android/keepass/GroupActivity.java index 39b21b84c..cdf4e3cb6 100644 --- a/src/com/android/keepass/GroupActivity.java +++ b/src/com/android/keepass/GroupActivity.java @@ -56,8 +56,8 @@ public class GroupActivity extends LockingListActivity { protected void onResume() { super.onResume(); - if ( Database.gDirty.get(mGroup) != null ) { - Database.gDirty.remove(mGroup); + if ( KeePass.db.gDirty.get(mGroup) != null ) { + KeePass.db.gDirty.remove(mGroup); BaseAdapter adapter = (BaseAdapter) getListAdapter(); adapter.notifyDataSetChanged(); @@ -86,9 +86,9 @@ public class GroupActivity extends LockingListActivity { assert(mId >= 0); if ( id == -1 ) { - mGroup = Database.gRoot; + mGroup = KeePass.db.gRoot; } else { - WeakReference wPw = Database.gGroups.get(id); + WeakReference wPw = KeePass.db.gGroups.get(id); mGroup = wPw.get(); } assert(mGroup != null); diff --git a/src/com/android/keepass/KeePass.java b/src/com/android/keepass/KeePass.java index 507d7189a..450aa2aaa 100644 --- a/src/com/android/keepass/KeePass.java +++ b/src/com/android/keepass/KeePass.java @@ -32,6 +32,8 @@ public class KeePass extends Activity { public static final int EXIT_LOCK = 1; public static final int EXIT_REFRESH = 2; public static final int EXIT_REFRESH_TITLE = 3; + + public static Database db = new Database(); @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/src/com/android/keepass/LockManager.java b/src/com/android/keepass/LockManager.java index 7b47e310a..a18d3455c 100644 --- a/src/com/android/keepass/LockManager.java +++ b/src/com/android/keepass/LockManager.java @@ -39,7 +39,7 @@ public class LockManager { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if ( action.equals(TimeoutIntents.LOCK) ) { - Database.clear(); + KeePass.db.clear(); mAct.setResult(KeePass.EXIT_LOCK); mAct.finish(); } diff --git a/src/com/android/keepass/PasswordActivity.java b/src/com/android/keepass/PasswordActivity.java index a97a6a48d..1a35ed1e8 100644 --- a/src/com/android/keepass/PasswordActivity.java +++ b/src/com/android/keepass/PasswordActivity.java @@ -80,7 +80,7 @@ public class PasswordActivity extends Activity { finish(); } - Database.clear(); + KeePass.db.clear(); } @Override @@ -255,7 +255,7 @@ public class PasswordActivity extends Activity { @Override public void run() { try { - Database.LoadData(PasswordActivity.this, mFileName, mPass, mKey); + KeePass.db.LoadData(PasswordActivity.this, mFileName, mPass, mKey); saveFileData(mFileName, mKey); uiHandler.post(new AfterLoad()); diff --git a/src/com/android/keepass/search/SearchDbHelper.java b/src/com/android/keepass/search/SearchDbHelper.java index 21452833d..b713b3341 100644 --- a/src/com/android/keepass/search/SearchDbHelper.java +++ b/src/com/android/keepass/search/SearchDbHelper.java @@ -122,7 +122,7 @@ public class SearchDbHelper { } - public PwGroup search(String qStr) { + public PwGroup search(Database db, String qStr) { Cursor cursor; cursor = mDb.query(true, SEARCH_TABLE, new String[] {KEY_UUID}, "match ?", new String[] {qStr}, null, null, null, null); @@ -134,7 +134,7 @@ public class SearchDbHelper { byte[] bUuid = cursor.getBlob(0); UUID uuid = Types.bytestoUUID(bUuid); - PwEntry entry = Database.gEntries.get(uuid).get(); + PwEntry entry = db.gEntries.get(uuid).get(); group.childEntries.add(entry); cursor.moveToNext(); diff --git a/src/org/phoneid/keepassj2me/PwEntry.java b/src/org/phoneid/keepassj2me/PwEntry.java index 930784789..22e8a836f 100644 --- a/src/org/phoneid/keepassj2me/PwEntry.java +++ b/src/org/phoneid/keepassj2me/PwEntry.java @@ -81,9 +81,9 @@ public class PwEntry { assign(source); } - public PwEntry(int parentId) { + public PwEntry(Database db, int parentId) { - WeakReference wPw = Database.gGroups.get(parentId); + WeakReference wPw = db.gGroups.get(parentId); parent = wPw.get(); groupId = parentId;