Migrate AndroidDevice from js to tsx
Summary: As per the title Reviewed By: jknoxville Differential Revision: D16667269 fbshipit-source-id: d213f4ebacf8050ae55a8e3268909da8535f2d93
This commit is contained in:
committed by
Facebook Github Bot
parent
f26a28f6f6
commit
eb26a74327
102
src/devices/AndroidDevice.tsx
Normal file
102
src/devices/AndroidDevice.tsx
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
import BaseDevice, {DeviceType, DeviceShell, LogLevel} from './BaseDevice';
|
||||
import {Priority} from 'adbkit-logcat-fb';
|
||||
import child_process from 'child_process';
|
||||
import child_process_promise from 'child-process-es6-promise';
|
||||
import ArchivedDevice from './ArchivedDevice';
|
||||
|
||||
type ADBClient = any;
|
||||
|
||||
export default class AndroidDevice extends BaseDevice {
|
||||
constructor(
|
||||
serial: string,
|
||||
deviceType: DeviceType,
|
||||
title: string,
|
||||
adb: ADBClient,
|
||||
) {
|
||||
super(serial, deviceType, title);
|
||||
this.adb = adb;
|
||||
this.os = 'Android';
|
||||
this.icon = 'icons/android.svg';
|
||||
this.adb.openLogcat(this.serial).then(reader => {
|
||||
reader.on('entry', entry => {
|
||||
let type: LogLevel = 'unknown';
|
||||
if (entry.priority === Priority.VERBOSE) {
|
||||
type = 'verbose';
|
||||
}
|
||||
if (entry.priority === Priority.DEBUG) {
|
||||
type = 'debug';
|
||||
}
|
||||
if (entry.priority === Priority.INFO) {
|
||||
type = 'info';
|
||||
}
|
||||
if (entry.priority === Priority.WARN) {
|
||||
type = 'warn';
|
||||
}
|
||||
if (entry.priority === Priority.ERROR) {
|
||||
type = 'error';
|
||||
}
|
||||
if (entry.priority === Priority.FATAL) {
|
||||
type = 'fatal';
|
||||
}
|
||||
|
||||
this.addLogEntry({
|
||||
tag: entry.tag,
|
||||
pid: entry.pid,
|
||||
tid: entry.tid,
|
||||
message: entry.message,
|
||||
date: entry.date,
|
||||
type,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
adb: ADBClient;
|
||||
pidAppMapping: {[key: number]: string} = {};
|
||||
logReader: any;
|
||||
|
||||
supportedColumns(): Array<string> {
|
||||
return ['date', 'pid', 'tid', 'tag', 'message', 'type', 'time'];
|
||||
}
|
||||
|
||||
reverse(ports: [number, number]): Promise<void> {
|
||||
return Promise.all(
|
||||
ports.map(port =>
|
||||
this.adb.reverse(this.serial, `tcp:${port}`, `tcp:${port}`),
|
||||
),
|
||||
).then(() => {
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
spawnShell(): DeviceShell | null | undefined {
|
||||
return child_process.spawn('adb', ['-s', this.serial, 'shell', '-t', '-t']);
|
||||
}
|
||||
|
||||
clearLogs(): Promise<void> {
|
||||
this.logEntries = [];
|
||||
return child_process_promise.spawn('adb', ['logcat', '-c']);
|
||||
}
|
||||
|
||||
archive(): ArchivedDevice {
|
||||
return new ArchivedDevice(
|
||||
this.serial,
|
||||
this.deviceType,
|
||||
this.title,
|
||||
this.os,
|
||||
[...this.logEntries],
|
||||
);
|
||||
}
|
||||
|
||||
navigateToLocation(location: string) {
|
||||
const shellCommand = `am start ${encodeURI(location)}`;
|
||||
this.adb.shell(this.serial, shellCommand);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user