Repository navigation
fix(android): start the permission request on the main thread (#92) - #93
Merged
marcocrupi merged 1 commit intoNov 13, 2026
Merged
Conversation
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.
Summary
requestPermission()on Android 13+ calledactivity.requestPermissions(...)on the native modules thread, because TurboModule promise methods run there. Starting that activity walks the view hierarchy (cancelPendingInputEvents), and if the UI thread changes the hierarchy at the same time it can fail with aNullPointerExceptionfromView.dispatchCancelPendingInputEvents(). We saw that in production right after a screen transition.This moves the call, together with its existing try/catch, into
UiThreadUtil.runOnUiThread { }. Same idea asNotifee.openNotificationSettings, which already starts its activity withactivity.runOnUiThread(...).Nothing else changes: the callback is still set before the request, results still come back through
onRequestPermissionsResult, a throw fromrequestPermissionsstill rejects the promise, and the path below API 33 and the missing Activity path stay as they were.Type of change
Related issue
Closes #92
Scope
Validation
Added
RequestPermissionThreadTest(Robolectric, API 33 and 36). It callsrequestPermissionfrom a background thread, checks thatrequestPermissionsisn't called on that thread, idles the main looper, then checks it ran once on the main thread with the right arguments. A second test checks that a throw on the main thread still rejects the promise. The first test fails without the change.yarn format:allstops at the iOS clang-format step on this machine (x86_64 binary, no Rosetta). The Java formatter ran clean, and no iOS files change.yarn format:allyarn validate:allyarn test:allManual validation details:
Documentation
CHANGELOG.mdwas updated under[Unreleased].Breaking changes
Does this pull request introduce a breaking change?
Additional notes
The change is in the bridge (
NotifeeApiModule.kt), core is untouched.I can't reproduce the NPE on demand, it's a race. The test covers the thread, not the crash itself. React Native's own
PermissionsAndroidmodule callsrequestPermissionsfrom the modules thread too, so this isn't unique to notify-kit.