Search in sources :

Example 1 with PwGroup

use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.

the class SearchTest method testBackupExcluded.

public void testBackupExcluded() {
    updateOmitSetting(true);
    PwGroup results = mDb.Search("BackupOnly");
    assertFalse("Search result found, but should not have been.", results.numbersOfChildEntries() > 0);
}
Also used : PwGroup(com.keepassdroid.database.PwGroup)

Example 2 with PwGroup

use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.

the class SearchTest method testBackupIncluded.

public void testBackupIncluded() {
    updateOmitSetting(false);
    PwGroup results = mDb.Search("BackupOnly");
    assertTrue("Search result not found.", results.numbersOfChildEntries() > 0);
}
Also used : PwGroup(com.keepassdroid.database.PwGroup)

Example 3 with PwGroup

use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.

the class DeleteEntry method testDelete.

public void testDelete() {
    Database db;
    Context ctx = getContext();
    try {
        db = TestData.GetDb(ctx, ASSET, PASSWORD, KEYFILE, FILENAME);
    } catch (Exception e) {
        assertTrue("Failed to open database: " + e.getMessage(), false);
        return;
    }
    PwDatabaseV3 pm = (PwDatabaseV3) db.pm;
    PwGroup group1 = getGroup(pm, GROUP1_NAME);
    assertNotNull("Could not find group1", group1);
    // Delete the group
    DeleteGroup task = new DeleteGroup(db, group1, null, true);
    task.run();
    // Verify the entries were deleted
    PwEntry entry1 = getEntry(pm, ENTRY1_NAME);
    assertNull("Entry 1 was not removed", entry1);
    PwEntry entry2 = getEntry(pm, ENTRY2_NAME);
    assertNull("Entry 2 was not removed", entry2);
    // Verify the entries were removed from the search index
    SearchDbHelper dbHelp = new SearchDbHelper(ctx);
    PwGroup results1 = dbHelp.search(db, ENTRY1_NAME);
    PwGroup results2 = dbHelp.search(db, ENTRY2_NAME);
    assertEquals("Entry1 was not removed from the search results", 0, results1.numbersOfChildEntries());
    assertEquals("Entry2 was not removed from the search results", 0, results2.numbersOfChildEntries());
    // Verify the group was deleted
    group1 = getGroup(pm, GROUP1_NAME);
    assertNull("Group 1 was not removed.", group1);
}
Also used : Context(android.content.Context) PwDatabaseV3(com.keepassdroid.database.PwDatabaseV3) SearchDbHelper(com.keepassdroid.search.SearchDbHelper) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) PwEntry(com.keepassdroid.database.PwEntry) PwGroup(com.keepassdroid.database.PwGroup) DeleteGroup(com.keepassdroid.database.edit.DeleteGroup)

Example 4 with PwGroup

use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.

the class PwDbV3Output method outputPlanGroupAndEntries.

public void outputPlanGroupAndEntries(OutputStream os) throws PwDbOutputException {
    LEDataOutputStream los = new LEDataOutputStream(os);
    if (useHeaderHash() && headerHashBlock != null) {
        try {
            los.writeUShort(0x0000);
            los.writeInt(headerHashBlock.length);
            los.write(headerHashBlock);
        } catch (IOException e) {
            throw new PwDbOutputException("Failed to output header hash: " + e.getMessage());
        }
    }
    // Groups
    List<PwGroup> groups = mPM.getGroups();
    for (int i = 0; i < groups.size(); i++) {
        PwGroupV3 pg = (PwGroupV3) groups.get(i);
        PwGroupOutputV3 pgo = new PwGroupOutputV3(pg, os);
        try {
            pgo.output();
        } catch (IOException e) {
            throw new PwDbOutputException("Failed to output a tree: " + e.getMessage());
        }
    }
    // Entries
    for (int i = 0; i < mPM.entries.size(); i++) {
        PwEntryV3 pe = (PwEntryV3) mPM.entries.get(i);
        PwEntryOutputV3 peo = new PwEntryOutputV3(pe, os);
        try {
            peo.output();
        } catch (IOException e) {
            throw new PwDbOutputException("Failed to output an entry.");
        }
    }
}
Also used : LEDataOutputStream(com.keepassdroid.stream.LEDataOutputStream) PwGroupV3(com.keepassdroid.database.PwGroupV3) PwEntryV3(com.keepassdroid.database.PwEntryV3) PwDbOutputException(com.keepassdroid.database.exception.PwDbOutputException) PwGroup(com.keepassdroid.database.PwGroup) IOException(java.io.IOException)

Example 5 with PwGroup

use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.

the class SearchDbHelper method search.

public PwGroup search(Database db, String qStr) {
    PwDatabase pm = db.pm;
    PwGroup group;
    if (pm instanceof PwDatabaseV3) {
        group = new PwGroupV3();
    } else if (pm instanceof PwDatabaseV4) {
        group = new PwGroupV4();
    } else {
        Log.d("SearchDbHelper", "Tried to search with unknown db");
        return null;
    }
    group.setName(mCtx.getString(R.string.search_results));
    group.setEntries(new ArrayList<>());
    // Search all entries
    Locale loc = Locale.getDefault();
    qStr = qStr.toLowerCase(loc);
    boolean isOmitBackup = omitBackup();
    Queue<PwGroup> worklist = new LinkedList<PwGroup>();
    if (pm.rootGroup != null) {
        worklist.add(pm.rootGroup);
    }
    while (worklist.size() != 0) {
        PwGroup top = worklist.remove();
        if (pm.isGroupSearchable(top, isOmitBackup)) {
            for (PwEntry entry : top.getChildEntries()) {
                processEntries(entry, group.getChildEntries(), qStr, loc);
            }
            for (PwGroup childGroup : top.getChildGroups()) {
                if (childGroup != null) {
                    worklist.add(childGroup);
                }
            }
        }
    }
    return group;
}
Also used : PwDatabaseV3(com.keepassdroid.database.PwDatabaseV3) Locale(java.util.Locale) PwGroupV3(com.keepassdroid.database.PwGroupV3) PwGroupV4(com.keepassdroid.database.PwGroupV4) PwDatabase(com.keepassdroid.database.PwDatabase) PwEntry(com.keepassdroid.database.PwEntry) PwGroup(com.keepassdroid.database.PwGroup) LinkedList(java.util.LinkedList) PwDatabaseV4(com.keepassdroid.database.PwDatabaseV4)

Aggregations

PwGroup (com.keepassdroid.database.PwGroup)10 PwDatabase (com.keepassdroid.database.PwDatabase)5 Database (com.keepassdroid.database.Database)3 PwEntry (com.keepassdroid.database.PwEntry)3 PwDatabaseV3 (com.keepassdroid.database.PwDatabaseV3)2 PwGroupId (com.keepassdroid.database.PwGroupId)2 PwGroupV3 (com.keepassdroid.database.PwGroupV3)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ScrollView (android.widget.ScrollView)1 PwDatabaseV4 (com.keepassdroid.database.PwDatabaseV4)1 PwEntryV3 (com.keepassdroid.database.PwEntryV3)1 PwGroupV4 (com.keepassdroid.database.PwGroupV4)1 AddEntry (com.keepassdroid.database.edit.AddEntry)1 DeleteGroup (com.keepassdroid.database.edit.DeleteGroup)1 OnFinish (com.keepassdroid.database.edit.OnFinish)1 RunnableOnFinish (com.keepassdroid.database.edit.RunnableOnFinish)1 UpdateEntry (com.keepassdroid.database.edit.UpdateEntry)1