Search in sources :

Example 1 with AutofillId

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());
}
Also used : RemoteViews(android.widget.RemoteViews) FillResponse(android.service.autofill.FillResponse) AssistStructure(android.app.assist.AssistStructure) IntentSender(android.content.IntentSender) AutofillId(android.view.autofill.AutofillId)

Example 2 with AutofillId

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;
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Dataset(android.service.autofill.Dataset) AutofillValue(android.view.autofill.AutofillValue) AutofillId(android.view.autofill.AutofillId) Nullable(android.support.annotation.Nullable)

Example 3 with AutofillId

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;
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Dataset(android.service.autofill.Dataset) ArrayList(java.util.ArrayList) AutofillValue(android.view.autofill.AutofillValue) AutofillId(android.view.autofill.AutofillId) Nullable(android.support.annotation.Nullable)

Example 4 with AutofillId

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());
    }
}
Also used : RemoteViews(android.widget.RemoteViews) FillResponse(android.service.autofill.FillResponse) FillContext(android.service.autofill.FillContext) AssistStructure(android.app.assist.AssistStructure) AutofillId(android.view.autofill.AutofillId) IntentSender(android.content.IntentSender)

Aggregations

AutofillId (android.view.autofill.AutofillId)4 RemoteViews (android.widget.RemoteViews)4 AssistStructure (android.app.assist.AssistStructure)2 IntentSender (android.content.IntentSender)2 Dataset (android.service.autofill.Dataset)2 FillResponse (android.service.autofill.FillResponse)2 Nullable (android.support.annotation.Nullable)2 AutofillValue (android.view.autofill.AutofillValue)2 FillContext (android.service.autofill.FillContext)1 ArrayList (java.util.ArrayList)1