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);
        }
        public void Add(AutofillFieldMetadata data)
        {
            _size++;
            SaveType |= data.SaveType;
            Ids.Add(data.Id);
            AutofillIds.Add(data.AutofillId);
            IdToFieldMap.Add(data.Id, data);

            if ((data.AutofillHints?.Count ?? 0) > 0)
            {
                AutofillHints.AddRange(data.AutofillHints);
                if (data.IsFocused)
                {
                    FocusedAutofillHints.AddRange(data.AutofillHints);
                }

                foreach (var hint in data.AutofillHints)
                {
                    if (!AutofillHintsToFieldsMap.ContainsKey(hint))
                    {
                        AutofillHintsToFieldsMap.Add(hint, new List <AutofillFieldMetadata>());
                    }

                    AutofillHintsToFieldsMap[hint].Add(data);
                }
            }
        }
        /**
         * Adds a {@code FilledAutofillField} to the collection, indexed by all of its hints.
         */
        public void Add([NonNull] FilledAutofillField filledAutofillField)
        {
            string[] autofillHints = filledAutofillField.GetAutofillHints();
            string   nextHint      = null;

            for (int i = 0; i < autofillHints.Length; i++)
            {
                string hint = autofillHints[i];
                if (i < autofillHints.Length - 1)
                {
                    nextHint = autofillHints[i + 1];
                }

                // First convert the compound W3C autofill hints
                if (IsW3CSectionPrefix(hint) && i < autofillHints.Length - 1)
                {
                    hint = autofillHints[++i];
                    if (CommonUtil.DEBUG)
                    {
                        Log.Debug(CommonUtil.TAG, "Hint is a W3C section prefix; using " + hint + " instead");
                    }
                    if (i < autofillHints.Length - 1)
                    {
                        nextHint = autofillHints[i + 1];
                    }
                }

                if (IsW3CTypePrefix(hint) && nextHint != null && IsW3CTypeHint(nextHint))
                {
                    hint = nextHint;
                    i++;
                    if (CommonUtil.DEBUG)
                    {
                        Log.Debug(CommonUtil.TAG, "Hint is a W3C type prefix; using " + hint + " instead");
                    }
                }

                if (IsW3CAddressType(hint) && nextHint != null)
                {
                    hint = nextHint;
                    i++;
                    if (CommonUtil.DEBUG)
                    {
                        Log.Debug(CommonUtil.TAG, "Hint is a W3C address prefix; using " + hint + " instead");
                    }
                }

                // Then check if the "actual" hint is supported.


                if (AutofillHints.IsValidHint(hint))
                {
                    mHintMap[hint] = filledAutofillField;
                }
                else
                {
                    Log.Error(CommonUtil.TAG, "Invalid hint: " + autofillHints[i]);
                }
            }
        }
        private void AppendViewMetadata([NonNull] DatasetWithFilledAutofillFields

                                        datasetWithFilledAutofillFields, [NonNull] string[] hints, int partition,
                                        [Nullable] string textValue, [Nullable] long dateValue, [Nullable] bool toggleValue,
                                        [Nullable] string[] autofillOptions, [Nullable] int listIndex)
        {
            for (int i = 0; i < hints.Length; i++)
            {
                String hint = hints[i];
                // Then check if the "actual" hint is supported.
                FieldTypeWithHeuristics fieldTypeWithHeuristics = mFieldTypesByAutofillHint[hint];
                if (fieldTypeWithHeuristics != null)
                {
                    FieldType fieldType = fieldTypeWithHeuristics.fieldType;
                    if (!AutofillHints.MatchesPartition(fieldType.GetPartition(), partition))
                    {
                        continue;
                    }
                    // Only add the field if the hint is supported by the type.
                    if (textValue != null)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.Text))
                        {
                            Util.Loge("Text is invalid type for hint '%s'", hint);
                        }
                    }
                    if (autofillOptions != null && listIndex != null && autofillOptions.Length > listIndex)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.List))
                        {
                            Util.Loge("List is invalid type for hint '%s'", hint);
                        }
                        textValue = autofillOptions[listIndex];
                    }
                    if (dateValue != null)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.Date))
                        {
                            Util.Loge("Date is invalid type for hint '%s'", hint);
                        }
                    }
                    if (toggleValue != null)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.Toggle))
                        {
                            Util.Loge("Toggle is invalid type for hint '%s'", hint);
                        }
                    }
                    String datasetId = datasetWithFilledAutofillFields.autofillDataset.GetId();
                    datasetWithFilledAutofillFields.Add(new FilledAutofillField(datasetId,
                                                                                mPackageName, fieldType.GetTypeName(), textValue, dateValue, toggleValue));
                }
                else
                {
                    Util.Loge("Invalid hint: %s", hint);
                }
            }
        }
        private DatasetWithFilledAutofillFields BuildCollectionForPartition(
            AutofillDataset dataset, int partition)
        {
            DatasetWithFilledAutofillFields datasetWithFilledAutofillFields =
                new DatasetWithFilledAutofillFields();

            datasetWithFilledAutofillFields.autofillDataset = dataset;
            foreach (var fieldTypeWithHeuristics in mFieldTypesWithHints)
            {
                if (AutofillHints.MatchesPartition(
                        fieldTypeWithHeuristics.getFieldType().GetPartition(), partition))
                {
                    var fakeField = AutofillHints.generateFakeField(fieldTypeWithHeuristics, mPackageName,
                                                                    mSeed, dataset.GetId());
                    datasetWithFilledAutofillFields.Add(fakeField);
                }
            }
            return(datasetWithFilledAutofillFields);
        }
Example #6
0
 public FilledAutofillField(params string[] hints)
 {
     mAutofillHints = AutofillHints.FilterForSupportedHints(hints);
     AutofillHints.ConvertToStoredHintNames(mAutofillHints);
 }