Skip to content

fix(android): TextInput crash when clipboard read access is denied - #59687

Open
olivier-bouillet wants to merge 1 commit into
react:mainfrom
olivier-bouillet:fix-android-textinput-clipboard-securityexception
Open

olivier-bouillet wants to merge 1 commit into
react:mainfrom
olivier-bouillet:fix-android-textinput-clipboard-securityexception

Conversation

@olivier-bouillet

@olivier-bouillet olivier-bouillet commented Oct 30, 2026 •

Copy link
Copy Markdown

Summary:

Fixes #59689 (reproducer: https://github.com/olivier-bouillet/rn-read-clipboard-crash-repro).

ClipboardManager throws a SecurityException when the READ_CLIPBOARD app op is set to MODE_ERRORED ("deny") for the app. ClipboardService.clipboardAccessAllowed calls AppOpsManager.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):

java.lang.SecurityException: com.example from uid 10240 not allowed to perform READ_CLIPBOARD
  at android.content.ClipboardManager.getPrimaryClip(ClipboardManager.java:253)
  at android.widget.TextView.paste(TextView.java:15514)
  at android.widget.TextView.onTextContextMenuItem(TextView.java:15029)
  at com.facebook.react.views.textinput.ReactEditText.onTextContextMenuItem(ReactEditText.kt:367)

TextView reads the clipboard from several places besides Paste, so with the op denied a TextInput crashes the app on a plain tap or long-press (the floating text menu calls canPaste() → hasPrimaryClip(), sometimes from a posted runnable with no ReactEditText frame 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 ReactEditText and treats a denial as an unavailable clipboard: the floating text menu is not shown, paste does nothing, and the denial is logged with FLog.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/cli app on 0.88.1 with a single <TextInput />, release build, React Native built from source with this patch applied (the same diff applies cleanly to main). Pixel 6a emulator, Android 16 (Google APIs image).

adb shell appops set com.clipboardrepro READ_CLIPBOARD deny
Action on the TextInput Before (0.88.1) After
Tap crash (Editor.startInsertionActionMode → TextView.canPaste) no crash
Long-press crash (SelectionActionModeHelper → onCreateActionMode → TextView.canPaste) no crash, no floating menu
Ctrl+V (input keycombination KEYCODE_CTRL_LEFT KEYCODE_V) crash (TextView.onKeyShortcut → canPaste) no crash
Accessibility tree read of the focused field crash (ReactAccessibilityDelegate → TextView.canPaste) no crash, node info returned
Typing — works

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 before getPrimaryClip() is reached, so the exact production stack above (Paste tapped, getPrimaryClip denied) could not be triggered on the emulator; it goes through the guarded onTextContextMenuItem. No unit test added: Robolectric's clipboard shadow does not model app-op denial.

🤖 Generated with Claude Code

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>
@meta-cla

meta-cla Bot commented Oct 30, 2026

Copy link
Copy Markdown

Hi @olivier-bouillet!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

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.

[Android] TextInput crashes with SecurityException when READ_CLIPBOARD is denied

1 participant