appium-android-driver 12.6.0 → 12.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/lib/commands/lock/exports.d.ts +26 -30
- package/build/lib/commands/lock/exports.d.ts.map +1 -1
- package/build/lib/commands/lock/exports.js +32 -32
- package/build/lib/commands/lock/exports.js.map +1 -1
- package/build/lib/commands/lock/helpers.d.ts +72 -58
- package/build/lib/commands/lock/helpers.d.ts.map +1 -1
- package/build/lib/commands/lock/helpers.js +82 -72
- package/build/lib/commands/lock/helpers.js.map +1 -1
- package/lib/commands/lock/exports.ts +147 -0
- package/lib/commands/lock/{helpers.js → helpers.ts} +133 -98
- package/package.json +2 -2
- package/lib/commands/lock/exports.js +0 -137
|
@@ -25,48 +25,24 @@ exports.PIN_UNLOCK_KEY_EVENT = 'pinWithKeyEvent';
|
|
|
25
25
|
exports.PASSWORD_UNLOCK = 'password';
|
|
26
26
|
exports.PATTERN_UNLOCK = 'pattern';
|
|
27
27
|
exports.FINGERPRINT_UNLOCK = 'fingerprint';
|
|
28
|
-
const UNLOCK_TYPES =
|
|
28
|
+
const UNLOCK_TYPES = [
|
|
29
29
|
exports.PIN_UNLOCK,
|
|
30
30
|
exports.PIN_UNLOCK_KEY_EVENT,
|
|
31
31
|
exports.PASSWORD_UNLOCK,
|
|
32
32
|
exports.PATTERN_UNLOCK,
|
|
33
33
|
exports.FINGERPRINT_UNLOCK,
|
|
34
|
-
]
|
|
34
|
+
];
|
|
35
35
|
exports.KEYCODE_NUMPAD_ENTER = 66;
|
|
36
36
|
exports.UNLOCK_WAIT_TIME = 100;
|
|
37
37
|
exports.INPUT_KEYS_WAIT_TIME = 100;
|
|
38
38
|
const NUMBER_ZERO_KEYCODE = 7;
|
|
39
39
|
const TOUCH_DELAY_MS = 1000;
|
|
40
40
|
/**
|
|
41
|
+
* Converts an unlock type to a credential type string.
|
|
41
42
|
*
|
|
42
|
-
* @param
|
|
43
|
-
* @returns
|
|
44
|
-
|
|
45
|
-
function isNonEmptyString(value) {
|
|
46
|
-
return typeof value === 'string' && value !== '';
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Wait for the display to be unlocked.
|
|
50
|
-
* Some devices automatically accept typed 'pin' and 'password' code
|
|
51
|
-
* without pressing the Enter key. But some devices need it.
|
|
52
|
-
* This method waits a few seconds first for such automatic acceptance case.
|
|
53
|
-
* If the device is still locked, then this method will try to send
|
|
54
|
-
* the enter key code.
|
|
55
|
-
*
|
|
56
|
-
* @param {import('appium-adb').ADB} adb The instance of ADB
|
|
57
|
-
*/
|
|
58
|
-
async function waitForUnlock(adb) {
|
|
59
|
-
await (0, asyncbox_1.sleep)(exports.UNLOCK_WAIT_TIME);
|
|
60
|
-
if (!(await adb.isScreenLocked())) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
await adb.keyevent(exports.KEYCODE_NUMPAD_ENTER);
|
|
64
|
-
await (0, asyncbox_1.sleep)(exports.UNLOCK_WAIT_TIME);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
68
|
-
* @param {import('../types').UnlockType} unlockType
|
|
69
|
-
* @returns {string}
|
|
43
|
+
* @param unlockType - The unlock type
|
|
44
|
+
* @returns The credential type string
|
|
45
|
+
* @throws {Error} If the unlock type is not known
|
|
70
46
|
*/
|
|
71
47
|
function toCredentialType(unlockType) {
|
|
72
48
|
const result = {
|
|
@@ -81,9 +57,11 @@ function toCredentialType(unlockType) {
|
|
|
81
57
|
throw new Error(`Unlock type '${unlockType}' is not known`);
|
|
82
58
|
}
|
|
83
59
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* @
|
|
60
|
+
* Validates unlock capabilities and returns them if valid.
|
|
61
|
+
*
|
|
62
|
+
* @param caps - The capabilities to validate
|
|
63
|
+
* @returns The validated capabilities
|
|
64
|
+
* @throws {Error} If the capabilities are invalid
|
|
87
65
|
*/
|
|
88
66
|
function validateUnlockCapabilities(caps) {
|
|
89
67
|
const { unlockKey, unlockType } = caps ?? {};
|
|
@@ -117,8 +95,9 @@ function validateUnlockCapabilities(caps) {
|
|
|
117
95
|
return caps;
|
|
118
96
|
}
|
|
119
97
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
98
|
+
* Performs a fast unlock using ADB commands.
|
|
99
|
+
*
|
|
100
|
+
* @param opts - Fast unlock options with credential and credential type
|
|
122
101
|
*/
|
|
123
102
|
async function fastUnlock(opts) {
|
|
124
103
|
const { credential, credentialType } = opts;
|
|
@@ -143,34 +122,36 @@ async function fastUnlock(opts) {
|
|
|
143
122
|
}
|
|
144
123
|
}
|
|
145
124
|
/**
|
|
125
|
+
* Encodes a password by replacing spaces with %s.
|
|
146
126
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @returns
|
|
127
|
+
* @param key - The password key
|
|
128
|
+
* @returns The encoded password
|
|
149
129
|
*/
|
|
150
130
|
function encodePassword(key) {
|
|
151
131
|
return `${key}`.replace(/\s/gi, '%s');
|
|
152
132
|
}
|
|
153
133
|
/**
|
|
134
|
+
* Converts a string key to an array of characters.
|
|
154
135
|
*
|
|
155
|
-
* @param
|
|
156
|
-
* @returns
|
|
136
|
+
* @param key - The key string
|
|
137
|
+
* @returns An array of characters
|
|
157
138
|
*/
|
|
158
139
|
function stringKeyToArr(key) {
|
|
159
140
|
return `${key}`.trim().replace(/\s+/g, '').split(/\s*/);
|
|
160
141
|
}
|
|
161
142
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* @
|
|
143
|
+
* Unlocks the device using fingerprint.
|
|
144
|
+
*
|
|
145
|
+
* @param capabilities - Driver capabilities containing unlockKey
|
|
165
146
|
*/
|
|
166
147
|
async function fingerprintUnlock(capabilities) {
|
|
167
148
|
await this.adb.fingerprint(String(capabilities.unlockKey));
|
|
168
149
|
await (0, asyncbox_1.sleep)(exports.UNLOCK_WAIT_TIME);
|
|
169
150
|
}
|
|
170
151
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* @
|
|
152
|
+
* Unlocks the device using PIN by clicking on-screen buttons.
|
|
153
|
+
*
|
|
154
|
+
* @param capabilities - Driver capabilities containing unlockKey
|
|
174
155
|
*/
|
|
175
156
|
async function pinUnlock(capabilities) {
|
|
176
157
|
this.log.info(`Trying to unlock device using pin ${capabilities.unlockKey}`);
|
|
@@ -184,7 +165,9 @@ async function pinUnlock(capabilities) {
|
|
|
184
165
|
const pins = {};
|
|
185
166
|
for (const el of els) {
|
|
186
167
|
const text = await this.getAttribute('text', support_1.util.unwrapElement(el));
|
|
187
|
-
|
|
168
|
+
if (text) {
|
|
169
|
+
pins[text] = el;
|
|
170
|
+
}
|
|
188
171
|
}
|
|
189
172
|
for (const pin of keys) {
|
|
190
173
|
const el = pins[pin];
|
|
@@ -193,9 +176,9 @@ async function pinUnlock(capabilities) {
|
|
|
193
176
|
await waitForUnlock(this.adb);
|
|
194
177
|
}
|
|
195
178
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* @
|
|
179
|
+
* Unlocks the device using PIN by sending key events.
|
|
180
|
+
*
|
|
181
|
+
* @param capabilities - Driver capabilities containing unlockKey
|
|
199
182
|
*/
|
|
200
183
|
async function pinUnlockWithKeyEvent(capabilities) {
|
|
201
184
|
this.log.info(`Trying to unlock device using pin with keycode ${capabilities.unlockKey}`);
|
|
@@ -211,9 +194,9 @@ async function pinUnlockWithKeyEvent(capabilities) {
|
|
|
211
194
|
await waitForUnlock(this.adb);
|
|
212
195
|
}
|
|
213
196
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* @
|
|
197
|
+
* Unlocks the device using password.
|
|
198
|
+
*
|
|
199
|
+
* @param capabilities - Driver capabilities containing unlockKey
|
|
217
200
|
*/
|
|
218
201
|
async function passwordUnlock(capabilities) {
|
|
219
202
|
const { unlockKey } = capabilities;
|
|
@@ -230,11 +213,12 @@ async function passwordUnlock(capabilities) {
|
|
|
230
213
|
await waitForUnlock(this.adb);
|
|
231
214
|
}
|
|
232
215
|
/**
|
|
216
|
+
* Calculates the position of a pattern key based on the initial position and piece size.
|
|
233
217
|
*
|
|
234
|
-
* @param
|
|
235
|
-
* @param
|
|
236
|
-
* @param
|
|
237
|
-
* @returns
|
|
218
|
+
* @param key - The pattern key number (1-9)
|
|
219
|
+
* @param initPos - The initial position of the pattern view
|
|
220
|
+
* @param piece - The size of each pattern piece
|
|
221
|
+
* @returns The calculated position for the key
|
|
238
222
|
*/
|
|
239
223
|
function getPatternKeyPosition(key, initPos, piece) {
|
|
240
224
|
/*
|
|
@@ -253,18 +237,17 @@ function getPatternKeyPosition(key, initPos, piece) {
|
|
|
253
237
|
};
|
|
254
238
|
}
|
|
255
239
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* @param
|
|
259
|
-
* @
|
|
240
|
+
* Generates pointer actions for pattern unlock gesture.
|
|
241
|
+
*
|
|
242
|
+
* @param keys - Array of pattern keys (string or number)
|
|
243
|
+
* @param initPos - The initial position of the pattern view
|
|
244
|
+
* @param piece - The size of each pattern piece
|
|
245
|
+
* @returns An array of W3C action objects for pattern unlock
|
|
260
246
|
*/
|
|
261
247
|
function getPatternActions(keys, initPos, piece) {
|
|
262
|
-
/** @type {import('@appium/types').StringRecord[]} */
|
|
263
248
|
// https://www.w3.org/TR/webdriver2/#actions
|
|
264
249
|
const pointerActions = [];
|
|
265
|
-
/** @type {number[]} */
|
|
266
250
|
const intKeys = keys.map((key) => (lodash_1.default.isString(key) ? lodash_1.default.parseInt(key) : key));
|
|
267
|
-
/** @type {import('@appium/types').Position|undefined} */
|
|
268
251
|
let lastPos;
|
|
269
252
|
for (const key of intKeys) {
|
|
270
253
|
const keyPos = getPatternKeyPosition(key, initPos, piece);
|
|
@@ -304,23 +287,27 @@ function getPatternActions(keys, initPos, piece) {
|
|
|
304
287
|
type: 'pointerMove',
|
|
305
288
|
duration: TOUCH_DELAY_MS,
|
|
306
289
|
x: moveTo.x + lastPos.x,
|
|
307
|
-
y: moveTo.y + lastPos.y
|
|
290
|
+
y: moveTo.y + lastPos.y,
|
|
308
291
|
});
|
|
309
292
|
lastPos = keyPos;
|
|
310
293
|
}
|
|
311
294
|
pointerActions.push({ type: 'pointerUp', button: 0 });
|
|
312
|
-
return [
|
|
295
|
+
return [
|
|
296
|
+
{
|
|
313
297
|
type: 'pointer',
|
|
314
298
|
id: 'patternUnlock',
|
|
315
299
|
parameters: {
|
|
316
300
|
pointerType: 'touch',
|
|
317
301
|
},
|
|
318
302
|
actions: pointerActions,
|
|
319
|
-
}
|
|
303
|
+
},
|
|
304
|
+
];
|
|
320
305
|
}
|
|
321
306
|
/**
|
|
322
|
-
*
|
|
323
|
-
*
|
|
307
|
+
* Verifies that the device has been unlocked.
|
|
308
|
+
*
|
|
309
|
+
* @param timeoutMs - Optional timeout in milliseconds (default: 2000)
|
|
310
|
+
* @throws {Error} If the device fails to unlock within the timeout
|
|
324
311
|
*/
|
|
325
312
|
async function verifyUnlock(timeoutMs = null) {
|
|
326
313
|
try {
|
|
@@ -335,8 +322,9 @@ async function verifyUnlock(timeoutMs = null) {
|
|
|
335
322
|
this.log.info('The device has been successfully unlocked');
|
|
336
323
|
}
|
|
337
324
|
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
325
|
+
* Unlocks the device using pattern gesture.
|
|
326
|
+
*
|
|
327
|
+
* @param capabilities - Driver capabilities containing unlockKey
|
|
340
328
|
*/
|
|
341
329
|
async function patternUnlock(capabilities) {
|
|
342
330
|
const { unlockKey } = capabilities;
|
|
@@ -363,8 +351,30 @@ async function patternUnlock(capabilities) {
|
|
|
363
351
|
// Waits a bit for the device to be unlocked
|
|
364
352
|
await (0, asyncbox_1.sleep)(exports.UNLOCK_WAIT_TIME);
|
|
365
353
|
}
|
|
354
|
+
// #region Private Functions
|
|
366
355
|
/**
|
|
367
|
-
*
|
|
368
|
-
* @typedef {import('../../driver').AndroidDriver} AndroidDriver
|
|
356
|
+
* Type guard to check if a value is a non-empty string.
|
|
369
357
|
*/
|
|
358
|
+
function isNonEmptyString(value) {
|
|
359
|
+
return typeof value === 'string' && value !== '';
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Waits for the display to be unlocked.
|
|
363
|
+
* Some devices automatically accept typed 'pin' and 'password' code
|
|
364
|
+
* without pressing the Enter key. But some devices need it.
|
|
365
|
+
* This method waits a few seconds first for such automatic acceptance case.
|
|
366
|
+
* If the device is still locked, then this method will try to send
|
|
367
|
+
* the enter key code.
|
|
368
|
+
*
|
|
369
|
+
* @param adb - The instance of ADB
|
|
370
|
+
*/
|
|
371
|
+
async function waitForUnlock(adb) {
|
|
372
|
+
await (0, asyncbox_1.sleep)(exports.UNLOCK_WAIT_TIME);
|
|
373
|
+
if (!(await adb.isScreenLocked())) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
await adb.keyevent(exports.KEYCODE_NUMPAD_ENTER);
|
|
377
|
+
await (0, asyncbox_1.sleep)(exports.UNLOCK_WAIT_TIME);
|
|
378
|
+
}
|
|
379
|
+
// #endregion
|
|
370
380
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../lib/commands/lock/helpers.
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../lib/commands/lock/helpers.ts"],"names":[],"mappings":";;;;;;AAiCA,4CAWC;AASD,gEAoCC;AAOD,gCAmBC;AAQD,wCAEC;AAQD,wCAEC;AAOD,8CAMC;AAOD,8BAwBC;AAOD,sDAgBC;AAOD,wCAgBC;AAUD,sDAiBC;AAUD,8CA+DC;AAQD,oCAUC;AAOD,sCA+BC;AA7XD,6CAAqC;AACrC,uCAAiD;AACjD,oDAAuB;AAMV,QAAA,UAAU,GAAG,KAAK,CAAC;AACnB,QAAA,oBAAoB,GAAG,iBAAiB,CAAC;AACzC,QAAA,eAAe,G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,CAAC;IACzC,MAAM,IAAA,gBAAK,EAAC,wBAAgB,CAAC,CAAC;AAChC,CAAC;AAED,aAAa"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import B from 'bluebird';
|
|
2
|
+
import {
|
|
3
|
+
validateUnlockCapabilities,
|
|
4
|
+
FINGERPRINT_UNLOCK,
|
|
5
|
+
fastUnlock,
|
|
6
|
+
PIN_UNLOCK,
|
|
7
|
+
pinUnlock,
|
|
8
|
+
PIN_UNLOCK_KEY_EVENT,
|
|
9
|
+
pinUnlockWithKeyEvent,
|
|
10
|
+
PASSWORD_UNLOCK,
|
|
11
|
+
passwordUnlock,
|
|
12
|
+
PATTERN_UNLOCK,
|
|
13
|
+
patternUnlock,
|
|
14
|
+
fingerprintUnlock,
|
|
15
|
+
toCredentialType,
|
|
16
|
+
verifyUnlock,
|
|
17
|
+
} from './helpers';
|
|
18
|
+
import _ from 'lodash';
|
|
19
|
+
import type {AndroidDriver, AndroidDriverCaps} from '../../driver';
|
|
20
|
+
import type {UnlockType} from '../types';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Locks the device and optionally unlocks it after a specified number of seconds.
|
|
24
|
+
*
|
|
25
|
+
* @param seconds - Optional number of seconds to wait before unlocking. If not provided or invalid, the device remains locked.
|
|
26
|
+
*/
|
|
27
|
+
export async function lock(this: AndroidDriver, seconds?: number): Promise<void> {
|
|
28
|
+
await this.adb.lock();
|
|
29
|
+
if (Number.isNaN(seconds ?? NaN)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const floatSeconds = parseFloat(String(seconds));
|
|
34
|
+
if (floatSeconds <= 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
await B.delay(1000 * floatSeconds);
|
|
38
|
+
await this.unlock();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the device screen is currently locked.
|
|
43
|
+
*
|
|
44
|
+
* @returns True if the screen is locked, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
export async function isLocked(this: AndroidDriver): Promise<boolean> {
|
|
47
|
+
return await this.adb.isScreenLocked();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Unlocks the device using the unlock options from session capabilities.
|
|
52
|
+
*/
|
|
53
|
+
export async function unlock(this: AndroidDriver): Promise<void> {
|
|
54
|
+
await unlockWithOptions.bind(this)();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Unlocks the device with the specified options.
|
|
59
|
+
*
|
|
60
|
+
* @param key - The unlock key. The value of this key depends on the actual unlock type and
|
|
61
|
+
* could be a pin/password/pattern value or a biometric finger id.
|
|
62
|
+
* If not provided then the corresponding value from session capabilities is used.
|
|
63
|
+
* @param type - The unlock type. If not provided then the corresponding value from session capabilities is used.
|
|
64
|
+
* @param strategy - Setting it to 'uiautomator' will enforce the driver to avoid using special
|
|
65
|
+
* ADB shortcuts in order to speed up the unlock procedure. 'uiautomator' by default.
|
|
66
|
+
* @param timeoutMs - The maximum time in milliseconds to wait until the screen gets unlocked. 2000ms by default.
|
|
67
|
+
*/
|
|
68
|
+
export async function mobileUnlock(
|
|
69
|
+
this: AndroidDriver,
|
|
70
|
+
key?: string,
|
|
71
|
+
type?: UnlockType,
|
|
72
|
+
strategy?: string,
|
|
73
|
+
timeoutMs?: number,
|
|
74
|
+
): Promise<void> {
|
|
75
|
+
if (!key && !type) {
|
|
76
|
+
await this.unlock();
|
|
77
|
+
} else {
|
|
78
|
+
await unlockWithOptions.bind(this)({
|
|
79
|
+
unlockKey: key,
|
|
80
|
+
unlockType: type,
|
|
81
|
+
unlockStrategy: strategy,
|
|
82
|
+
unlockSuccessTimeout: timeoutMs,
|
|
83
|
+
} as AndroidDriverCaps);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// #region Internal Helpers
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Unlocks the device with the specified capabilities.
|
|
91
|
+
*
|
|
92
|
+
* @param caps - Optional capabilities to use for unlocking. If not provided, uses session capabilities.
|
|
93
|
+
*/
|
|
94
|
+
export async function unlockWithOptions(
|
|
95
|
+
this: AndroidDriver,
|
|
96
|
+
caps: AndroidDriverCaps | null = null,
|
|
97
|
+
): Promise<void> {
|
|
98
|
+
if (!(await this.adb.isScreenLocked())) {
|
|
99
|
+
this.log.info('Screen already unlocked, doing nothing');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const capabilities = caps ?? this.opts;
|
|
104
|
+
this.log.debug('Screen is locked, trying to unlock');
|
|
105
|
+
if (!capabilities.unlockType && !capabilities.unlockKey) {
|
|
106
|
+
this.log.info(
|
|
107
|
+
`Neither 'unlockType' nor 'unlockKey' capability is provided. ` +
|
|
108
|
+
`Assuming the device is locked with a simple lock screen.`,
|
|
109
|
+
);
|
|
110
|
+
await this.adb.dismissKeyguard();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const validated = validateUnlockCapabilities(capabilities);
|
|
115
|
+
const {unlockType, unlockKey, unlockStrategy, unlockSuccessTimeout} = validated;
|
|
116
|
+
if (!unlockType) {
|
|
117
|
+
throw new Error('unlockType is required after validation');
|
|
118
|
+
}
|
|
119
|
+
if (
|
|
120
|
+
unlockKey &&
|
|
121
|
+
unlockType !== FINGERPRINT_UNLOCK &&
|
|
122
|
+
(_.isNil(unlockStrategy) || _.toLower(unlockStrategy) === 'locksettings') &&
|
|
123
|
+
(await this.adb.isLockManagementSupported())
|
|
124
|
+
) {
|
|
125
|
+
await fastUnlock.bind(this)({
|
|
126
|
+
credential: unlockKey,
|
|
127
|
+
credentialType: toCredentialType(unlockType as UnlockType),
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
const unlockMethodMap: Record<string, (this: AndroidDriver, caps: AndroidDriverCaps) => Promise<void>> = {
|
|
131
|
+
[PIN_UNLOCK]: pinUnlock,
|
|
132
|
+
[PIN_UNLOCK_KEY_EVENT]: pinUnlockWithKeyEvent,
|
|
133
|
+
[PASSWORD_UNLOCK]: passwordUnlock,
|
|
134
|
+
[PATTERN_UNLOCK]: patternUnlock,
|
|
135
|
+
[FINGERPRINT_UNLOCK]: fingerprintUnlock,
|
|
136
|
+
};
|
|
137
|
+
const unlockMethod = unlockMethodMap[unlockType];
|
|
138
|
+
if (!unlockMethod) {
|
|
139
|
+
throw new Error(`Unknown unlock type: ${unlockType}`);
|
|
140
|
+
}
|
|
141
|
+
await unlockMethod.bind(this)(capabilities);
|
|
142
|
+
}
|
|
143
|
+
await verifyUnlock.bind(this)(unlockSuccessTimeout);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// #endregion
|
|
147
|
+
|