Java Code Examples for android.app.assist.AssistStructure#ViewNode

The following examples show how to use android.app.assist.AssistStructure#ViewNode . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatasetAdapter.java    From input-samples with Apache License 2.0 6 votes vote down vote up
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
        HashMap<String, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
        Map<String, FilledAutofillField> filledAutofillFieldsByTypeName,
        Dataset.Builder builder, MutableBoolean setValueAtLeastOnce) {
    String[] rawHints = viewNode.getAutofillHints();
    if (rawHints == null || rawHints.length == 0) {
        logv("No af hints at ViewNode - %s", viewNode.getIdEntry());
        return;
    }
    String fieldTypeName = AutofillHints.getFieldTypeNameFromAutofillHints(
            fieldTypesByAutofillHint, Arrays.asList(rawHints));
    if (fieldTypeName == null) {
        return;
    }
    FilledAutofillField field = filledAutofillFieldsByTypeName.get(fieldTypeName);
    if (field == null) {
        return;
    }
    bindValueToNode(viewNode, field, builder, setValueAtLeastOnce);
}
 
Example 2
Source File: ClientViewMetadataBuilder.java    From input-samples with Apache License 2.0 6 votes vote down vote up
private void parseNode(AssistStructure.ViewNode root, List<String> allHints,
        MutableInt autofillSaveType, List<AutofillId> autofillIds,
        List<AutofillId> focusedAutofillIds) {
    String[] hints = root.getAutofillHints();
    if (hints != null) {
        for (String hint : hints) {
            FieldTypeWithHeuristics fieldTypeWithHints = mFieldTypesByAutofillHint.get(hint);
            if (fieldTypeWithHints != null && fieldTypeWithHints.fieldType != null) {
                allHints.add(hint);
                autofillSaveType.value |= fieldTypeWithHints.fieldType.getSaveInfo();
                autofillIds.add(root.getAutofillId());
            }
        }
    }
    if (root.isFocused()) {
        focusedAutofillIds.add(root.getAutofillId());
    }
}
 
Example 3
Source File: DatasetAdapter.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
        HashMap<String, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
        Map<String, FilledAutofillField> filledAutofillFieldsByTypeName,
        Dataset.Builder builder, MutableBoolean setValueAtLeastOnce) {
    String[] rawHints = viewNode.getAutofillHints();
    if (rawHints == null || rawHints.length == 0) {
        logv("No af hints at ViewNode - %s", viewNode.getIdEntry());
        return;
    }
    String fieldTypeName = AutofillHints.getFieldTypeNameFromAutofillHints(
            fieldTypesByAutofillHint, Arrays.asList(rawHints));
    if (fieldTypeName == null) {
        return;
    }
    FilledAutofillField field = filledAutofillFieldsByTypeName.get(fieldTypeName);
    if (field == null) {
        return;
    }
    bindValueToNode(viewNode, field, builder, setValueAtLeastOnce);
}
 
Example 4
Source File: ClientViewMetadataBuilder.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
private void parseNode(AssistStructure.ViewNode root, List<String> allHints,
        MutableInt autofillSaveType, List<AutofillId> autofillIds,
        List<AutofillId> focusedAutofillIds) {
    String[] hints = root.getAutofillHints();
    if (hints != null) {
        for (String hint : hints) {
            FieldTypeWithHeuristics fieldTypeWithHints = mFieldTypesByAutofillHint.get(hint);
            if (fieldTypeWithHints != null && fieldTypeWithHints.fieldType != null) {
                allHints.add(hint);
                autofillSaveType.value |= fieldTypeWithHints.fieldType.getSaveInfo();
                autofillIds.add(root.getAutofillId());
            }
        }
    }
    if (root.isFocused()) {
        focusedAutofillIds.add(root.getAutofillId());
    }
}
 
Example 5
Source File: ClientAutofillDataBuilder.java    From input-samples with Apache License 2.0 5 votes vote down vote up
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
        DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, int partition) {
    String[] hints = viewNode.getAutofillHints();
    if (hints == null || hints.length == 0) {
        return;
    }
    AutofillValue autofillValue = viewNode.getAutofillValue();
    String textValue = null;
    Long dateValue = null;
    Boolean toggleValue = null;
    CharSequence[] autofillOptions = null;
    Integer listIndex = null;
    if (autofillValue != null) {
        if (autofillValue.isText()) {
            // Using toString of AutofillValue.getTextValue in order to save it to
            // SharedPreferences.
            textValue = autofillValue.getTextValue().toString();
        } else if (autofillValue.isDate()) {
            dateValue = autofillValue.getDateValue();
        } else if (autofillValue.isList()) {
            autofillOptions = viewNode.getAutofillOptions();
            listIndex = autofillValue.getListValue();
        } else if (autofillValue.isToggle()) {
            toggleValue = autofillValue.getToggleValue();
        }
    }
    appendViewMetadata(datasetWithFilledAutofillFields,
            hints, partition, textValue, dateValue, toggleValue,
            autofillOptions, listIndex);
}
 
Example 6
Source File: ClientViewMetadataBuilder.java    From input-samples with Apache License 2.0 5 votes vote down vote up
private void parseWebDomain(AssistStructure.ViewNode viewNode, StringBuilder validWebDomain) {
    String webDomain = viewNode.getWebDomain();
    if (webDomain != null) {
        logd("child web domain: %s", webDomain);
        if (validWebDomain.length() > 0) {
            if (!webDomain.equals(validWebDomain.toString())) {
                throw new SecurityException("Found multiple web domains: valid= "
                        + validWebDomain + ", child=" + webDomain);
            }
        } else {
            validWebDomain.append(webDomain);
        }
    }
}
 
Example 7
Source File: ClientParser.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Traverses through the {@link AssistStructure} and does something at each {@link ViewNode}.
 *
 * @param processor contains action to be performed on each {@link ViewNode}.
 */
public void parse(NodeProcessor processor) {
    for (AssistStructure structure : mStructures) {
        int nodes = structure.getWindowNodeCount();
        for (int i = 0; i < nodes; i++) {
            AssistStructure.ViewNode viewNode = structure.getWindowNodeAt(i).getRootViewNode();
            traverseRoot(viewNode, processor);
        }
    }
}
 
Example 8
Source File: ClientParser.java    From input-samples with Apache License 2.0 5 votes vote down vote up
private void traverseRoot(AssistStructure.ViewNode viewNode, NodeProcessor processor) {
    processor.processNode(viewNode);
    int childrenSize = viewNode.getChildCount();
    if (childrenSize > 0) {
        for (int i = 0; i < childrenSize; i++) {
            traverseRoot(viewNode.getChildAt(i), processor);
        }
    }
}
 
Example 9
Source File: ClientAutofillDataBuilder.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
private void parseAutofillFields(AssistStructure.ViewNode viewNode,
        DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, int partition) {
    String[] hints = viewNode.getAutofillHints();
    if (hints == null || hints.length == 0) {
        return;
    }
    AutofillValue autofillValue = viewNode.getAutofillValue();
    String textValue = null;
    Long dateValue = null;
    Boolean toggleValue = null;
    CharSequence[] autofillOptions = null;
    Integer listIndex = null;
    if (autofillValue != null) {
        if (autofillValue.isText()) {
            // Using toString of AutofillValue.getTextValue in order to save it to
            // SharedPreferences.
            textValue = autofillValue.getTextValue().toString();
        } else if (autofillValue.isDate()) {
            dateValue = autofillValue.getDateValue();
        } else if (autofillValue.isList()) {
            autofillOptions = viewNode.getAutofillOptions();
            listIndex = autofillValue.getListValue();
        } else if (autofillValue.isToggle()) {
            toggleValue = autofillValue.getToggleValue();
        }
    }
    appendViewMetadata(datasetWithFilledAutofillFields,
            hints, partition, textValue, dateValue, toggleValue,
            autofillOptions, listIndex);
}
 
Example 10
Source File: ClientViewMetadataBuilder.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
private void parseWebDomain(AssistStructure.ViewNode viewNode, StringBuilder validWebDomain) {
    String webDomain = viewNode.getWebDomain();
    if (webDomain != null) {
        logd("child web domain: %s", webDomain);
        if (validWebDomain.length() > 0) {
            if (!webDomain.equals(validWebDomain.toString())) {
                throw new SecurityException("Found multiple web domains: valid= "
                        + validWebDomain + ", child=" + webDomain);
            }
        } else {
            validWebDomain.append(webDomain);
        }
    }
}
 
Example 11
Source File: ClientParser.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Traverses through the {@link AssistStructure} and does something at each {@link ViewNode}.
 *
 * @param processor contains action to be performed on each {@link ViewNode}.
 */
public void parse(NodeProcessor processor) {
    for (AssistStructure structure : mStructures) {
        int nodes = structure.getWindowNodeCount();
        for (int i = 0; i < nodes; i++) {
            AssistStructure.ViewNode viewNode = structure.getWindowNodeAt(i).getRootViewNode();
            traverseRoot(viewNode, processor);
        }
    }
}
 
Example 12
Source File: ClientParser.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
private void traverseRoot(AssistStructure.ViewNode viewNode, NodeProcessor processor) {
    processor.processNode(viewNode);
    int childrenSize = viewNode.getChildCount();
    if (childrenSize > 0) {
        for (int i = 0; i < childrenSize; i++) {
            traverseRoot(viewNode.getChildAt(i), processor);
        }
    }
}
 
Example 13
Source File: DatasetAdapter.java    From input-samples with Apache License 2.0 4 votes vote down vote up
void bindValueToNode(AssistStructure.ViewNode viewNode,
        FilledAutofillField field, Dataset.Builder builder,
        MutableBoolean setValueAtLeastOnce) {
    AutofillId autofillId = viewNode.getAutofillId();
    if (autofillId == null) {
        logw("Autofill ID null for %s", viewNode.toString());
        return;
    }
    int autofillType = viewNode.getAutofillType();
    switch (autofillType) {
        case View.AUTOFILL_TYPE_LIST:
            CharSequence[] options = viewNode.getAutofillOptions();
            int listValue = -1;
            if (options != null) {
                listValue = indexOf(viewNode.getAutofillOptions(), field.getTextValue());
            }
            if (listValue != -1) {
                builder.setValue(autofillId, AutofillValue.forList(listValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_DATE:
            Long dateValue = field.getDateValue();
            if (dateValue != null) {
                builder.setValue(autofillId, AutofillValue.forDate(dateValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_TEXT:
            String textValue = field.getTextValue();
            if (textValue != null) {
                builder.setValue(autofillId, AutofillValue.forText(textValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_TOGGLE:
            Boolean toggleValue = field.getToggleValue();
            if (toggleValue != null) {
                builder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_NONE:
        default:
            logw("Invalid autofill type - %d", autofillType);
            break;
    }
}
 
Example 14
Source File: FillContext.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Finds {@link ViewNode ViewNodes} that have the requested ids.
 *
 * @param ids The ids of the node to find.
 *
 * @return The nodes indexed in the same way as the ids.
 *
 * @hide
 */
@NonNull public ViewNode[] findViewNodesByAutofillIds(@NonNull AutofillId[] ids) {
    final LinkedList<ViewNode> nodesToProcess = new LinkedList<>();
    final ViewNode[] foundNodes = new AssistStructure.ViewNode[ids.length];

    // Indexes of foundNodes that are not found yet
    final SparseIntArray missingNodeIndexes = new SparseIntArray(ids.length);

    for (int i = 0; i < ids.length; i++) {
        if (mViewNodeLookupTable != null) {
            int lookupTableIndex = mViewNodeLookupTable.indexOfKey(ids[i]);

            if (lookupTableIndex >= 0) {
                foundNodes[i] = mViewNodeLookupTable.valueAt(lookupTableIndex);
            } else {
                missingNodeIndexes.put(i, /* ignored */ 0);
            }
        } else {
            missingNodeIndexes.put(i, /* ignored */ 0);
        }
    }

    final int numWindowNodes = mStructure.getWindowNodeCount();
    for (int i = 0; i < numWindowNodes; i++) {
        nodesToProcess.add(mStructure.getWindowNodeAt(i).getRootViewNode());
    }

    while (missingNodeIndexes.size() > 0 && !nodesToProcess.isEmpty()) {
        final ViewNode node = nodesToProcess.removeFirst();

        for (int i = 0; i < missingNodeIndexes.size(); i++) {
            final int index = missingNodeIndexes.keyAt(i);
            final AutofillId id = ids[index];

            if (id.equals(node.getAutofillId())) {
                foundNodes[index] = node;

                if (mViewNodeLookupTable == null) {
                    mViewNodeLookupTable = new ArrayMap<>(ids.length);
                }

                mViewNodeLookupTable.put(id, node);

                missingNodeIndexes.removeAt(i);
                break;
            }
        }

        for (int i = 0; i < node.getChildCount(); i++) {
            nodesToProcess.addLast(node.getChildAt(i));
        }
    }

    // Remember which ids could not be resolved to not search for them again the next time
    for (int i = 0; i < missingNodeIndexes.size(); i++) {
        if (mViewNodeLookupTable == null) {
            mViewNodeLookupTable = new ArrayMap<>(missingNodeIndexes.size());
        }

        mViewNodeLookupTable.put(ids[missingNodeIndexes.keyAt(i)], null);
    }

    return foundNodes;
}
 
Example 15
Source File: DatasetAdapter.java    From android-AutofillFramework with Apache License 2.0 4 votes vote down vote up
void bindValueToNode(AssistStructure.ViewNode viewNode,
        FilledAutofillField field, Dataset.Builder builder,
        MutableBoolean setValueAtLeastOnce) {
    AutofillId autofillId = viewNode.getAutofillId();
    if (autofillId == null) {
        logw("Autofill ID null for %s", viewNode.toString());
        return;
    }
    int autofillType = viewNode.getAutofillType();
    switch (autofillType) {
        case View.AUTOFILL_TYPE_LIST:
            CharSequence[] options = viewNode.getAutofillOptions();
            int listValue = -1;
            if (options != null) {
                listValue = indexOf(viewNode.getAutofillOptions(), field.getTextValue());
            }
            if (listValue != -1) {
                builder.setValue(autofillId, AutofillValue.forList(listValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_DATE:
            Long dateValue = field.getDateValue();
            if (dateValue != null) {
                builder.setValue(autofillId, AutofillValue.forDate(dateValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_TEXT:
            String textValue = field.getTextValue();
            if (textValue != null) {
                builder.setValue(autofillId, AutofillValue.forText(textValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_TOGGLE:
            Boolean toggleValue = field.getToggleValue();
            if (toggleValue != null) {
                builder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
                setValueAtLeastOnce.value = true;
            }
            break;
        case View.AUTOFILL_TYPE_NONE:
        default:
            logw("Invalid autofill type - %d", autofillType);
            break;
    }
}