Skip to content

Guard WindowManager access in DisplayMetricsHolder for non-visual contexts#55810

Open
alanleedev wants to merge 1 commit intofacebook:mainfrom
alanleedev:export-D94283765
Open

Guard WindowManager access in DisplayMetricsHolder for non-visual contexts#55810
alanleedev wants to merge 1 commit intofacebook:mainfrom
alanleedev:export-D94283765

Conversation

@alanleedev
Copy link
Contributor

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

@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 Feb 27, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 27, 2026

@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
…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
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. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants