Skip to content

Android: TalkBack does not announce state changes of checkboxes and switches #861

Open

Description

@fidderr

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:

  1. The node has a state description (AccessibilityNodeInfo.setStateDescription, API 30+).
  2. The host raises TYPE_WINDOW_CONTENT_CHANGED with CONTENT_CHANGE_TYPE_STATE_DESCRIPTION for 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: when toggled() or is_selected() changes in a tree update, raise TYPE_WINDOW_CONTENT_CHANGED with CONTENT_CHANGE_TYPE_STATE_DESCRIPTION for 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 accesskit 0.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 --check and cargo clippy -p accesskit_android --target aarch64-linux-android --all-features -- -D warnings pass. cargo +1.87 check -p accesskit_android --target aarch64-linux-android passes (MSRV). cargo test -p accesskit_android has 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions