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; } } }
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 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()); }
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); }
private void ParseNode(AssistStructure.ViewNode root, List <String> allHints, MutableInt autofillSaveType, List <AutofillId> autofillIds, List <AutofillId> focusedAutofillIds) { String[] hints = root.GetAutofillHints(); if (hints != null) { foreach (string hint in hints) { FieldTypeWithHeuristics fieldTypeWithHints = mFieldTypesByAutofillHint[hint]; if (fieldTypeWithHints != null && fieldTypeWithHints.fieldType != null) { allHints.Add(hint); autofillSaveType.Value |= fieldTypeWithHints.fieldType.GetSaveInfo(); } } } if (root.IsFocused) { focusedAutofillIds.Add(root.AutofillId); } autofillIds.Add(root.AutofillId); }
void ParseLocked(bool forFill, bool isManualRequest, AssistStructure.ViewNode viewNode, ref string validWebdomain) { String webDomain = viewNode.WebDomain; if (webDomain != null) { Log.Debug(CommonUtil.Tag, $"child web domain: {webDomain}"); if (!string.IsNullOrEmpty(validWebdomain)) { if (webDomain == validWebdomain) { throw new Java.Lang.SecurityException($"Found multiple web domains: valid= {validWebdomain}, child={webDomain}"); } } else { validWebdomain = webDomain; } } string[] viewHints = viewNode.GetAutofillHints(); if (viewHints != null && viewHints.Length == 1 && viewHints.First() == "off" && viewNode.IsFocused && isManualRequest) { viewHints[0] = "on"; } CommonUtil.logd("viewHints=" + viewHints); CommonUtil.logd("class=" + viewNode.ClassName); CommonUtil.logd("tag=" + (viewNode?.HtmlInfo?.Tag ?? "(null)")); if (viewNode?.HtmlInfo?.Tag == "input") { foreach (var p in viewNode.HtmlInfo.Attributes) { CommonUtil.logd("attr=" + p.First + "/" + p.Second); } } if (viewHints != null && viewHints.Length > 0 && viewHints.First() != "on" /*if hint is "on", treat as if there is no hint*/) { if (forFill) { AutofillFields.Add(new AutofillFieldMetadata(viewNode)); } else { //TODO implement save throw new NotImplementedException("TODO: Port and use AutoFill hints"); //ClientFormData.Add(new FilledAutofillField(viewNode)); } } else { if (viewNode.ClassName == "android.widget.EditText" || viewNode?.HtmlInfo?.Tag == "input") { _editTextsWithoutHint.Add(viewNode); } } var childrenSize = viewNode.ChildCount; if (childrenSize > 0) { for (int i = 0; i < childrenSize; i++) { ParseLocked(forFill, isManualRequest, viewNode.GetChildAt(i), ref validWebdomain); } } }
void ParseLocked(bool forFill, bool isManualRequest, AssistStructure.ViewNode viewNode, ref string validWebdomain) { String webDomain = viewNode.WebDomain; if ((PackageId == null) && (!string.IsNullOrWhiteSpace(viewNode.IdPackage)) && (viewNode.IdPackage != "android")) { PackageId = viewNode.IdPackage; } DomainName outDomain; if (DomainName.TryParse(webDomain, domainSuffixParserCache, out outDomain)) { webDomain = outDomain.RegisterableDomainName; } if (webDomain != null) { if (!string.IsNullOrEmpty(validWebdomain)) { if (webDomain != validWebdomain) { throw new Java.Lang.SecurityException($"Found multiple web domains: valid= {validWebdomain}, child={webDomain}"); } } else { validWebdomain = webDomain; } } string[] viewHints = viewNode.GetAutofillHints(); if (viewHints != null && viewHints.Length == 1 && viewHints.First() == "off" && viewNode.IsFocused && isManualRequest) { viewHints[0] = "on"; } if (viewHints != null && viewHints.Any()) { CommonUtil.logd("viewHints=" + viewHints); CommonUtil.logd("class=" + viewNode.ClassName); CommonUtil.logd("tag=" + (viewNode?.HtmlInfo?.Tag ?? "(null)")); } if (viewNode?.HtmlInfo?.Tag == "input") { foreach (var p in viewNode.HtmlInfo.Attributes) { CommonUtil.logd("attr=" + p.First + "/" + p.Second); } } if (viewHints != null && viewHints.Length > 0 && viewHints.First() != "on" /*if hint is "on", treat as if there is no hint*/) { if (forFill) { AutofillFields.Add(new AutofillFieldMetadata(viewNode)); } else { FilledAutofillField filledAutofillField = new FilledAutofillField(viewNode); ClientFormData.Add(filledAutofillField); } } else { if (viewNode.ClassName == "android.widget.EditText" || viewNode?.HtmlInfo?.Tag == "input") { _editTextsWithoutHint.Add(viewNode); } } var childrenSize = viewNode.ChildCount; if (childrenSize > 0) { for (int i = 0; i < childrenSize; i++) { ParseLocked(forFill, isManualRequest, viewNode.GetChildAt(i), ref validWebdomain); } } }
public FilledAutofillField(AssistStructure.ViewNode viewNode) : this(viewNode, viewNode.GetAutofillHints()) { }
public AutofillFieldMetadata(AssistStructure.ViewNode view) : this(view, view.GetAutofillHints()) { }
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); } } }
public FilledAutofillField(AssistStructure.ViewNode viewNode) { string[] rawHints = AutofillHintsHelper.FilterForSupportedHints(viewNode.GetAutofillHints()); 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 = hintList.ToArray(); //TODO port updated FilledAutofillField for saving 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; } } }