Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
24ca465
fix(android): bound helper output and verify installed artifacts
thymikee Nov 30, 2026
5b36515
fix(android): enforce helper resource boundaries
thymikee Nov 30, 2026
cd5ec29
fix(android): satisfy helper boundary gates
thymikee Nov 30, 2026
54b6189
test(android): expect cached helper revalidation
thymikee Nov 30, 2026
3070f6f
test(android): expect cached helper repair
thymikee Nov 30, 2026
2e43d99
test(android): inject fill verification poll budget
thymikee Nov 30, 2026
6bc4fcf
test(android): complete fill deadline clock
thymikee Nov 30, 2026
f3bacc0
test(android): preserve helper inspection in fill fixture
thymikee Nov 30, 2026
a378cf3
fix(android): revalidate cached helper APK bytes
thymikee Nov 30, 2026
f8a7d17
fix(android): preserve complete captures and warm helper sessions
thymikee Nov 30, 2026
5ec69ce
fix(android): bound helper XML across windows and preserve fill text
thymikee Nov 30, 2026
accbe07
fix(android): revalidate warm helper installs and flag clipped text
thymikee Nov 30, 2026
d26a187
chore(android): format fill failure reason type
thymikee Nov 30, 2026
5f1b9df
test(android): accept valid wait deadline outcome
thymikee Nov 30, 2026
a950ea5
fix: address Android helper review findings
thymikee Nov 30, 2026
4bd3b1a
test(android): reuse trusted IME helper fixture
thymikee Nov 30, 2026
b791ee2
fix(android): keep helper admission table private
thymikee Nov 30, 2026
60e55bd
test(android): assert default deadline without fake-clock drift
thymikee Nov 30, 2026
503229c
test(android): keep late fill verification on real helper time
thymikee Nov 30, 2026
fdf0502
fix(android): refuse clipped text reads and explain helper checks
thymikee Nov 30, 2026
d8efb52
refactor(android): keep text reads and guidance within budgets
thymikee Nov 30, 2026
59a1e54
fix(android): reject clipped selector text and narrow helper scope
thymikee Dec 1, 2026
530e259
fix(android): classify clipped selector fallback before diagnostics
thymikee Dec 1, 2026
34cfb92
fix(android): attribute clipped text read reason to get
thymikee Dec 1, 2026
d9323ac
fix(android): omit clipped non-text helper attributes
thymikee Dec 1, 2026
7e9c0c4
test(android): pin fill verification polling budget
thymikee Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@
? null
: stats.activeWindowMetadata.withIndex(windowCount);
if (root != null
&& AccessibilityTreeXml.remainingDocumentChars(xml)
> AccessibilityTreeXml.NODE_SUFFIX_RESERVE_CHARS
&& AccessibilityCaptureStabilizer.canAppendActiveWindowFallback(
windowCount, fallbackMetadata != null)) {
AccessibilityTreeXml.appendNode(
xml, root, windowCount, 0, maxDepth, maxNodes, stats, fallbackMetadata);
xml, root, windowCount, 0, maxDepth, maxNodes, stats, fallbackMetadata,
xml.length() + AccessibilityTreeXml.remainingDocumentChars(xml));
windowCount += 1;
stats.activeWindowRootMissing = false;
}
Expand Down Expand Up @@ -190,11 +193,13 @@
return 0;
}
int windowCount = 0;
for (int index = 0; index < windows.size(); index += 1) {
if (stats.nodeCount >= maxNodes) {
if (stats.nodeCount >= maxNodes
|| AccessibilityTreeXml.remainingDocumentChars(xml)
<= AccessibilityTreeXml.NODE_SUFFIX_RESERVE_CHARS) {
stats.truncated = true;
break;
}

Check warning on line 202 in android/snapshot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/AccessibilityTreeCapture.java

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

minor: Character-budget break in the window loop skips windows without marking their roots missing

When the XML character budget is consumed by an earlier window (e.g. IME), `appendInteractiveWindowRoots` breaks out of the window loop before later windows are listed, so `missingRootWindowTypes.add(...)` and `stats.activeWindowRootMissing |= activeWindow` never execute for them. The result has `truncated=true` yet `isComplete()` returns true, and `AccessibilityCaptureStabilizer` accepts the partial tree without attempting an active-window fallback. Record skipped windows as missing roots (or clear completeness flags) when the loop breaks on the character budget.
Comment on lines 196 to 202

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆕 🟡 Minor · Window loop's <= reserve check lets one more window cross the 8 MiB document cap

A capture whose document ends with remainingDocumentChars(xml) == NODE_SUFFIX_RESERVE_CHARS + 1 (≈540,704 chars) passes the loop's <= guard, so the window lands past MAX_XML_CHARS at ~8 MiB + 540K chars. appendNode's guard is >= but the window path checks xml.length() + reserve >= maxXmlChars inside a fresh builder starting at 0, so it double-counts the reserve.

Suggested change

      if (stats.nodeCount >= maxNodes
          || AccessibilityTreeXml.remainingDocumentChars(xml)
              < AccessibilityTreeXml.NODE_SUFFIX_RESERVE_CHARS) {

Raised as major, posted as minor: no verification confirmed it.

Details

persona: senior-developer

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Comment on lines 196 to 202

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆕 🟡 Minor · Character-budget break in the window loop skips windows without marking their roots missing

When the XML character budget is consumed by an earlier window (e.g. IME), appendInteractiveWindowRoots breaks out of the window loop before later windows are listed, so missingRootWindowTypes.add(...) and stats.activeWindowRootMissing |= activeWindow never execute for them. The result has truncated=true yet isComplete() returns true, and AccessibilityCaptureStabilizer accepts the partial tree without attempting an active-window fallback. Record skipped windows as missing roots (or clear completeness flags) when the loop breaks on the character budget.

Details

persona: jvm

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

AccessibilityWindowInfo window = windows.get(index);
AccessibilityNodeInfo root = null;
boolean activeWindow = isActiveWindow(window);
Expand Down Expand Up @@ -222,7 +227,8 @@
maxDepth,
maxNodes,
windowStats,
windowMetadata);
windowMetadata,
AccessibilityTreeXml.remainingDocumentChars(xml));
xml.append(windowXml);

Check warning on line 232 in android/snapshot-helper/src/main/java/com/callstack/agentdevice/snapshothelper/AccessibilityTreeCapture.java

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

minor: Window loop's <= reserve check lets one more window cross the 8 MiB document cap

A capture whose document ends with `remainingDocumentChars(xml) == NODE_SUFFIX_RESERVE_CHARS + 1` (≈540,704 chars) passes the loop's `<=` guard, so the window lands past `MAX_XML_CHARS` at \~8 MiB + 540K chars. `appendNode`'s guard is `>=` but the window path checks `xml.length() + reserve >= maxXmlChars` inside a fresh builder starting at 0, so it double-counts the reserve.
stats.copyFrom(windowStats);
windowCount += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@

/** Serializes accessibility nodes using the helper's host-consumed XML contract. */
final class AccessibilityTreeXml {
static final int MAX_XML_CHARS = 8 * 1024 * 1024;
private static final int MAX_APP_ATTRIBUTE_CHARS = 64 * 1024;
private static final int MAX_TEXT_ATTRIBUTE_CHARS = 6 * 64 * 1024;
static final int NODE_SUFFIX_RESERVE_CHARS = 8 * MAX_APP_ATTRIBUTE_CHARS + 4096;

private AccessibilityTreeXml() {}

static int remainingDocumentChars(StringBuilder document) {
return MAX_XML_CHARS - document.length() - "</hierarchy>".length();
}

@SuppressWarnings("deprecation")
static void appendNode(
StringBuilder xml,
Expand All @@ -23,8 +32,10 @@ static void appendNode(
int maxDepth,
int maxNodes,
Stats stats,
WindowMetadata windowMetadata) {
if (stats.nodeCount >= maxNodes) {
WindowMetadata windowMetadata,
int maxXmlChars) {
if (stats.nodeCount >= maxNodes
|| xml.length() + NODE_SUFFIX_RESERVE_CHARS >= maxXmlChars) {
stats.truncated = true;
return;
}
Expand All @@ -39,7 +50,7 @@ static void appendNode(
}
CharSequence text = node.getText();
if (text != null) {
appendAttribute(xml, "text", text);
appendTextAttribute(xml, text, stats, maxXmlChars - NODE_SUFFIX_RESERVE_CHARS);
}
// getText() returns the HINT for an empty field on modern Android, so `text` alone cannot
// distinguish a cleared field from one whose value equals its hint; only this flag can
Expand All @@ -48,18 +59,30 @@ static void appendNode(
appendAttribute(xml, "hint-showing", Boolean.toString(node.isShowingHintText()));
// The hint itself, whether or not the field is showing it: `text` holds the hint only while
// the field is empty, so a filled field's placeholder is readable nowhere else.
appendNonEmptyAttribute(xml, "hint", node.getHintText());
appendAppAttribute(
xml, "hint", node.getHintText(), stats,
maxXmlChars - NODE_SUFFIX_RESERVE_CHARS, MAX_APP_ATTRIBUTE_CHARS);
}
appendAttribute(xml, "editable", Boolean.toString(node.isEditable()));
// Accessibility selection offsets, not a measurement of the value's length. Read-only
// selectable text exposes a selection too, so they do not depend on `editable`; -1 = unavailable.
appendNonNegativeAttribute(xml, "selection-start", node.getTextSelectionStart());
appendNonNegativeAttribute(xml, "selection-end", node.getTextSelectionEnd());
appendNonEmptyAttribute(xml, "resource-id", node.getViewIdResourceName());
appendAttribute(xml, "class", node.getClassName());
appendNonEmptyAttribute(xml, "package", node.getPackageName());
appendNonEmptyAttribute(xml, "content-desc", node.getContentDescription());
appendNonEmptyAttribute(xml, "role-description", roleDescription(node));
appendAppAttribute(
xml, "resource-id", node.getViewIdResourceName(), stats,
maxXmlChars - NODE_SUFFIX_RESERVE_CHARS, MAX_APP_ATTRIBUTE_CHARS);
appendAppAttribute(
xml, "class", node.getClassName(), stats,
maxXmlChars - NODE_SUFFIX_RESERVE_CHARS, MAX_APP_ATTRIBUTE_CHARS);
appendAppAttribute(
xml, "package", node.getPackageName(), stats,
maxXmlChars - NODE_SUFFIX_RESERVE_CHARS, MAX_APP_ATTRIBUTE_CHARS);
appendAppAttribute(
xml, "content-desc", node.getContentDescription(), stats,
maxXmlChars - NODE_SUFFIX_RESERVE_CHARS, MAX_APP_ATTRIBUTE_CHARS);
appendAppAttribute(
xml, "role-description", roleDescription(node), stats,
maxXmlChars - NODE_SUFFIX_RESERVE_CHARS, MAX_APP_ATTRIBUTE_CHARS);
appendTrueAttribute(xml, "heading", isHeading(node));
appendAttribute(xml, "visible-to-user", Boolean.toString(node.isVisibleToUser()));
appendDrawingOrderAttribute(xml, node);
Expand Down Expand Up @@ -95,7 +118,7 @@ static void appendNode(
}
appendAttribute(xml, "password", Boolean.toString(node.isPassword()));
appendBoundsAttribute(xml, "bounds", bounds.left, bounds.top, bounds.right, bounds.bottom);
appendScreenReaderFacts(xml, node, stats);
appendScreenReaderFacts(xml, node, stats, maxXmlChars - NODE_SUFFIX_RESERVE_CHARS);

int childCount = depth >= maxDepth ? 0 : node.getChildCount();
if (depth >= maxDepth && node.getChildCount() > 0) {
Expand All @@ -108,18 +131,22 @@ static void appendNode(

xml.append(">");
int index = 0;
while (index < childCount && stats.nodeCount < maxNodes) {
while (index < childCount && stats.nodeCount < maxNodes
&& xml.length() + NODE_SUFFIX_RESERVE_CHARS < maxXmlChars) {
int count = Math.min(
AccessibilityReadBatch.MAX_READS, Math.min(childCount - index, maxNodes - stats.nodeCount));
int offset = 0;
try (AccessibilityReadBatch<AccessibilityNodeInfo> children =
new AccessibilityReadBatch<>(
index, count, childIndex -> AccessibilityNodeReads.child(node, childIndex),
AccessibilityNodeInfo::recycle)) {
for (; offset < count && stats.nodeCount < maxNodes; offset += 1) {
for (; offset < count && stats.nodeCount < maxNodes
&& xml.length() + NODE_SUFFIX_RESERVE_CHARS < maxXmlChars; offset += 1) {
AccessibilityNodeInfo child = children.get(offset);
if (child != null) {
appendNode(xml, child, index + offset, depth + 1, maxDepth, maxNodes, stats, null);
appendNode(
xml, child, index + offset, depth + 1, maxDepth, maxNodes, stats, null,
maxXmlChars);
}
}
}
Expand Down Expand Up @@ -168,6 +195,58 @@ private static void appendNonEmptyAttribute(
appendAttribute(xml, name, value);
}

static void appendAppAttribute(
StringBuilder xml, String name, CharSequence value, Stats stats) {
appendAppAttribute(xml, name, value, stats, MAX_XML_CHARS, MAX_APP_ATTRIBUTE_CHARS);
}

static void appendTextAttribute(
StringBuilder xml, CharSequence value, Stats stats, int maxXmlChars) {
appendAppAttribute(xml, "text", value, stats, maxXmlChars, MAX_TEXT_ATTRIBUTE_CHARS);
}

private static void appendAppAttribute(
StringBuilder xml,
String name,
CharSequence value,
Stats stats,
int maxXmlChars, int maxAttributeChars) {
if (value == null || value.length() == 0) return;
String prefix = " " + name + "=\"";
int escapedBudget =
Math.min(maxAttributeChars, maxXmlChars - xml.length() - prefix.length() - 1);
if (escapedBudget <= 0) {
stats.truncated = true;
return;
}
xml.append(prefix);
int attributeStart = xml.length() - prefix.length();
int valueStart = xml.length();
int consumed = appendEscaped(xml, value, escapedBudget);
String clippedMarker = " " + name + "-clipped=\"true\"";
if (consumed < value.length()
&& escapedBudget < maxAttributeChars
&& escapedBudget >= clippedMarker.length()) {
xml.setLength(valueStart);
consumed = appendEscaped(xml, value, escapedBudget - clippedMarker.length());
}
xml.append('"');
if (consumed < value.length()) {
if (!name.equals("text")) {
xml.setLength(attributeStart);
stats.truncated = true;
return;
}
boolean markerFits = xml.length() + clippedMarker.length() <= maxXmlChars;
if (markerFits) {
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
xml.append(clippedMarker);
} else {
xml.setLength(attributeStart);
}
if (escapedBudget < maxAttributeChars || !markerFits) stats.truncated = true;
}
Comment thread
thymikee marked this conversation as resolved.
Resolved
Comment thread
thymikee marked this conversation as resolved.
Resolved
}
Comment thread
thymikee marked this conversation as resolved.
Resolved
Comment thread
thymikee marked this conversation as resolved.
Resolved

private static void appendNonNegativeAttribute(StringBuilder xml, String name, int value) {
if (value >= 0) {
appendAttribute(xml, name, Integer.toString(value));
Expand Down Expand Up @@ -230,7 +309,7 @@ static void appendLongClickableAttribute(StringBuilder xml, boolean longClickabl
// its focus rules read. `checked` above already marks a checkable node.
@SuppressWarnings("deprecation")
private static void appendScreenReaderFacts(
StringBuilder xml, AccessibilityNodeInfo node, Stats stats) {
StringBuilder xml, AccessibilityNodeInfo node, Stats stats, int maxXmlChars) {
appendTraversalLink(xml, "traversal-before", node.getTraversalBefore(), stats);
appendTraversalLink(xml, "traversal-after", node.getTraversalAfter(), stats);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Expand All @@ -242,7 +321,9 @@ private static void appendScreenReaderFacts(
appendTrueAttribute(
xml, "focus-action", hasAccessibilityAction(node, AccessibilityAction.ACTION_FOCUS));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
appendNonEmptyAttribute(xml, "state-description", node.getStateDescription());
appendAppAttribute(
xml, "state-description", node.getStateDescription(), stats, maxXmlChars,
MAX_APP_ATTRIBUTE_CHARS);
}
appendTrueAttribute(xml, "collection", node.getCollectionInfo() != null);
appendTrueAttribute(xml, "range", node.getRangeInfo() != null);
Expand Down Expand Up @@ -270,38 +351,57 @@ private static boolean hasAccessibilityAction(
}

private static void appendEscaped(StringBuilder xml, String value) {
appendEscaped(xml, value, Integer.MAX_VALUE);
}

private static int appendEscaped(StringBuilder xml, CharSequence value, int maxChars) {
int appendedChars = 0;
for (int index = 0; index < value.length(); index += 1) {
char character = value.charAt(index);
String escaped;
switch (character) {
case '&':
xml.append("&amp;");
escaped = "&amp;";
break;
case '<':
xml.append("&lt;");
escaped = "&lt;";
break;
case '>':
xml.append("&gt;");
escaped = "&gt;";
break;
case '"':
xml.append("&quot;");
escaped = "&quot;";
break;
case '\'':
xml.append("&apos;");
escaped = "&apos;";
break;
case '\n':
xml.append("&#10;");
escaped = "&#10;";
break;
case '\r':
xml.append("&#13;");
escaped = "&#13;";
break;
case '\t':
xml.append("&#9;");
escaped = "&#9;";
break;
default:
xml.append(character);
break;
int sourceChars =
Character.isHighSurrogate(character)
&& index + 1 < value.length()
&& Character.isLowSurrogate(value.charAt(index + 1))
? 2
: 1;
if (appendedChars + sourceChars > maxChars) return index;
xml.append(value, index, index + sourceChars);
appendedChars += sourceChars;
index += sourceChars - 1;
continue;
}
if (appendedChars + escaped.length() > maxChars) return index;
xml.append(escaped);
appendedChars += escaped.length();
}
return value.length();
}

static final class Stats {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,83 @@ static void run() {
" window-bounds=\"[-2147483648,-1][0,2147483647]\"");
assertLongClickable(true, " long-clickable=\"true\"");
assertLongClickable(false, " long-clickable=\"false\"");
assertAppAttributeBoundsEscapedOutput();
assertClippedDescriptionIsOmitted();
assertTextAttributeAdmitsMaximumFill();
assertDocumentLimitedTextMarksClip();
assertUnmarkedPartialTextIsOmitted();
assertWindowBudgetUsesDocumentLength();
}

private static void assertAppAttributeBoundsEscapedOutput() {
StringBuilder value = new StringBuilder();
for (int index = 0; index < 64 * 1024; index += 1) value.append('&');
StringBuilder xml = new StringBuilder();
AccessibilityTreeXml.Stats stats = new AccessibilityTreeXml.Stats();
AccessibilityTreeXml.appendAppAttribute(xml, "text", value, stats);
if (xml.length() > 64 * 1024 + " text=\"\" text-clipped=\"true\"".length()) {
throw new AssertionError("Escaped app attribute exceeded its serialized limit");
}
if (stats.truncated || !xml.toString().endsWith(" text-clipped=\"true\"")) {
throw new AssertionError("Clipped value must stay distinct from missing nodes and stay well formed");
}
}

private static void assertClippedDescriptionIsOmitted() {
StringBuilder xml = new StringBuilder();
AccessibilityTreeXml.Stats stats = new AccessibilityTreeXml.Stats();
AccessibilityTreeXml.appendAppAttribute(xml, "content-desc", "x".repeat(70 * 1024), stats);
if (!stats.truncated || xml.length() != 0) {
throw new AssertionError("Clipped descriptions must not look complete to the host");
}
}

private static void assertTextAttributeAdmitsMaximumFill() {
StringBuilder value = new StringBuilder();
for (int index = 0; index < 64 * 1024; index += 1) value.append('"');
StringBuilder xml = new StringBuilder();
AccessibilityTreeXml.Stats stats = new AccessibilityTreeXml.Stats();
AccessibilityTreeXml.appendTextAttribute(xml, value, stats, AccessibilityTreeXml.MAX_XML_CHARS);
if (stats.truncated || xml.indexOf("text-clipped") >= 0
|| xml.length() != " text=\"\"".length() + 6 * 64 * 1024) {
throw new AssertionError("Maximum admitted fill text must remain complete after XML escaping");
}
}

private static void assertWindowBudgetUsesDocumentLength() {
StringBuilder document = new StringBuilder("<hierarchy>");
int fillerChars = AccessibilityTreeXml.MAX_XML_CHARS
- document.length() - "</hierarchy>".length() - 16;
document.append("x".repeat(fillerChars));
if (AccessibilityTreeXml.remainingDocumentChars(document) != 16) {
throw new AssertionError("Document setup must leave 16 remaining chars");
}
StringBuilder nextWindow = new StringBuilder();
AccessibilityTreeXml.Stats stats = new AccessibilityTreeXml.Stats();
AccessibilityTreeXml.appendTextAttribute(
nextWindow, "&".repeat(64), stats, AccessibilityTreeXml.remainingDocumentChars(document));
if (!stats.truncated || nextWindow.length() > 16) {
throw new AssertionError("A second window must use only the document's remaining characters");
}
}

private static void assertDocumentLimitedTextMarksClip() {
StringBuilder xml = new StringBuilder();
AccessibilityTreeXml.Stats stats = new AccessibilityTreeXml.Stats();
AccessibilityTreeXml.appendTextAttribute(xml, "x".repeat(70 * 1024), stats, 64 * 1024);
if (!stats.truncated || !xml.toString().endsWith(" text-clipped=\"true\"")
|| xml.length() > 64 * 1024) {
throw new AssertionError("Document-limited text must report its clip within the document budget");
}
}

private static void assertUnmarkedPartialTextIsOmitted() {
StringBuilder xml = new StringBuilder();
AccessibilityTreeXml.Stats stats = new AccessibilityTreeXml.Stats();
AccessibilityTreeXml.appendTextAttribute(xml, "abcdef", stats, 10);
if (!stats.truncated || xml.length() != 0) {
throw new AssertionError("Partial text without room for a clip marker must be omitted");
}
}

private static void assertLongClickable(boolean longClickable, String expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ test.each<Partial<SnapshotNode>>([
{ identifier: 'create' },
{ contentDescription: 'Create a draft' },
{ text: '' },
{ textClipped: true },
{ enabled: false },
{ selected: true },
{ checked: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const PRESENTATION_SCALAR_FIELDS = {
value: true,
contentDescription: true,
text: true,
textClipped: true,
identifier: true,
enabled: true,
editable: true,
Expand Down
Loading
Loading