-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathemulator-helper.ts
122 lines (110 loc) · 3.25 KB
/
emulator-helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { RUNNING_EMULATOR_STATUS, DeviceTypes } from "../constants";
import * as _ from "lodash";
import { injector } from "../yok";
export class EmulatorHelper implements Mobile.IEmulatorHelper {
// https://developer.android.com/guide/topics/manifest/uses-sdk-element
public mapAndroidApiLevelToVersion = {
"android-35": "15.0.0",
"android-34": "14.0.0",
"android-33": "13.0.0",
"android-32": "12.0.0",
"android-31": "12.0.0",
"android-30": "11.0.0",
"android-29": "10.0.0",
"android-28": "9.0.0",
"android-27": "8.1.0",
"android-26": "8.0.0",
"android-25": "7.1.1",
"android-24": "7.0.0",
"android-23": "6.0.0",
"android-22": "5.1.0",
"android-21": "5.0.0",
"android-20": "4.4.0",
"android-19": "4.4.0",
"android-18": "4.3.0",
"android-17": "4.2.2",
};
public getEmulatorsFromAvailableEmulatorsOutput(
availableEmulatorsOutput: Mobile.IListEmulatorsOutput
): Mobile.IDeviceInfo[] {
return <Mobile.IDeviceInfo[]>_(availableEmulatorsOutput)
.valuesIn()
.map((value: Mobile.IEmulatorImagesOutput) => value.devices)
.concat()
.flatten()
.value();
}
public getErrorsFromAvailableEmulatorsOutput(
availableEmulatorsOutput: Mobile.IListEmulatorsOutput
): string[] {
return <string[]>_(availableEmulatorsOutput)
.valuesIn()
.map((value: Mobile.IEmulatorImagesOutput) => value.errors)
.concat()
.flatten()
.value();
}
public getEmulatorByImageIdentifier(
imageIdentifier: string,
emulators: Mobile.IDeviceInfo[]
): Mobile.IDeviceInfo {
const imagerIdentifierLowerCase =
imageIdentifier && imageIdentifier.toLowerCase();
return _.find(
emulators,
(emulator) =>
emulator &&
emulator.imageIdentifier &&
imageIdentifier &&
emulator.imageIdentifier.toLowerCase() === imagerIdentifierLowerCase
);
}
public getEmulatorByIdOrName(
emulatorIdOrName: string,
emulators: Mobile.IDeviceInfo[]
): Mobile.IDeviceInfo {
const emulatorIdOrNameLowerCase =
emulatorIdOrName && emulatorIdOrName.toLowerCase();
return _.find(
emulators,
(emulator) =>
emulator &&
emulatorIdOrNameLowerCase &&
((emulator.identifier &&
emulator.identifier.toLowerCase() === emulatorIdOrNameLowerCase) ||
emulator.displayName.toLowerCase() === emulatorIdOrNameLowerCase)
);
}
public isEmulatorRunning(emulator: Mobile.IDeviceInfo): boolean {
return emulator && emulator.status === RUNNING_EMULATOR_STATUS;
}
public getEmulatorByStartEmulatorOptions(
options: Mobile.IStartEmulatorOptions,
emulators: Mobile.IDeviceInfo[]
): Mobile.IDeviceInfo {
let result: Mobile.IDeviceInfo = null;
if (options.emulator) {
result = options.emulator;
}
if (!result && options.imageIdentifier) {
result = this.getEmulatorByImageIdentifier(
options.imageIdentifier,
emulators
);
}
if (!result && options.emulatorIdOrName) {
result = this.getEmulatorByIdOrName(options.emulatorIdOrName, emulators);
}
return result;
}
public setRunningAndroidEmulatorProperties(
emulatorId: string,
emulator: Mobile.IDeviceInfo
): void {
emulator.identifier = emulatorId;
emulator.status = RUNNING_EMULATOR_STATUS;
emulator.type = DeviceTypes.Device;
//emulator.isTablet; // TODO: consider to do this here!!!
}
}
injector.register("emulatorHelper", EmulatorHelper);