Move crash reporting listener to the server

Summary: Changelog: Move crash watcher to the server. Add 'device-crash' event. Add 'device-start-crash-watcher', 'device-stop-crash-watcher' commands. Add 'onDeviceCrash' method to Plugin Client.

Reviewed By: mweststrate

Differential Revision: D33089810

fbshipit-source-id: ed62ee7c1129e5e25af18b444744b0796f567b72
This commit is contained in:
Andrey Goncharov
2021-12-20 11:37:25 -08:00
committed by Facebook GitHub Bot
parent 9fd45b96d2
commit 731749b41f
21 changed files with 519 additions and 426 deletions

View File

@@ -11,9 +11,10 @@ import {SandyPluginDefinition} from './SandyPluginDefinition';
import {BasePluginInstance, BasePluginClient} from './PluginBase';
import {FlipperLib} from './FlipperLib';
import {Atom, ReadOnlyAtom} from '../state/atom';
import {DeviceOS, DeviceType, DeviceLogEntry} from 'flipper-common';
import {DeviceOS, DeviceType, DeviceLogEntry, CrashLog} from 'flipper-common';
export type DeviceLogListener = (entry: DeviceLogEntry) => void;
export type CrashLogListener = (crash: CrashLog) => void;
export interface Device {
readonly isArchived: boolean;
@@ -24,7 +25,9 @@ export interface Device {
readonly connected: Atom<boolean>;
executeShell(command: string): Promise<string>;
addLogListener(callback: DeviceLogListener): Symbol;
addCrashListener(callback: CrashLogListener): Symbol;
removeLogListener(id: Symbol): void;
removeCrashListener(id: Symbol): void;
executeShell(command: string): Promise<string>;
forwardPort(local: string, remote: string): Promise<boolean>;
clearLogs(): Promise<void>;

View File

@@ -12,7 +12,7 @@ import EventEmitter from 'eventemitter3';
import {SandyPluginDefinition} from './SandyPluginDefinition';
import {MenuEntry, NormalizedMenuEntry, normalizeMenuEntry} from './MenuEntry';
import {FlipperLib} from './FlipperLib';
import {Device, DeviceLogListener} from './DevicePlugin';
import {CrashLogListener, Device, DeviceLogListener} from './DevicePlugin';
import {batched} from '../state/batch';
import {Idler} from '../utils/Idler';
import {Notification} from './Notification';
@@ -84,6 +84,12 @@ export interface BasePluginClient {
*/
onDeviceLogEntry(cb: DeviceLogListener): () => void;
/**
* Listener that is triggered if the underlying device crashes.
* Listeners established with this mechanism will automatically be cleaned up during destroy
*/
onDeviceCrash(cb: CrashLogListener): () => void;
/**
* Creates a Paste (similar to a Github Gist).
* Facebook only function. Resolves to undefined if creating a paste failed.
@@ -186,6 +192,7 @@ export abstract class BasePluginInstance {
menuEntries: NormalizedMenuEntry[] = [];
logListeners: Symbol[] = [];
crashListeners: Symbol[] = [];
readonly instanceId = ++staticInstanceId;
@@ -316,6 +323,13 @@ export abstract class BasePluginInstance {
this.device.removeLogListener(handle);
};
},
onDeviceCrash: (cb: CrashLogListener): (() => void) => {
const handle = this.device.addCrashListener(cb);
this.crashListeners.push(handle);
return () => {
this.device.removeCrashListener(handle);
};
},
writeTextToClipboard: this.flipperLib.writeTextToClipboard,
createPaste: this.flipperLib.createPaste,
isFB: this.flipperLib.isFB,
@@ -365,6 +379,9 @@ export abstract class BasePluginInstance {
this.logListeners.splice(0).forEach((handle) => {
this.device.removeLogListener(handle);
});
this.crashListeners.splice(0).forEach((handle) => {
this.device.removeCrashListener(handle);
});
this.events.emit('destroy');
this.destroyed = true;
}