Repository navigation
Description
What happens
On Android, TalkBack stays silent after a checkbox or switch exposed through accesskit_android is activated. Focusing the node is fine ("not checked, Sort by name, checkbox, double-tap to toggle"), and double-tap toggles it, but the new state ("checked" / "not checked") is never announced. A framework CheckBox announces it.
Seen with a Slint app (Slint's Android backend uses accesskit_android 0.9.1 through InjectingAdapter) on a OnePlus phone with Android 16 (API 36) and TalkBack from the Android Accessibility Suite.
Cause
TalkBack only announces a state change when both of these are true:
- The node has a state description (
AccessibilityNodeInfo.setStateDescription, API 30+). - The host raises
TYPE_WINDOW_CONTENT_CHANGEDwithCONTENT_CHANGE_TYPE_STATE_DESCRIPTIONfor that node.
accesskit_android does neither. AdapterChangeHandler::node_updated raises events for text, scroll and live-region changes, and ends with // TODO: other events. No state description is set on any node.
I found this with a hand-written virtual node in a test activity, varying which events and properties it exposed and counting TalkBack's speech requests after a double-tap. Speech came only with both 1 and 2. Either one alone did nothing. A TYPE_VIEW_CLICKED with class, checked state and text, as CompoundButton sends, was not needed.
Proposed change
fidderr/accesskit@0abc719 (branch android-announce-state-changes, on top of main dea4384), in adapters/android only:
node.rs: nodes with a toggled or selected state get a state description. It uses the framework's own localized strings (android.R.string-style "checked" / "not checked" / "selected" / "not selected", looked up through the system resources), as the framework's compound buttons do. Mixed state gets none.adapter.rs/event.rs: whentoggled()oris_selected()changes in a tree update, raiseTYPE_WINDOW_CONTENT_CHANGEDwithCONTENT_CHANGE_TYPE_STATE_DESCRIPTIONfor that node.- Both are skipped below API 30.
The Java delegate and classes.dex are unchanged.
Testing
- With the change (applied to the published 0.9.1 crate in a Slint test app, because Slint is on
accesskit0.25.2), real TalkBack on the device announced, from a recording, translated from the device's locale: "not checked, Make the C++ code, checkbox, in list, double-tap to toggle, checked". A second double-tap gave "not checked". - Without the change there were 0 speech requests after the toggle.
cargo fmt --checkandcargo clippy -p accesskit_android --target aarch64-linux-android --all-features -- -D warningspass.cargo +1.87 check -p accesskit_android --target aarch64-linux-androidpasses (MSRV).cargo test -p accesskit_androidhas no tests to run.- Not tested: devices below API 30, where the code path is skipped, and other screen readers.
I'm happy to open this as a PR, or to change the approach if you prefer something else, for example also covering expanded/collapsed.
Activity