Intercepting all redboxes in Android Ads Manager

Summary:
Implement a handler to allow intercepting all RN redboxes in Android, including exceptions in both JS and Java.

The handler is not open sourced, so there is only an open-source interface called **RedBoxHandler** in //fbandroid/java/com/facebook/catalyst/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/devsupport//, meantime there is an internal class called **FBRedBoxHandler**, which implements **RedBoxHandler** and is located in //fbandroid/java/com/facebook/fbreact/redboxhandler//, actually handles the exception information.

The code structure is as follows:
  - **AdsManagerActivity** has a member variable of **FBRedBoxHandler**.
  - **AdsManagerActivity** passes this handler all the way down to the **DevSupportManagerImpl**, through** ReactInstanceManager**, **ReactInstanceManagerImpl**, **DevSupportManagerFactory**.
  - **DevSupportManagerImpl** intercepts the exceptions just before showing the redboxes, like this:

              mRedBoxDialog.setExceptionDetails(message, stack);
              mRedBoxDialog.setErrorCookie(errorCookie);
              if (mRedBoxHandler != null) {
                mRedBoxHandler.handleRedbox(message, stack);
              }
              mRedBoxDialog.show();

By now, the internal class just prints information for each redbox to logcat, including exception message and stack trace.

Reviewed By: mkonicek

Differential Revision: D3369064

fbshipit-source-id: 199012c4b6ecf4b3d3aff51a26c9c9901847b6fc
This commit is contained in:
Siqi Liu
2016-06-03 17:11:51 -07:00
committed by Facebook Github Bot 5
parent 5961764668
commit 5aa0e098b4
8 changed files with 177 additions and 34 deletions

View File

@@ -25,6 +25,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.devsupport.DevSupportManager;
import com.facebook.react.devsupport.RedBoxHandler;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.uimanager.UIImplementationProvider;
import com.facebook.react.uimanager.ViewManager;
@@ -188,6 +189,7 @@ public abstract class ReactInstanceManager {
protected @Nullable JSCConfig mJSCConfig;
protected @Nullable Activity mCurrentActivity;
protected @Nullable DefaultHardwareBackBtnHandler mDefaultHardwareBackBtnHandler;
protected @Nullable RedBoxHandler mRedBoxHandler;
protected Builder() {
}
@@ -297,6 +299,11 @@ public abstract class ReactInstanceManager {
return this;
}
public Builder setRedBoxHandler(RedBoxHandler redBoxHandler) {
mRedBoxHandler = redBoxHandler;
return this;
}
/**
* Instantiates a new {@link ReactInstanceManagerImpl}.
* Before calling {@code build}, the following must be called:
@@ -335,7 +342,8 @@ public abstract class ReactInstanceManager {
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider,
mNativeModuleCallExceptionHandler,
mJSCConfig);
mJSCConfig,
mRedBoxHandler);
}
}
}