From 447a7a3527e3e38e4c3ceb330d12d77afe7bc0b4 Mon Sep 17 00:00:00 2001 From: lukmccall Date: Tue, 14 Oct 2025 09:03:29 -0700 Subject: [PATCH] Fix request permission is not always resolving in Android 16 (#53898) Summary: Fixes: https://github.com/facebook/react-native/issues/53887 Fixes: https://github.com/expo/expo/issues/39480 In the latest Android 16 update, requesting permissions does not always change the app's state (the `onPause` and `onResume` functions aren't called). For instance, when you deny permission 3 times, the last promise won't resolve until you move the app to the background. The current logic inside the `ReactActivityDelegate` assumes that Android will call `onResume` after receiving permission state information from the system, which is no longer the case. Probably connected with [this commit](https://android.googlesource.com/platform/packages/modules/Permission/%2B/5dca0ccb26f2b99d706a1d3e9402f851e849c913) ## Changelog: [ANDROID] [FIXED] - Fix request permission not always resolving in Android 16 Pull Request resolved: https://github.com/facebook/react-native/pull/53898 Test Plan: - I've tested it in the RNTester by denying the camera permission three times. - I've also checked if the patch works with the Expo permissions code. Reviewed By: javache Differential Revision: D83059478 Pulled By: cortinico fbshipit-source-id: 7bf33b379a1b6606ad2da2f75d337bf951e3986b --- .../facebook/react/ReactActivityDelegate.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index 12793d95d94..82d815ce2d5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -21,6 +21,7 @@ import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Nullsafe; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactContext; +import com.facebook.react.common.LifecycleState; import com.facebook.react.interfaces.fabric.ReactSurface; import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags; import com.facebook.react.modules.core.PermissionListener; @@ -247,7 +248,7 @@ public class ReactActivityDelegate { public void onRequestPermissionsResult( final int requestCode, final String[] permissions, final int[] grantResults) { - mPermissionsCallback = + Callback permissionsCallback = args -> { if (mPermissionListener != null && mPermissionListener.onRequestPermissionsResult( @@ -255,6 +256,29 @@ public class ReactActivityDelegate { mPermissionListener = null; } }; + + LifecycleState lifecycle; + if (isFabricEnabled()) { + ReactHost reactHost = getReactHost(); + lifecycle = reactHost != null ? reactHost.getLifecycleState() : LifecycleState.BEFORE_CREATE; + } else { + ReactNativeHost reactNativeHost = getReactNativeHost(); + if (!reactNativeHost.hasInstance()) { + lifecycle = LifecycleState.BEFORE_CREATE; + } else { + lifecycle = reactNativeHost.getReactInstanceManager().getLifecycleState(); + } + } + + // If the permission request didn't show a dialog to the user, we can call the callback + // immediately. + // Otherwise, we need to wait until onResume to call it. + if (lifecycle == LifecycleState.RESUMED) { + permissionsCallback.invoke(); + return; + } + + mPermissionsCallback = permissionsCallback; } protected Context getContext() {