Add dev mode to Android settings menu

Differential Revision: D2521488

fb-gh-sync-id: 28ae23a43570682e42eec4b6995235e8c65dd786
This commit is contained in:
Mike Armstrong
2015-10-07 23:55:19 -07:00
committed by facebook-github-bot-9
parent 3b370ce438
commit 34c26f31f6
4 changed files with 34 additions and 8 deletions

View File

@@ -29,6 +29,7 @@ public class DevInternalSettings implements
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
private static final String PREFS_FPS_DEBUG_KEY = "fps_debug"; private static final String PREFS_FPS_DEBUG_KEY = "fps_debug";
private static final String PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug";
private static final String PREFS_DEBUG_SERVER_HOST_KEY = "debug_http_host"; private static final String PREFS_DEBUG_SERVER_HOST_KEY = "debug_http_host";
private static final String PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug"; private static final String PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug";
private static final String PREFS_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change"; private static final String PREFS_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change";
@@ -54,12 +55,19 @@ public class DevInternalSettings implements
return mPreferences.getBoolean(PREFS_ANIMATIONS_DEBUG_KEY, false); return mPreferences.getBoolean(PREFS_ANIMATIONS_DEBUG_KEY, false);
} }
@Override
public boolean isJSDevModeEnabled() {
return mPreferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true);
}
public @Nullable String getDebugServerHost() { public @Nullable String getDebugServerHost() {
return mPreferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null); return mPreferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null);
} }
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (PREFS_FPS_DEBUG_KEY.equals(key) || PREFS_RELOAD_ON_JS_CHANGE_KEY.equals(key)) { if (PREFS_FPS_DEBUG_KEY.equals(key) ||
PREFS_RELOAD_ON_JS_CHANGE_KEY.equals(key) ||
PREFS_JS_DEV_MODE_DEBUG_KEY.equals(key)) {
mDebugManager.reloadSettings(); mDebugManager.reloadSettings();
} }
} }

View File

@@ -54,7 +54,7 @@ import okio.Sink;
private static final String DEVICE_LOCALHOST = "localhost"; private static final String DEVICE_LOCALHOST = "localhost";
private static final String BUNDLE_URL_FORMAT = private static final String BUNDLE_URL_FORMAT =
"http://%s:8081/%s.bundle?platform=android"; "http://%s:8081/%s.bundle?platform=android&dev=%s";
private static final String SOURCE_MAP_URL_FORMAT = private static final String SOURCE_MAP_URL_FORMAT =
BUNDLE_URL_FORMAT.replaceFirst("\\.bundle", ".map"); BUNDLE_URL_FORMAT.replaceFirst("\\.bundle", ".map");
private static final String LAUNCH_CHROME_DEVTOOLS_COMMAND_URL_FORMAT = private static final String LAUNCH_CHROME_DEVTOOLS_COMMAND_URL_FORMAT =
@@ -111,6 +111,13 @@ import okio.Sink;
return "localhost"; return "localhost";
} }
/**
* @return whether we should enabled dev mode or not when requesting JS bundles.
*/
private boolean getDevMode() {
return mSettings.isJSDevModeEnabled();
}
/** /**
* @return the host to use when connecting to the bundle server. * @return the host to use when connecting to the bundle server.
*/ */
@@ -145,15 +152,15 @@ import okio.Sink;
return Build.FINGERPRINT.contains("generic"); return Build.FINGERPRINT.contains("generic");
} }
private String createBundleURL(String host, String jsModulePath) { private String createBundleURL(String host, String jsModulePath, boolean devMode) {
return String.format(BUNDLE_URL_FORMAT, host, jsModulePath); return String.format(BUNDLE_URL_FORMAT, host, jsModulePath, devMode);
} }
public void downloadBundleFromURL( public void downloadBundleFromURL(
final BundleDownloadCallback callback, final BundleDownloadCallback callback,
final String jsModulePath, final String jsModulePath,
final File outputFile) { final File outputFile) {
final String bundleURL = createBundleURL(getDebugServerHost(), jsModulePath); final String bundleURL = createBundleURL(getDebugServerHost(), jsModulePath, getDevMode());
Request request = new Request.Builder() Request request = new Request.Builder()
.url(bundleURL) .url(bundleURL)
.build(); .build();
@@ -288,17 +295,17 @@ import okio.Sink;
} }
public String getSourceMapUrl(String mainModuleName) { public String getSourceMapUrl(String mainModuleName) {
return String.format(Locale.US, SOURCE_MAP_URL_FORMAT, getDebugServerHost(), mainModuleName); return String.format(Locale.US, SOURCE_MAP_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode());
} }
public String getSourceUrl(String mainModuleName) { public String getSourceUrl(String mainModuleName) {
return String.format(Locale.US, BUNDLE_URL_FORMAT, getDebugServerHost(), mainModuleName); return String.format(Locale.US, BUNDLE_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode());
} }
public String getJSBundleURLForRemoteDebugging(String mainModuleName) { public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
// The host IP we use when connecting to the JS bundle server from the emulator is not the // The host IP we use when connecting to the JS bundle server from the emulator is not the
// same as the one needed to connect to the same server from the Chrome proxy running on the // same as the one needed to connect to the same server from the Chrome proxy running on the
// host itself. // host itself.
return createBundleURL(getHostForJSProxy(), mainModuleName); return createBundleURL(getHostForJSProxy(), mainModuleName, getDevMode());
} }
} }

View File

@@ -23,4 +23,9 @@ public interface DeveloperSettings {
* @return Whether debug information about transitions should be displayed. * @return Whether debug information about transitions should be displayed.
*/ */
boolean isAnimationFpsDebugEnabled(); boolean isAnimationFpsDebugEnabled();
/**
* @return Whether dev mode should be enabled in JS bundles.
*/
boolean isJSDevModeEnabled();
} }

View File

@@ -7,6 +7,12 @@
android:key="catalyst_perf" android:key="catalyst_perf"
android:title="Performance" android:title="Performance"
> >
<CheckBoxPreference
android:key="js_dev_mode_debug"
android:title="JS Dev Mode"
android:summary="Load JavaScript bundle with __DEV__ = true for easier debugging. Disable for performance testing."
android:defaultValue="true"
/>
<CheckBoxPreference <CheckBoxPreference
android:key="fps_debug" android:key="fps_debug"
android:title="FPS Debugging" android:title="FPS Debugging"