Permalink
Browse files

Separate port constant for inspector proxy server.

Reviewed By: johnislarry

Differential Revision: D5282980

fbshipit-source-id: e714965e2bb4849e24138d326c757352b238aba6
  • Loading branch information...
Hypuk authored and facebook-github-bot committed Jun 21, 2017
1 parent 7d1981e commit 1ae54b510889738a3580625931d2c9a53beb7cc1
@@ -14,9 +14,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -28,7 +26,6 @@
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.network.OkHttpCallUtil;
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
@@ -316,7 +313,7 @@ public String getInspectorDeviceUrl() {
return String.format(
Locale.US,
INSPECTOR_DEVICE_URL_FORMAT,
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
mSettings.getPackagerConnectionSettings().getInspectorServerHost(),
AndroidInfoHelpers.getFriendlyDeviceName());
}
@@ -2,13 +2,18 @@
package com.facebook.react.modules.systeminfo;
import java.util.Locale;
import android.os.Build;
public class AndroidInfoHelpers {
public static final String EMULATOR_LOCALHOST = "10.0.2.2:8081";
public static final String GENYMOTION_LOCALHOST = "10.0.3.2:8081";
public static final String DEVICE_LOCALHOST = "localhost:8081";
public static final String EMULATOR_LOCALHOST = "10.0.2.2";
public static final String GENYMOTION_LOCALHOST = "10.0.3.2";
public static final String DEVICE_LOCALHOST = "localhost";
private static final int DEBUG_SERVER_HOST_PORT = 8081;
private static final int INSPECTOR_PROXY_PORT = 8081;
private static boolean isRunningOnGenymotion() {
return Build.FINGERPRINT.contains("vbox");
@@ -19,18 +24,11 @@ private static boolean isRunningOnStockEmulator() {
}
public static String getServerHost() {
// Since genymotion runs in vbox it use different hostname to refer to adb host.
// We detect whether app runs on genymotion and replace js bundle server hostname accordingly
if (isRunningOnGenymotion()) {
return GENYMOTION_LOCALHOST;
}
if (isRunningOnStockEmulator()) {
return EMULATOR_LOCALHOST;
}
return getServerIpAddress(DEBUG_SERVER_HOST_PORT);
}
return DEVICE_LOCALHOST;
public static String getInspectorProxyHost() {
return getServerIpAddress(INSPECTOR_PROXY_PORT);
}
public static String getFriendlyDeviceName() {
@@ -41,4 +39,20 @@ public static String getFriendlyDeviceName() {
return Build.MODEL + " - " + Build.VERSION.RELEASE + " - API " + Build.VERSION.SDK_INT;
}
}
private static String getServerIpAddress(int port) {
// Since genymotion runs in vbox it use different hostname to refer to adb host.
// We detect whether app runs on genymotion and replace js bundle server hostname accordingly
String ipAddress;
if (isRunningOnGenymotion()) {
ipAddress = GENYMOTION_LOCALHOST;
} else if (isRunningOnStockEmulator()) {
ipAddress = EMULATOR_LOCALHOST;
} else {
ipAddress = DEVICE_LOCALHOST;
}
return String.format(Locale.US, "%s:%d", ipAddress, port);
}
}
@@ -53,6 +53,10 @@ public String getDebugServerHost() {
return host;
}
public String getInspectorServerHost() {
return AndroidInfoHelpers.getInspectorProxyHost();
}
public @Nullable String getPackageName() {
return mPackageName;
}

0 comments on commit 1ae54b5

Please sign in to comment.