Crash reporting plugin android (#328)
Summary: This PR adds the barebone of a crash reporting plugin in android. Since there is no easy way to stack the PR's in git, creating a new PR, but this depends on the [iOS PR](https://github.com/facebook/flipper/pull/322) Pull Request resolved: https://github.com/facebook/flipper/pull/328 Reviewed By: jknoxville, passy Differential Revision: D13137447 Pulled By: priteshrnandgaonkar fbshipit-source-id: 3b86cebbb1ea01601405dd7ba58e1caa2b506065
This commit is contained in:
committed by
Facebook Github Bot
parent
d475a50f2a
commit
37c973d0c9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004-present, Facebook, Inc.
|
* Copyright (c) Facebook, Inc.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
@@ -12,6 +12,7 @@ import android.content.Context;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import com.facebook.flipper.android.AndroidFlipperClient;
|
import com.facebook.flipper.android.AndroidFlipperClient;
|
||||||
import com.facebook.flipper.core.FlipperClient;
|
import com.facebook.flipper.core.FlipperClient;
|
||||||
|
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
|
||||||
import com.facebook.flipper.plugins.example.ExampleFlipperPlugin;
|
import com.facebook.flipper.plugins.example.ExampleFlipperPlugin;
|
||||||
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
|
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
|
||||||
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
|
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
|
||||||
@@ -64,6 +65,7 @@ public class FlipperSampleApplication extends Application {
|
|||||||
new SharedPreferencesDescriptor("other_sample", Context.MODE_PRIVATE))));
|
new SharedPreferencesDescriptor("other_sample", Context.MODE_PRIVATE))));
|
||||||
client.addPlugin(new LeakCanaryFlipperPlugin());
|
client.addPlugin(new LeakCanaryFlipperPlugin());
|
||||||
client.addPlugin(new ExampleFlipperPlugin());
|
client.addPlugin(new ExampleFlipperPlugin());
|
||||||
|
client.addPlugin(new CrashReporterPlugin());
|
||||||
client.start();
|
client.start();
|
||||||
|
|
||||||
getSharedPreferences("sample", Context.MODE_PRIVATE).edit().putString("Hello", "world").apply();
|
getSharedPreferences("sample", Context.MODE_PRIVATE).edit().putString("Hello", "world").apply();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2004-present, Facebook, Inc.
|
* Copyright (c) Facebook, Inc.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
* file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc.
|
||||||
|
*
|
||||||
|
* 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.flipper.plugins.crashreporter;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import com.facebook.flipper.core.FlipperConnection;
|
||||||
|
import com.facebook.flipper.core.FlipperObject;
|
||||||
|
import com.facebook.flipper.core.FlipperPlugin;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
public class CrashReporterPlugin implements FlipperPlugin {
|
||||||
|
public static final String ID = "CrashReporter";
|
||||||
|
|
||||||
|
@Nullable private Activity mActivity;
|
||||||
|
|
||||||
|
@Nullable private FlipperConnection mConnection;
|
||||||
|
|
||||||
|
@Nullable private Thread.UncaughtExceptionHandler prevHandler;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Activity to be used to display incoming messages
|
||||||
|
*/
|
||||||
|
public void setActivity(Activity activity) {
|
||||||
|
mActivity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnect(FlipperConnection connection) {
|
||||||
|
mConnection = connection;
|
||||||
|
prevHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(
|
||||||
|
new Thread.UncaughtExceptionHandler() {
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
|
||||||
|
if (mConnection != null) {
|
||||||
|
FlipperConnection connection = mConnection;
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
paramThrowable.printStackTrace(pw);
|
||||||
|
connection.send(
|
||||||
|
"crash-report",
|
||||||
|
new FlipperObject.Builder()
|
||||||
|
.put("callstack", sw.toString())
|
||||||
|
.put("cause", paramThrowable.toString())
|
||||||
|
.put("reason", paramThrowable.toString())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
if (prevHandler != null) {
|
||||||
|
prevHandler.uncaughtException(paramThread, paramThrowable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnect() {
|
||||||
|
mConnection = null;
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(prevHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean runInBackground() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user