Send notifications on litho's error boundary
Summary: Sends notifications to crash reportr plugin whenever the error boundary happens Reviewed By: danielbuechele Differential Revision: D13307473 fbshipit-source-id: dc0c6d2ebac32881fdb1aa5f63def824a115cf9e
This commit is contained in:
committed by
Facebook Github Bot
parent
d331ec2f10
commit
9cfa1b3074
@@ -1,9 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Copyright (c) Facebook, Inc.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
|
||||||
* file in the root directory of this source tree.
|
|
||||||
*
|
*
|
||||||
|
* <p>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.sample;
|
package com.facebook.flipper.sample;
|
||||||
|
|
||||||
@@ -65,7 +64,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.addPlugin(CrashReporterPlugin.getInstance());
|
||||||
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,9 +1,8 @@
|
|||||||
/*
|
/**
|
||||||
* Copyright (c) Facebook, Inc.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the LICENSE
|
|
||||||
* file in the root directory of this source tree.
|
|
||||||
*
|
*
|
||||||
|
* <p>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;
|
package com.facebook.flipper.plugins.crashreporter;
|
||||||
|
|
||||||
@@ -22,7 +21,16 @@ public class CrashReporterPlugin implements FlipperPlugin {
|
|||||||
@Nullable private FlipperConnection mConnection;
|
@Nullable private FlipperConnection mConnection;
|
||||||
|
|
||||||
@Nullable private Thread.UncaughtExceptionHandler prevHandler;
|
@Nullable private Thread.UncaughtExceptionHandler prevHandler;
|
||||||
|
private static CrashReporterPlugin crashreporterPlugin = null;
|
||||||
|
|
||||||
|
private CrashReporterPlugin() {}
|
||||||
|
|
||||||
|
// static method to create instance of Singleton class
|
||||||
|
public static CrashReporterPlugin getInstance() {
|
||||||
|
if (crashreporterPlugin == null) crashreporterPlugin = new CrashReporterPlugin();
|
||||||
|
|
||||||
|
return crashreporterPlugin;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Activity to be used to display incoming messages
|
* Activity to be used to display incoming messages
|
||||||
*/
|
*/
|
||||||
@@ -38,21 +46,7 @@ public class CrashReporterPlugin implements FlipperPlugin {
|
|||||||
new Thread.UncaughtExceptionHandler() {
|
new Thread.UncaughtExceptionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
|
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
|
||||||
if (mConnection != null) {
|
sendExceptionMessage(paramThread, paramThrowable);
|
||||||
FlipperConnection connection = mConnection;
|
|
||||||
FlipperArray.Builder builder = new FlipperArray.Builder();
|
|
||||||
for (StackTraceElement stackTraceElement : paramThrowable.getStackTrace()) {
|
|
||||||
builder.put(stackTraceElement.toString());
|
|
||||||
}
|
|
||||||
FlipperArray arr = builder.build();
|
|
||||||
connection.send(
|
|
||||||
"crash-report",
|
|
||||||
new FlipperObject.Builder()
|
|
||||||
.put("callstack", arr)
|
|
||||||
.put("name", paramThrowable.toString())
|
|
||||||
.put("reason", paramThrowable.getMessage())
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
if (prevHandler != null) {
|
if (prevHandler != null) {
|
||||||
prevHandler.uncaughtException(paramThread, paramThrowable);
|
prevHandler.uncaughtException(paramThread, paramThrowable);
|
||||||
}
|
}
|
||||||
@@ -60,6 +54,24 @@ public class CrashReporterPlugin implements FlipperPlugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendExceptionMessage(Thread paramThread, Throwable paramThrowable) {
|
||||||
|
if (mConnection != null) {
|
||||||
|
FlipperConnection connection = mConnection;
|
||||||
|
FlipperArray.Builder builder = new FlipperArray.Builder();
|
||||||
|
for (StackTraceElement stackTraceElement : paramThrowable.getStackTrace()) {
|
||||||
|
builder.put(stackTraceElement.toString());
|
||||||
|
}
|
||||||
|
FlipperArray arr = builder.build();
|
||||||
|
connection.send(
|
||||||
|
"crash-report",
|
||||||
|
new FlipperObject.Builder()
|
||||||
|
.put("callstack", arr)
|
||||||
|
.put("name", paramThrowable.toString())
|
||||||
|
.put("reason", paramThrowable.getMessage())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect() {
|
public void onDisconnect() {
|
||||||
mConnection = null;
|
mConnection = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user