diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java index 6d0946d8d..569f1c7bd 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java @@ -36,4 +36,14 @@ public class ReactSettingsForTests implements DeveloperSettings { public boolean isElementInspectorEnabled() { return false; } + + @Override + public boolean isRemoteJSDebugEnabled() { + return false; + } + + @Override + public void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled) { + + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java index 1b72f4d0a..9f5ed6c19 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java @@ -59,6 +59,7 @@ import com.facebook.react.devsupport.DevSupportManagerFactory; import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; import com.facebook.react.modules.core.DeviceEventManagerModule; +import com.facebook.react.modules.debug.DeveloperSettings; import com.facebook.react.uimanager.AppRegistry; import com.facebook.react.uimanager.DisplayMetricsHolder; import com.facebook.react.uimanager.UIImplementationProvider; @@ -362,8 +363,13 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; UiThreadUtil.assertOnUiThread(); if (mUseDeveloperSupport && mJSMainModuleName != null) { - if (mDevSupportManager.hasUpToDateJSBundleInCache()) { - // If there is a up-to-date bundle downloaded from server, always use that + final DeveloperSettings devSettings = mDevSupportManager.getDevSettings(); + + // If remote JS debugging is enabled, load from dev server. + if (mDevSupportManager.hasUpToDateJSBundleInCache() && + !devSettings.isRemoteJSDebugEnabled()) { + // If there is a up-to-date bundle downloaded from server, + // with remote JS debugging disabled, always use that. onJSBundleLoadedFromServer(); } else if (mJSBundleFile == null) { mDevSupportManager.handleReloadJS(); @@ -379,6 +385,8 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; if (packagerIsRunning) { mDevSupportManager.handleReloadJS(); } else { + // If dev server is down, disable the remote JS debugging. + devSettings.setRemoteJSDebugEnabled(false); recreateReactContextInBackgroundFromBundleFile(); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java index 349cd22db..2899be2b8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java @@ -36,6 +36,7 @@ public class DevInternalSettings implements private static final String PREFS_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change"; private static final String PREFS_INSPECTOR_DEBUG_KEY = "inspector_debug"; private static final String PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement"; + private static final String PREFS_REMOTE_JS_DEBUG_KEY = "remote_js_debug"; private final SharedPreferences mPreferences; private final DevSupportManager mDebugManager; @@ -108,4 +109,14 @@ public class DevInternalSettings implements public void setElementInspectorEnabled(boolean enabled) { mPreferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply(); } + + @Override + public boolean isRemoteJSDebugEnabled() { + return mPreferences.getBoolean(PREFS_REMOTE_JS_DEBUG_KEY, false); + } + + @Override + public void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled) { + mPreferences.edit().putBoolean(PREFS_REMOTE_JS_DEBUG_KEY, remoteJSDebugEnabled).apply(); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index 3925a0e82..55057a8ed 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -106,7 +106,6 @@ public class DevSupportManagerImpl implements DevSupportManager { private @Nullable DebugOverlayController mDebugOverlayController; private @Nullable ReactContext mCurrentContext; private DevInternalSettings mDevSettings; - private boolean mIsUsingJSProxy = false; private boolean mIsReceiverRegistered = false; private boolean mIsShakeDetectorStarted = false; private boolean mIsDevSupportEnabled = false; @@ -139,10 +138,10 @@ public class DevSupportManagerImpl implements DevSupportManager { String action = intent.getAction(); if (DevServerHelper.getReloadAppAction(context).equals(action)) { if (intent.getBooleanExtra(DevServerHelper.RELOAD_APP_EXTRA_JS_PROXY, false)) { - mIsUsingJSProxy = true; + mDevSettings.setRemoteJSDebugEnabled(true); mDevServerHelper.launchJSDevtools(); } else { - mIsUsingJSProxy = false; + mDevSettings.setRemoteJSDebugEnabled(false); } handleReloadJS(); } @@ -265,13 +264,13 @@ public class DevSupportManagerImpl implements DevSupportManager { } }); options.put( - mIsUsingJSProxy ? + mDevSettings.isRemoteJSDebugEnabled() ? mApplicationContext.getString(R.string.catalyst_debugjs_off) : mApplicationContext.getString(R.string.catalyst_debugjs), new DevOptionHandler() { @Override public void onOptionSelected() { - mIsUsingJSProxy = !mIsUsingJSProxy; + mDevSettings.setRemoteJSDebugEnabled(!mDevSettings.isRemoteJSDebugEnabled()); handleReloadJS(); } }); @@ -297,7 +296,7 @@ public class DevSupportManagerImpl implements DevSupportManager { } }); options.put( - mApplicationContext.getString(R.string.catalyst_element_inspector), + mApplicationContext.getString(R.string.catalyst_element_inspector), new DevOptionHandler() { @Override public void onOptionSelected() { @@ -340,7 +339,7 @@ public class DevSupportManagerImpl implements DevSupportManager { mCurrentContext.getCatalystInstance().supportsProfiling()) { options.put( mApplicationContext.getString( - mIsCurrentlyProfiling ? R.string.catalyst_stop_profile : + mIsCurrentlyProfiling ? R.string.catalyst_stop_profile : R.string.catalyst_start_profile), new DevOptionHandler() { @Override @@ -581,13 +580,13 @@ public class DevSupportManagerImpl implements DevSupportManager { ProgressDialog progressDialog = new ProgressDialog(mApplicationContext); progressDialog.setTitle(R.string.catalyst_jsload_title); progressDialog.setMessage(mApplicationContext.getString( - mIsUsingJSProxy ? R.string.catalyst_remotedbg_message : R.string.catalyst_jsload_message)); + mDevSettings.isRemoteJSDebugEnabled() ? R.string.catalyst_remotedbg_message : R.string.catalyst_jsload_message)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); progressDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); progressDialog.show(); - if (mIsUsingJSProxy) { + if (mDevSettings.isRemoteJSDebugEnabled()) { reloadJSInProxyMode(progressDialog); } else { reloadJSFromServer(progressDialog); diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java index 5defb9386..afb72dd87 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java @@ -38,4 +38,15 @@ public interface DeveloperSettings { * @return Whether element inspector is enabled. */ boolean isElementInspectorEnabled(); + + /** + * @return Whether remote JS debugging is enabled. + */ + boolean isRemoteJSDebugEnabled(); + + /** + * Enable/Disable remote JS debugging. + */ + void setRemoteJSDebugEnabled(boolean remoteJSDebugEnabled); + }