From d20ac69fc87ef4f9f5921356c6bbfc0587a9375c Mon Sep 17 00:00:00 2001 From: James Ide Date: Wed, 29 Apr 2020 22:29:33 -0700 Subject: [PATCH] Replace duplicate code in AndroidInfoModule with call to AndroidInfoHelpers (#28756) Summary: The AndroidInfoModule class defines a `getServerHost()` method that duplicates the logic in `AndroidInfoHelpers.getServerHost(context)`. This commit makes AndroidInfoModule call into AndroidInfoHelpers so that potential future changes to `AndroidInfoHelpers.getServerHost` don't need to be duplicated in `AndroidInfoModule.getServerHost`. ## Changelog [Android] [Changed] - Internal change to make `PlatformConstants` use the same method to determine `ServerHost` as other code paths Pull Request resolved: https://github.com/facebook/react-native/pull/28756 Test Plan: Tested by running the RNTester app and editing the root component to print out `NativeModules.PlatformConstants.getConstants()` and verified one of the properties was: `"ServerHost": "10.0.2.2:8081"`. Differential Revision: D21252158 Pulled By: shergin fbshipit-source-id: b460197e5f1d972a5b91991c32a929294e358d9f --- .../react/modules/systeminfo/AndroidInfoModule.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java index 24c6f4deb4c..acfc5bc5c24 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java @@ -73,7 +73,7 @@ public class AndroidInfoModule extends NativePlatformConstantsAndroidSpec implem constants.put("Fingerprint", Build.FINGERPRINT); constants.put("Model", Build.MODEL); if (ReactBuildConfig.DEBUG) { - constants.put("ServerHost", getServerHost()); + constants.put("ServerHost", AndroidInfoHelpers.getServerHost(getReactApplicationContext().getApplicationContext())); } constants.put( "isTesting", "true".equals(System.getProperty(IS_TESTING)) || isRunningScreenshotTest()); @@ -98,12 +98,4 @@ public class AndroidInfoModule extends NativePlatformConstantsAndroidSpec implem return false; } } - - private String getServerHost() { - Resources resources = getReactApplicationContext().getApplicationContext().getResources(); - - Integer devServerPort = resources.getInteger(R.integer.react_native_dev_server_port); - - return AndroidInfoHelpers.getServerHost(devServerPort); - } }