Skip to content

Commit

Permalink
Add perftest dev support manager
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Michael Anthony Leon authored and facebook-github-bot committed Nov 4, 2022
1 parent 44f3234 commit f0b7cbe
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public DevSupportManager create(
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
Expand Down Expand Up @@ -94,10 +98,7 @@ public DevSupportManager create(
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit f0b7cbe

Please sign in to comment.