public static Dataset BuildDataset(Context context, FieldCollection fields, FilledItem filledItem, InlinePresentationSpec inlinePresentationSpec = null) { var overlayPresentation = BuildOverlayPresentation( filledItem.Name, filledItem.Subtitle, filledItem.Icon, context); var inlinePresentation = BuildInlinePresentation( inlinePresentationSpec, filledItem.Name, filledItem.Subtitle, filledItem.Icon, null, context); var datasetBuilder = new Dataset.Builder(overlayPresentation); if (inlinePresentation != null) { datasetBuilder.SetInlinePresentation(inlinePresentation); } if (filledItem.ApplyToFields(fields, datasetBuilder)) { return(datasetBuilder.Build()); } return(null); }
private void ParseAutofillFields(AssistStructure.ViewNode viewNode, Dictionary <string, FieldTypeWithHeuristics> fieldTypesByAutofillHint, Dictionary <string, FilledAutofillField> filledAutofillFieldsByTypeName, Dataset.Builder builder, MutableBoolean setValueAtLeastOnce) { var rawHints = viewNode.GetAutofillHints(); if (rawHints == null || rawHints.Length == 0) { Util.Logv("No af hints at ViewNode - %s", viewNode.IdEntry); return; } string fieldTypeName = AutofillHints.GetFieldTypeNameFromAutofillHints( fieldTypesByAutofillHint, rawHints.ToList()); if (fieldTypeName == null) { return; } FilledAutofillField field = filledAutofillFieldsByTypeName[fieldTypeName]; if (field == null) { return; } BindValueToNode(viewNode, field, builder, setValueAtLeastOnce); }
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()); }
/** * Wraps autofill data in a LoginCredential Dataset object which can then be sent back to the * client View. */ public static Dataset NewDataset( Context context, AutofillFieldMetadataCollection autofillFields, FilledAutofillFieldCollection filledAutofillFieldCollection, bool datasetAuth) { var datasetName = filledAutofillFieldCollection.GetDatasetName(); if (datasetName != null) { Dataset.Builder datasetBuilder; if (datasetAuth) { datasetBuilder = new Dataset.Builder (NewRemoteViews(context.PackageName, datasetName, Resource.Drawable.ic_lock_black_24dp)); var sender = AuthActivity.GetAuthIntentSenderForDataset(context, datasetName); datasetBuilder.SetAuthentication(sender); } else { datasetBuilder = new Dataset.Builder (NewRemoteViews(context.PackageName, datasetName, Resource.Drawable.ic_person_black_24dp)); } var setValueAtLeastOnce = filledAutofillFieldCollection.ApplyToFields(autofillFields, datasetBuilder); if (setValueAtLeastOnce) { return(datasetBuilder.Build()); } } return(null); }
/// <summary> /// Wraps autofill data in a LoginCredential Dataset object which can then be sent back to the /// client View. /// </summary> /// <returns>The dataset.</returns> /// <param name="context">Context.</param> /// <param name="autofillFields">Autofill fields.</param> /// <param name="filledAutofillFieldCollection">Filled autofill field collection.</param> public static Dataset NewDataset(Context context, AutofillFieldMetadataCollection autofillFields, FilledAutofillFieldCollection filledAutofillFieldCollection, IAutofillIntentBuilder intentBuilder, Android.Widget.Inline.InlinePresentationSpec inlinePresentationSpec) { var datasetName = filledAutofillFieldCollection.DatasetName ?? "[noname]"; var datasetBuilder = new Dataset.Builder(NewRemoteViews(context.PackageName, datasetName, intentBuilder.AppIconResource)); datasetBuilder.SetId(datasetName); var setValueAtLeastOnce = filledAutofillFieldCollection.ApplyToFields(autofillFields, datasetBuilder); AddInlinePresentation(context, inlinePresentationSpec, datasetName, datasetBuilder, intentBuilder.AppIconResource); if (setValueAtLeastOnce) { return(datasetBuilder.Build()); } else { Kp2aLog.Log("Failed to set at least one value. #fields=" + autofillFields.GetAutofillIds().Length + " " + autofillFields.FocusedAutofillCanonicalHints); } return(null); }
public static Dataset BuildVaultDataset(Context context, FieldCollection fields, string uri, bool locked, IList <InlinePresentationSpec> inlinePresentationSpecs = null) { var intent = new Intent(context, typeof(MainActivity)); intent.PutExtra("autofillFramework", true); if (fields.FillableForLogin) { intent.PutExtra("autofillFrameworkFillType", (int)CipherType.Login); } else if (fields.FillableForCard) { intent.PutExtra("autofillFrameworkFillType", (int)CipherType.Card); } else if (fields.FillableForIdentity) { intent.PutExtra("autofillFrameworkFillType", (int)CipherType.Identity); } else { return(null); } intent.PutExtra("autofillFrameworkUri", uri); var pendingIntent = PendingIntent.GetActivity(context, ++_pendingIntentId, intent, PendingIntentFlags.CancelCurrent); var overlayPresentation = BuildOverlayPresentation( AppResources.AutofillWithBitwarden, locked ? AppResources.VaultIsLocked : AppResources.GoToMyVault, Resource.Drawable.icon, context); var inlinePresentation = BuildInlinePresentation( inlinePresentationSpecs?.Last(), AppResources.Bitwarden, locked ? AppResources.VaultIsLocked : AppResources.MyVault, Resource.Drawable.icon, pendingIntent, context); var datasetBuilder = new Dataset.Builder(overlayPresentation); if (inlinePresentation != null) { datasetBuilder.SetInlinePresentation(inlinePresentation); } datasetBuilder.SetAuthentication(pendingIntent?.IntentSender); // Dataset must have a value set. We will reset this in the main activity when the real item is chosen. foreach (var autofillId in fields.AutofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } return(datasetBuilder.Build()); }
public static Dataset BuildDataset(Context context, FieldCollection fields, FilledItem filledItem) { var datasetBuilder = new Dataset.Builder( BuildListView(filledItem.Name, filledItem.Subtitle, filledItem.Icon, context)); if (filledItem.ApplyToFields(fields, datasetBuilder)) { return(datasetBuilder.Build()); } return(null); }
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); }
public Dataset BuildDatasetForFocusedNode(FilledAutofillField filledAutofillField, FieldType fieldType, RemoteViews remoteViews) { Dataset.Builder datasetBuilder = new Dataset.Builder(remoteViews); bool setAtLeastOneValue = BindDatasetToFocusedNode(filledAutofillField, fieldType, datasetBuilder); if (!setAtLeastOneValue) { return(null); } return(datasetBuilder.Build()); }
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()); }
/// <summary> /// Wraps autofill data in a LoginCredential Dataset object which can then be sent back to the /// client View. /// </summary> /// <returns>The dataset.</returns> /// <param name="context">Context.</param> /// <param name="autofillFields">Autofill fields.</param> /// <param name="filledAutofillFieldCollection">Filled autofill field collection.</param> public static Dataset NewDataset(Context context, AutofillFieldMetadataCollection autofillFields, FilledAutofillFieldCollection filledAutofillFieldCollection, IAutofillIntentBuilder intentBuilder) { var datasetName = filledAutofillFieldCollection.DatasetName; if (datasetName != null) { var datasetBuilder = new Dataset.Builder(NewRemoteViews(context.PackageName, datasetName, intentBuilder.AppIconResource)); var setValueAtLeastOnce = filledAutofillFieldCollection.ApplyToFields(autofillFields, datasetBuilder); if (setValueAtLeastOnce) { return(datasetBuilder.Build()); } } return(null); }
/** * Wraps autofill data in a {@link Dataset} object with an IntentSender, which can then be * sent back to the client. */ public Dataset BuildDataset(Dictionary <string, FieldTypeWithHeuristics> fieldTypesByAutofillHint, DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, RemoteViews remoteViews, IntentSender intentSender) { Dataset.Builder datasetBuilder = new Dataset.Builder(remoteViews); if (intentSender != null) { datasetBuilder.SetAuthentication(intentSender); } bool setAtLeastOneValue = BindDataset(fieldTypesByAutofillHint, datasetWithFilledAutofillFields, datasetBuilder); if (!setAtLeastOneValue) { return(null); } return(datasetBuilder.Build()); }
private static bool ApplyValue(Dataset.Builder builder, FieldCollection fieldCollection, string hint, string value, bool monthValue = false) { bool setValues = false; if (fieldCollection.HintToFieldsMap.ContainsKey(hint) && !string.IsNullOrWhiteSpace(value)) { foreach (var f in fieldCollection.HintToFieldsMap[hint]) { var val = ApplyValue(f, value, monthValue); if (val != null) { setValues = true; builder.SetValue(f.AutofillId, val); } } } return(setValues); }
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()); } }
/** * Build an autofill {@link Dataset} using saved data and the client's AssistStructure. */ private bool BindDataset(Dictionary <string, FieldTypeWithHeuristics> fieldTypesByAutofillHint, DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, Dataset.Builder datasetBuilder) { MutableBoolean setValueAtLeastOnce = new MutableBoolean(false); var filledAutofillFieldsByTypeName = datasetWithFilledAutofillFields .filledAutofillFields .ToDictionary(x => x.GetFieldTypeName(), x => x); mClientParser.Parse(new BindDatasetNodeProcessor { datasetBuilder = datasetBuilder, setValueAtLeastOnce = setValueAtLeastOnce, fieldTypesByAutofillHint = fieldTypesByAutofillHint, filledAutofillFieldsByTypeName = filledAutofillFieldsByTypeName, datasetAdapter = this }); return(setValueAtLeastOnce.Value); }
public static void AddInlinePresentation(Context context, InlinePresentationSpec inlinePresentationSpec, string datasetName, Dataset.Builder datasetBuilder, int iconId) { if (inlinePresentationSpec != null) { var inlinePresentation = BuildInlinePresentation(inlinePresentationSpec, datasetName, "", iconId, null, context); datasetBuilder.SetInlinePresentation(inlinePresentation); } }
/** * Populates a {@link Dataset.Builder} with appropriate values for each {@link AutofillId} * in a {@code AutofillFieldMetadataCollection}. * * In other words, it constructs an autofill * {@link Dataset.Builder} by applying saved values (from this {@code FilledAutofillFieldCollection}) * to Views specified in a {@code AutofillFieldMetadataCollection}, which represents the current * page the user is on. */ public bool ApplyToFields(AutofillFieldMetadataCollection autofillFieldMetadataCollection, Dataset.Builder datasetBuilder) { var setValueAtLeastOnce = false; var allHints = autofillFieldMetadataCollection.AutofillHints; for (var hintIndex = 0; hintIndex < allHints.Count; hintIndex++) { var hint = allHints[hintIndex]; if (!autofillFieldMetadataCollection.AutofillHintsToFieldsMap.ContainsKey(hint)) { continue; } var fillableAutofillFields = autofillFieldMetadataCollection.AutofillHintsToFieldsMap[hint]; for (var autofillFieldIndex = 0; autofillFieldIndex < fillableAutofillFields.Count; autofillFieldIndex++) { if (!HintMap.ContainsKey(hint)) { continue; } var filledAutofillField = HintMap[hint]; var autofillFieldMetadata = fillableAutofillFields[autofillFieldIndex]; var autofillId = autofillFieldMetadata.AutofillId; var autofillType = autofillFieldMetadata.AutofillType; switch (autofillType) { case AutofillType.List: int listValue = autofillFieldMetadata.GetAutofillOptionIndex(filledAutofillField.TextValue); if (listValue != -1) { datasetBuilder.SetValue(autofillId, AutofillValue.ForList(listValue)); setValueAtLeastOnce = true; } break; case AutofillType.Date: var dateValue = filledAutofillField.DateValue; if (dateValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForDate(dateValue.Value)); setValueAtLeastOnce = true; } break; case AutofillType.Text: var textValue = filledAutofillField.TextValue; if (textValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText(textValue)); setValueAtLeastOnce = true; } break; case AutofillType.Toggle: var toggleValue = filledAutofillField.ToggleValue; if (toggleValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForToggle(toggleValue.Value)); setValueAtLeastOnce = true; } break; case AutofillType.None: default: break; } } } return(setValueAtLeastOnce); }
/// <summary> /// Populates a Dataset.Builder with appropriate values for each AutofillId /// in a AutofillFieldMetadataCollection. /// /// In other words, it constructs an autofill Dataset.Builder /// by applying saved values (from this FilledAutofillFieldCollection) /// to Views specified in a AutofillFieldMetadataCollection, which represents the current /// page the user is on. /// </summary> /// <returns><c>true</c>, if to fields was applyed, <c>false</c> otherwise.</returns> /// <param name="autofillFieldMetadataCollection">Autofill field metadata collection.</param> /// <param name="datasetBuilder">Dataset builder.</param> public bool ApplyToFields(AutofillFieldMetadataCollection autofillFieldMetadataCollection, Dataset.Builder datasetBuilder) { bool setValueAtLeastOnce = false; foreach (string hint in autofillFieldMetadataCollection.AllAutofillCanonicalHints) { foreach (AutofillFieldMetadata autofillFieldMetadata in autofillFieldMetadataCollection.GetFieldsForHint(hint)) { FilledAutofillField filledAutofillField; if (!HintMap.TryGetValue(hint, out filledAutofillField) || (filledAutofillField == null)) { continue; } var autofillId = autofillFieldMetadata.AutofillId; var autofillType = autofillFieldMetadata.AutofillType; switch (autofillType) { case AutofillType.List: var listValue = autofillFieldMetadata.GetAutofillOptionIndex(filledAutofillField.TextValue); if (listValue != -1) { datasetBuilder.SetValue(autofillId, AutofillValue.ForList(listValue)); setValueAtLeastOnce = true; } break; case AutofillType.Date: var dateValue = filledAutofillField.DateValue; datasetBuilder.SetValue(autofillId, AutofillValue.ForDate((long)dateValue)); setValueAtLeastOnce = true; break; case AutofillType.Text: var textValue = filledAutofillField.TextValue; if (textValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText(textValue)); setValueAtLeastOnce = true; } break; case AutofillType.Toggle: var toggleValue = filledAutofillField.ToggleValue; if (toggleValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForToggle(toggleValue.Value)); setValueAtLeastOnce = true; } break; default: Log.Warn(CommonUtil.Tag, "Invalid autofill type - " + autofillType); break; } } } return(setValueAtLeastOnce); }
void BindValueToNode(AssistStructure.ViewNode viewNode, FilledAutofillField field, Dataset.Builder builder, MutableBoolean setValueAtLeastOnce) { AutofillId autofillId = viewNode.AutofillId; if (autofillId == null) { Util.Logw("Autofill ID null for %s", viewNode.ToString()); return; } int autofillType = (int)viewNode.AutofillType; switch (autofillType) { case (int)AutofillType.List: var options = viewNode.GetAutofillOptions(); int listValue = -1; if (options != null) { listValue = Util.IndexOf(viewNode.GetAutofillOptions(), field.GetTextValue()); } if (listValue != -1) { builder.SetValue(autofillId, AutofillValue.ForList(listValue)); setValueAtLeastOnce.Value = true; } break; case (int)AutofillType.Date: var dateValue = field.GetDateValue(); if (dateValue != null) { builder.SetValue(autofillId, AutofillValue.ForDate(dateValue)); setValueAtLeastOnce.Value = true; } break; case (int)AutofillType.Text: string textValue = field.GetTextValue(); if (textValue != null) { builder.SetValue(autofillId, AutofillValue.ForText(textValue)); setValueAtLeastOnce.Value = true; } break; case (int)AutofillType.Toggle: var toggleValue = field.GetToggleValue(); if (toggleValue != null) { builder.SetValue(autofillId, AutofillValue.ForToggle(toggleValue)); setValueAtLeastOnce.Value = true; } break; case (int)AutofillType.None: break; default: Util.Logw("Invalid autofill type - %d", autofillType); break; } }
/** * Populates a {@link Dataset.Builder} with appropriate values for each {@link AutofillId} * in a {@code AutofillFieldMetadataCollection}. * * In other words, it constructs an autofill * {@link Dataset.Builder} by applying saved values (from this {@code FilledAutofillFieldCollection}) * to Views specified in a {@code AutofillFieldMetadataCollection}, which represents the current * page the user is on. */ public bool ApplyToFields(AutofillFieldMetadataCollection autofillFieldMetadataCollection, Dataset.Builder datasetBuilder) { bool setValueAtLeastOnce = false; List <string> allHints = autofillFieldMetadataCollection.GetAllHints(); for (var hintIndex = 0; hintIndex < allHints.Count; hintIndex++) { string hint = allHints[hintIndex]; var fillableAutofillFields = autofillFieldMetadataCollection.GetFieldsForHint(hint); if (fillableAutofillFields == null) { continue; } for (var autofillFieldIndex = 0; autofillFieldIndex < fillableAutofillFields.Count; autofillFieldIndex++) { var filledAutofillField = mHintMap.FirstOrDefault(x => x.Key == hint); if (filledAutofillField.Value == null) { continue; } var autofillFieldMetadata = fillableAutofillFields[autofillFieldIndex]; AutofillId autofillId = autofillFieldMetadata.GetId(); var autofillType = autofillFieldMetadata.GetAutofillType(); switch (autofillType) { case AutofillType.List: int listValue = autofillFieldMetadata.GetAutofillOptionIndex(filledAutofillField.Value.GetTextValue()); if (listValue != -1) { datasetBuilder.SetValue(autofillId, AutofillValue.ForList(listValue)); setValueAtLeastOnce = true; } break; case AutofillType.Date: var dateValue = filledAutofillField.Value.GetDateValue(); if (dateValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForDate(dateValue)); setValueAtLeastOnce = true; } break; case AutofillType.Text: var textValue = filledAutofillField.Value.GetTextValue(); if (textValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText(textValue)); setValueAtLeastOnce = true; } break; case AutofillType.Toggle: var toggleValue = filledAutofillField.Value.GetToggleValue(); if (toggleValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForToggle(toggleValue)); setValueAtLeastOnce = true; } break; case AutofillType.None: break; default: Log.Warn(CommonUtil.TAG, "Invalid autofill type - " + autofillType); break; } } } return(setValueAtLeastOnce); }
/// <summary> /// Populates a Dataset.Builder with appropriate values for each AutofillId /// in a AutofillFieldMetadataCollection. /// /// In other words, it constructs an autofill Dataset.Builder /// by applying saved values (from this FilledAutofillFieldCollection) /// to Views specified in a AutofillFieldMetadataCollection, which represents the current /// page the user is on. /// </summary> /// <returns><c>true</c>, if to fields was applyed, <c>false</c> otherwise.</returns> /// <param name="autofillFieldMetadataCollection">Autofill field metadata collection.</param> /// <param name="datasetBuilder">Dataset builder.</param> public bool ApplyToFields(AutofillFieldMetadataCollection autofillFieldMetadataCollection, Dataset.Builder datasetBuilder) { bool setValueAtLeastOnce = false; foreach (string hint in autofillFieldMetadataCollection.AllAutofillCanonicalHints) { foreach (AutofillFieldMetadata autofillFieldMetadata in autofillFieldMetadataCollection.GetFieldsForHint(hint)) { FilledAutofillField filledAutofillField; if (!HintMap.TryGetValue(hint, out filledAutofillField) || (filledAutofillField == null)) { continue; } var autofillId = autofillFieldMetadata.AutofillId; var autofillType = autofillFieldMetadata.AutofillType; switch (autofillType) { case AutofillType.List: var listValue = autofillFieldMetadata.GetAutofillOptionIndex(filledAutofillField.TextValue); if (listValue != -1) { datasetBuilder.SetValue(autofillId, AutofillValue.ForList(listValue)); setValueAtLeastOnce = true; } break; case AutofillType.Date: var dateValue = filledAutofillField.DateValue; datasetBuilder.SetValue(autofillId, AutofillValue.ForDate((long)dateValue)); setValueAtLeastOnce = true; break; case AutofillType.Text: var textValue = filledAutofillField.TextValue; if (textValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText(textValue)); setValueAtLeastOnce = true; } break; case AutofillType.Toggle: var toggleValue = filledAutofillField.ToggleValue; if (toggleValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForToggle(toggleValue.Value)); setValueAtLeastOnce = true; } break; default: Log.Warn(CommonUtil.Tag, "Invalid autofill type - " + autofillType); break; } } } /* * if (!setValueAtLeastOnce) * { * Kp2aLog.Log("No value set. Hint keys : " + string.Join(",", HintMap.Keys)); * foreach (string hint in autofillFieldMetadataCollection.AllAutofillCanonicalHints) * { * Kp2aLog.Log("No value set. Hint = " + hint); * foreach (AutofillFieldMetadata autofillFieldMetadata in autofillFieldMetadataCollection * .GetFieldsForHint(hint)) * { * Kp2aLog.Log("No value set. fieldForHint = " + autofillFieldMetadata.AutofillId.ToString()); * FilledAutofillField filledAutofillField; * if (!HintMap.TryGetValue(hint, out filledAutofillField) || (filledAutofillField == null)) * { * Kp2aLog.Log("No value set. Hint map does not contain value, " + * (filledAutofillField == null)); * continue; * } * * Kp2aLog.Log("autofill type=" + autofillFieldMetadata.AutofillType); * } * } * }*/ return(setValueAtLeastOnce); }
/// <summary> /// Populates a Dataset.Builder with appropriate values for each AutofillId /// in a AutofillFieldMetadataCollection. /// /// In other words, it constructs an autofill Dataset.Builder /// by applying saved values (from this FilledAutofillFieldCollection) /// to Views specified in a AutofillFieldMetadataCollection, which represents the current /// page the user is on. /// </summary> /// <returns><c>true</c>, if to fields was applyed, <c>false</c> otherwise.</returns> /// <param name="autofillFieldMetadataCollection">Autofill field metadata collection.</param> /// <param name="datasetBuilder">Dataset builder.</param> public bool ApplyToFields(AutofillFieldMetadataCollection autofillFieldMetadataCollection, Dataset.Builder datasetBuilder) { bool setValueAtLeastOnce = false; List <string> allHints = autofillFieldMetadataCollection.AllAutofillHints; for (int hintIndex = 0; hintIndex < allHints.Count; hintIndex++) { string hint = allHints[hintIndex]; List <AutofillFieldMetadata> fillableAutofillFields = autofillFieldMetadataCollection.GetFieldsForHint(hint); if (fillableAutofillFields == null) { continue; } for (int autofillFieldIndex = 0; autofillFieldIndex < fillableAutofillFields.Count; autofillFieldIndex++) { FilledAutofillField filledAutofillField = HintMap[hint]; if (filledAutofillField == null) { continue; } AutofillFieldMetadata autofillFieldMetadata = fillableAutofillFields[autofillFieldIndex]; var autofillId = autofillFieldMetadata.AutofillId; var autofillType = autofillFieldMetadata.AutofillType; switch (autofillType) { case AutofillType.List: var listValue = autofillFieldMetadata.GetAutofillOptionIndex(filledAutofillField.TextValue); if (listValue != -1) { datasetBuilder.SetValue(autofillId, AutofillValue.ForList(listValue)); setValueAtLeastOnce = true; } break; case AutofillType.Date: var dateValue = filledAutofillField.DateValue; datasetBuilder.SetValue(autofillId, AutofillValue.ForDate((long)dateValue)); setValueAtLeastOnce = true; break; case AutofillType.Text: var textValue = filledAutofillField.TextValue; if (textValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText(textValue)); setValueAtLeastOnce = true; } break; case AutofillType.Toggle: var toggleValue = filledAutofillField.ToggleValue; if (toggleValue != null) { datasetBuilder.SetValue(autofillId, AutofillValue.ForToggle(toggleValue.Value)); setValueAtLeastOnce = true; } break; default: Log.Warn(CommonUtil.Tag, "Invalid autofill type - " + autofillType); break; } } } return(setValueAtLeastOnce); }
private bool BindDatasetToFocusedNode(FilledAutofillField field, FieldType fieldType, Dataset.Builder builder) { MutableBoolean setValueAtLeastOnce = new MutableBoolean(false); mClientParser.Parse(new BindDatasetToFocusedNodeProcessor() { field = field, builder = builder, datasetAdapter = this, setValueAtLeastOnce = setValueAtLeastOnce }); return(setValueAtLeastOnce.Value); }
public bool ApplyToFields(FieldCollection fieldCollection, Dataset.Builder datasetBuilder) { if (!fieldCollection?.Fields.Any() ?? true) { return(false); } var setValues = false; if (Type == CipherType.Login) { if (fieldCollection.PasswordFields.Any() && !string.IsNullOrWhiteSpace(_password)) { foreach (var f in fieldCollection.PasswordFields) { var val = ApplyValue(f, _password); if (val != null) { setValues = true; datasetBuilder.SetValue(f.AutofillId, val); } } } if (fieldCollection.UsernameFields.Any() && !string.IsNullOrWhiteSpace(Subtitle)) { foreach (var f in fieldCollection.UsernameFields) { var val = ApplyValue(f, Subtitle); if (val != null) { setValues = true; datasetBuilder.SetValue(f.AutofillId, val); } } } } else if (Type == CipherType.Card) { if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintCreditCardNumber, _cardNumber)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintCreditCardSecurityCode, _cardCode)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintCreditCardExpirationMonth, _cardExpMonth, true)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintCreditCardExpirationYear, _cardExpYear)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintName, _cardName)) { setValues = true; } } else if (Type == CipherType.Identity) { if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintPhone, _idPhone)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintEmailAddress, _idEmail)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintUsername, _idUsername)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintPostalAddress, _idAddress)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintPostalCode, _idPostalCode)) { setValues = true; } if (ApplyValue(datasetBuilder, fieldCollection, Android.Views.View.AutofillHintName, Subtitle)) { setValues = true; } } return(setValues); }
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); } }