VisualTree

Register the native Android VisualTree tool suite to inspect the view hierarchy, capture screenshots, and manage diagnostic overlays.

Install

Published artifact: ai.ansight:ansight-tools-visualtree-android.

dependencies {
    debugImplementation("ai.ansight:ansight-tools-visualtree-android:1.4.0-preview.1")
}

Register the Suite

import ai.ansight.runtime.AnsightOptions
import ai.ansight.tools.visualtree.withVisualTreeTools

val options = AnsightOptions.createBuilder()
    .withVisualTreeTools()
    .withReadOnlyToolAccess()
    .build()

Registration API

  • withVisualTreeTools(): registers the visual tree, screenshot, and diagnostic overlay suite.
  • AndroidVisualTreeTools.create(): creates the suite tools for lower-level registration.
  • withReadOnlyToolAccess(): exposes visual tree, screenshot, node inspection, and read-only overlay tools.
  • withReadWriteToolAccess(): also exposes overlay creation, update, removal, and clearing; every overlay mutation uses Write.

Visual-Tree Providers

AndroidVisualTreeProviderRegistry always exposes the Android view hierarchy as native. Additional UI frameworks can implement AndroidVisualTreeProvider and register their own stable source:

import ai.ansight.tools.visualtree.AndroidVisualTreeProviderRegistry

AndroidVisualTreeProviderRegistry.register(
    provider = customProvider,
    replaceExisting = true,
)

The provider supplies source, displayName, getVisualTree(...), and inspectNode(...). Pass source to ui.get_visual_tree or ui.inspect_node; omitting it selects native. Responses use the shared compact visual-tree v2 contract.

Specific Concerns

  • The native provider captures every top-level Android window root owned by the foreground activity, including dialogs and popup windows when present.
  • Screenshot capture exports rendered UI content.
  • ui.get_screenshot streams bytes over the binary transfer channel.
  • Overlay removal tools use Write consistently across platforms.

Important: Calling screenshot tools will result in an FPS drop while the current frame is captured, encoded, and transferred. Avoid screenshot-heavy investigations during trend measurements unless visual evidence is required.

Tool Matrix

NameIdPolicyDescription
Get Visual Treeui.get_visual_treeReadReturns the current visual hierarchy for the requested source.
Get Screenshotui.get_screenshotReadCaptures a screenshot and streams bytes over binary transfer.
Inspect Nodeui.inspect_nodeReadReturns one node from the current visual tree.
Show Overlayui.show_overlayWriteShows a rectangular diagnostic overlay.
Get Overlayui.get_overlayReadReturns one diagnostic overlay.
Query Overlaysui.query_overlaysReadLists active diagnostic overlays.
Update Overlayui.update_overlayWriteUpdates a diagnostic overlay.
Remove Overlayui.remove_overlayWriteRemoves a diagnostic overlay.
Clear Overlaysui.clear_overlaysWriteClears diagnostic overlays.

Tool Details

Use read tools for inspection and screenshots. ui.get_visual_tree and ui.inspect_node accept an optional source argument for provider selection. Their responses include a top-level types registry referenced by each node’s typeId, semantic roles and actions, automation ids, presentation data, and structural child order. See the Visual-Tree Payload Contract. Use write tools only when the session needs to create, update, remove, or clear overlays remotely.