appium-android-driver 14.0.2 → 14.0.3

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.
Files changed (178) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/lib/commands/app-management.d.ts +1 -1
  3. package/build/lib/commands/app-management.d.ts.map +1 -1
  4. package/build/lib/commands/app-management.js +2 -4
  5. package/build/lib/commands/app-management.js.map +1 -1
  6. package/build/lib/commands/appearance.d.ts.map +1 -1
  7. package/build/lib/commands/appearance.js.map +1 -1
  8. package/build/lib/commands/bidi/models.d.ts +1 -1
  9. package/build/lib/commands/bidi/models.d.ts.map +1 -1
  10. package/build/lib/commands/bidi/models.js +1 -1
  11. package/build/lib/commands/bidi/models.js.map +1 -1
  12. package/build/lib/commands/bluetooth.d.ts.map +1 -1
  13. package/build/lib/commands/bluetooth.js.map +1 -1
  14. package/build/lib/commands/context/cache.d.ts +1 -1
  15. package/build/lib/commands/context/cache.d.ts.map +1 -1
  16. package/build/lib/commands/context/cache.js.map +1 -1
  17. package/build/lib/commands/context/exports.d.ts.map +1 -1
  18. package/build/lib/commands/context/exports.js +3 -4
  19. package/build/lib/commands/context/exports.js.map +1 -1
  20. package/build/lib/commands/context/helpers.d.ts.map +1 -1
  21. package/build/lib/commands/context/helpers.js +21 -26
  22. package/build/lib/commands/context/helpers.js.map +1 -1
  23. package/build/lib/commands/device/common.d.ts +1 -1
  24. package/build/lib/commands/device/common.d.ts.map +1 -1
  25. package/build/lib/commands/device/common.js +8 -16
  26. package/build/lib/commands/device/common.js.map +1 -1
  27. package/build/lib/commands/device/emulator-actions.d.ts.map +1 -1
  28. package/build/lib/commands/device/emulator-actions.js +1 -1
  29. package/build/lib/commands/device/emulator-actions.js.map +1 -1
  30. package/build/lib/commands/device/emulator-console.d.ts.map +1 -1
  31. package/build/lib/commands/device/emulator-console.js.map +1 -1
  32. package/build/lib/commands/device/utils.d.ts.map +1 -1
  33. package/build/lib/commands/device/utils.js +5 -6
  34. package/build/lib/commands/device/utils.js.map +1 -1
  35. package/build/lib/commands/deviceidle.d.ts.map +1 -1
  36. package/build/lib/commands/deviceidle.js.map +1 -1
  37. package/build/lib/commands/element.d.ts.map +1 -1
  38. package/build/lib/commands/element.js.map +1 -1
  39. package/build/lib/commands/execute.d.ts.map +1 -1
  40. package/build/lib/commands/execute.js +2 -4
  41. package/build/lib/commands/execute.js.map +1 -1
  42. package/build/lib/commands/file-actions.d.ts.map +1 -1
  43. package/build/lib/commands/file-actions.js +6 -20
  44. package/build/lib/commands/file-actions.js.map +1 -1
  45. package/build/lib/commands/find.d.ts +1 -1
  46. package/build/lib/commands/find.d.ts.map +1 -1
  47. package/build/lib/commands/find.js +1 -1
  48. package/build/lib/commands/find.js.map +1 -1
  49. package/build/lib/commands/geolocation.d.ts.map +1 -1
  50. package/build/lib/commands/geolocation.js +5 -12
  51. package/build/lib/commands/geolocation.js.map +1 -1
  52. package/build/lib/commands/gestures.d.ts.map +1 -1
  53. package/build/lib/commands/gestures.js.map +1 -1
  54. package/build/lib/commands/image-injection.d.ts.map +1 -1
  55. package/build/lib/commands/image-injection.js +2 -2
  56. package/build/lib/commands/image-injection.js.map +1 -1
  57. package/build/lib/commands/ime.d.ts.map +1 -1
  58. package/build/lib/commands/ime.js +1 -7
  59. package/build/lib/commands/ime.js.map +1 -1
  60. package/build/lib/commands/intent.d.ts.map +1 -1
  61. package/build/lib/commands/intent.js +2 -3
  62. package/build/lib/commands/intent.js.map +1 -1
  63. package/build/lib/commands/keyboard.d.ts.map +1 -1
  64. package/build/lib/commands/keyboard.js.map +1 -1
  65. package/build/lib/commands/legacy.d.ts.map +1 -1
  66. package/build/lib/commands/legacy.js.map +1 -1
  67. package/build/lib/commands/lock/exports.d.ts.map +1 -1
  68. package/build/lib/commands/lock/exports.js.map +1 -1
  69. package/build/lib/commands/lock/helpers.d.ts.map +1 -1
  70. package/build/lib/commands/lock/helpers.js +2 -9
  71. package/build/lib/commands/lock/helpers.js.map +1 -1
  72. package/build/lib/commands/log.d.ts +1 -1
  73. package/build/lib/commands/log.d.ts.map +1 -1
  74. package/build/lib/commands/log.js +6 -8
  75. package/build/lib/commands/log.js.map +1 -1
  76. package/build/lib/commands/media-projection.d.ts.map +1 -1
  77. package/build/lib/commands/media-projection.js +2 -2
  78. package/build/lib/commands/media-projection.js.map +1 -1
  79. package/build/lib/commands/memory.d.ts.map +1 -1
  80. package/build/lib/commands/memory.js.map +1 -1
  81. package/build/lib/commands/misc.d.ts.map +1 -1
  82. package/build/lib/commands/misc.js.map +1 -1
  83. package/build/lib/commands/network.d.ts.map +1 -1
  84. package/build/lib/commands/network.js +4 -11
  85. package/build/lib/commands/network.js.map +1 -1
  86. package/build/lib/commands/nfc.d.ts.map +1 -1
  87. package/build/lib/commands/nfc.js.map +1 -1
  88. package/build/lib/commands/performance.d.ts.map +1 -1
  89. package/build/lib/commands/performance.js +4 -21
  90. package/build/lib/commands/performance.js.map +1 -1
  91. package/build/lib/commands/permissions.d.ts.map +1 -1
  92. package/build/lib/commands/permissions.js +4 -7
  93. package/build/lib/commands/permissions.js.map +1 -1
  94. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  95. package/build/lib/commands/recordscreen.js +2 -2
  96. package/build/lib/commands/recordscreen.js.map +1 -1
  97. package/build/lib/commands/resources.d.ts.map +1 -1
  98. package/build/lib/commands/resources.js.map +1 -1
  99. package/build/lib/commands/shell.d.ts.map +1 -1
  100. package/build/lib/commands/shell.js +1 -6
  101. package/build/lib/commands/shell.js.map +1 -1
  102. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  103. package/build/lib/commands/streamscreen.js +6 -9
  104. package/build/lib/commands/streamscreen.js.map +1 -1
  105. package/build/lib/commands/system-bars.d.ts.map +1 -1
  106. package/build/lib/commands/system-bars.js +1 -1
  107. package/build/lib/commands/system-bars.js.map +1 -1
  108. package/build/lib/commands/time.d.ts.map +1 -1
  109. package/build/lib/commands/time.js +1 -1
  110. package/build/lib/commands/time.js.map +1 -1
  111. package/build/lib/commands/types.d.ts +4 -4
  112. package/build/lib/commands/types.d.ts.map +1 -1
  113. package/build/lib/doctor/checks.d.ts.map +1 -1
  114. package/build/lib/doctor/checks.js +2 -2
  115. package/build/lib/doctor/checks.js.map +1 -1
  116. package/build/lib/driver.d.ts +8 -8
  117. package/build/lib/driver.d.ts.map +1 -1
  118. package/build/lib/driver.js +14 -20
  119. package/build/lib/driver.js.map +1 -1
  120. package/build/lib/execute-method-map.d.ts.map +1 -1
  121. package/build/lib/execute-method-map.js +1 -10
  122. package/build/lib/execute-method-map.js.map +1 -1
  123. package/build/lib/index.d.ts +1 -1
  124. package/build/lib/index.d.ts.map +1 -1
  125. package/build/lib/index.js +1 -1
  126. package/build/lib/index.js.map +1 -1
  127. package/build/lib/method-map.d.ts.map +1 -1
  128. package/build/lib/method-map.js.map +1 -1
  129. package/build/lib/utils.d.ts.map +1 -1
  130. package/build/lib/utils.js +1 -1
  131. package/build/lib/utils.js.map +1 -1
  132. package/lib/commands/app-management.ts +15 -43
  133. package/lib/commands/appearance.ts +1 -5
  134. package/lib/commands/bidi/models.ts +5 -12
  135. package/lib/commands/bluetooth.ts +1 -0
  136. package/lib/commands/context/cache.ts +2 -1
  137. package/lib/commands/context/exports.ts +17 -40
  138. package/lib/commands/context/helpers.ts +37 -88
  139. package/lib/commands/device/common.ts +16 -29
  140. package/lib/commands/device/emulator-actions.ts +12 -49
  141. package/lib/commands/device/emulator-console.ts +1 -0
  142. package/lib/commands/device/utils.ts +7 -16
  143. package/lib/commands/deviceidle.ts +1 -0
  144. package/lib/commands/element.ts +6 -20
  145. package/lib/commands/execute.ts +6 -13
  146. package/lib/commands/file-actions.ts +17 -50
  147. package/lib/commands/find.ts +4 -6
  148. package/lib/commands/geolocation.ts +9 -17
  149. package/lib/commands/gestures.ts +2 -1
  150. package/lib/commands/image-injection.ts +9 -19
  151. package/lib/commands/ime.ts +2 -7
  152. package/lib/commands/intent.ts +3 -3
  153. package/lib/commands/keyboard.ts +4 -14
  154. package/lib/commands/legacy.ts +1 -0
  155. package/lib/commands/lock/exports.ts +5 -10
  156. package/lib/commands/lock/helpers.ts +16 -51
  157. package/lib/commands/log.ts +12 -22
  158. package/lib/commands/media-projection.ts +9 -21
  159. package/lib/commands/memory.ts +2 -5
  160. package/lib/commands/misc.ts +3 -5
  161. package/lib/commands/network.ts +9 -27
  162. package/lib/commands/nfc.ts +1 -0
  163. package/lib/commands/performance.ts +12 -48
  164. package/lib/commands/permissions.ts +10 -22
  165. package/lib/commands/recordscreen.ts +16 -41
  166. package/lib/commands/resources.ts +3 -9
  167. package/lib/commands/shell.ts +3 -7
  168. package/lib/commands/streamscreen.ts +17 -37
  169. package/lib/commands/system-bars.ts +7 -13
  170. package/lib/commands/time.ts +4 -8
  171. package/lib/commands/types.ts +9 -10
  172. package/lib/doctor/checks.ts +11 -18
  173. package/lib/driver.ts +43 -65
  174. package/lib/execute-method-map.ts +1 -10
  175. package/lib/index.ts +1 -1
  176. package/lib/method-map.ts +1 -0
  177. package/lib/utils.ts +4 -6
  178. package/package.json +24 -34
@@ -1,7 +1,8 @@
1
1
  import {util} from '@appium/support';
2
- import {sleep, waitForCondition} from 'asyncbox';
3
- import type {ADB} from 'appium-adb';
4
2
  import type {Position, StringRecord} from '@appium/types';
3
+ import type {ADB} from 'appium-adb';
4
+ import {sleep, waitForCondition} from 'asyncbox';
5
+
5
6
  import type {AndroidDriver, AndroidDriverCaps} from '../../driver.js';
6
7
  import type {UnlockType, FastUnlockOptions} from '../types.js';
7
8
 
@@ -10,13 +11,7 @@ export const PIN_UNLOCK_KEY_EVENT = 'pinWithKeyEvent';
10
11
  export const PASSWORD_UNLOCK = 'password';
11
12
  export const PATTERN_UNLOCK = 'pattern';
12
13
  export const FINGERPRINT_UNLOCK = 'fingerprint';
13
- const UNLOCK_TYPES = [
14
- PIN_UNLOCK,
15
- PIN_UNLOCK_KEY_EVENT,
16
- PASSWORD_UNLOCK,
17
- PATTERN_UNLOCK,
18
- FINGERPRINT_UNLOCK,
19
- ] as const;
14
+ const UNLOCK_TYPES = [PIN_UNLOCK, PIN_UNLOCK_KEY_EVENT, PASSWORD_UNLOCK, PATTERN_UNLOCK, FINGERPRINT_UNLOCK] as const;
20
15
  export const KEYCODE_NUMPAD_ENTER = 66;
21
16
  export const UNLOCK_WAIT_TIME = 100;
22
17
  export const INPUT_KEYS_WAIT_TIME = 100;
@@ -62,27 +57,20 @@ export function validateUnlockCapabilities<T extends AndroidDriverCaps>(caps: T)
62
57
  }
63
58
  } else if (unlockType === PATTERN_UNLOCK) {
64
59
  if (!/^[1-9]{2,9}$/.test(String(unlockKey)?.trim())) {
65
- throw new Error(
66
- `Unlock key value '${unlockKey}' must only include from two to nine digits in range 1..9`,
67
- );
60
+ throw new Error(`Unlock key value '${unlockKey}' must only include from two to nine digits in range 1..9`);
68
61
  }
69
62
  if (/([1-9]).*?\1/.test(String(unlockKey)?.trim())) {
70
- throw new Error(
71
- `Unlock key value '${unlockKey}' must define a valid pattern where repeats are not allowed`,
72
- );
63
+ throw new Error(`Unlock key value '${unlockKey}' must define a valid pattern where repeats are not allowed`);
73
64
  }
74
65
  } else if (unlockType === PASSWORD_UNLOCK) {
75
66
  // Dont trim password key, you can use blank spaces in your android password
76
67
  // ¯\_(ツ)_/¯
77
68
  if (!/.{4,}/g.test(String(unlockKey))) {
78
- throw new Error(
79
- `The minimum allowed length of unlock key value '${unlockKey}' is 4 characters`,
80
- );
69
+ throw new Error(`The minimum allowed length of unlock key value '${unlockKey}' is 4 characters`);
81
70
  }
82
71
  } else {
83
72
  throw new Error(
84
- `Invalid unlock type '${unlockType}'. ` +
85
- `Only the following unlock types are supported: ${UNLOCK_TYPES}`,
73
+ `Invalid unlock type '${unlockType}'. Only the following unlock types are supported: ${UNLOCK_TYPES}`,
86
74
  );
87
75
  }
88
76
  return caps;
@@ -139,10 +127,7 @@ export function stringKeyToArr(key: string): string[] {
139
127
  *
140
128
  * @param capabilities - Driver capabilities containing unlockKey
141
129
  */
142
- export async function fingerprintUnlock(
143
- this: AndroidDriver,
144
- capabilities: AndroidDriverCaps,
145
- ): Promise<void> {
130
+ export async function fingerprintUnlock(this: AndroidDriver, capabilities: AndroidDriverCaps): Promise<void> {
146
131
  await this.adb.fingerprint(String(capabilities.unlockKey));
147
132
  await sleep(UNLOCK_WAIT_TIME);
148
133
  }
@@ -152,10 +137,7 @@ export async function fingerprintUnlock(
152
137
  *
153
138
  * @param capabilities - Driver capabilities containing unlockKey
154
139
  */
155
- export async function pinUnlock(
156
- this: AndroidDriver,
157
- capabilities: AndroidDriverCaps,
158
- ): Promise<void> {
140
+ export async function pinUnlock(this: AndroidDriver, capabilities: AndroidDriverCaps): Promise<void> {
159
141
  this.log.info(`Trying to unlock device using pin ${capabilities.unlockKey}`);
160
142
  await this.adb.dismissKeyguard();
161
143
  const keys = stringKeyToArr(String(capabilities.unlockKey));
@@ -183,10 +165,7 @@ export async function pinUnlock(
183
165
  *
184
166
  * @param capabilities - Driver capabilities containing unlockKey
185
167
  */
186
- export async function pinUnlockWithKeyEvent(
187
- this: AndroidDriver,
188
- capabilities: AndroidDriverCaps,
189
- ): Promise<void> {
168
+ export async function pinUnlockWithKeyEvent(this: AndroidDriver, capabilities: AndroidDriverCaps): Promise<void> {
190
169
  this.log.info(`Trying to unlock device using pin with keycode ${capabilities.unlockKey}`);
191
170
  await this.adb.dismissKeyguard();
192
171
  const keys = stringKeyToArr(String(capabilities.unlockKey));
@@ -206,10 +185,7 @@ export async function pinUnlockWithKeyEvent(
206
185
  *
207
186
  * @param capabilities - Driver capabilities containing unlockKey
208
187
  */
209
- export async function passwordUnlock(
210
- this: AndroidDriver,
211
- capabilities: AndroidDriverCaps,
212
- ): Promise<void> {
188
+ export async function passwordUnlock(this: AndroidDriver, capabilities: AndroidDriverCaps): Promise<void> {
213
189
  const {unlockKey} = capabilities;
214
190
  this.log.info(`Trying to unlock device using password ${unlockKey}`);
215
191
  await this.adb.dismissKeyguard();
@@ -241,8 +217,7 @@ export function getPatternKeyPosition(key: number, initPos: Position, piece: num
241
217
  */
242
218
  const cols = 3;
243
219
  const pins = 9;
244
- const xPos = (key: number, x: number, piece: number) =>
245
- Math.round(x + (key % cols || cols) * piece - piece / 2);
220
+ const xPos = (key: number, x: number, piece: number) => Math.round(x + (key % cols || cols) * piece - piece / 2);
246
221
  const yPos = (key: number, y: number, piece: number) =>
247
222
  Math.round(y + (Math.ceil((key % pins || pins) / cols) * piece - piece / 2));
248
223
  return {
@@ -259,11 +234,7 @@ export function getPatternKeyPosition(key: number, initPos: Position, piece: num
259
234
  * @param piece - The size of each pattern piece
260
235
  * @returns An array of W3C action objects for pattern unlock
261
236
  */
262
- export function getPatternActions(
263
- keys: string[] | number[],
264
- initPos: Position,
265
- piece: number,
266
- ): StringRecord[] {
237
+ export function getPatternActions(keys: string[] | number[], initPos: Position, piece: number): StringRecord[] {
267
238
  // https://www.w3.org/TR/webdriver2/#actions
268
239
  const pointerActions: StringRecord[] = [];
269
240
  const intKeys = keys.map((key) => (typeof key === 'string' ? parseInt(key, 10) : key));
@@ -330,10 +301,7 @@ export function getPatternActions(
330
301
  * @param timeoutMs - Optional timeout in milliseconds (default: 2000)
331
302
  * @throws {Error} If the device fails to unlock within the timeout
332
303
  */
333
- export async function verifyUnlock(
334
- this: AndroidDriver,
335
- timeoutMs: number | null = null,
336
- ): Promise<void> {
304
+ export async function verifyUnlock(this: AndroidDriver, timeoutMs: number | null = null): Promise<void> {
337
305
  try {
338
306
  await waitForCondition(async () => !(await this.adb.isScreenLocked()), {
339
307
  waitMs: timeoutMs ?? 2000,
@@ -350,10 +318,7 @@ export async function verifyUnlock(
350
318
  *
351
319
  * @param capabilities - Driver capabilities containing unlockKey
352
320
  */
353
- export async function patternUnlock(
354
- this: AndroidDriver,
355
- capabilities: AndroidDriverCaps,
356
- ): Promise<void> {
321
+ export async function patternUnlock(this: AndroidDriver, capabilities: AndroidDriverCaps): Promise<void> {
357
322
  const {unlockKey} = capabilities;
358
323
  this.log.info(`Trying to unlock device using pattern ${unlockKey}`);
359
324
  await this.adb.dismissKeyguard();
@@ -1,21 +1,18 @@
1
- import {DEFAULT_WS_PATHNAME_PREFIX, BaseDriver} from 'appium/driver.js';
1
+ import type {EventEmitter} from 'node:events';
2
2
  import os from 'node:os';
3
- import {WebSocket, WebSocketServer} from 'ws';
3
+
4
+ import {util} from '@appium/support';
4
5
  import type {AppiumServer, WSServer} from '@appium/types';
5
- import type {EventEmitter} from 'node:events';
6
6
  import type {ADB} from 'appium-adb';
7
7
  import type {Chromedriver} from 'appium-chromedriver';
8
- import {
9
- GET_SERVER_LOGS_FEATURE,
10
- toLogRecord,
11
- nativeLogEntryToSeleniumEntry,
12
- type LogEntry,
13
- } from '../utils.js';
14
- import {NATIVE_WIN} from './context/helpers.js';
8
+ import {DEFAULT_WS_PATHNAME_PREFIX, BaseDriver} from 'appium/driver.js';
9
+ import {WebSocket, WebSocketServer} from 'ws';
10
+
11
+ import type {AndroidDriver} from '../driver.js';
12
+ import {GET_SERVER_LOGS_FEATURE, toLogRecord, nativeLogEntryToSeleniumEntry, type LogEntry} from '../utils.js';
15
13
  import {BIDI_EVENT_NAME} from './bidi/constants.js';
16
14
  import {makeLogEntryAddedEvent} from './bidi/models.js';
17
- import type {AndroidDriver} from '../driver.js';
18
- import {util} from '@appium/support';
15
+ import {NATIVE_WIN} from './context/helpers.js';
19
16
 
20
17
  export const supportedLogTypes = {
21
18
  logcat: {
@@ -57,10 +54,7 @@ export async function mobileStartLogsBroadcast(this: AndroidDriver): Promise<voi
57
54
  return;
58
55
  }
59
56
 
60
- this.log.info(
61
- `Starting logcat broadcasting on web socket server ` +
62
- `${JSON.stringify(server.address())} to ${pathname}`,
63
- );
57
+ this.log.info(`Starting logcat broadcasting on web socket server ${JSON.stringify(server.address())} to ${pathname}`);
64
58
  // https://github.com/websockets/ws/blob/master/doc/ws.md
65
59
  const wss = new WebSocketServer({
66
60
  noServer: true,
@@ -126,8 +120,7 @@ export async function mobileStopLogsBroadcast(this: AndroidDriver): Promise<void
126
120
  }
127
121
 
128
122
  this.log.debug(
129
- `Stopping logcat broadcasting on web socket server ` +
130
- `${JSON.stringify(server.address())} to ${pathname}`,
123
+ `Stopping logcat broadcasting on web socket server ${JSON.stringify(server.address())} to ${pathname}`,
131
124
  );
132
125
  await server.removeWebSocketHandler(pathname);
133
126
  }
@@ -141,10 +134,7 @@ export async function getLogTypes(this: AndroidDriver): Promise<string[]> {
141
134
  // XXX why doesn't `super` work here?
142
135
  const nativeLogTypes = await BaseDriver.prototype.getLogTypes.call(this);
143
136
  if (this.isWebContext()) {
144
- const webLogTypes = (await (this.chromedriver as Chromedriver).jwproxy.command(
145
- '/log/types',
146
- 'GET',
147
- )) as string[];
137
+ const webLogTypes = (await (this.chromedriver as Chromedriver).jwproxy.command('/log/types', 'GET')) as string[];
148
138
  return [...nativeLogTypes, ...webLogTypes];
149
139
  }
150
140
  return nativeLogTypes;
@@ -1,10 +1,12 @@
1
+ import path from 'node:path';
2
+
1
3
  import {fs, net, util} from '@appium/support';
2
4
  import type {NetOptions, HttpUploadOptions} from '@appium/support';
3
- import dayjs from 'dayjs';
4
- import path from 'node:path';
5
5
  import type {HTTPMethod, StringRecord} from '@appium/types';
6
- import type {AndroidDriver} from '../driver.js';
7
6
  import type {ADB} from 'appium-adb';
7
+ import dayjs from 'dayjs';
8
+
9
+ import type {AndroidDriver} from '../driver.js';
8
10
  import type {FormFields} from './types.js';
9
11
 
10
12
  // https://github.com/appium/io.appium.settings#internal-audio--video-recording
@@ -60,9 +62,7 @@ export async function mobileStartMediaProjectionRecording(
60
62
  if (didStart) {
61
63
  this.log.info(`A new media projection recording '${fname}' has been successfully started`);
62
64
  } else {
63
- this.log.info(
64
- 'Another media projection recording is already in progress. There is nothing to start',
65
- );
65
+ this.log.info('Another media projection recording is already in progress. There is nothing to start');
66
66
  }
67
67
  return didStart;
68
68
  }
@@ -72,9 +72,7 @@ export async function mobileStartMediaProjectionRecording(
72
72
  *
73
73
  * @returns Promise that resolves to `true` if recording is running, `false` otherwise.
74
74
  */
75
- export async function mobileIsMediaProjectionRecordingRunning(
76
- this: AndroidDriver,
77
- ): Promise<boolean> {
75
+ export async function mobileIsMediaProjectionRecordingRunning(this: AndroidDriver): Promise<boolean> {
78
76
  await verifyMediaProjectionRecordingIsSupported(this.adb);
79
77
 
80
78
  const recorder = this.settingsApp.makeMediaProjectionRecorder();
@@ -129,9 +127,7 @@ export async function mobileStopMediaProjectionRecording(
129
127
 
130
128
  if (util.isEmpty(remotePath)) {
131
129
  const {size} = await fs.stat(recentRecordingPath);
132
- this.log.debug(
133
- `The size of the resulting media projection recording is ${util.toReadableSizeString(size)}`,
134
- );
130
+ this.log.debug(`The size of the resulting media projection recording is ${util.toReadableSizeString(size)}`);
135
131
  }
136
132
  try {
137
133
  return await uploadRecordedMedia(recentRecordingPath, remotePath, {
@@ -157,15 +153,7 @@ async function uploadRecordedMedia(
157
153
  return (await util.toInMemoryBase64(localFile)).toString();
158
154
  }
159
155
 
160
- const {
161
- user,
162
- pass,
163
- method,
164
- headers,
165
- fileFieldName,
166
- formFields,
167
- uploadTimeout: timeout,
168
- } = uploadOptions;
156
+ const {user, pass, method, headers, fileFieldName, formFields, uploadTimeout: timeout} = uploadOptions;
169
157
  const options: NetOptions & HttpUploadOptions = {
170
158
  method: method || 'PUT',
171
159
  headers,
@@ -1,4 +1,5 @@
1
1
  import {errors} from 'appium/driver.js';
2
+
2
3
  import type {AndroidDriver} from '../driver.js';
3
4
  import type {TrimMemoryLevel} from './types.js';
4
5
 
@@ -12,11 +13,7 @@ import type {TrimMemoryLevel} from './types.js';
12
13
  * @returns Promise that resolves when the trim memory event is sent.
13
14
  * @throws {errors.InvalidArgumentError} If pkg or level arguments are not provided.
14
15
  */
15
- export async function mobileSendTrimMemory(
16
- this: AndroidDriver,
17
- pkg: string,
18
- level: TrimMemoryLevel,
19
- ): Promise<void> {
16
+ export async function mobileSendTrimMemory(this: AndroidDriver, pkg: string, level: TrimMemoryLevel): Promise<void> {
20
17
  if (!pkg) {
21
18
  throw new errors.InvalidArgumentError(`The 'pkg' argument must be provided`);
22
19
  }
@@ -1,5 +1,6 @@
1
- import {errors} from 'appium/driver.js';
2
1
  import type {Size, Rect, StringRecord} from '@appium/types';
2
+ import {errors} from 'appium/driver.js';
3
+
3
4
  import type {AndroidDriver} from '../driver.js';
4
5
  import type {SmsListResult, ListSmsOpts} from './types.js';
5
6
 
@@ -86,10 +87,7 @@ export async function mobileGetNotifications(this: AndroidDriver): Promise<Strin
86
87
  * @param opts Optional parameters for listing SMS messages.
87
88
  * @returns Promise that resolves to the SMS list result.
88
89
  */
89
- export async function mobileListSms(
90
- this: AndroidDriver,
91
- opts?: ListSmsOpts,
92
- ): Promise<SmsListResult> {
90
+ export async function mobileListSms(this: AndroidDriver, opts?: ListSmsOpts): Promise<SmsListResult> {
93
91
  return await this.settingsApp.getSmsList(opts);
94
92
  }
95
93
 
@@ -1,5 +1,6 @@
1
- import {errors} from 'appium/driver.js';
2
1
  import {util} from '@appium/support';
2
+ import {errors} from 'appium/driver.js';
3
+
3
4
  import type {AndroidDriver} from '../driver.js';
4
5
  import type {ServiceType, GetConnectivityResult} from './types.js';
5
6
 
@@ -9,11 +10,7 @@ const DATA_MASK = 0b100;
9
10
  const WIFI_KEY_NAME = 'wifi';
10
11
  const DATA_KEY_NAME = 'data';
11
12
  const AIRPLANE_MODE_KEY_NAME = 'airplaneMode';
12
- const SUPPORTED_SERVICE_NAMES: ServiceType[] = [
13
- WIFI_KEY_NAME,
14
- DATA_KEY_NAME,
15
- AIRPLANE_MODE_KEY_NAME,
16
- ];
13
+ const SUPPORTED_SERVICE_NAMES: ServiceType[] = [WIFI_KEY_NAME, DATA_KEY_NAME, AIRPLANE_MODE_KEY_NAME];
17
14
 
18
15
  /**
19
16
  * Gets the current network connection state.
@@ -123,14 +120,8 @@ export async function mobileGetConnectivity(
123
120
  const unsupportedServices = svcs.filter((svc) => !SUPPORTED_SERVICE_NAMES.includes(svc));
124
121
  if (unsupportedServices.length > 0) {
125
122
  throw new errors.InvalidArgumentError(
126
- `${util.pluralize(
127
- 'Service name',
128
- unsupportedServices.length,
129
- false,
130
- )} ${unsupportedServices} ` +
131
- `${
132
- unsupportedServices.length === 1 ? 'is' : 'are'
133
- } not known. Only the following services are ` +
123
+ `${util.pluralize('Service name', unsupportedServices.length, false)} ${unsupportedServices} ` +
124
+ `${unsupportedServices.length === 1 ? 'is' : 'are'} not known. Only the following services are ` +
134
125
  `suported: ${SUPPORTED_SERVICE_NAMES}`,
135
126
  );
136
127
  }
@@ -138,9 +129,7 @@ export async function mobileGetConnectivity(
138
129
  const [wifi, data, airplaneMode] = await Promise.all([
139
130
  svcs.includes(WIFI_KEY_NAME) ? this.adb.isWifiOn() : Promise.resolve(undefined),
140
131
  svcs.includes(DATA_KEY_NAME) ? this.adb.isDataOn() : Promise.resolve(undefined),
141
- svcs.includes(AIRPLANE_MODE_KEY_NAME)
142
- ? this.adb.isAirplaneModeOn()
143
- : Promise.resolve(undefined),
132
+ svcs.includes(AIRPLANE_MODE_KEY_NAME) ? this.adb.isAirplaneModeOn() : Promise.resolve(undefined),
144
133
  ]);
145
134
  const result: GetConnectivityResult = {};
146
135
  if (wifi !== undefined) {
@@ -185,16 +174,12 @@ export async function setNetworkConnection(this: AndroidDriver, type: number): P
185
174
  }
186
175
  } else {
187
176
  this.log.info(
188
- `Not changing airplane mode, since it is already ${
189
- shouldEnableAirplaneMode ? 'enabled' : 'disabled'
190
- }`,
177
+ `Not changing airplane mode, since it is already ${shouldEnableAirplaneMode ? 'enabled' : 'disabled'}`,
191
178
  );
192
179
  }
193
180
 
194
181
  if (shouldEnableWifi === isWiFiEnabled && shouldEnableDataConnection === isDataEnabled) {
195
- this.log.info(
196
- 'Not changing data connection/Wi-Fi states, since they are already set to expected values',
197
- );
182
+ this.log.info('Not changing data connection/Wi-Fi states, since they are already set to expected values');
198
183
  if (await this.adb.isAirplaneModeOn()) {
199
184
  return AIRPLANE_MODE_MASK | currentState;
200
185
  }
@@ -204,10 +189,7 @@ export async function setNetworkConnection(this: AndroidDriver, type: number): P
204
189
  if (shouldEnableWifi !== isWiFiEnabled) {
205
190
  await this.setWifiState(shouldEnableWifi);
206
191
  } else {
207
- this.log.info(
208
- `Not changing Wi-Fi state, since it is already ` +
209
- `${shouldEnableWifi ? 'enabled' : 'disabled'}`,
210
- );
192
+ this.log.info(`Not changing Wi-Fi state, since it is already ${shouldEnableWifi ? 'enabled' : 'disabled'}`);
211
193
  }
212
194
 
213
195
  if (shouldEnableAirplaneMode) {
@@ -1,4 +1,5 @@
1
1
  import {errors} from 'appium/driver.js';
2
+
2
3
  import type {AndroidDriver} from '../driver.js';
3
4
  import type {NfcAction} from './types.js';
4
5
 
@@ -1,20 +1,12 @@
1
+ import {util} from '@appium/support';
1
2
  import {retryInterval} from 'asyncbox';
2
3
  import type {ExecError} from 'teen_process';
4
+
3
5
  import type {AndroidDriver} from '../driver.js';
4
6
  import type {PerformanceDataType} from './types.js';
5
- import {util} from '@appium/support';
6
7
 
7
8
  export const NETWORK_KEYS = [
8
- [
9
- 'bucketStart',
10
- 'activeTime',
11
- 'rxBytes',
12
- 'rxPackets',
13
- 'txBytes',
14
- 'txPackets',
15
- 'operations',
16
- 'bucketDuration',
17
- ],
9
+ ['bucketStart', 'activeTime', 'rxBytes', 'rxPackets', 'txBytes', 'txPackets', 'operations', 'bucketDuration'],
18
10
  ['st', 'activeTime', 'rb', 'rp', 'tb', 'tp', 'op', 'bucketDuration'],
19
11
  ] as const;
20
12
 
@@ -45,8 +37,7 @@ export const SUPPORTED_PERFORMANCE_DATA_TYPES = Object.freeze({
45
37
  'the amount of memory used by the process - memory information for applications on real devices and simulators',
46
38
  batteryinfo:
47
39
  'the remaining battery power - battery power information for applications on real devices and simulators',
48
- networkinfo:
49
- 'the network statistics - network rx/tx information for applications on real devices and simulators',
40
+ networkinfo: 'the network statistics - network rx/tx information for applications on real devices and simulators',
50
41
  } as const);
51
42
 
52
43
  export const MEMINFO_TITLES = Object.freeze({
@@ -101,11 +92,7 @@ export async function getPerformanceData(
101
92
  default:
102
93
  throw new Error(
103
94
  `No performance data of type '${dataType}' found. ` +
104
- `Only the following values are supported: ${JSON.stringify(
105
- SUPPORTED_PERFORMANCE_DATA_TYPES,
106
- [' '],
107
- 2,
108
- )}`,
95
+ `Only the following values are supported: ${JSON.stringify(SUPPORTED_PERFORMANCE_DATA_TYPES, [' '], 2)}`,
109
96
  );
110
97
  }
111
98
  }
@@ -156,11 +143,7 @@ export async function mobileGetPerformanceData(
156
143
  * and the second row contains the corresponding values.
157
144
  * @throws {Error} If memory data cannot be retrieved or parsed.
158
145
  */
159
- export async function getMemoryInfo(
160
- this: AndroidDriver,
161
- packageName: string,
162
- retries: number = 2,
163
- ): Promise<any[][]> {
146
+ export async function getMemoryInfo(this: AndroidDriver, packageName: string, retries: number = 2): Promise<any[][]> {
164
147
  return (await retryInterval(retries, RETRY_PAUSE_MS, async () => {
165
148
  const cmd = [
166
149
  'dumpsys',
@@ -211,10 +194,7 @@ export async function getMemoryInfo(
211
194
  * for each time bucket.
212
195
  * @throws {Error} If network traffic data cannot be retrieved or parsed.
213
196
  */
214
- export async function getNetworkTrafficInfo(
215
- this: AndroidDriver,
216
- retries: number = 2,
217
- ): Promise<any[][]> {
197
+ export async function getNetworkTrafficInfo(this: AndroidDriver, retries: number = 2): Promise<any[][]> {
218
198
  return (await retryInterval(retries, RETRY_PAUSE_MS, async () => {
219
199
  const returnValue: any[][] = [];
220
200
  let bucketDuration: string | undefined;
@@ -429,9 +409,7 @@ export async function getCPUInfo(
429
409
  const match = usagesPattern.exec(output);
430
410
  if (!match) {
431
411
  this.log.debug(output);
432
- throw new Error(
433
- `Unable to parse cpu usage data for '${packageName}'. Check the server log for more details`,
434
- );
412
+ throw new Error(`Unable to parse cpu usage data for '${packageName}'. Check the server log for more details`);
435
413
  }
436
414
  const user = match[1];
437
415
  const kernel = match[2];
@@ -471,22 +449,11 @@ export async function getBatteryInfo(this: AndroidDriver, retries: number = 2):
471
449
  * except 'TOTAL', which skips the second type name
472
450
  * !!! valDict gets mutated
473
451
  */
474
- function parseMeminfoForApi19To29(
475
- entries: string[],
476
- valDict: Record<string, string | number>,
477
- ): void {
452
+ function parseMeminfoForApi19To29(entries: string[], valDict: Record<string, string | number>): void {
478
453
  const [type, subType] = entries;
479
454
  if (type === MEMINFO_TITLES.NATIVE && subType === MEMINFO_TITLES.HEAP) {
480
- [
481
- ,
482
- ,
483
- valDict.nativePss,
484
- valDict.nativePrivateDirty,
485
- ,
486
- ,
487
- valDict.nativeHeapSize,
488
- valDict.nativeHeapAllocatedSize,
489
- ] = entries;
455
+ [, , valDict.nativePss, valDict.nativePrivateDirty, , , valDict.nativeHeapSize, valDict.nativeHeapAllocatedSize] =
456
+ entries;
490
457
  } else if (type === MEMINFO_TITLES.DALVIK && subType === MEMINFO_TITLES.HEAP) {
491
458
  [, , valDict.dalvikPss, valDict.dalvikPrivateDirty] = entries;
492
459
  } else if (type === MEMINFO_TITLES.EGL && subType === MEMINFO_TITLES.MTRACK) {
@@ -504,10 +471,7 @@ function parseMeminfoForApi19To29(
504
471
  * ['<System Type>', '<Memory Type>', <pss total>, <private dirty>, <private clean>, <swapPss dirty>, <rss total>, <heap size>, <heap alloc>, <heap free>]
505
472
  * !!! valDict gets mutated
506
473
  */
507
- function parseMeminfoForApiAbove29(
508
- entries: string[],
509
- valDict: Record<string, string | number>,
510
- ): void {
474
+ function parseMeminfoForApiAbove29(entries: string[], valDict: Record<string, string | number>): void {
511
475
  const [type, subType] = entries;
512
476
  if (type === MEMINFO_TITLES.NATIVE && subType === MEMINFO_TITLES.HEAP) {
513
477
  [
@@ -1,7 +1,8 @@
1
+ import {util} from '@appium/support';
1
2
  import {errors} from 'appium/driver.js';
2
- import {ADB_SHELL_FEATURE} from '../utils.js';
3
+
3
4
  import type {AndroidDriver} from '../driver.js';
4
- import {util} from '@appium/support';
5
+ import {ADB_SHELL_FEATURE} from '../utils.js';
5
6
 
6
7
  const ALL_PERMISSIONS_MAGIC = 'all';
7
8
  const PM_ACTION = Object.freeze({
@@ -67,8 +68,7 @@ export async function mobileChangePermissions(
67
68
  if (!appPackage) {
68
69
  throw new errors.InvalidArgumentError(`A valid appPackage must be provided`);
69
70
  }
70
- action ??=
71
- target?.toLowerCase() === PERMISSION_TARGET.APPOPS ? APPOPS_ACTION.ALLOW : PM_ACTION.GRANT;
71
+ action ??= target?.toLowerCase() === PERMISSION_TARGET.APPOPS ? APPOPS_ACTION.ALLOW : PM_ACTION.GRANT;
72
72
  if (permissions == null) {
73
73
  throw new errors.InvalidArgumentError(`'permissions' argument is required`);
74
74
  }
@@ -78,11 +78,7 @@ export async function mobileChangePermissions(
78
78
 
79
79
  switch (target?.toLowerCase()) {
80
80
  case PERMISSION_TARGET.PM:
81
- return await changePermissionsViaPm.bind(this)(
82
- permissions,
83
- appPackage,
84
- action?.toLowerCase() as PMAction,
85
- );
81
+ return await changePermissionsViaPm.bind(this)(permissions, appPackage, action?.toLowerCase() as PMAction);
86
82
  case PERMISSION_TARGET.APPOPS:
87
83
  this.assertFeatureEnabled(ADB_SHELL_FEATURE);
88
84
  return await changePermissionsViaAppops.bind(this)(
@@ -91,9 +87,7 @@ export async function mobileChangePermissions(
91
87
  action?.toLowerCase() as AppOpsAction,
92
88
  );
93
89
  default:
94
- throw new errors.InvalidArgumentError(
95
- `'target' argument must be one of: ${Object.values(PERMISSION_TARGET)}`,
96
- );
90
+ throw new errors.InvalidArgumentError(`'target' argument must be one of: ${Object.values(PERMISSION_TARGET)}`);
97
91
  }
98
92
  }
99
93
  /**
@@ -138,8 +132,7 @@ async function changePermissionsViaPm(
138
132
  ): Promise<void> {
139
133
  if (!Object.values(PM_ACTION).includes(action)) {
140
134
  throw new errors.InvalidArgumentError(
141
- `Unknown action '${action}'. ` +
142
- `Only ${JSON.stringify(Object.values(PM_ACTION))} actions are supported`,
135
+ `Unknown action '${action}'. Only ${JSON.stringify(Object.values(PM_ACTION))} actions are supported`,
143
136
  );
144
137
  }
145
138
 
@@ -149,9 +142,7 @@ async function changePermissionsViaPm(
149
142
  const grantedPermissions = await this.adb.getGrantedPermissions(appPackage, dumpsys);
150
143
  if (action === PM_ACTION.GRANT) {
151
144
  const reqPermissons = await this.adb.getReqPermissions(appPackage, dumpsys);
152
- affectedPermissions = reqPermissons.filter(
153
- (permission) => !grantedPermissions.includes(permission),
154
- );
145
+ affectedPermissions = reqPermissons.filter((permission) => !grantedPermissions.includes(permission));
155
146
  } else {
156
147
  affectedPermissions = grantedPermissions;
157
148
  }
@@ -164,9 +155,7 @@ async function changePermissionsViaPm(
164
155
  if (action === PM_ACTION.GRANT) {
165
156
  await this.adb.grantPermissions(appPackage, affectedPermissions);
166
157
  } else {
167
- await Promise.all(
168
- affectedPermissions.map((name) => this.adb.revokePermission(appPackage, name)),
169
- );
158
+ await Promise.all(affectedPermissions.map((name) => this.adb.revokePermission(appPackage, name)));
170
159
  }
171
160
  }
172
161
  async function changePermissionsViaAppops(
@@ -177,8 +166,7 @@ async function changePermissionsViaAppops(
177
166
  ): Promise<void> {
178
167
  if (!Object.values(APPOPS_ACTION).includes(action)) {
179
168
  throw new errors.InvalidArgumentError(
180
- `Unknown action '${action}'. ` +
181
- `Only ${JSON.stringify(Object.values(APPOPS_ACTION))} actions are supported`,
169
+ `Unknown action '${action}'. Only ${JSON.stringify(Object.values(APPOPS_ACTION))} actions are supported`,
182
170
  );
183
171
  }
184
172
  if (typeof permissions === 'string' && permissions.toLowerCase() === ALL_PERMISSIONS_MAGIC) {