Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Allow SonarFlowReporter to use an existing Flipper Network Plugin if …
Browse files Browse the repository at this point in the history
…any was presented, or fall to DI

Summary:
After adding Graphservice to AMA Android, I tried to integrate Flipper network plugin to capture GS requests and send them to Flipper. However, I noticed that AMA uses Catalyst shell package which will [init Flipper initially](https://www.internalfb.com/code/fbsource/[56757675f594]/fbandroid/java/com/facebook/catalyst/shell/FbReactApplicationBaseSonarUtil.java?lines=25-39) so any attempt to use DI to create a new network plugin to catch GS traffic won't work since Flipper singleton will relay on the first network plugin that was created before DI.
This changes will resolve the problem, before letting DI create a new network plugin object, it will look for an existing one so it reuse it, if non were declared then it will create a new instance.

Reviewed By: WilliamY97

Differential Revision: D57799647

fbshipit-source-id: 6d059bcc63060f832d2c0bceeeff5f216db6a7a2
  • Loading branch information
Abdul Babil authored and facebook-github-bot committed Jun 5, 2024
1 parent d7a2c3f commit e8eafa7
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
public class NetworkFlipperPlugin extends BufferingFlipperPlugin implements NetworkReporter {
public static final String ID = "Network";
private static final int MAX_BODY_SIZE_IN_BYTES = 1024 * 1024;

private final List<NetworkResponseFormatter> mFormatters;
private List<NetworkResponseFormatter> mFormatters;

public NetworkFlipperPlugin() {
this(null);
Expand All @@ -35,6 +34,10 @@ public String getId() {
return ID;
}

public void setFormatters(List<NetworkResponseFormatter> formatters) {
mFormatters = formatters;
}

@Override
public void reportRequest(final RequestInfo requestInfo) {
(new ErrorReportingRunnable(getConnection()) {
Expand Down

0 comments on commit e8eafa7

Please sign in to comment.