Add runInBackground Interface method

Summary:
Add support for plugins to opt in to background for android.
This diff does the following
- Adds a method `runInBackground` in java interface of `FlipperPlugin`
- Make the network plugin opt in to run in background

Reviewed By: danielbuechele

Differential Revision: D10360033

fbshipit-source-id: b31c7550d00b760b7033c150232e3925b6272d24
This commit is contained in:
Pritesh Nandgaonkar
2018-10-15 05:45:03 -07:00
committed by Facebook Github Bot
parent e58961e184
commit 14e38c087f
8 changed files with 44 additions and 0 deletions

View File

@@ -198,6 +198,11 @@ class JFlipperPlugin : public jni::JavaClass<JFlipperPlugin> {
static const auto method = javaClassStatic()->getMethod<void()>("onDisconnect");
method(self());
}
bool runInBackground() {
static const auto method = javaClassStatic()->getMethod<jboolean()>("runInBackground");
return method(self()) == JNI_TRUE;
}
};
class JFlipperStateUpdateListener : public jni::JavaClass<JFlipperStateUpdateListener> {
@@ -247,6 +252,10 @@ class JFlipperPluginWrapper : public FlipperPlugin {
jplugin->didDisconnect();
}
virtual bool runInBackground() override {
return jplugin->runInBackground();
}
JFlipperPluginWrapper(jni::global_ref<JFlipperPlugin> plugin): jplugin(plugin) {}
};

View File

@@ -34,4 +34,9 @@ public interface FlipperPlugin {
* longer valid. Do not try to use the connection in or after this method has been called.
*/
void onDisconnect() throws Exception;
/**
Returns true if the plugin is meant to be run in background too, otherwise it returns false.
*/
boolean runInBackground();
}

View File

@@ -37,6 +37,11 @@ public abstract class BufferingFlipperPlugin implements FlipperPlugin {
mConnection = null;
}
@Override
public boolean runInBackground() {
return true;
}
public synchronized FlipperConnection getConnection() {
return mConnection;
}

View File

@@ -31,4 +31,9 @@ public class ConsoleFlipperPlugin implements FlipperPlugin {
}
public void onDisconnect() throws Exception {}
@Override
public boolean runInBackground() {
return false;
}
}

View File

@@ -171,6 +171,11 @@ public class InspectorFlipperPlugin implements FlipperPlugin {
mConnection = null;
}
@Override
public boolean runInBackground() {
return false;
}
final FlipperReceiver mShouldShowLithoAccessibilitySettings =
new MainThreadFlipperReceiver(mConnection) {
@Override

View File

@@ -57,6 +57,11 @@ public class LeakCanaryFlipperPlugin implements FlipperPlugin {
mConnection = null;
}
@Override
public boolean runInBackground() {
return false;
}
private void sendLeakList() {
if (mConnection != null) {
JSONObject obj = new JSONObject();

View File

@@ -68,4 +68,9 @@ public class SandboxFlipperPlugin implements FlipperPlugin {
@Override
public void onDisconnect() {}
@Override
public boolean runInBackground() {
return false;
}
}

View File

@@ -200,6 +200,11 @@ public class SharedPreferencesFlipperPlugin implements FlipperPlugin {
mConnection = null;
}
@Override
public boolean runInBackground() {
return false;
}
public static class SharedPreferencesDescriptor {
public final String name;
public final int mode;