From 8b4f5073a18d919a39c64c428f58b11059d1b47a Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Wed, 1 Sep 2021 07:29:32 -0700 Subject: [PATCH] Log created views with mounting errors Summary: Displays views from the surface mounting manager after we hit a crash during mounting. This change should help with debugging mounting crashes (e.g. when view is added before removal) Changelog: [Internal] Reviewed By: cortinico Differential Revision: D30681339 fbshipit-source-id: f83cecaf8e418a2fa5aa0713513c51bb1be77013 --- .../fabric/mounting/MountItemDispatcher.java | 10 +++++++++- .../mounting/SurfaceMountingManager.java | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java index 2370e84ba2fa97..ca2c7df44f148c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java @@ -13,6 +13,7 @@ import static com.facebook.react.fabric.FabricUIManager.IS_DEVELOPMENT_ENVIRONMENT; import android.os.SystemClock; +import android.view.View; import androidx.annotation.AnyThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -274,10 +275,17 @@ private boolean dispatchMountItems() { executeOrEnqueue(mountItem); } catch (Throwable e) { // If there's an exception, we want to log diagnostics in prod and rethrow. - FLog.e(TAG, "dispatchMountItems: caught exception, displaying all MountItems", e); + FLog.e(TAG, "dispatchMountItems: caught exception, displaying mount state", e); for (MountItem m : mountItemsToDispatch) { printMountItem(m, "dispatchMountItems: mountItem"); } + if (mountItem.getSurfaceId() != View.NO_ID) { + SurfaceMountingManager surfaceManager = + mMountingManager.getSurfaceManager(mountItem.getSurfaceId()); + if (surfaceManager != null) { + surfaceManager.printSurfaceState(); + } + } if (ReactIgnorableMountingException.isIgnorable(e)) { ReactSoftExceptionLogger.logSoftException(TAG, e); diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 1f05f824c8f6ec..f93d1c20dcadf8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -963,6 +963,25 @@ public View getView(int reactTag) { return (ViewGroupManager) viewState.mViewManager; } + public void printSurfaceState() { + FLog.e(TAG, "Views created for surface {%d}:", getSurfaceId()); + for (ViewState viewState : mTagToViewState.values()) { + String viewManagerName = + viewState.mViewManager != null ? viewState.mViewManager.getName() : null; + @Nullable View view = viewState.mView; + @Nullable View parent = view != null ? (View) view.getParent() : null; + @Nullable Integer parentTag = parent != null ? parent.getId() : null; + + FLog.e( + TAG, + "<%s id=%d parentTag=%s isRoot=%b />", + viewManagerName, + viewState.mReactTag, + parentTag, + viewState.mIsRoot); + } + } + /** * This class holds view state for react tags. Objects of this class are stored into the {@link * #mTagToViewState}, and they should be updated in the same thread.