fix(clipboard): null-safe keyboard icon access and input-view race guard in suggestion callbacks - #434
Open
Lloyd-Jackman-UKPL wants to merge 1 commit into
Conversation
…ard in suggestion callbacks A screenshot arriving while the keyboard view is torn down crashes the IME: ClipboardHistoryManager.getScreenshotSuggestionView() reads Keyboard.mIconsSet through mKeyboardSwitcher.keyboard without a null check, throwing 'NullPointerException: ... Keyboard.mIconsSet on a null object reference' from the MediaStore ContentObserver callback. - add activeKeyboardIcons(): null-safe accessor for the active keyboard's icon set; all four icon call sites degrade to icon-less suggestions instead of crashing when no keyboard view exists - skip tryShowClipboardSuggestion() from the screenshot observer while the input view is not shown; the next input show surfaces it anyway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Description
The IME process dies when a screenshot lands while the keyboard view does not exist. Observed three times in one day on a Pixel-era Samsung (S24+, Android 16) running the debug build:
The MediaStore ContentObserver fires as soon as any screenshot appears system-wide, even while the IME service is idle with no input view inflated.
Root Cause
Two independent problems combine:
getScreenshotSuggestionView()/getClipboardSuggestionView()readlatinIME.mKeyboardSwitcher.keyboard.mIconsSetunguarded.mKeyboardSwitcher.keyboardis null whenever no keyboard view is currently built, so any callback racing view construction/teardown NPEs on the main thread.onChangecallsupdateLatestScreenshotCache { latinIME.tryShowClipboardSuggestion() }without checking that an input view exists, guaranteeing that race is reachable in normal use.Fix
activeKeyboardIcons(): null-safe access to the active keyboard's icon set (KeyboardIconsSet?). All four icon call sites now degrade gracefully - the suggestion renders icon-less instead of crashing.tryShowClipboardSuggestion()whileisInputViewShownis false. Nothing is lost: the next input-view show re-runs clipboard/screenshot suggestion logic through the normal path.No behaviour change when the keyboard view exists (the overwhelmingly common case) - icons resolve exactly as before.
How to Verify
FATAL EXCEPTION: main, NPE atgetScreenshotSuggestionView). After: no crash; opening an editable field still shows the screenshot suggestion normally.Test Plan
:app:compileStandardDebugKotlinpasses on the PR branchRisk Assessment
Low - strictly defensive changes: null-guards that fall back to not drawing two toolbar icons in a transient state, plus skipping a speculative UI refresh that the next input-show repeats anyway. No change to commit paths, gesture handling, or prediction.