Skip to content

Prevent DeviceInfo crash when WindowMetrics API is missing - #58077

Open
gooddev97 wants to merge 1 commit into
react:mainfrom
gooddev97:fix/window-metrics-api-fallback
Open

Prevent DeviceInfo crash when WindowMetrics API is missing#58077
gooddev97 wants to merge 1 commit into
react:mainfrom
gooddev97:fix/window-metrics-api-fallback

Conversation

@gooddev97

Copy link
Copy Markdown

Summary:

Fixes #57785.

Some modified Android runtimes report API 34 or later while shipping a WindowMetrics implementation without getDensity(). WindowMetricsCalculator then throws NoSuchMethodError while NativeDeviceInfo exports its constants, crashing the app before the JavaScript runtime is ready.

This change catches only that missing-method failure around the window metrics lookup, reports it as a soft exception, and returns the resource display metrics that were already copied as the fallback. Normal Android runtimes continue to use the current window bounds path unchanged.

The regression test injects a WindowMetricsCalculator that throws the same NoSuchMethodError and verifies that resource width, height, density, and density DPI are returned. Before the production change, this test failed at DeviceInfoModule.kt:46 with the uncaught error.

Changelog:

[ANDROID] [FIXED] - Prevent a startup crash when the WindowMetrics API is missing on an inconsistent Android runtime

Test Plan:

  • JAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.modules.deviceinfo.DeviceInfoModuleTest -Preact.internal.useHermesStable=true --no-daemon — BUILD SUCCESSFUL (8 tests)
  • JAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :packages:react-native:ReactAndroid:ktfmtCheck -Preact.internal.useHermesStable=true --no-daemon --rerun-tasks — BUILD SUCCESSFUL
  • JAVA_HOME=$(/usr/libexec/java_home -v 17) ./gradlew :packages:react-native:ReactAndroid:lintDebug -Preact.internal.useHermesStable=true --no-daemon — BUILD SUCCESSFUL

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 23, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

1 participant