diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevSupportManagerFactory.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevSupportManagerFactory.java index 97862539f42..d25dc60eec2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevSupportManagerFactory.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevSupportManagerFactory.java @@ -61,6 +61,10 @@ public class DefaultDevSupportManagerFactory implements DevSupportManagerFactory if (!enableOnCreate) { return new DisabledDevSupportManager(); } + // Developer support is enabled, we now must choose whether to return a DevSupportManager, + // or a more lean profiling-only PerftestDevSupportManager. We make the choice by first + // trying to return the full support DevSupportManager and if it fails, then just + // return PerftestDevSupportManager. try { // ProGuard is surprisingly smart in this case and will keep a class if it detects a call to // Class.forName() with a static string. So instead we generate a quasi-dynamic string to @@ -94,10 +98,7 @@ public class DefaultDevSupportManagerFactory implements DevSupportManagerFactory customPackagerCommandHandlers, surfaceDelegateFactory); } catch (Exception e) { - throw new RuntimeException( - "Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found" - + " or could not be created", - e); + return new PerftestDevSupportManager(applicationContext); } } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/PerftestDevSupportManager.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/PerftestDevSupportManager.java new file mode 100644 index 00000000000..2be621fc38f --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/PerftestDevSupportManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.devsupport; + +import android.content.Context; + +/** + * Interface for accessing and interacting with development features related to performance testing. + * Communication is enabled via the Inspector, but everything else is disabled. + */ +public final class PerftestDevSupportManager extends DisabledDevSupportManager { + private final DevServerHelper mDevServerHelper; + private final DevInternalSettings mDevSettings; + private final InspectorPackagerConnection.BundleStatus mBundleStatus; + + public PerftestDevSupportManager(Context applicationContext) { + mDevSettings = + new DevInternalSettings( + applicationContext, + new DevInternalSettings.Listener() { + @Override + public void onInternalSettingsChanged() {} + }); + mBundleStatus = new InspectorPackagerConnection.BundleStatus(); + mDevServerHelper = + new DevServerHelper( + mDevSettings, + applicationContext.getPackageName(), + new InspectorPackagerConnection.BundleStatusProvider() { + @Override + public InspectorPackagerConnection.BundleStatus getBundleStatus() { + return mBundleStatus; + } + }); + } + + @Override + public DevInternalSettings getDevSettings() { + return mDevSettings; + } + + @Override + public void startInspector() { + mDevServerHelper.openInspectorConnection(); + } + + @Override + public void stopInspector() { + mDevServerHelper.closeInspectorConnection(); + } +}