use of android.app.assist.AssistStructure in project KeePassDX by Kunzisoft.
the class GroupActivity method onNodeClick.
@Override
public void onNodeClick(PwNode node) {
// Add event when we have Autofill
AssistStructure assistStructure = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
assistStructure = autofillHelper.getAssistStructure();
if (assistStructure != null) {
mAdapter.registerANodeToUpdate(node);
switch(node.getType()) {
case GROUP:
GroupActivity.launch(this, (PwGroup) node, assistStructure);
break;
case ENTRY:
// Build response with the entry selected
autofillHelper.buildResponseWhenEntrySelected(this, (PwEntry) node);
finish();
break;
}
}
}
if (assistStructure == null) {
super.onNodeClick(node);
}
}
use of android.app.assist.AssistStructure in project KeePassDX by Kunzisoft.
the class AutoFillAuthActivity method startFileSelectActivity.
@Override
protected void startFileSelectActivity() {
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent());
if (assistStructure != null) {
FileSelectActivity.launch(this, assistStructure);
} else {
setResult(RESULT_CANCELED);
finish();
}
}
use of android.app.assist.AssistStructure in project KeePassDX by Kunzisoft.
the class AutofillHelper method buildResponseWhenEntrySelected.
/**
* Method to hit when right key is selected
*/
public void buildResponseWhenEntrySelected(Activity activity, PwEntry entry) {
Intent mReplyIntent;
Intent intent = activity.getIntent();
if (isIntentContainsExtraAssistStructureKey(intent)) {
AssistStructure structure = intent.getParcelableExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE);
StructureParser.Result result = new StructureParser(structure).parse();
// New Response
FillResponse.Builder responseBuilder = new FillResponse.Builder();
Dataset dataset = buildDataset(activity, entry, result);
responseBuilder.addDataset(dataset);
mReplyIntent = new Intent();
Log.d(activity.getClass().getName(), "Successed Autofill auth.");
mReplyIntent.putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, responseBuilder.build());
activity.setResult(Activity.RESULT_OK, mReplyIntent);
} else {
Log.w(activity.getClass().getName(), "Failed Autofill auth.");
activity.setResult(Activity.RESULT_CANCELED);
}
}
use of android.app.assist.AssistStructure 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());
}
}
use of android.app.assist.AssistStructure in project passman-android by nextcloud.
the class CredentialAutofillService method onFillRequest.
@Override
public void onFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) {
Log.d(TAG, "onFillRequest()");
List<FillContext> fillContexts = request.getFillContexts();
ArrayList<AssistStructure> structures = new ArrayList<>();
for (FillContext fc : fillContexts) {
structures.add(fc.getStructure());
}
final AssistStructure latestAssistStructure = fillContexts.get(fillContexts.size() - 1).getStructure();
// Find autofillable fields
AutofillFieldCollection fields = getAutofillableFields(latestAssistStructure, false);
final String packageName = getApplicationContext().getPackageName();
final String requesterPackageName = latestAssistStructure.getActivityComponent().getPackageName();
Log.d(TAG, "autofillable fields for: " + requesterPackageName + ": " + fields);
// Passman should not authenticate itself
if (fields.isEmpty() || requesterPackageName.startsWith("es.wolfi.app.passman")) {
Log.d(TAG, "No autofillable fields for: " + requesterPackageName);
callback.onSuccess(null);
return;
}
// Create the base response
FillResponse.Builder response = new FillResponse.Builder();
// Open Vault
SingleTon ton = SingleTon.getTon();
final Vault v = getAutofillVault(ton);
if (v == null) {
Toast.makeText(getApplicationContext(), getString(R.string.autofill_noactivevault), Toast.LENGTH_SHORT).show();
Log.d(TAG, getString(R.string.autofill_noactivevault));
callback.onSuccess(null);
return;
}
if (!v.is_unlocked()) {
Toast.makeText(getApplicationContext(), getString(R.string.autofill_vaultlocked), Toast.LENGTH_SHORT).show();
Log.d(TAG, getString(R.string.autofill_vaultlocked));
callback.onSuccess(null);
return;
}
// If we get here, we have an unlocked vault
Log.d(TAG, "Vault ready to go");
CredentialAutofillService.WebDomainResult domain = getLikelyDomain(structures);
// Grab Credentials from vault
ArrayList<Credential> allCred = v.getCredentials();
if (allCred.isEmpty()) {
Toast.makeText(getApplicationContext(), getString(R.string.autofill_vaultempty), Toast.LENGTH_SHORT).show();
Log.d(TAG, getString(R.string.autofill_vaultempty));
callback.onSuccess(null);
return;
}
// Find the credentials which match the requesting package name
List<Credential> matchingCredentials = findMatchingCredentials(allCred, requesterPackageName, domain);
Log.d(TAG, "Number of matching credentials for package: " + requesterPackageName + ":" + matchingCredentials.size());
/*
* TODO: validate package signature
* (Maybe store apk signature or signing cert thumbprint in custom field)
*/
Set<AutofillId> tempFields = new HashSet<>();
for (Credential thisCred : matchingCredentials) {
String credLabel = returnBestString(thisCred.getLabel(), thisCred.getUrl(), thisCred.getUsername());
Dataset.Builder dataset = new Dataset.Builder();
// simplify into a function
AutofillField bestUsername = fields.getRequiredId(View.AUTOFILL_HINT_USERNAME);
AutofillField bestEmail = fields.getRequiredId(View.AUTOFILL_HINT_EMAIL_ADDRESS);
AutofillField bestPassword = fields.getRequiredId(View.AUTOFILL_HINT_PASSWORD);
if (bestUsername != null) {
String value = returnBestString(thisCred.getUsername(), thisCred.getEmail(), thisCred.getLabel());
buildAndAddPresentation(dataset, packageName, bestUsername, value, credLabel);
tempFields.add(bestUsername.getAutofillid());
}
if (bestEmail != null) {
String value = returnBestString(thisCred.getEmail(), thisCred.getUsername(), thisCred.getLabel());
buildAndAddPresentation(dataset, packageName, bestEmail, value, credLabel);
tempFields.add(bestEmail.getAutofillid());
}
if (bestPassword != null) {
String value = thisCred.getPassword();
buildAndAddPresentation(dataset, packageName, bestPassword, value, "Password for: " + credLabel);
tempFields.add(bestPassword.getAutofillid());
}
if (bestUsername != null || bestEmail != null || bestPassword != null) {
response.addDataset(dataset.build());
}
}
if (tempFields.size() > 0) {
Log.d(TAG, "Requesting save info");
AutofillId[] requiredIds = new AutofillId[tempFields.size()];
tempFields.toArray(requiredIds);
response.setSaveInfo(new SaveInfo.Builder(SaveInfo.SAVE_DATA_TYPE_PASSWORD, requiredIds).setFlags(FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE).build());
Log.d(TAG, "Building and calling success");
callback.onSuccess(response.build());
return;
}
Log.d(TAG, "Failed to find anything to do, bailing");
callback.onSuccess(null);
}
Aggregations