Scope Android autofill candidates
This commit is contained in:
@@ -10,9 +10,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
final class AutofillCacheStore {
|
||||
private static final String TAG = "KeePassGOAutofill";
|
||||
@@ -41,21 +39,25 @@ final class AutofillCacheStore {
|
||||
}
|
||||
|
||||
static List<Entry> chooserCandidates(Context context, String rawTarget) {
|
||||
List<Entry> entries = readEntries(context);
|
||||
return chooserCandidatesFromEntries(readEntries(context), rawTarget);
|
||||
}
|
||||
|
||||
static List<Entry> chooserCandidatesFromEntries(List<Entry> entries, String rawTarget) {
|
||||
if (entries.isEmpty()) {
|
||||
return entries;
|
||||
}
|
||||
Entry direct = fromMatcherEntry(AutofillTargetMatcher.findBestMatch(toMatcherEntries(entries), rawTarget));
|
||||
if (direct != null) {
|
||||
List<Entry> resolved = new ArrayList<>();
|
||||
resolved.add(direct);
|
||||
return resolved;
|
||||
return fromMatcherEntries(AutofillTargetMatcher.chooserCandidates(toMatcherEntries(entries), rawTarget));
|
||||
}
|
||||
|
||||
static List<Entry> relevantCandidates(Context context, String rawTarget) {
|
||||
return relevantCandidatesFromEntries(readEntries(context), rawTarget);
|
||||
}
|
||||
|
||||
static List<Entry> relevantCandidatesFromEntries(List<Entry> entries, String rawTarget) {
|
||||
if (entries.isEmpty()) {
|
||||
return entries;
|
||||
}
|
||||
entries.sort(Comparator
|
||||
.comparing((Entry entry) -> entry.title.toLowerCase(Locale.US))
|
||||
.thenComparing(entry -> String.join("/", entry.path).toLowerCase(Locale.US))
|
||||
.thenComparing(entry -> entry.id));
|
||||
return entries;
|
||||
return fromMatcherEntries(AutofillTargetMatcher.relevantCandidates(toMatcherEntries(entries), rawTarget));
|
||||
}
|
||||
|
||||
private static List<AutofillTargetMatcher.Entry> toMatcherEntries(List<Entry> entries) {
|
||||
@@ -82,6 +84,14 @@ final class AutofillCacheStore {
|
||||
return new Entry(entry.id, entry.title, entry.username, entry.password, entry.host, entry.url, entry.targets, entry.path);
|
||||
}
|
||||
|
||||
private static List<Entry> fromMatcherEntries(List<AutofillTargetMatcher.Entry> entries) {
|
||||
List<Entry> converted = new ArrayList<>(entries.size());
|
||||
for (AutofillTargetMatcher.Entry entry : entries) {
|
||||
converted.add(fromMatcherEntry(entry));
|
||||
}
|
||||
return converted;
|
||||
}
|
||||
|
||||
private static List<Entry> readEntries(Context context) {
|
||||
File cacheFile = findCacheFile(context);
|
||||
if (cacheFile == null) {
|
||||
|
||||
Reference in New Issue
Block a user