Repository navigation
fix(android): TextInput crash when clipboard read access is denied - #59687
olivier-bouillet wants to merge 1 commit into
Conversation
ClipboardManager throws a SecurityException when the READ_CLIPBOARD app op is set to MODE_ERRORED for the app, which some OEM clipboard privacy settings do. TextView reads the clipboard from its floating text menu, keyboard shortcuts, accessibility info and actions, and when pasting, so a tap, a long-press, Ctrl+V or an accessibility service focusing a TextInput crashes the app. Guard those entry points in ReactEditText and treat a denial as an unavailable clipboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary:
Fixes #59689 (reproducer: https://github.com/olivier-bouillet/rn-read-clipboard-crash-repro).
ClipboardManagerthrows aSecurityExceptionwhen theREAD_CLIPBOARDapp op is set toMODE_ERRORED("deny") for the app.ClipboardService.clipboardAccessAllowedcallsAppOpsManager.noteOp/checkOp, which throw in that mode (AppOpsManager.java, ClipboardService.java). Some OEM clipboard privacy settings put apps in that mode; we see it in production on a realme RMX3830 (Android 15):TextViewreads the clipboard from several places besides Paste, so with the op denied aTextInputcrashes the app on a plain tap or long-press (the floating text menu callscanPaste()→hasPrimaryClip(), sometimes from a posted runnable with noReactEditTextframe on the stack), on Ctrl+V (onKeyShortcut→canPaste()), and as soon as an accessibility service queries the focused field (onInitializeAccessibilityNodeInfo→canPaste()).This change guards those entry points in
ReactEditTextand treats a denial as an unavailable clipboard: the floating text menu is not shown, paste does nothing, and the denial is logged withFLog.w. When clipboard access is allowed, behaviour is unchanged.Changelog:
[ANDROID] [FIXED] - Fix crash in TextInput when the app is denied clipboard read access (READ_CLIPBOARD app op)
Test Plan:
Bare
@react-native-community/cliapp on 0.88.1 with a single<TextInput />, release build, React Native built from source with this patch applied (the same diff applies cleanly tomain). Pixel 6a emulator, Android 16 (Google APIs image).adb shell appops set com.clipboardrepro READ_CLIPBOARD denyEditor.startInsertionActionMode→TextView.canPaste)SelectionActionModeHelper→onCreateActionMode→TextView.canPaste)input keycombination KEYCODE_CTRL_LEFT KEYCODE_V)TextView.onKeyShortcut→canPaste)ReactAccessibilityDelegate→TextView.canPaste)Then
adb shell appops set com.clipboardrepro READ_CLIPBOARD allow: long-press shows Cut / Copy / Paste as before, and Paste inserts the copied text.Not covered: on stock Android
canPaste()fails beforegetPrimaryClip()is reached, so the exact production stack above (Paste tapped,getPrimaryClipdenied) could not be triggered on the emulator; it goes through the guardedonTextContextMenuItem. No unit test added: Robolectric's clipboard shadow does not model app-op denial.🤖 Generated with Claude Code