android.app.assist.AssistStructure.ViewNode Java Examples

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: MultiStepsService.java    From input-samples with Apache License 2.0 6 votes vote down vote up
private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
        @NonNull ViewNode node) {
    String[] hints = node.getAutofillHints();
    if (hints != null) {
        // We're simple, we only care about the first hint
        String hint = hints[0];
        AutofillId id = node.getAutofillId();
        if (!fields.containsKey(hint)) {
            Log.v(TAG, "Setting hint '" + hint + "' on " + id);
            fields.put(hint, id);
        } else {
            Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
                    + " because it was already set");
        }
    }
    int childrenSize = node.getChildCount();
    for (int i = 0; i < childrenSize; i++) {
        addAutofillableFields(fields, node.getChildAt(i));
    }
}
 
Example #2
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a node if it matches the filter criteria for the given id.
 */
public static ViewNode findNodeByFilter(@NonNull ViewNode node, @NonNull Object id,
        @NonNull NodeFilter filter) {
    if (filter.matches(node, id)) {
        return node;
    }
    final int childrenSize = node.getChildCount();
    if (childrenSize > 0) {
        for (int i = 0; i < childrenSize; i++) {
            final ViewNode found = findNodeByFilter(node.getChildAt(i), id, filter);
            if (found != null) {
                return found;
            }
        }
    }
    return null;
}
 
Example #3
Source File: BasicService.java    From input-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Adds any autofillable view from the {@link ViewNode} and its descendants to the map.
 */
private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
        @NonNull ViewNode node) {
    String[] hints = node.getAutofillHints();
    if (hints != null) {
        // We're simple, we only care about the first hint
        String hint = hints[0].toLowerCase();

        if (hint != null) {
            AutofillId id = node.getAutofillId();
            if (!fields.containsKey(hint)) {
                Log.v(TAG, "Setting hint '" + hint + "' on " + id);
                fields.put(hint, id);
            } else {
                Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
                        + " because it was already set");
            }
        }
    }
    int childrenSize = node.getChildCount();
    for (int i = 0; i < childrenSize; i++) {
        addAutofillableFields(fields, node.getChildAt(i));
    }
}
 
Example #4
Source File: DebugService.java    From input-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Adds any autofillable view from the {@link ViewNode} and its descendants to the map.
 */
private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
        @NonNull ViewNode node) {
    String hint = getHint(node);
    if (hint != null) {
        AutofillId id = node.getAutofillId();
        if (!fields.containsKey(hint)) {
            Log.v(TAG, "Setting hint '" + hint + "' on " + id);
            fields.put(hint, id);
        } else {
            Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
                    + " because it was already set");
        }
    }
    int childrenSize = node.getChildCount();
    for (int i = 0; i < childrenSize; i++) {
        addAutofillableFields(fields, node.getChildAt(i));
    }
}
 
Example #5
Source File: DebugService.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
/**
 * Adds any autofillable view from the {@link ViewNode} and its descendants to the map.
 */
private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
        @NonNull ViewNode node) {
    String hint = getHint(node);
    if (hint != null) {
        AutofillId id = node.getAutofillId();
        if (!fields.containsKey(hint)) {
            Log.v(TAG, "Setting hint '" + hint + "' on " + id);
            fields.put(hint, id);
        } else {
            Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
                    + " because it was already set");
        }
    }
    int childrenSize = node.getChildCount();
    for (int i = 0; i < childrenSize; i++) {
        addAutofillableFields(fields, node.getChildAt(i));
    }
}
 
Example #6
Source File: BasicService.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
/**
 * Adds any autofillable view from the {@link ViewNode} and its descendants to the map.
 */
private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
        @NonNull ViewNode node) {
    String[] hints = node.getAutofillHints();
    if (hints != null) {
        // We're simple, we only care about the first hint
        String hint = hints[0].toLowerCase();

        if (hint != null) {
            AutofillId id = node.getAutofillId();
            if (!fields.containsKey(hint)) {
                Log.v(TAG, "Setting hint '" + hint + "' on " + id);
                fields.put(hint, id);
            } else {
                Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
                        + " because it was already set");
            }
        }
    }
    int childrenSize = node.getChildCount();
    for (int i = 0; i < childrenSize; i++) {
        addAutofillableFields(fields, node.getChildAt(i));
    }
}
 
Example #7
Source File: Util.java    From input-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a node if it matches the filter criteria for the given id.
 */
public static ViewNode findNodeByFilter(@NonNull ViewNode node, @NonNull Object id,
        @NonNull NodeFilter filter) {
    if (filter.matches(node, id)) {
        return node;
    }
    final int childrenSize = node.getChildCount();
    if (childrenSize > 0) {
        for (int i = 0; i < childrenSize; i++) {
            final ViewNode found = findNodeByFilter(node.getChildAt(i), id, filter);
            if (found != null) {
                return found;
            }
        }
    }
    return null;
}
 
Example #8
Source File: MultiStepsService.java    From android-AutofillFramework with Apache License 2.0 6 votes vote down vote up
private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
        @NonNull ViewNode node) {
    String[] hints = node.getAutofillHints();
    if (hints != null) {
        // We're simple, we only care about the first hint
        String hint = hints[0];
        AutofillId id = node.getAutofillId();
        if (!fields.containsKey(hint)) {
            Log.v(TAG, "Setting hint '" + hint + "' on " + id);
            fields.put(hint, id);
        } else {
            Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
                    + " because it was already set");
        }
    }
    int childrenSize = node.getChildCount();
    for (int i = 0; i < childrenSize; i++) {
        addAutofillableFields(fields, node.getChildAt(i));
    }
}
 
Example #9
Source File: MultiStepsService.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
@NonNull
private ArrayMap<String, AutofillId> getAutofillableFields(@NonNull AssistStructure structure) {
    ArrayMap<String, AutofillId> fields = new ArrayMap<>();
    int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        ViewNode node = structure.getWindowNodeAt(i).getRootViewNode();
        addAutofillableFields(fields, node);
    }
    return fields;
}
 
Example #10
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a node if it matches the filter criteria for the given id.
 */
public static ViewNode findNodeByFilter(@NonNull AssistStructure structure, @NonNull Object id,
        @NonNull NodeFilter filter) {
    logv("Parsing request for activity %s", structure.getActivityComponent());
    final int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        final WindowNode windowNode = structure.getWindowNodeAt(i);
        final ViewNode rootNode = windowNode.getRootViewNode();
        final ViewNode node = findNodeByFilter(rootNode, id, filter);
        if (node != null) {
            return node;
        }
    }
    return null;
}
 
Example #11
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a node if it matches the filter criteria for the given id.
 */
public static ViewNode findNodeByFilter(@NonNull List<FillContext> contexts, @NonNull Object id,
        @NonNull NodeFilter filter) {
    for (FillContext context : contexts) {
        ViewNode node = findNodeByFilter(context.getStructure(), id, filter);
        if (node != null) {
            return node;
        }
    }
    return null;
}
 
Example #12
Source File: DebugService.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Uses heuristics to infer an autofill hint from a {@code string}.
 *
 * @return standard autofill hint, or {@code null} when it could not be inferred.
 */
@Nullable
protected String inferHint(ViewNode node, @Nullable String actualHint) {
    if (actualHint == null) return null;

    String hint = actualHint.toLowerCase();
    if (hint.contains("label") || hint.contains("container")) {
        Log.v(TAG, "Ignoring 'label/container' hint: " + hint);
        return null;
    }

    if (hint.contains("password")) return View.AUTOFILL_HINT_PASSWORD;
    if (hint.contains("username")
            || (hint.contains("login") && hint.contains("id")))
        return View.AUTOFILL_HINT_USERNAME;
    if (hint.contains("email")) return View.AUTOFILL_HINT_EMAIL_ADDRESS;
    if (hint.contains("name")) return View.AUTOFILL_HINT_NAME;
    if (hint.contains("phone")) return View.AUTOFILL_HINT_PHONE;

    // When everything else fails, return the full string - this is helpful to help app
    // developers visualize when autofill is triggered when it shouldn't (for example, in a
    // chat conversation window), so they can mark the root view of such activities with
    // android:importantForAutofill=noExcludeDescendants
    if (node.isEnabled() && node.getAutofillType() != View.AUTOFILL_TYPE_NONE) {
        Log.v(TAG, "Falling back to " + actualHint);
        return actualHint;
    }
    return null;
}
 
Example #13
Source File: DebugService.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the {@link AssistStructure} representing the activity being autofilled, and returns a
 * map of autofillable fields (represented by their autofill ids) mapped by the hint associate
 * with them.
 *
 * <p>An autofillable field is a {@link ViewNode} whose {@link #getHint(ViewNode)} metho
 */
@NonNull
private ArrayMap<String, AutofillId> getAutofillableFields(@NonNull AssistStructure structure) {
    ArrayMap<String, AutofillId> fields = new ArrayMap<>();
    int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        ViewNode node = structure.getWindowNodeAt(i).getRootViewNode();
        addAutofillableFields(fields, node);
    }
    return fields;
}
 
Example #14
Source File: BasicService.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the {@link AssistStructure} representing the activity being autofilled, and returns a
 * map of autofillable fields (represented by their autofill ids) mapped by the hint associate
 * with them.
 *
 * <p>An autofillable field is a {@link ViewNode} whose {@link #getHint(ViewNode)} metho
 */
@NonNull
private Map<String, AutofillId> getAutofillableFields(@NonNull AssistStructure structure) {
    Map<String, AutofillId> fields = new ArrayMap<>();
    int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        ViewNode node = structure.getWindowNodeAt(i).getRootViewNode();
        addAutofillableFields(fields, node);
    }
    return fields;
}
 
Example #15
Source File: MultiStepsService.java    From input-samples with Apache License 2.0 5 votes vote down vote up
@NonNull
private ArrayMap<String, AutofillId> getAutofillableFields(@NonNull AssistStructure structure) {
    ArrayMap<String, AutofillId> fields = new ArrayMap<>();
    int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        ViewNode node = structure.getWindowNodeAt(i).getRootViewNode();
        addAutofillableFields(fields, node);
    }
    return fields;
}
 
Example #16
Source File: Util.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a node if it matches the filter criteria for the given id.
 */
public static ViewNode findNodeByFilter(@NonNull AssistStructure structure, @NonNull Object id,
        @NonNull NodeFilter filter) {
    logv("Parsing request for activity %s", structure.getActivityComponent());
    final int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        final WindowNode windowNode = structure.getWindowNodeAt(i);
        final ViewNode rootNode = windowNode.getRootViewNode();
        final ViewNode node = findNodeByFilter(rootNode, id, filter);
        if (node != null) {
            return node;
        }
    }
    return null;
}
 
Example #17
Source File: Util.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a node if it matches the filter criteria for the given id.
 */
public static ViewNode findNodeByFilter(@NonNull List<FillContext> contexts, @NonNull Object id,
        @NonNull NodeFilter filter) {
    for (FillContext context : contexts) {
        ViewNode node = findNodeByFilter(context.getStructure(), id, filter);
        if (node != null) {
            return node;
        }
    }
    return null;
}
 
Example #18
Source File: DebugService.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Uses heuristics to infer an autofill hint from a {@code string}.
 *
 * @return standard autofill hint, or {@code null} when it could not be inferred.
 */
@Nullable
protected String inferHint(ViewNode node, @Nullable String actualHint) {
    if (actualHint == null) return null;

    String hint = actualHint.toLowerCase();
    if (hint.contains("label") || hint.contains("container")) {
        Log.v(TAG, "Ignoring 'label/container' hint: " + hint);
        return null;
    }

    if (hint.contains("password")) return View.AUTOFILL_HINT_PASSWORD;
    if (hint.contains("username")
            || (hint.contains("login") && hint.contains("id")))
        return View.AUTOFILL_HINT_USERNAME;
    if (hint.contains("email")) return View.AUTOFILL_HINT_EMAIL_ADDRESS;
    if (hint.contains("name")) return View.AUTOFILL_HINT_NAME;
    if (hint.contains("phone")) return View.AUTOFILL_HINT_PHONE;

    // When everything else fails, return the full string - this is helpful to help app
    // developers visualize when autofill is triggered when it shouldn't (for example, in a
    // chat conversation window), so they can mark the root view of such activities with
    // android:importantForAutofill=noExcludeDescendants
    if (node.isEnabled() && node.getAutofillType() != View.AUTOFILL_TYPE_NONE) {
        Log.v(TAG, "Falling back to " + actualHint);
        return actualHint;
    }
    return null;
}
 
Example #19
Source File: DebugService.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the {@link AssistStructure} representing the activity being autofilled, and returns a
 * map of autofillable fields (represented by their autofill ids) mapped by the hint associate
 * with them.
 *
 * <p>An autofillable field is a {@link ViewNode} whose {@link #getHint(ViewNode)} metho
 */
@NonNull
private ArrayMap<String, AutofillId> getAutofillableFields(@NonNull AssistStructure structure) {
    ArrayMap<String, AutofillId> fields = new ArrayMap<>();
    int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        ViewNode node = structure.getWindowNodeAt(i).getRootViewNode();
        addAutofillableFields(fields, node);
    }
    return fields;
}
 
Example #20
Source File: BasicService.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the {@link AssistStructure} representing the activity being autofilled, and returns a
 * map of autofillable fields (represented by their autofill ids) mapped by the hint associate
 * with them.
 *
 * <p>An autofillable field is a {@link ViewNode} whose {@link #getHint(ViewNode)} metho
 */
@NonNull
private Map<String, AutofillId> getAutofillableFields(@NonNull AssistStructure structure) {
    Map<String, AutofillId> fields = new ArrayMap<>();
    int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        ViewNode node = structure.getWindowNodeAt(i).getRootViewNode();
        addAutofillableFields(fields, node);
    }
    return fields;
}
 
Example #21
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 #22
Source File: Util.java    From input-samples with Apache License 2.0 4 votes vote down vote up
private static void dumpNode(String prefix, ViewNode node) {
    StringBuilder builder = new StringBuilder();
    builder.append(prefix)
            .append("autoFillId: ").append(node.getAutofillId())
            .append("\tidEntry: ").append(node.getIdEntry())
            .append("\tid: ").append(node.getId())
            .append("\tclassName: ").append(node.getClassName())
            .append('\n');

    builder.append(prefix)
            .append("focused: ").append(node.isFocused())
            .append("\tvisibility").append(node.getVisibility())
            .append("\tchecked: ").append(node.isChecked())
            .append("\twebDomain: ").append(node.getWebDomain())
            .append("\thint: ").append(node.getHint())
            .append('\n');

    HtmlInfo htmlInfo = node.getHtmlInfo();

    if (htmlInfo != null) {
        builder.append(prefix)
                .append("HTML TAG: ").append(htmlInfo.getTag())
                .append(" attrs: ").append(htmlInfo.getAttributes())
                .append('\n');
    }

    String[] afHints = node.getAutofillHints();
    CharSequence[] options = node.getAutofillOptions();
    builder.append(prefix).append("afType: ").append(getAutofillTypeAsString(node.getAutofillType()))
            .append("\tafValue:")
            .append(getAutofillValueAndTypeAsString(node.getAutofillValue()))
            .append("\tafOptions:").append(options == null ? "N/A" : Arrays.toString(options))
            .append("\tafHints: ").append(afHints == null ? "N/A" : Arrays.toString(afHints))
            .append("\tinputType:").append(node.getInputType())
            .append('\n');

    int numberChildren = node.getChildCount();
    builder.append(prefix).append("# children: ").append(numberChildren)
            .append("\ttext: ").append(node.getText())
            .append('\n');

    Log.v(TAG, builder.toString());
    final String prefix2 = prefix + "  ";
    for (int i = 0; i < numberChildren; i++) {
        Log.v(TAG, prefix + "child #" + i);
        dumpNode(prefix2, node.getChildAt(i));
    }
}
 
Example #23
Source File: Util.java    From input-samples with Apache License 2.0 4 votes vote down vote up
private static void dumpNode(StringBuilder builder, String prefix, ViewNode node, int childNumber) {
    builder.append(prefix)
            .append("child #").append(childNumber).append("\n");

    builder.append(prefix)
            .append("autoFillId: ").append(node.getAutofillId())
            .append("\tidEntry: ").append(node.getIdEntry())
            .append("\tid: ").append(node.getId())
            .append("\tclassName: ").append(node.getClassName())
            .append('\n');

    builder.append(prefix)
            .append("focused: ").append(node.isFocused())
            .append("\tvisibility").append(node.getVisibility())
            .append("\tchecked: ").append(node.isChecked())
            .append("\twebDomain: ").append(node.getWebDomain())
            .append("\thint: ").append(node.getHint())
            .append('\n');

    HtmlInfo htmlInfo = node.getHtmlInfo();

    if (htmlInfo != null) {
        builder.append(prefix)
                .append("HTML TAG: ").append(htmlInfo.getTag())
                .append(" attrs: ").append(htmlInfo.getAttributes())
                .append('\n');
    }

    String[] afHints = node.getAutofillHints();
    CharSequence[] options = node.getAutofillOptions();
    builder.append(prefix).append("afType: ").append(getTypeAsString(node.getAutofillType()))
            .append("\tafValue:")
            .append(getAutofillValueAndTypeAsString(node.getAutofillValue()))
            .append("\tafOptions:").append(options == null ? "N/A" : Arrays.toString(options))
            .append("\tafHints: ").append(afHints == null ? "N/A" : Arrays.toString(afHints))
            .append("\tinputType:").append(node.getInputType())
            .append('\n');

    int numberChildren = node.getChildCount();
    builder.append(prefix).append("# children: ").append(numberChildren)
            .append("\ttext: ").append(node.getText())
            .append('\n');

    final String prefix2 = prefix + "  ";
    for (int i = 0; i < numberChildren; i++) {
        dumpNode(builder, prefix2, node.getChildAt(i), i);
    }
    logv(builder.toString());
}
 
Example #24
Source File: DebugService.java    From android-AutofillFramework with Apache License 2.0 4 votes vote down vote up
@Nullable
protected String getHint(@NonNull ViewNode node) {

    // First try the explicit autofill hints...

    String[] hints = node.getAutofillHints();
    if (hints != null) {
        // We're simple, we only care about the first hint
        return hints[0].toLowerCase();
    }

    // Then try some rudimentary heuristics based on other node properties

    String viewHint = node.getHint();
    String hint = inferHint(node, viewHint);
    if (hint != null) {
        Log.d(TAG, "Found hint using view hint(" + viewHint + "): " + hint);
        return hint;
    } else if (!TextUtils.isEmpty(viewHint)) {
        Log.v(TAG, "No hint using view hint: " + viewHint);
    }

    String resourceId = node.getIdEntry();
    hint = inferHint(node, resourceId);
    if (hint != null) {
        Log.d(TAG, "Found hint using resourceId(" + resourceId + "): " + hint);
        return hint;
    } else if (!TextUtils.isEmpty(resourceId)) {
        Log.v(TAG, "No hint using resourceId: " + resourceId);
    }

    CharSequence text = node.getText();
    CharSequence className = node.getClassName();
    if (text != null && className != null && className.toString().contains("EditText")) {
        hint = inferHint(node, text.toString());
        if (hint != null) {
            // NODE: text should not be logged, as it could contain PII
            Log.d(TAG, "Found hint using text(" + text + "): " + hint);
            return hint;
        }
    } else if (!TextUtils.isEmpty(text)) {
        // NODE: text should not be logged, as it could contain PII
        Log.v(TAG, "No hint using text: " + text + " and class " + className);
    }
    return null;
}
 
Example #25
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 4 votes vote down vote up
private static void dumpNode(StringBuilder builder, String prefix, ViewNode node, int childNumber) {
    builder.append(prefix)
            .append("child #").append(childNumber).append("\n");

    builder.append(prefix)
            .append("autoFillId: ").append(node.getAutofillId())
            .append("\tidEntry: ").append(node.getIdEntry())
            .append("\tid: ").append(node.getId())
            .append("\tclassName: ").append(node.getClassName())
            .append('\n');

    builder.append(prefix)
            .append("focused: ").append(node.isFocused())
            .append("\tvisibility").append(node.getVisibility())
            .append("\tchecked: ").append(node.isChecked())
            .append("\twebDomain: ").append(node.getWebDomain())
            .append("\thint: ").append(node.getHint())
            .append('\n');

    HtmlInfo htmlInfo = node.getHtmlInfo();

    if (htmlInfo != null) {
        builder.append(prefix)
                .append("HTML TAG: ").append(htmlInfo.getTag())
                .append(" attrs: ").append(htmlInfo.getAttributes())
                .append('\n');
    }

    String[] afHints = node.getAutofillHints();
    CharSequence[] options = node.getAutofillOptions();
    builder.append(prefix).append("afType: ").append(getTypeAsString(node.getAutofillType()))
            .append("\tafValue:")
            .append(getAutofillValueAndTypeAsString(node.getAutofillValue()))
            .append("\tafOptions:").append(options == null ? "N/A" : Arrays.toString(options))
            .append("\tafHints: ").append(afHints == null ? "N/A" : Arrays.toString(afHints))
            .append("\tinputType:").append(node.getInputType())
            .append('\n');

    int numberChildren = node.getChildCount();
    builder.append(prefix).append("# children: ").append(numberChildren)
            .append("\ttext: ").append(node.getText())
            .append('\n');

    final String prefix2 = prefix + "  ";
    for (int i = 0; i < numberChildren; i++) {
        dumpNode(builder, prefix2, node.getChildAt(i), i);
    }
    logv(builder.toString());
}
 
Example #26
Source File: DebugService.java    From input-samples with Apache License 2.0 4 votes vote down vote up
@Nullable
protected String getHint(@NonNull ViewNode node) {

    // First try the explicit autofill hints...

    String[] hints = node.getAutofillHints();
    if (hints != null) {
        // We're simple, we only care about the first hint
        return hints[0].toLowerCase();
    }

    // Then try some rudimentary heuristics based on other node properties

    String viewHint = node.getHint();
    String hint = inferHint(node, viewHint);
    if (hint != null) {
        Log.d(TAG, "Found hint using view hint(" + viewHint + "): " + hint);
        return hint;
    } else if (!TextUtils.isEmpty(viewHint)) {
        Log.v(TAG, "No hint using view hint: " + viewHint);
    }

    String resourceId = node.getIdEntry();
    hint = inferHint(node, resourceId);
    if (hint != null) {
        Log.d(TAG, "Found hint using resourceId(" + resourceId + "): " + hint);
        return hint;
    } else if (!TextUtils.isEmpty(resourceId)) {
        Log.v(TAG, "No hint using resourceId: " + resourceId);
    }

    CharSequence text = node.getText();
    CharSequence className = node.getClassName();
    if (text != null && className != null && className.toString().contains("EditText")) {
        hint = inferHint(node, text.toString());
        if (hint != null) {
            // NODE: text should not be logged, as it could contain PII
            Log.d(TAG, "Found hint using text(" + text + "): " + hint);
            return hint;
        }
    } else if (!TextUtils.isEmpty(text)) {
        // NODE: text should not be logged, as it could contain PII
        Log.v(TAG, "No hint using text: " + text + " and class " + className);
    }
    return null;
}
 
Example #27
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 4 votes vote down vote up
private static void dumpNode(String prefix, ViewNode node) {
    StringBuilder builder = new StringBuilder();
    builder.append(prefix)
            .append("autoFillId: ").append(node.getAutofillId())
            .append("\tidEntry: ").append(node.getIdEntry())
            .append("\tid: ").append(node.getId())
            .append("\tclassName: ").append(node.getClassName())
            .append('\n');

    builder.append(prefix)
            .append("focused: ").append(node.isFocused())
            .append("\tvisibility").append(node.getVisibility())
            .append("\tchecked: ").append(node.isChecked())
            .append("\twebDomain: ").append(node.getWebDomain())
            .append("\thint: ").append(node.getHint())
            .append('\n');

    HtmlInfo htmlInfo = node.getHtmlInfo();

    if (htmlInfo != null) {
        builder.append(prefix)
                .append("HTML TAG: ").append(htmlInfo.getTag())
                .append(" attrs: ").append(htmlInfo.getAttributes())
                .append('\n');
    }

    String[] afHints = node.getAutofillHints();
    CharSequence[] options = node.getAutofillOptions();
    builder.append(prefix).append("afType: ").append(getAutofillTypeAsString(node.getAutofillType()))
            .append("\tafValue:")
            .append(getAutofillValueAndTypeAsString(node.getAutofillValue()))
            .append("\tafOptions:").append(options == null ? "N/A" : Arrays.toString(options))
            .append("\tafHints: ").append(afHints == null ? "N/A" : Arrays.toString(afHints))
            .append("\tinputType:").append(node.getInputType())
            .append('\n');

    int numberChildren = node.getChildCount();
    builder.append(prefix).append("# children: ").append(numberChildren)
            .append("\ttext: ").append(node.getText())
            .append('\n');

    Log.v(TAG, builder.toString());
    final String prefix2 = prefix + "  ";
    for (int i = 0; i < numberChildren; i++) {
        Log.v(TAG, prefix + "child #" + i);
        dumpNode(prefix2, node.getChildAt(i));
    }
}
 
Example #28
Source File: ContentViewCore.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void createVirtualStructure(ViewStructure viewNode, AccessibilitySnapshotNode node,
        final boolean ignoreScrollOffset) {
    viewNode.setClassName(node.className);
    if (node.hasSelection) {
        viewNode.setText(node.text, node.startSelection, node.endSelection);
    } else {
        viewNode.setText(node.text);
    }
    int left = (int) mRenderCoordinates.fromLocalCssToPix(node.x);
    int top = (int) mRenderCoordinates.fromLocalCssToPix(node.y);
    int width = (int) mRenderCoordinates.fromLocalCssToPix(node.width);
    int height = (int) mRenderCoordinates.fromLocalCssToPix(node.height);

    Rect boundsInParent = new Rect(left, top, left + width, top + height);
    if (node.isRootNode) {
        // Offset of the web content relative to the View.
        boundsInParent.offset(0, (int) mRenderCoordinates.getContentOffsetYPix());
        if (!ignoreScrollOffset) {
            boundsInParent.offset(-(int) mRenderCoordinates.getScrollXPix(),
                    -(int) mRenderCoordinates.getScrollYPix());
        }
    }

    viewNode.setDimens(boundsInParent.left, boundsInParent.top, 0, 0, width, height);
    viewNode.setChildCount(node.children.size());
    if (node.hasStyle) {
        // The text size should be in physical pixels, not CSS pixels.
        float textSize = mRenderCoordinates.fromLocalCssToPix(node.textSize);

        int style = (node.bold ? ViewNode.TEXT_STYLE_BOLD : 0)
                | (node.italic ? ViewNode.TEXT_STYLE_ITALIC : 0)
                | (node.underline ? ViewNode.TEXT_STYLE_UNDERLINE : 0)
                | (node.lineThrough ? ViewNode.TEXT_STYLE_STRIKE_THRU : 0);
        viewNode.setTextStyle(textSize, node.color, node.bgcolor, style);
    }
    for (int i = 0; i < node.children.size(); i++) {
        createVirtualStructure(viewNode.asyncNewChild(i), node.children.get(i), true);
    }
    viewNode.asyncCommit();
}
 
Example #29
Source File: Util.java    From input-samples with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the node passes the filter for such given id.
 */
boolean matches(ViewNode node, Object id);
 
Example #30
Source File: Util.java    From android-AutofillFramework with Apache License 2.0 2 votes vote down vote up
/**
 * Returns whether the node passes the filter for such given id.
 */
boolean matches(ViewNode node, Object id);