microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.4.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/test/resources/simulators/avdManager.ts

57lines · modeblame

a2e27a97digeff10 years ago1// 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";
52f3873ddigeff10 years ago5import {DeviceType} from "../../../common/android/adb";
c51e2d6bdigeff10 years ago6import {AdbSimulator} from "./adbSimulator";
a2e27a97digeff10 years ago7
8export interface IAVDManager {
9// Intends to simulate: android create avd -n <name> -t <targetID> [-<option> <value>] ...
10create(avdId: string): Q.Promise<void>;
11// Intends to simulate: emulator -avd WVGA800 -scale 96dpi -dpi-device 160
12launch(avdId: string): Q.Promise<string>;
13createAndLaunch(avdId: string): Q.Promise<string>;
0766856fdigeff10 years ago14createAndLaunchAll(avdIds: string[]): Q.Promise<string[]>;
a2e27a97digeff10 years ago15}
16
17interface IDeviceStateMapping {
4232e082digeff10 years ago18[avdId: string]: any;
a2e27a97digeff10 years ago19}
20
21/* Simulation of AVD Manager. */
22export class AVDManager implements IAVDManager {
23private nextAvailablePort = 5555;
24
25private devices: IDeviceStateMapping = {};
26
c51e2d6bdigeff10 years ago27constructor(private adb: AdbSimulator) {}
a2e27a97digeff10 years ago28
29public createAndLaunch(avdId: string): Q.Promise<string> {
30return this.create(avdId).then(() =>
31this.launch(avdId));
32}
33
34// Intends to simulate: android create avd -n <name> -t <targetID> [-<option> <value>] ...
35public create(avdId: string): Q.Promise<void> {
36if (!this.devices[avdId]) {
37this.devices[avdId] = {};
38return Q.resolve<void>(void 0);
39} else {
40throw new Error("Implement to match AVD: Device already exists");
41}
42}
43
44// Intends to simulate: emulator -avd WVGA800 -scale 96dpi -dpi-device 160
45public launch(avdId: string): Q.Promise<string> {
46if (this.devices[avdId]) {
52f3873ddigeff10 years ago47this.adb.notifyDeviceWasConnected(avdId, DeviceType.AndroidSdkEmulator);
a2e27a97digeff10 years ago48return Q(`emulator-${this.nextAvailablePort++}`);
49} else {
50throw new Error("Implement to match AVD: Device doesn't exists");
51}
52}
53
0766856fdigeff10 years ago54public createAndLaunchAll(avdIds: string[]): Q.Promise<string[]> {
a2e27a97digeff10 years ago55return Q.all(avdIds.map(avdId => this.createAndLaunch(avdId)));
56}
57}