Add list-devices option to list the available devices.
Summary: This diff adds an option of `--list-devices` which will list the currently active devices on the machine. It will be later used to select a device by passing an `id` as an argument. Reviewed By: danielbuechele Differential Revision: D15524250 fbshipit-source-id: 7a79ceb1e431a25adcb4e05bc0cb68407c527806
This commit is contained in:
committed by
Facebook Github Bot
parent
53b852dbe6
commit
c94c2c8455
@@ -14,11 +14,12 @@ import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js';
|
||||
import {getAdbClient} from '../utils/adbClient';
|
||||
import {default as which} from 'which';
|
||||
import {promisify} from 'util';
|
||||
import type {ServerPorts} from '../reducers/application';
|
||||
|
||||
function createDevice(
|
||||
adbClient: any,
|
||||
device: any,
|
||||
store: Store,
|
||||
ports: ?ServerPorts,
|
||||
): Promise<AndroidDevice> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const type =
|
||||
@@ -32,13 +33,22 @@ function createDevice(
|
||||
name = (await getRunningEmulatorName(device.id)) || name;
|
||||
}
|
||||
const androidDevice = new AndroidDevice(device.id, type, name, adbClient);
|
||||
const ports = store.getState().application.serverPorts;
|
||||
androidDevice.reverse([ports.secure, ports.insecure]);
|
||||
if (ports) {
|
||||
androidDevice.reverse([ports.secure, ports.insecure]);
|
||||
}
|
||||
resolve(androidDevice);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function getActiveAndroidDevices(): Promise<Array<BaseDevice>> {
|
||||
const client = await getAdbClient();
|
||||
const androidDevices = await client.listDevices();
|
||||
return await Promise.all(
|
||||
androidDevices.map(device => createDevice(client, device)),
|
||||
);
|
||||
}
|
||||
|
||||
function getRunningEmulatorName(id: string): Promise<?string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const port = id.replace('emulator-', '');
|
||||
@@ -138,7 +148,11 @@ export default (store: Store, logger: Logger) => {
|
||||
};
|
||||
|
||||
async function registerDevice(adbClient: any, deviceData: any, store: Store) {
|
||||
const androidDevice = await createDevice(adbClient, deviceData, store);
|
||||
const androidDevice = await createDevice(
|
||||
adbClient,
|
||||
deviceData,
|
||||
store.getState().application.serverPorts,
|
||||
);
|
||||
logger.track('usage', 'register-device', {
|
||||
os: 'Android',
|
||||
name: androidDevice.title,
|
||||
|
||||
Reference in New Issue
Block a user