Fix for app restart on Android in case of remote debugging (#45775)

Summary:
Added a check in setRemoteJSDebugEnabled in DevSupportManagerBase.java to check for PREFS_REMOTE_JS_DEBUG_KEY to see if the value has changed.

Fix for https://github.com/facebook/react-native/issues/45399 - App restarting when `NativeDevSettings.setIsDebuggingRemotely` is used in a landing component. If this was invoked from a component load or action that would fire on app start, it was creating an infinite loop where the app would keep on restart before eventually leading to a crash.

## Changelog:
[ANDROID] [FIXED] - Fix issue with `NativeDevSettings.setIsDebuggingRemotely` where the app would keep on restarting if remote debugging was invoked from an action / component that was called on app start.

Pull Request resolved: https://github.com/facebook/react-native/pull/45775

Test Plan:
Create a new project using RN CLI.
Set `newArchEnabled=false`.�
Install modules using `yarn install`.�
Build from source for Android by setting the following in `settings.gradle`-�
```
includeBuild('../node_modules/react-native') {
     dependencySubstitution {
         substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid"))
         substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid"))
         substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
         substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
     }
 }
```
Set the ANDROID_HOME and ANDROID_NDK_HOME environment variables required for react native.�Call `NativeDevSettings.setIsDebuggingRemotely` from App.tsx which is the landing component.�
Test with both `hermesEnabled=true` and `hermesEnabled=false` and ensure that app does not keep on restarting after fix.

Reviewed By: cipolleschi

Differential Revision: D60377406

Pulled By: huntie

fbshipit-source-id: c8faf184b50b67f50f8a4b6851df9d0ef3350949
This commit is contained in:
Sushant Sardeshpande
2024-08-08 07:58:23 -07:00
committed by Facebook GitHub Bot
parent 5d70411b48
commit beebf4a0a3
@@ -998,11 +998,13 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
return;
}
UiThreadUtil.runOnUiThread(
() -> {
mDevSettings.setRemoteJSDebugEnabled(isRemoteJSDebugEnabled);
handleReloadJS();
});
if (mDevSettings.isRemoteJSDebugEnabled() != isRemoteJSDebugEnabled) {
UiThreadUtil.runOnUiThread(
() -> {
mDevSettings.setRemoteJSDebugEnabled(isRemoteJSDebugEnabled);
handleReloadJS();
});
}
}
@Override