/** * 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.DatasetName; if (datasetName != null) { Dataset.Builder datasetBuilder; if (datasetAuth) { datasetBuilder = new Dataset.Builder( NewRemoteViews(context.PackageName, datasetName, "username", Resource.Drawable.fa_lock)); //IntentSender sender = AuthActivity.getAuthIntentSenderForDataset(context, datasetName); //datasetBuilder.SetAuthentication(sender); } else { datasetBuilder = new Dataset.Builder( NewRemoteViews(context.PackageName, datasetName, "username", Resource.Drawable.user)); } var setValueAtLeastOnce = filledAutofillFieldCollection.ApplyToFields(autofillFields, datasetBuilder); if (setValueAtLeastOnce) { return(datasetBuilder.Build()); } } return(null); }
/** * Wraps autofill data in a Response object (essentially a series of Datasets) which can then * be sent back to the client View. */ public static FillResponse NewResponse(Context context, bool datasetAuth, AutofillFieldMetadataCollection autofillFields, IDictionary <string, FilledAutofillFieldCollection> clientFormDataMap) { var responseBuilder = new FillResponse.Builder(); if (clientFormDataMap != null) { foreach (var datasetName in clientFormDataMap.Keys) { if (clientFormDataMap.ContainsKey(datasetName)) { var dataset = NewDataset(context, autofillFields, clientFormDataMap[datasetName], datasetAuth); if (dataset != null) { responseBuilder.AddDataset(dataset); } } } } if (autofillFields.SaveType != SaveDataType.Generic) { responseBuilder.SetSaveInfo( new SaveInfo.Builder(autofillFields.SaveType, autofillFields.AutofillIds.ToArray()).Build()); return(responseBuilder.Build()); } else { //Log.d(TAG, "These fields are not meant to be saved by autofill."); return(null); } }
/** * 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); }