fix(snapshothelper): preserve TalkBack during Android helper automation

MV
2d ago
+45-1

Summary

With the snapshot helper session open, TalkBack stays enabled in secure settings but unbound, so focus and speech cannot be validated during snapshots or helper input. Closing the session lets TalkBack bind and connect to speech, and a later long press can leave it rebinding. The shared helper connection always called getUiAutomation() with no flags. Android suppresses other accessibility services for as long as that connection is held, unless the caller passes FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES, which exists from API 24.

Persistence settings never requested that flag, so both persistent sessions and one-shot operations kept TalkBack unbound.

On API 24 and newer, tryGetConnectedUiAutomation now connects with UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES so enabled services such as TalkBack can stay bound during snapshots and gestures. API 23 still uses the no-argument connection because the flagged overload is unavailable there. The helper README records that this covers persistent sessions and one-shot operations, and that reader exploration gestures and speech verification remain a separate feature. Refs #4179.

Refs #4179

Test plan

npx --no-install vitest run test/repo-guards/android-helper-accessibility-services.test.ts passed with one test.
The tests in test/repo-guards/android-helper-accessibility-services.test.ts fail without the fix in the agent-device SnapshotInstrumentation change (checked by reverting the source changes).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.