private void AddDisableDataset(string query, AutofillId[] autofillIds, FillResponse.Builder responseBuilder, bool isManual) { bool isQueryDisabled = IsQueryDisabled(query); if (isQueryDisabled && !isManual) { return; } bool isForDisable = !isQueryDisabled; var sender = IntentBuilder.GetDisableIntentSenderForResponse(this, query, isManual, isForDisable); RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, GetString(isForDisable ? Resource.String.autofill_disable : Resource.String.autofill_enable_for, new Java.Lang.Object[] { GetDisplayNameForQuery(query, this) }), Resource.Drawable.ic_menu_close_grey); var datasetBuilder = new Dataset.Builder(presentation); datasetBuilder.SetAuthentication(sender); foreach (var autofillId in autofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } responseBuilder.AddDataset(datasetBuilder.Build()); }
private List <Dataset> BuildEntryDatasets(string query, string queryDomain, string queryPackage, AutofillId[] autofillIds, StructureParser parser, DisplayWarning warning) { List <Dataset> result = new List <Dataset>(); Kp2aLog.Log("AF: BuildEntryDatasets"); var suggestedEntries = GetSuggestedEntries(query).ToDictionary(e => e.DatasetName, e => e); Kp2aLog.Log("AF: BuildEntryDatasets found " + suggestedEntries.Count + " entries"); foreach (var filledAutofillFieldCollection in suggestedEntries.Values) { if (filledAutofillFieldCollection == null) { continue; } if (warning == DisplayWarning.None) { FilledAutofillFieldCollection partitionData = AutofillHintsHelper.FilterForPartition(filledAutofillFieldCollection, parser.AutofillFields.FocusedAutofillCanonicalHints); Kp2aLog.Log("AF: Add dataset"); result.Add(AutofillHelper.NewDataset(this, parser.AutofillFields, partitionData, IntentBuilder)); } else { //return an "auth" dataset (actually for just warning the user in case domain/package dont match) var sender = IntentBuilder.GetAuthIntentSenderForWarning(this, query, queryDomain, queryPackage, warning); var datasetName = filledAutofillFieldCollection.DatasetName; if (datasetName == null) { Kp2aLog.Log("AF: dataset name is null"); continue; } RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, datasetName, AppNames.LauncherIcon); var datasetBuilder = new Dataset.Builder(presentation); datasetBuilder.SetAuthentication(sender); //need to add placeholders so we can directly fill after ChooseActivity foreach (var autofillId in autofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } Kp2aLog.Log("AF: Add auth dataset"); result.Add(datasetBuilder.Build()); } } return(result); }
private void AddQueryDataset(string query, string queryDomain, string queryPackage, bool isManual, AutofillId[] autofillIds, FillResponse.Builder responseBuilder, bool autoReturnFromQuery, DisplayWarning warning) { var sender = IntentBuilder.GetAuthIntentSenderForResponse(this, query, queryDomain, queryPackage, isManual, autoReturnFromQuery, warning); RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, GetString(Resource.String.autofill_sign_in_prompt), AppNames.LauncherIcon); var datasetBuilder = new Dataset.Builder(presentation); datasetBuilder.SetAuthentication(sender); //need to add placeholders so we can directly fill after ChooseActivity foreach (var autofillId in autofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } responseBuilder.AddDataset(datasetBuilder.Build()); }
private Dataset BuildEntryDataset(string query, string queryDomain, string queryPackage, AutofillId[] autofillIds, StructureParser parser, DisplayWarning warning) { var filledAutofillFieldCollection = GetSuggestedEntry(query); if (filledAutofillFieldCollection == null) { return(null); } if (warning == DisplayWarning.None) { //can return an actual dataset int partitionIndex = AutofillHintsHelper.GetPartitionIndex(parser.AutofillFields.FocusedAutofillCanonicalHints.FirstOrDefault()); FilledAutofillFieldCollection partitionData = AutofillHintsHelper.FilterForPartition(filledAutofillFieldCollection, partitionIndex); return(AutofillHelper.NewDataset(this, parser.AutofillFields, partitionData, IntentBuilder)); } else { //return an "auth" dataset (actually for just warning the user in case domain/package dont match) var sender = IntentBuilder.GetAuthIntentSenderForWarning(this, query, queryDomain, queryPackage, warning); var datasetName = filledAutofillFieldCollection.DatasetName; if (datasetName == null) { return(null); } RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, datasetName, AppNames.LauncherIcon); var datasetBuilder = new Dataset.Builder(presentation); datasetBuilder.SetAuthentication(sender); //need to add placeholders so we can directly fill after ChooseActivity foreach (var autofillId in autofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } return(datasetBuilder.Build()); } }
public override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback) { bool isManual = (request.Flags & FillRequest.FlagManualRequest) != 0; CommonUtil.logd("onFillRequest " + (isManual ? "manual" : "auto")); var structure = request.FillContexts[request.FillContexts.Count - 1].Structure; //TODO support package signature verification as soon as this is supported in Keepass storage var clientState = request.ClientState; CommonUtil.logd("onFillRequest(): data=" + CommonUtil.BundleToString(clientState)); cancellationSignal.CancelEvent += (sender, e) => { Log.Warn(CommonUtil.Tag, "Cancel autofill not implemented yet."); }; // Parse AutoFill data in Activity string query = null; var parser = new StructureParser(this, structure); try { query = parser.ParseForFill(isManual); } catch (Java.Lang.SecurityException e) { Log.Warn(CommonUtil.Tag, "Security exception handling request"); callback.OnFailure(e.Message); return; } AutofillFieldMetadataCollection autofillFields = parser.AutofillFields; bool responseAuth = true; var autofillIds = autofillFields.GetAutofillIds(); if (responseAuth && autofillIds.Length != 0 && CanAutofill(query)) { var responseBuilder = new FillResponse.Builder(); var sender = IntentBuilder.GetAuthIntentSenderForResponse(this, query, isManual); RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, GetString(Resource.String.autofill_sign_in_prompt), AppNames.LauncherIcon); var datasetBuilder = new Dataset.Builder(presentation); datasetBuilder.SetAuthentication(sender); //need to add placeholders so we can directly fill after ChooseActivity foreach (var autofillId in autofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } responseBuilder.AddDataset(datasetBuilder.Build()); callback.OnSuccess(responseBuilder.Build()); } else { var datasetAuth = true; var response = AutofillHelper.NewResponse(this, datasetAuth, autofillFields, null, IntentBuilder); callback.OnSuccess(response); } }