LogBox: do less work in production when LogBox shouldn't even be running

Summary:
Do we need this? Is it possible for any of these codepaths to execute in production? If so, it would be nice to avoid NPEs or even scheduling work on the UI thread.

Maybe we want to add soft exception logging for if these paths are called?

Changelog: [Internal] make sure LogBox does even less work when it's not hooked up

Reviewed By: rickhanlonii

Differential Revision: D20156812

fbshipit-source-id: ba9faedcb3b0951e6913724ca99549dc2d16237e
This commit is contained in:
Joshua Gross
2020-03-04 19:38:24 -08:00
committed by Facebook Github Bot
parent e1de7a5e65
commit 782e06a059
@@ -32,11 +32,12 @@ public class LogBoxModule extends NativeLogBoxSpec {
super(reactContext);
mDevSupportManager = devSupportManager;
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
if (mReactRootView == null) {
if (mReactRootView == null && mDevSupportManager != null) {
mReactRootView = mDevSupportManager.createRootView("LogBox");
if (mReactRootView == null) {
FLog.e(
@@ -55,25 +56,27 @@ public class LogBoxModule extends NativeLogBoxSpec {
@Override
public void show() {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
if (mLogBoxDialog == null && mReactRootView != null) {
Activity context = getCurrentActivity();
if (context == null || context.isFinishing()) {
FLog.e(
ReactConstants.TAG,
"Unable to launch logbox because react activity "
+ "is not available, here is the error that logbox would've displayed: ");
return;
if (mReactRootView != null) {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
if (mLogBoxDialog == null && mReactRootView != null) {
Activity context = getCurrentActivity();
if (context == null || context.isFinishing()) {
FLog.e(
ReactConstants.TAG,
"Unable to launch logbox because react activity "
+ "is not available, here is the error that logbox would've displayed: ");
return;
}
mLogBoxDialog = new LogBoxDialog(context, mReactRootView);
mLogBoxDialog.setCancelable(false);
mLogBoxDialog.show();
}
mLogBoxDialog = new LogBoxDialog(context, mReactRootView);
mLogBoxDialog.setCancelable(false);
mLogBoxDialog.show();
}
}
});
});
}
}
@Override
@@ -83,7 +86,7 @@ public class LogBoxModule extends NativeLogBoxSpec {
@Override
public void run() {
if (mLogBoxDialog != null) {
if (mReactRootView.getParent() != null) {
if (mReactRootView != null && mReactRootView.getParent() != null) {
((ViewGroup) mReactRootView.getParent()).removeView(mReactRootView);
}
mLogBoxDialog.dismiss();