Skip to content

Commit 4d1a568

Browse files
Matt Blagdenfacebook-github-bot
authored andcommitted
Add perftest dev support manager
Summary: 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. With this change, if a developer opts into developer support in a release build (i.e. `enableOnCreate == true && ReactBuildConfig.DEBUG == false` in the `DevSupportManagerFactory`), the `PerfTestDevSupportManager` will be used, allowing use of things like heap size reporting and the sampling profiler. (`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: rubennorte Differential Revision: D39468561 fbshipit-source-id: cb3c82e7a8ee74316b23f57dc8d0cc6e5cdb18a7
1 parent f353119 commit 4d1a568

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.content.Context;
1111
import androidx.annotation.Nullable;
1212
import com.facebook.react.common.SurfaceDelegateFactory;
13+
import com.facebook.react.common.build.ReactBuildConfig;
1314
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
1415
import com.facebook.react.devsupport.interfaces.DevSupportManager;
1516
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
@@ -61,6 +62,9 @@ public DevSupportManager create(
6162
if (!enableOnCreate) {
6263
return new DisabledDevSupportManager();
6364
}
65+
if (!ReactBuildConfig.DEBUG) {
66+
return new PerftestDevSupportManager(applicationContext);
67+
}
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
Lines changed: 56 additions & 0 deletions
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)