Example #1
0
        public FilledAutofillField(AssistStructure.ViewNode viewNode)
        {
            AutofillHints = AutofillHelper.FilterForSupportedHints(viewNode.GetAutofillHints());
            AutofillValue autofillValue = viewNode.AutofillValue;

            if (autofillValue != null)
            {
                if (autofillValue.IsList)
                {
                    string[] autofillOptions = viewNode.GetAutofillOptions();
                    int      index           = autofillValue.ListValue;
                    if (autofillOptions != null && autofillOptions.Length > 0)
                    {
                        TextValue = autofillOptions[index];
                    }
                }
                else if (autofillValue.IsDate)
                {
                    DateValue = autofillValue.DateValue;
                }
                else if (autofillValue.IsText)
                {
                    // Using toString of AutofillValue.getTextValue in order to save it to
                    // SharedPreferences.
                    TextValue = autofillValue.TextValue;
                }
            }
        }
Example #2
0
        private static void DumpNode(StringBuilder builder, String prefix, AssistStructure.ViewNode node, int childNumber)
        {
            builder.Append(prefix)
            .Append("child #").Append(Integer.ToString(childNumber)).Append("\n");

            builder.Append(prefix)
            .Append("autoFillId: ").Append(node.AutofillId.ToString())
            .Append("\tidEntry: ").Append(node.IdEntry)
            .Append("\tid: ").Append(node.Id.ToString())
            .Append("\tclassName: ").Append(node.ClassName)
            .Append('\n');

            builder.Append(prefix)
            .Append("focused: ").Append(node.IsFocused.ToString())
            .Append("\tvisibility").Append(node.Visibility.ToString())
            .Append("\tchecked: ").Append(node.IsChecked.ToString())
            .Append("\twebDomain: ").Append(node.WebDomain)
            .Append("\thint: ").Append(node.Hint)
            .Append('\n');

            ViewStructure.HtmlInfo htmlInfo = node.HtmlInfo;

            if (htmlInfo != null)
            {
                builder.Append(prefix)
                .Append("HTML TAG: ").Append(htmlInfo.Tag)
                .Append(" attrs: ").Append(htmlInfo.Attributes.ToString())
                .Append('\n');
            }

            var afHints = string.Join(string.Empty, node.GetAutofillHints()).ToCharArray();
            var options = string.Join(string.Empty, node.GetAutofillOptions()).ToCharArray();

            builder.Append(prefix).Append("afType: ").Append(GetTypeAsString((int)node.AutofillType))
            .Append("\tafValue:")
            .Append(getAutofillValueAndTypeAsString(node.AutofillValue))
            .Append("\tafOptions:").Append(options == null ? "N/A" : Arrays.ToString(options))
            .Append("\tafHints: ").Append(afHints == null ? "N/A" : Arrays.ToString(afHints))
            .Append("\tinputType:").Append(node.InputType.ToString())
            .Append('\n');

            int numberChildren = node.ChildCount;

            builder.Append(prefix).Append("# children: ").Append(numberChildren.ToString())
            .Append("\ttext: ").Append(node.Text)
            .Append('\n');

            String prefix2 = prefix + "  ";

            for (int i = 0; i < numberChildren; i++)
            {
                DumpNode(builder, prefix2, node.GetChildAt(i), i);
            }
            Logv(builder.ToString());
        }
Example #3
0
        public AutofillFieldMetadata(AssistStructure.ViewNode view, string[] autofillHints)
        {
            AutofillId      = view.AutofillId;
            AutofillType    = view.AutofillType;
            AutofillOptions = view.GetAutofillOptions();
            Focused         = view.IsFocused;
            var supportedHints = AutofillHintsHelper.FilterForSupportedHints(autofillHints);
            var canonicalHints = AutofillHintsHelper.ConvertToCanonicalHints(supportedHints);

            SetHints(canonicalHints.ToArray());
        }
Example #4
0
        public AutofillFieldMetadata(AssistStructure.ViewNode view)
        {
            mAutofillId      = view.AutofillId;
            mAutofillType    = view.AutofillType;
            mAutofillOptions = view.GetAutofillOptions();
            mFocused         = view.IsFocused;
            var hints = AutofillHints.FilterForSupportedHints(view.GetAutofillHints());

            if (hints != null)
            {
                AutofillHints.ConvertToStoredHintNames(hints);
                SetHints(hints);
            }
        }
        private void ParseAutofillFields(AssistStructure.ViewNode viewNode,
                                         DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, int partition)
        {
            string[] hints = viewNode.GetAutofillHints();
            if (hints == null || hints.Length == 0)
            {
                return;
            }
            var    autofillValue = viewNode.AutofillValue;
            string textValue     = null;
            long   dateValue     = Long.MinValue;
            bool   toggleValue   = false;

            string[] autofillOptions = null;
            int      listIndex       = Int32.MinValue;

            if (autofillValue != null)
            {
                if (autofillValue.IsText)
                {
                    // Using toString of AutofillValue.getTextValue in order to save it to
                    // SharedPreferences.
                    textValue = autofillValue.TextValue;
                }
                else if (autofillValue.IsDate)
                {
                    dateValue = autofillValue.DateValue;
                }
                else if (autofillValue.IsList)
                {
                    autofillOptions = viewNode.GetAutofillOptions();
                    listIndex       = autofillValue.ListValue;
                }
                else if (autofillValue.IsToggle)
                {
                    toggleValue = autofillValue.ToggleValue;
                }
            }
            AppendViewMetadata(datasetWithFilledAutofillFields, hints, partition, textValue, dateValue, toggleValue, autofillOptions, listIndex);
        }
Example #6
0
        public FilledAutofillField(AssistStructure.ViewNode viewNode, string[] hints)
        {
            string[]      rawHints = AutofillHintsHelper.FilterForSupportedHints(hints);
            List <string> hintList = new List <string>();

            string nextHint = null;

            for (int i = 0; i < rawHints.Length; i++)
            {
                string hint = rawHints[i];
                if (i < rawHints.Length - 1)
                {
                    nextHint = rawHints[i + 1];
                }
                // First convert the compound W3C autofill hints
                if (W3cHints.isW3cSectionPrefix(hint) && i < rawHints.Length - 1)
                {
                    hint = rawHints[++i];
                    CommonUtil.logd($"Hint is a W3C section prefix; using {hint} instead");
                    if (i < rawHints.Length - 1)
                    {
                        nextHint = rawHints[i + 1];
                    }
                }
                if (W3cHints.isW3cTypePrefix(hint) && nextHint != null && W3cHints.isW3cTypeHint(nextHint))
                {
                    hint = nextHint;
                    i++;
                    CommonUtil.logd($"Hint is a W3C type prefix; using {hint} instead");
                }
                if (W3cHints.isW3cAddressType(hint) && nextHint != null)
                {
                    hint = nextHint;
                    i++;
                    CommonUtil.logd($"Hint is a W3C address prefix; using  {hint} instead");
                }

                // Then check if the "actual" hint is supported.
                if (AutofillHintsHelper.IsSupportedHint(hint))
                {
                    hintList.Add(hint);
                }
                else
                {
                    CommonUtil.loge($"Invalid hint: {rawHints[i]}");
                }
            }
            AutofillHints = AutofillHintsHelper.ConvertToCanonicalHints(hintList.ToArray()).ToArray();

            AutofillValue autofillValue = viewNode.AutofillValue;

            if (autofillValue != null)
            {
                if (autofillValue.IsList)
                {
                    string[] autofillOptions = viewNode.GetAutofillOptions();
                    int      index           = autofillValue.ListValue;
                    if (autofillOptions != null && autofillOptions.Length > 0)
                    {
                        TextValue = autofillOptions[index];
                    }
                }
                else if (autofillValue.IsDate)
                {
                    DateValue = autofillValue.DateValue;
                }
                else if (autofillValue.IsText)
                {
                    TextValue = autofillValue.TextValue;
                }
            }
        }
        private void ParseLocked(bool forFill, AssistStructure.ViewNode viewNode, StringBuilder validWebDomain)
        {
            var webDomain = viewNode.WebDomain;

            if (webDomain != null)
            {
                if (CommonUtil.DEBUG)
                {
                    Log.Debug(CommonUtil.TAG, "child web domain: " + webDomain);
                }
                if (validWebDomain.Length() > 0)
                {
                    if (webDomain != validWebDomain.ToString())
                    {
                        throw new SecurityException("Found multiple web domains: valid= "
                                                    + validWebDomain + ", child=" + webDomain);
                    }
                }
                else
                {
                    validWebDomain.Append(webDomain);
                }
            }

            if (viewNode.GetAutofillHints() != null)
            {
                var filteredHints = AutofillHints.FilterForSupportedHints(
                    viewNode.GetAutofillHints());
                if (filteredHints != null && filteredHints.Length > 0)
                {
                    if (forFill)
                    {
                        mAutofillFields.Add(new AutofillFieldMetadata(viewNode));
                    }
                    else
                    {
                        var           filledAutofillField = new FilledAutofillField(viewNode.GetAutofillHints());
                        AutofillValue autofillValue       = viewNode.AutofillValue;
                        if (autofillValue.IsText)
                        {
                            // Using toString of AutofillValue.getTextValue in order to save it to
                            // SharedPreferences.
                            filledAutofillField.SetTextValue(autofillValue.TextValue);
                        }
                        else if (autofillValue.IsDate)
                        {
                            filledAutofillField.SetDateValue(autofillValue.DateValue);
                        }
                        else if (autofillValue.IsList)
                        {
                            filledAutofillField.SetListValue(viewNode.GetAutofillOptions(),
                                                             autofillValue.ListValue);
                        }

                        mFilledAutofillFieldCollection.Add(filledAutofillField);
                    }
                }
            }

            int childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    ParseLocked(forFill, viewNode.GetChildAt(i), validWebDomain);
                }
            }
        }
        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;
            }
        }