Skip to content

Commit da358d0

Browse files
cortinicofacebook-github-bot
authored andcommitted
DevServerHelper should not depend on internal ctor parameter (#37265)
Summary: Pull Request resolved: #37265 DevServerHelper was having a constructor parameter as `DevInternalSettings` which is effectively internal. This should not be the case as that class is Internal as was bleeding out of the public API. I've updated the primary constructor to take instead: ``` public DevServerHelper( DeveloperSettings settings, String packageName, InspectorPackagerConnection.BundleStatusProvider bundleStatusProvider, PackagerConnectionSettings packagerConnectionSettings) { ``` This is breaking change for users that were depending on the Internal class. Changelog: [Android] [Removed] - DevServerHelper should not depend on internal ctor parameter Reviewed By: mdvacca Differential Revision: D45600283 fbshipit-source-id: e73139dbdf5f2505201b2d2c8b5a9143b7e207ba
1 parent 8aa2281 commit da358d0

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import com.facebook.react.common.ReactConstants;
1717
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
1818
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
19+
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
1920
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
2021
import com.facebook.react.packagerconnection.FileIoHandler;
2122
import com.facebook.react.packagerconnection.JSPackagerClient;
2223
import com.facebook.react.packagerconnection.NotificationOnlyHandler;
24+
import com.facebook.react.packagerconnection.PackagerConnectionSettings;
2325
import com.facebook.react.packagerconnection.ReconnectingWebSocket.ConnectionCallback;
2426
import com.facebook.react.packagerconnection.RequestHandler;
2527
import com.facebook.react.packagerconnection.RequestOnlyHandler;
@@ -99,7 +101,10 @@ public String typeID() {
99101
}
100102
}
101103

102-
private final DevInternalSettings mSettings;
104+
private final DeveloperSettings mSettings;
105+
106+
private final PackagerConnectionSettings mPackagerConnectionSettings;
107+
103108
private final OkHttpClient mClient;
104109
private final BundleDownloader mBundleDownloader;
105110
private final PackagerStatusCheck mPackagerStatusCheck;
@@ -110,10 +115,12 @@ public String typeID() {
110115
private InspectorPackagerConnection.BundleStatusProvider mBundlerStatusProvider;
111116

112117
public DevServerHelper(
113-
DevInternalSettings settings,
118+
DeveloperSettings developerSettings,
114119
String packageName,
115-
InspectorPackagerConnection.BundleStatusProvider bundleStatusProvider) {
116-
mSettings = settings;
120+
InspectorPackagerConnection.BundleStatusProvider bundleStatusProvider,
121+
PackagerConnectionSettings packagerConnectionSettings) {
122+
mSettings = developerSettings;
123+
mPackagerConnectionSettings = packagerConnectionSettings;
117124
mBundlerStatusProvider = bundleStatusProvider;
118125
mClient =
119126
new OkHttpClient.Builder()
@@ -181,10 +188,7 @@ public void onDisconnected() {
181188

182189
mPackagerClient =
183190
new JSPackagerClient(
184-
clientId,
185-
mSettings.getPackagerConnectionSettings(),
186-
handlers,
187-
onPackagerConnectedCallback);
191+
clientId, mPackagerConnectionSettings, handlers, onPackagerConnectedCallback);
188192
mPackagerClient.init();
189193

190194
return null;
@@ -277,14 +281,14 @@ public String getWebsocketProxyURL() {
277281
return String.format(
278282
Locale.US,
279283
"ws://%s/debugger-proxy?role=client",
280-
mSettings.getPackagerConnectionSettings().getDebugServerHost());
284+
mPackagerConnectionSettings.getDebugServerHost());
281285
}
282286

283287
private String getInspectorDeviceUrl() {
284288
return String.format(
285289
Locale.US,
286290
"http://%s/inspector/device?name=%s&app=%s",
287-
mSettings.getPackagerConnectionSettings().getInspectorServerHost(),
291+
mPackagerConnectionSettings.getInspectorServerHost(),
288292
AndroidInfoHelpers.getFriendlyDeviceName(),
289293
mPackageName);
290294
}
@@ -315,8 +319,7 @@ public void downloadBundleFromURL(
315319
/** @return the host to use when connecting to the bundle server from the host itself. */
316320
private String getHostForJSProxy() {
317321
// Use custom port if configured. Note that host stays "localhost".
318-
String host =
319-
Assertions.assertNotNull(mSettings.getPackagerConnectionSettings().getDebugServerHost());
322+
String host = Assertions.assertNotNull(mPackagerConnectionSettings.getDebugServerHost());
320323
int portOffset = host.lastIndexOf(':');
321324
if (portOffset > -1) {
322325
return "localhost" + host.substring(portOffset);
@@ -362,8 +365,7 @@ private String createBundleURL(
362365
}
363366

364367
private String createBundleURL(String mainModuleID, BundleType type) {
365-
return createBundleURL(
366-
mainModuleID, type, mSettings.getPackagerConnectionSettings().getDebugServerHost());
368+
return createBundleURL(mainModuleID, type, mPackagerConnectionSettings.getDebugServerHost());
367369
}
368370

369371
private static String createResourceURL(String host, String resourcePath) {
@@ -372,18 +374,15 @@ private static String createResourceURL(String host, String resourcePath) {
372374

373375
public String getDevServerBundleURL(final String jsModulePath) {
374376
return createBundleURL(
375-
jsModulePath,
376-
BundleType.BUNDLE,
377-
mSettings.getPackagerConnectionSettings().getDebugServerHost());
377+
jsModulePath, BundleType.BUNDLE, mPackagerConnectionSettings.getDebugServerHost());
378378
}
379379

380380
public String getDevServerSplitBundleURL(String jsModulePath) {
381-
return createSplitBundleURL(
382-
jsModulePath, mSettings.getPackagerConnectionSettings().getDebugServerHost());
381+
return createSplitBundleURL(jsModulePath, mPackagerConnectionSettings.getDebugServerHost());
383382
}
384383

385384
public void isPackagerRunning(final PackagerStatusCallback callback) {
386-
String host = mSettings.getPackagerConnectionSettings().getDebugServerHost();
385+
String host = mPackagerConnectionSettings.getDebugServerHost();
387386
if (host == null) {
388387
FLog.w(ReactConstants.TAG, "No packager host configured.");
389388
callback.onPackagerStatusFetched(false);
@@ -396,7 +395,7 @@ private String createLaunchJSDevtoolsCommandUrl() {
396395
return String.format(
397396
Locale.US,
398397
"http://%s/launch-js-devtools",
399-
mSettings.getPackagerConnectionSettings().getDebugServerHost());
398+
mPackagerConnectionSettings.getDebugServerHost());
400399
}
401400

402401
public void launchJSDevtools() {
@@ -443,8 +442,7 @@ public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
443442
public @Nullable File downloadBundleResourceFromUrlSync(
444443
final String resourcePath, final File outputFile) {
445444
final String resourceURL =
446-
createResourceURL(
447-
mSettings.getPackagerConnectionSettings().getDebugServerHost(), resourcePath);
445+
createResourceURL(mPackagerConnectionSettings.getDebugServerHost(), resourcePath);
448446
final Request request = new Request.Builder().url(resourceURL).build();
449447

450448
try (Response response = mClient.newCall(request).execute()) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ public DevSupportManagerBase(
138138
mBundleStatus = new InspectorPackagerConnection.BundleStatus();
139139
mDevServerHelper =
140140
new DevServerHelper(
141-
mDevSettings, mApplicationContext.getPackageName(), () -> mBundleStatus);
141+
mDevSettings,
142+
mApplicationContext.getPackageName(),
143+
() -> mBundleStatus,
144+
mDevSettings.getPackagerConnectionSettings());
142145
mBundleDownloadListener = devBundleDownloadListener;
143146

144147
// Prepare shake gesture detector (will be started/stopped from #reload)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/PerftestDevSupportManager.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ public void onInternalSettingsChanged() {}
3131
new DevServerHelper(
3232
mDevSettings,
3333
applicationContext.getPackageName(),
34-
new InspectorPackagerConnection.BundleStatusProvider() {
35-
@Override
36-
public InspectorPackagerConnection.BundleStatus getBundleStatus() {
37-
return mBundleStatus;
38-
}
39-
});
34+
(InspectorPackagerConnection.BundleStatusProvider) () -> mBundleStatus,
35+
mDevSettings.getPackagerConnectionSettings());
4036
}
4137

4238
@Override

0 commit comments

Comments
 (0)