From fe484e77242564be1a7fee2bb4ad29ac799b74ba Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Wed, 13 Dec 2023 06:45:58 -0800 Subject: [PATCH] Fix "Show Perf Monitor" crash in Catalyst Summary: "Show Perf Monitor" is crashing due to some methods in FpsDebugFrameCallback.java calls bridge-only methods. Changelog: [Android][Changed] - Fix "Show Perf Monitor" crash in Catalyst Reviewed By: cortinico Differential Revision: D52053678 --- .../modules/debug/FpsDebugFrameCallback.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java index b9bd2c5eb68c23..395e338e1b8974 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/FpsDebugFrameCallback.java @@ -75,8 +75,7 @@ public FpsInfo( public FpsDebugFrameCallback(ReactContext reactContext) { mReactContext = reactContext; - mUIManagerModule = - Assertions.assertNotNull(reactContext.getNativeModule(UIManagerModule.class)); + mUIManagerModule = reactContext.getNativeModule(UIManagerModule.class); mDidJSUpdateUiDuringFrameDetector = new DidJSUpdateUiDuringFrameDetector(); } @@ -125,10 +124,16 @@ public void start() { } public void start(double targetFps) { - mReactContext - .getCatalystInstance() - .addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector); - mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector); + // T172641976: re-think if we need to implement addBridgeIdleDebugListener and + // removeBridgeIdleDebugListener for Bridgeless + if (!mReactContext.isBridgeless()) { + mReactContext + .getCatalystInstance() + .addBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector); + } + if (mUIManagerModule != null) { + mUIManagerModule.setViewHierarchyUpdateDebugListener(mDidJSUpdateUiDuringFrameDetector); + } mTargetFps = targetFps; UiThreadUtil.runOnUiThread( () -> { @@ -144,10 +149,14 @@ public void startAndRecordFpsAtEachFrame() { } public void stop() { - mReactContext - .getCatalystInstance() - .removeBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector); - mUIManagerModule.setViewHierarchyUpdateDebugListener(null); + if (!mReactContext.isBridgeless()) { + mReactContext + .getCatalystInstance() + .removeBridgeIdleDebugListener(mDidJSUpdateUiDuringFrameDetector); + } + if (mUIManagerModule != null) { + mUIManagerModule.setViewHierarchyUpdateDebugListener(null); + } UiThreadUtil.runOnUiThread( () -> { mChoreographer = Choreographer.getInstance();