Remove Flipper actions in Dev Menu, add new Open Debugger action (Android) (#39254)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39254

## Context

RFC: Decoupling Flipper from React Native core: https://github.com/react-native-community/discussions-and-proposals/pull/641

## Changes

- Removes Flipper-backed "Launch Debugger" and "Launch React DevTools" actions from the Dev Menu.
- Adds replacement "Launch Debugger" action triggering the new one-click Hermes debugger flow for 0.73.

Changelog:
[Android][Changed] Remove Flipper actions in Dev Menu, add new Open Debugger action

#rn-oss-skip-export

Reviewed By: cortinico

Differential Revision: D46187942

fbshipit-source-id: 6f2123a98558922f0110349e93b9156312604dff
This commit is contained in:
Alex Hunt
2023-09-16 13:48:24 -07:00
committed by Facebook GitHub Bot
parent 5bfc507655
commit 3bc402f612
4 changed files with 32 additions and 59 deletions
@@ -82,7 +82,7 @@ class DevInternalSettings
@Override
public boolean isDeviceDebugEnabled() {
return ReactBuildConfig.IS_INTERNAL_BUILD && ReactBuildConfig.DEBUG;
return ReactBuildConfig.DEBUG;
}
@Override
@@ -7,7 +7,7 @@
package com.facebook.react.devsupport;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -36,15 +36,12 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okio.Okio;
import okio.Sink;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Helper class for all things about the debug server running in the engineer's host machine.
@@ -240,38 +237,6 @@ public class DevServerHelper {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void openUrl(final ReactContext context, final String url, final String errorMessage) {
new AsyncTask<Void, String, Boolean>() {
@Override
protected Boolean doInBackground(Void... ignore) {
return doSync();
}
public boolean doSync() {
try {
String openUrlEndpoint = getOpenUrlEndpoint(context);
String jsonString = new JSONObject().put("url", url).toString();
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonString);
Request request = new Request.Builder().url(openUrlEndpoint).post(body).build();
OkHttpClient client = new OkHttpClient();
client.newCall(request).execute();
return true;
} catch (JSONException | IOException e) {
FLog.e(ReactConstants.TAG, "Failed to open URL" + url, e);
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (!result) {
RNLog.w(context, errorMessage);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public String getWebsocketProxyURL() {
return String.format(
Locale.US,
@@ -296,11 +261,6 @@ public class DevServerHelper {
mBundleDownloader.downloadBundleFromURL(callback, outputFile, bundleURL, bundleInfo);
}
private String getOpenUrlEndpoint(Context context) {
return String.format(
Locale.US, "http://%s/open-url", AndroidInfoHelpers.getServerHost(context));
}
public void downloadBundleFromURL(
DevBundleDownloadListener callback,
File outputFile,
@@ -458,4 +418,30 @@ public class DevServerHelper {
return null;
}
}
/** Attempt to open the JS debugger on the host machine (on-device CDP debugging). */
public void openDebugger(final ReactContext context, final String errorMessage) {
// TODO(huntie): Requests to dev server should not assume 'http' URL scheme
String requestUrl =
String.format(
Locale.US,
"http://%s/open-debugger?appId=%s",
mPackagerConnectionSettings.getInspectorServerHost(),
Uri.encode(mPackageName));
Request request =
new Request.Builder().url(requestUrl).method("POST", RequestBody.create(null, "")).build();
mClient
.newCall(request)
.enqueue(
new Callback() {
@Override
public void onFailure(@NonNull Call _call, @NonNull IOException _e) {
RNLog.w(context, errorMessage);
}
@Override
public void onResponse(@NonNull Call _call, @NonNull Response _response) {}
});
}
}
@@ -78,9 +78,6 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
private static final int JAVA_ERROR_COOKIE = -1;
private static final int JSEXCEPTION_ERROR_COOKIE = -1;
private static final String RELOAD_APP_ACTION_SUFFIX = ".RELOAD_APP_ACTION";
private static final String FLIPPER_DEBUGGER_URL =
"flipper://null/Hermesdebuggerrn?device=React%20Native";
private static final String FLIPPER_DEVTOOLS_URL = "flipper://null/React?device=React%20Native";
private static final String EXOPACKAGE_LOCATION_FORMAT =
"/data/local/tmp/exopackage/%s//secondary-dex";
@@ -369,8 +366,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
});
if (mDevSettings.isDeviceDebugEnabled()) {
// For on-device debugging we link out to Flipper.
// Since we're assuming Flipper is available, also include the DevTools.
// On-device JS debugging (CDP). Render action to open debugger frontend.
// Reset the old debugger setting so no one gets stuck.
// TODO: Remove in a few weeks.
@@ -381,17 +377,9 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
options.put(
mApplicationContext.getString(R.string.catalyst_debug_open),
() ->
mDevServerHelper.openUrl(
mDevServerHelper.openDebugger(
mCurrentContext,
FLIPPER_DEBUGGER_URL,
mApplicationContext.getString(R.string.catalyst_open_flipper_error)));
options.put(
mApplicationContext.getString(R.string.catalyst_devtools_open),
() ->
mDevServerHelper.openUrl(
mCurrentContext,
FLIPPER_DEVTOOLS_URL,
mApplicationContext.getString(R.string.catalyst_open_flipper_error)));
mApplicationContext.getString(R.string.catalyst_open_debugger_error)));
}
options.put(
@@ -3,8 +3,7 @@
<string name="catalyst_reload" project="catalyst" translatable="false">Reload</string>
<string name="catalyst_reload_error" project="catalyst" translatable="false">Failed to load bundle. Try restarting the bundler or reconnecting your device.</string>
<string name="catalyst_change_bundle_location" project="catalyst" translatable="false">Change Bundle Location</string>
<string name="catalyst_open_flipper_error" project="catalyst" translatable="false">Failed to open Flipper. Please check that Metro is running.</string>
<string name="catalyst_devtools_open" project="catalyst" translatable="false">Open React DevTools</string>
<string name="catalyst_open_debugger_error" project="catalyst" translatable="false">Failed to open debugger. Please check that the dev server is running.</string>
<string name="catalyst_debug_open" project="catalyst" translatable="false">Open Debugger</string>
<string name="catalyst_debug_connecting" project="catalyst" translatable="false">Connecting to debugger...</string>
<string name="catalyst_debug_error" project="catalyst" translatable="false">Failed to connect to debugger!</string>