Guard WindowManager access in DisplayMetricsHolder for non-visual contexts#55810
Open
alanleedev wants to merge 1 commit intofacebook:mainfrom
Open
Guard WindowManager access in DisplayMetricsHolder for non-visual contexts#55810alanleedev wants to merge 1 commit intofacebook:mainfrom
alanleedev wants to merge 1 commit intofacebook:mainfrom
Conversation
|
@alanleedev has exported this pull request. If you are a Meta employee, you can view the originating Diff in D94283765. |
alanleedev
added a commit
to alanleedev/react-native
that referenced
this pull request
Feb 27, 2026
…texts (facebook#55810) Summary: `DisplayMetricsHolder.initDisplayMetrics()` calls `context.getSystemService(WINDOW_SERVICE)` which throws `IllegalAccessException` on Android 11+ (API 30+) when called from a non-visual context (e.g. Application context). Multiple callers pass non-Activity contexts (ReactHostImpl, UIManagerModule, DeviceInfoModule, ReactInstance, ReactInstanceManager). This adds a try-catch around the WindowManager access as defense-in-depth. When it fails, `screenDisplayMetrics` retains the values already copied from resource display metrics via `setTo()`, which is a graceful degradation (only missing system decor dimensions like nav bar height). Changelog: [Internal] - Guard WindowManager access in DisplayMetricsHolder against non-visual contexts on API 30+ Reviewed By: javache, mdvacca Differential Revision: D94283765
1610c72 to
7563cd8
Compare
…texts (facebook#55810) Summary: Pull Request resolved: facebook#55810 `DisplayMetricsHolder.initDisplayMetrics()` calls `context.getSystemService(WINDOW_SERVICE)` which throws `IllegalAccessException` on Android 11+ (API 30+) when called from a non-visual context (e.g. Application context). Multiple callers pass non-Activity contexts (ReactHostImpl, UIManagerModule, DeviceInfoModule, ReactInstance, ReactInstanceManager). This adds a try-catch around the WindowManager access as defense-in-depth. When it fails, `screenDisplayMetrics` retains the values already copied from resource display metrics via `setTo()`, which is a graceful degradation (only missing system decor dimensions like nav bar height). Changelog: [Internal] - Guard WindowManager access in DisplayMetricsHolder against non-visual contexts on API 30+ Reviewed By: javache, mdvacca Differential Revision: D94283765
7563cd8 to
4ad39be
Compare
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:
DisplayMetricsHolder.initDisplayMetrics()callscontext.getSystemService(WINDOW_SERVICE)which throwsIllegalAccessExceptionon Android 11+ (API 30+) when called from a non-visual context (e.g. Application context). Multiple callers pass non-Activity contexts (ReactHostImpl, UIManagerModule, DeviceInfoModule, ReactInstance, ReactInstanceManager).This adds a try-catch around the WindowManager access as defense-in-depth. When it fails,
screenDisplayMetricsretains the values already copied from resource display metrics viasetTo(), which is a graceful degradation (only missing system decor dimensions like nav bar height).Changelog: [Internal] - Guard WindowManager access in DisplayMetricsHolder against non-visual contexts on API 30+
Reviewed By: javache, mdvacca
Differential Revision: D94283765