Skip to content

fix(composer): stop the keys listener removing itself mid-callback - #259

Open
Tarquinen wants to merge 2 commits into
devfrom
insets-listener-removal
Open

Tarquinen wants to merge 2 commits into
devfrom
insets-listener-removal

Conversation

@Tarquinen

Copy link
Copy Markdown
Member

Fixes a crash Play reports as an IndexOutOfBoundsException in InsetsController.invokeControllableInsetsChangedListeners.

The composer field's controllable-insets listener removed itself from inside its own callback. Android walks that list by index with the size read up front, so when two composers are composed at once (a subagent page over its session) and a recreated window gets control of the keyboard, the second read runs past the end. The listener now just marks itself done and is removed in onDispose, so it still asks for the keyboard at most once.

Verified with a new Robolectric test in ComposerKeyboardProgressTests (fails without the fix with the same exception, passes with it), scripts/check.sh, and on the emulator: with a subagent page open and the keyboard up, changing font size crashes dev and doesn't crash this branch, and the keyboard comes back up for the focused field. The Catch Up preview with a font size change didn't crash on either.

Nothing visible changes, so no media.

Fixes #247

The composer field's OnControllableInsetsChangedListener removed itself
inside its own callback. InsetsController walks that list by index with
the size read up front, so with two composers composed (a subagent page
over its session) the second read ran past the end and the app crashed
with IndexOutOfBoundsException when a recreated window got control of the
keys (Play crash, issue #247). The listener now marks itself done and
stays registered until onDispose removes it, so it still asks for the
keys at most once.

Verified: new Robolectric test in ComposerKeyboardProgressTests fails
without the fix with the same IndexOutOfBoundsException and passes with
it; scripts/check.sh (vm.sh check) passes. On the emulator (Pixel 8,
API 36, session-lab): subagent page open with the keyboard up, then a
font scale change crashes dev and doesn't crash the branch, where the
keyboard comes back up for the focused field. The Catch Up preview with a
font scale change didn't crash on dev or the branch.
Review follow-up for #259. The regression test now focuses one field with
a counting SoftwareKeyboardController and gives the window control of the
keys, takes it away and gives it again: the listener asks for the keys
once. Since the listener now stays registered, the asked guard is the only
thing stopping a repeat request; without it the test fails at the second
assertion. docs/parity/composer.md counts four ComposerKeyboardProgressTests.

Verified: the test passes, and fails with the asked guard removed;
vm.sh check :feature:composer passes.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash: IndexOutOfBoundsException in Preconditions.outOfBounds

1 participant