use of android.view.autofill.AutofillId in project TinyKeePass by sorz.
the class TinyAutofillService method onFillRequest.
@Override
public void onFillRequest(@NonNull FillRequest request, @NonNull CancellationSignal cancellationSignal, @NonNull FillCallback callback) {
cancellationSignal.setOnCancelListener(() -> Log.d(TAG, "autofill canceled."));
if (!hasDatabaseConfigured(this)) {
callback.onSuccess(null);
return;
}
AssistStructure structure = request.getFillContexts().get(request.getFillContexts().size() - 1).getStructure();
StructureParser.Result parseResult = new StructureParser(structure).parse();
if (parseResult.password.isEmpty()) {
Log.d(TAG, "no password field found");
callback.onSuccess(null);
return;
}
FillResponse.Builder responseBuilder = new FillResponse.Builder();
RemoteViews presentation = AutofillUtils.getRemoteViews(this, getString(R.string.autofill_unlock_db), android.R.drawable.ic_lock_lock);
IntentSender sender = AuthActivity.getAuthIntentSenderForResponse(this);
AutofillId[] autofillIds = parseResult.allAutofillIds().toArray(AutofillId[]::new);
responseBuilder.setAuthentication(autofillIds, sender, presentation);
callback.onSuccess(responseBuilder.build());
}
use of android.view.autofill.AutofillId in project TinyKeePass by sorz.
the class AutofillUtils method buildDataset.
@Nullable
static Dataset buildDataset(Context context, Entry entry, StructureParser.Result struct) {
String title = makeEntryTitle(context, entry);
RemoteViews views = getRemoteViews(context, title, R.drawable.ic_person_blue_24dp);
views.setImageViewBitmap(R.id.imageIcon, getIcon(entry));
Dataset.Builder builder = new Dataset.Builder(views);
builder.setId(entry.getUuid().toString());
if (notEmpty(entry.getPassword())) {
AutofillValue value = AutofillValue.forText(entry.getPassword());
struct.password.forEach(id -> builder.setValue(id, value));
}
if (notEmpty(entry.getUsername())) {
AutofillValue value = AutofillValue.forText(entry.getUsername());
Stream<AutofillId> ids = struct.username.stream();
if (entry.getUsername().contains("@") || struct.username.isEmpty())
ids = Stream.concat(ids, struct.email.stream());
ids.forEach(id -> builder.setValue(id, value));
}
try {
return builder.build();
} catch (IllegalArgumentException e) {
// if not value be set
return null;
}
}
use of android.view.autofill.AutofillId in project KeePassDX by Kunzisoft.
the class AutofillHelper method buildDataset.
@Nullable
private Dataset buildDataset(Context context, PwEntry entry, StructureParser.Result struct) {
String title = makeEntryTitle(entry);
RemoteViews views = newRemoteViews(context.getPackageName(), title);
Dataset.Builder builder = new Dataset.Builder(views);
builder.setId(entry.getUUID().toString());
if (entry.getPassword() != null) {
AutofillValue value = AutofillValue.forText(entry.getPassword());
struct.password.forEach(id -> builder.setValue(id, value));
}
if (entry.getUsername() != null) {
AutofillValue value = AutofillValue.forText(entry.getUsername());
List<AutofillId> ids = new ArrayList<>(struct.username);
if (entry.getUsername().contains("@") || struct.username.isEmpty())
ids.addAll(struct.email);
ids.forEach(id -> builder.setValue(id, value));
}
try {
return builder.build();
} catch (IllegalArgumentException e) {
// if not value be set
return null;
}
}
use of android.view.autofill.AutofillId in project KeePassDX by Kunzisoft.
the class KeeAutofillService method onFillRequest.
@Override
public void onFillRequest(@NonNull FillRequest request, @NonNull CancellationSignal cancellationSignal, @NonNull FillCallback callback) {
List<FillContext> fillContexts = request.getFillContexts();
AssistStructure latestStructure = fillContexts.get(fillContexts.size() - 1).getStructure();
cancellationSignal.setOnCancelListener(() -> Log.e(TAG, "Cancel autofill not implemented in this sample."));
FillResponse.Builder responseBuilder = new FillResponse.Builder();
// Check user's settings for authenticating Responses and Datasets.
StructureParser.Result parseResult = new StructureParser(latestStructure).parse();
AutofillId[] autofillIds = parseResult.allAutofillIds();
if (!Arrays.asList(autofillIds).isEmpty()) {
// If the entire Autofill Response is authenticated, AuthActivity is used
// to generate Response.
IntentSender sender = AutoFillAuthActivity.getAuthIntentSenderForResponse(this);
RemoteViews presentation = new RemoteViews(getPackageName(), R.layout.autofill_service_unlock);
responseBuilder.setAuthentication(autofillIds, sender, presentation);
callback.onSuccess(responseBuilder.build());
}
}
Aggregations