microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4b124a08cf4726fc4b6b1f843dcd24e31f33db5e

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 {DeviceType} from "../../../common/android/adb";
6import {AdbSimulator} from "./adbSimulator";
7
8export interface IAVDManager {
9 // Intends to simulate: android create avd -n <name> -t <targetID> [-<option> <value>] ...
10 create(avdId: string): Q.Promise<void>;
11 // Intends to simulate: emulator -avd WVGA800 -scale 96dpi -dpi-device 160
12 launch(avdId: string): Q.Promise<string>;
13 createAndLaunch(avdId: string): Q.Promise<string>;
14 createAndLaunchAll(avdIds: string[]): Q.Promise<string[]>;
15}
16
17interface IDeviceStateMapping {
18 [avdId: string]: any;
19}
20
21/* Simulation of AVD Manager. */
22export class AVDManager implements IAVDManager {
23 private nextAvailablePort = 5555;
24
25 private devices: IDeviceStateMapping = {};
26
27 constructor(private adb: AdbSimulator) {}
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.adb.notifyDeviceWasConnected(avdId, DeviceType.AndroidSdkEmulator);
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}