Separate port constant for inspector proxy server.

Reviewed By: johnislarry

Differential Revision: D5282980

fbshipit-source-id: e714965e2bb4849e24138d326c757352b238aba6
This commit is contained in:
Nurzhan Bakibayev 2017-06-21 08:00:52 -07:00 committed by Facebook Github Bot
parent 7d1981ef82
commit 1ae54b5108
3 changed files with 33 additions and 18 deletions

View File

@ -14,9 +14,7 @@ import javax.annotation.Nullable;
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 android.os.Handler;
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 class DevServerHelper {
return String.format(
Locale.US,
INSPECTOR_DEVICE_URL_FORMAT,
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
mSettings.getPackagerConnectionSettings().getInspectorServerHost(),
AndroidInfoHelpers.getFriendlyDeviceName());
}

View File

@ -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 @@ public class AndroidInfoHelpers {
}
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
return getServerIpAddress(DEBUG_SERVER_HOST_PORT);
}
if (isRunningOnGenymotion()) {
return GENYMOTION_LOCALHOST;
}
if (isRunningOnStockEmulator()) {
return EMULATOR_LOCALHOST;
}
return DEVICE_LOCALHOST;
public static String getInspectorProxyHost() {
return getServerIpAddress(INSPECTOR_PROXY_PORT);
}
public static String getFriendlyDeviceName() {
@ -41,4 +39,20 @@ public class AndroidInfoHelpers {
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);
}
}

View File

@ -53,6 +53,10 @@ public class PackagerConnectionSettings {
return host;
}
public String getInspectorServerHost() {
return AndroidInfoHelpers.getInspectorProxyHost();
}
public @Nullable String getPackageName() {
return mPackageName;
}