microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
8b2be31e754e9f0cdcb9f30d07d7b34dc181dcc7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/test/resources/simulators/avdManager.ts

57lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as Q from "q";
5import {DeviceHelper} from "./deviceHelper";
6
7export interface IAVDManager {
8 // Intends to simulate: android create avd -n <name> -t <targetID> [-<option> <value>] ...
9 create(avdId: string): Q.Promise<void>;
10 // Intends to simulate: emulator -avd WVGA800 -scale 96dpi -dpi-device 160
11 launch(avdId: string): Q.Promise<string>;
12 createAndLaunch(avdId: string): Q.Promise<string>;
13 createAndLaunchAll(...avdIds: string[]): Q.Promise<string[]>;
14}
15
16interface IDeviceStateMapping {
17 [avdId: string]: any;
18}
19
20/* Simulation of AVD Manager. */
21export class AVDManager implements IAVDManager {
22 private nextAvailablePort = 5555;
23
24 private devices: IDeviceStateMapping = {};
25
26 constructor(private deviceHelper: DeviceHelper) {
27 }
28
29 public createAndLaunch(avdId: string): Q.Promise<string> {
30 return this.create(avdId).then(() =>
31 this.launch(avdId));
32 }
33
34 // Intends to simulate: android create avd -n <name> -t <targetID> [-<option> <value>] ...
35 public create(avdId: string): Q.Promise<void> {
36 if (!this.devices[avdId]) {
37 this.devices[avdId] = {};
38 return Q.resolve<void>(void 0);
39 } else {
40 throw new Error("Implement to match AVD: Device already exists");
41 }
42 }
43
44 // Intends to simulate: emulator -avd WVGA800 -scale 96dpi -dpi-device 160
45 public launch(avdId: string): Q.Promise<string> {
46 if (this.devices[avdId]) {
47 this.deviceHelper.notifyDeviceWasConnected(avdId);
48 return Q(`emulator-${this.nextAvailablePort++}`);
49 } else {
50 throw new Error("Implement to match AVD: Device doesn't exists");
51 }
52 }
53
54 public createAndLaunchAll(...avdIds: string[]): Q.Promise<string[]> {
55 return Q.all(avdIds.map(avdId => this.createAndLaunch(avdId)));
56 }
57}