-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathAttachedAndroidAllocDriver.js
More file actions
61 lines (51 loc) · 1.76 KB
/
AttachedAndroidAllocDriver.js
File metadata and controls
61 lines (51 loc) · 1.76 KB
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
/**
* @typedef {import('../../../../common/drivers/android/cookies').AndroidDeviceCookie} AndroidDeviceCookie
*/
const AndroidAllocDriver = require('../AndroidAllocDriver');
class AttachedAndroidAllocDriver extends AndroidAllocDriver {
/**
* @param {object} options
* @param {import('../../../../common/drivers/android/exec/ADB')} options.adb
* @param {import('../../../DeviceRegistry')} options.deviceRegistry
* @param {import('../FreeDeviceFinder')} options.freeDeviceFinder
*/
constructor({ adb, deviceRegistry, freeDeviceFinder }) {
super({ adb });
this._deviceRegistry = deviceRegistry;
this._freeDeviceFinder = freeDeviceFinder;
}
async init() {
await this._deviceRegistry.unregisterZombieDevices();
}
/**
* @param deviceConfig
* @return {Promise<AndroidDeviceCookie>}
*/
async allocate(deviceConfig) {
const adbNamePattern = deviceConfig.device.adbName;
const adbName = await this._deviceRegistry.registerDevice(async () =>
(await this._freeDeviceFinder.findFreeDevice(adbNamePattern)).adbName);
return { id: adbName, adbName };
}
/**
* @param {AndroidDeviceCookie} deviceCookie
* @param {{ deviceConfig: Detox.DetoxSharedAndroidDriverConfig }} configs
* @returns {Promise<AndroidDeviceCookie>}
*/
async postAllocate(deviceCookie, configs) {
const { adbName } = deviceCookie;
await this._adb.apiLevel(adbName);
await this._adb.unlockScreen(adbName);
await super.postAllocate(deviceCookie, configs);
return deviceCookie;
}
/**
* @param cookie { AndroidDeviceCookie }
* @return {Promise<void>}
*/
async free(cookie) {
const { adbName } = cookie;
await this._deviceRegistry.unregisterDevice(adbName);
}
}
module.exports = AttachedAndroidAllocDriver;