mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-19 13:08:11 +08:00
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:
committed by
Facebook Github Bot 5
parent
5961764668
commit
5aa0e098b4
@@ -67,6 +67,7 @@ import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.react.devsupport.RedBoxHandler;
|
||||
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_JS_MODULE_CONFIG_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_JS_MODULE_CONFIG_START;
|
||||
@@ -125,6 +126,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
private final MemoryPressureRouter mMemoryPressureRouter;
|
||||
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
|
||||
private final @Nullable JSCConfig mJSCConfig;
|
||||
private @Nullable RedBoxHandler mRedBoxHandler;
|
||||
|
||||
private final ReactInstanceDevCommandsHandler mDevInterface =
|
||||
new ReactInstanceDevCommandsHandler() {
|
||||
@@ -276,6 +278,37 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
UIImplementationProvider uiImplementationProvider,
|
||||
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
|
||||
@Nullable JSCConfig jscConfig) {
|
||||
|
||||
this(applicationContext,
|
||||
currentActivity,
|
||||
defaultHardwareBackBtnHandler,
|
||||
jsBundleFile,
|
||||
jsMainModuleName,
|
||||
packages,
|
||||
useDeveloperSupport,
|
||||
bridgeIdleDebugListener,
|
||||
initialLifecycleState,
|
||||
uiImplementationProvider,
|
||||
nativeModuleCallExceptionHandler,
|
||||
jscConfig,
|
||||
null);
|
||||
}
|
||||
|
||||
/* package */ XReactInstanceManagerImpl(
|
||||
Context applicationContext,
|
||||
@Nullable Activity currentActivity,
|
||||
@Nullable DefaultHardwareBackBtnHandler defaultHardwareBackBtnHandler,
|
||||
@Nullable String jsBundleFile,
|
||||
@Nullable String jsMainModuleName,
|
||||
List<ReactPackage> packages,
|
||||
boolean useDeveloperSupport,
|
||||
@Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
|
||||
LifecycleState initialLifecycleState,
|
||||
UIImplementationProvider uiImplementationProvider,
|
||||
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler,
|
||||
@Nullable JSCConfig jscConfig,
|
||||
@Nullable RedBoxHandler redBoxHandler) {
|
||||
|
||||
initializeSoLoaderIfNecessary(applicationContext);
|
||||
|
||||
// TODO(9577825): remove this
|
||||
@@ -289,11 +322,13 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
mJSMainModuleName = jsMainModuleName;
|
||||
mPackages = packages;
|
||||
mUseDeveloperSupport = useDeveloperSupport;
|
||||
mRedBoxHandler = redBoxHandler;
|
||||
mDevSupportManager = DevSupportManagerFactory.create(
|
||||
applicationContext,
|
||||
mDevInterface,
|
||||
mJSMainModuleName,
|
||||
useDeveloperSupport);
|
||||
useDeveloperSupport,
|
||||
mRedBoxHandler);
|
||||
mBridgeIdleDebugListener = bridgeIdleDebugListener;
|
||||
mLifecycleState = initialLifecycleState;
|
||||
mUIImplementationProvider = uiImplementationProvider;
|
||||
|
||||
Reference in New Issue
Block a user