Restore adb executeShell [5/n]

Summary: Expose executeShell explicitly through the device interface

Reviewed By: jameslawson

Differential Revision: D31055959

fbshipit-source-id: b14395d0783ede265c6ae39c397ea93a85a78336
This commit is contained in:
Michel Weststrate
2021-09-22 09:01:29 -07:00
committed by Facebook GitHub Bot
parent 4463e7ede2
commit 8cf182cc26
4 changed files with 7 additions and 12 deletions

View File

@@ -42,6 +42,7 @@ export interface Device {
readonly serial: string; readonly serial: string;
readonly deviceType: DeviceType; readonly deviceType: DeviceType;
onLogEntry(cb: DeviceLogListener): () => void; onLogEntry(cb: DeviceLogListener): () => void;
executeShell(command: string): Promise<string>;
} }
export type DevicePluginPredicate = (device: Device) => boolean; export type DevicePluginPredicate = (device: Device) => boolean;
@@ -69,6 +70,7 @@ export interface RealFlipperDevice {
deviceType: DeviceType; deviceType: DeviceType;
addLogListener(callback: DeviceLogListener): Symbol; addLogListener(callback: DeviceLogListener): Symbol;
removeLogListener(id: Symbol): void; removeLogListener(id: Symbol): void;
executeShell(command: string): Promise<string>;
} }
export class SandyDevicePluginInstance extends BasePluginInstance { export class SandyDevicePluginInstance extends BasePluginInstance {

View File

@@ -216,6 +216,9 @@ export abstract class BasePluginInstance {
realDevice.removeLogListener(handle); realDevice.removeLogListener(handle);
}; };
}, },
executeShell(command: string): Promise<string> {
return realDevice.executeShell(command);
},
}; };
} }

View File

@@ -506,6 +506,7 @@ function createMockDevice(options?: StartPluginOptions): RealFlipperDevice & {
addLogEntry(entry: DeviceLogEntry) { addLogEntry(entry: DeviceLogEntry) {
logListeners.forEach((f) => f?.(entry)); logListeners.forEach((f) => f?.(entry));
}, },
executeShell: jest.fn(),
}; };
} }

View File

@@ -74,18 +74,7 @@ function formatFrequency(freq: number) {
export function devicePlugin(client: PluginClient<{}, {}>) { export function devicePlugin(client: PluginClient<{}, {}>) {
const device = client.device; const device = client.device;
const executeShell = async (command: string) => { const executeShell = async (command: string) => device.executeShell(command);
// TODO: fix
return new Promise<string>((resolve, reject) => {
(device.realDevice as any).adb
.shell(device.serial, command)
.then(adb.util.readAll)
.then(function (output: {toString: () => {trim: () => string}}) {
resolve(output.toString().trim());
})
.catch((e: unknown) => reject(e));
});
};
let intervalID: NodeJS.Timer | null = null; let intervalID: NodeJS.Timer | null = null;
const cpuState = createState<CPUState>({ const cpuState = createState<CPUState>({