Skip to content

Commit f0b7cbe

Browse files
fbmal7facebook-github-bot
authored andcommitted
Add perftest dev support manager
Summary: This is the 2nd iteration of D39468561 (4d1a568). We first check if the `BridgeDevSupportManager` can be used before we return the `PerfTestDevSupportManager`. This is to avoid a breakage of Quantum that happened on the previous diff. Add a `DevSupportManager` that can be used for performance testing. This `DevSupportManager` allows the inspector connection to be established, but leaves everything else disabled. Previously, if Developer Support was enabled on a release build, the application would present an error as it unsuccessfully attempted to use the bridge dev support manager. This is now conceptually the new flow for deciding what DevSupportManager to choose. ``` if (developerSupportEnabled) { if (full support available) { use full support (i.e. bridge) } else { use profiling-only support (i.e. perftest) } } else { disable dev support } ``` The first attempt at this diff erroneously used this logic: ``` if (developerSupportEnabled) { if (debug build) { use full support (i.e. bridge) } else { use profiling-only support (i.e. perftest) } } else { disable dev support } ``` So now we are always checking to see if the `BridgeDevSupportManager` is available, and if it is, we use it. (`enableOnCrease` indicates the development mode setting: https://www.internalfb.com/code/fbsource/[6b8a941fdf2a0fd58d9db36f5a59fa5fb53ad2df]/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java?lines=259) Changelog: [internal] Reviewed By: makovkastar Differential Revision: D40948243 fbshipit-source-id: 50c6b6b905f5b9c5b5ecc090b36edbd6090ea774
1 parent 44f3234 commit f0b7cbe

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevSupportManagerFactory.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public DevSupportManager create(
6161
if (!enableOnCreate) {
6262
return new DisabledDevSupportManager();
6363
}
64+
// Developer support is enabled, we now must choose whether to return a DevSupportManager,
65+
// or a more lean profiling-only PerftestDevSupportManager. We make the choice by first
66+
// trying to return the full support DevSupportManager and if it fails, then just
67+
// return PerftestDevSupportManager.
6468
try {
6569
// ProGuard is surprisingly smart in this case and will keep a class if it detects a call to
6670
// Class.forName() with a static string. So instead we generate a quasi-dynamic string to
@@ -94,10 +98,7 @@ public DevSupportManager create(
9498
customPackagerCommandHandlers,
9599
surfaceDelegateFactory);
96100
} catch (Exception e) {
97-
throw new RuntimeException(
98-
"Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found"
99-
+ " or could not be created",
100-
e);
101+
return new PerftestDevSupportManager(applicationContext);
101102
}
102103
}
103104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.devsupport;
9+
10+
import android.content.Context;
11+
12+
/**
13+
* Interface for accessing and interacting with development features related to performance testing.
14+
* Communication is enabled via the Inspector, but everything else is disabled.
15+
*/
16+
public final class PerftestDevSupportManager extends DisabledDevSupportManager {
17+
private final DevServerHelper mDevServerHelper;
18+
private final DevInternalSettings mDevSettings;
19+
private final InspectorPackagerConnection.BundleStatus mBundleStatus;
20+
21+
public PerftestDevSupportManager(Context applicationContext) {
22+
mDevSettings =
23+
new DevInternalSettings(
24+
applicationContext,
25+
new DevInternalSettings.Listener() {
26+
@Override
27+
public void onInternalSettingsChanged() {}
28+
});
29+
mBundleStatus = new InspectorPackagerConnection.BundleStatus();
30+
mDevServerHelper =
31+
new DevServerHelper(
32+
mDevSettings,
33+
applicationContext.getPackageName(),
34+
new InspectorPackagerConnection.BundleStatusProvider() {
35+
@Override
36+
public InspectorPackagerConnection.BundleStatus getBundleStatus() {
37+
return mBundleStatus;
38+
}
39+
});
40+
}
41+
42+
@Override
43+
public DevInternalSettings getDevSettings() {
44+
return mDevSettings;
45+
}
46+
47+
@Override
48+
public void startInspector() {
49+
mDevServerHelper.openInspectorConnection();
50+
}
51+
52+
@Override
53+
public void stopInspector() {
54+
mDevServerHelper.closeInspectorConnection();
55+
}
56+
}

0 commit comments

Comments
 (0)