appium-android-driver 7.8.3 → 8.0.1

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 (261) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/build/lib/commands/app-management.d.ts +129 -5
  3. package/build/lib/commands/app-management.d.ts.map +1 -1
  4. package/build/lib/commands/app-management.js +433 -128
  5. package/build/lib/commands/app-management.js.map +1 -1
  6. package/build/lib/commands/appearance.d.ts +17 -4
  7. package/build/lib/commands/appearance.d.ts.map +1 -1
  8. package/build/lib/commands/appearance.js +32 -33
  9. package/build/lib/commands/appearance.js.map +1 -1
  10. package/build/lib/commands/context/cache.d.ts +19 -0
  11. package/build/lib/commands/context/cache.d.ts.map +1 -0
  12. package/build/lib/commands/context/cache.js +32 -0
  13. package/build/lib/commands/context/cache.js.map +1 -0
  14. package/build/lib/commands/context/exports.d.ts +141 -0
  15. package/build/lib/commands/context/exports.d.ts.map +1 -0
  16. package/build/lib/commands/context/exports.js +351 -0
  17. package/build/lib/commands/context/exports.js.map +1 -0
  18. package/build/lib/commands/context/helpers.d.ts +98 -0
  19. package/build/lib/commands/context/helpers.d.ts.map +1 -0
  20. package/build/lib/commands/context/helpers.js +715 -0
  21. package/build/lib/commands/context/helpers.js.map +1 -0
  22. package/build/lib/commands/device/common.d.ts +23 -0
  23. package/build/lib/commands/device/common.d.ts.map +1 -0
  24. package/build/lib/commands/device/common.js +230 -0
  25. package/build/lib/commands/device/common.js.map +1 -0
  26. package/build/lib/commands/device/emulator-actions.d.ts +114 -0
  27. package/build/lib/commands/device/emulator-actions.d.ts.map +1 -0
  28. package/build/lib/commands/device/emulator-actions.js +197 -0
  29. package/build/lib/commands/device/emulator-actions.js.map +1 -0
  30. package/build/lib/commands/device/emulator-console.d.ts +7 -0
  31. package/build/lib/commands/device/emulator-console.d.ts.map +1 -0
  32. package/build/lib/commands/device/emulator-console.js +24 -0
  33. package/build/lib/commands/device/emulator-console.js.map +1 -0
  34. package/build/lib/commands/device/utils.d.ts +50 -0
  35. package/build/lib/commands/device/utils.d.ts.map +1 -0
  36. package/build/lib/commands/device/utils.js +238 -0
  37. package/build/lib/commands/device/utils.js.map +1 -0
  38. package/build/lib/commands/deviceidle.d.ts +8 -5
  39. package/build/lib/commands/deviceidle.d.ts.map +1 -1
  40. package/build/lib/commands/deviceidle.js +31 -37
  41. package/build/lib/commands/deviceidle.js.map +1 -1
  42. package/build/lib/commands/element.d.ts +99 -5
  43. package/build/lib/commands/element.d.ts.map +1 -1
  44. package/build/lib/commands/element.js +152 -116
  45. package/build/lib/commands/element.js.map +1 -1
  46. package/build/lib/commands/execute.d.ts +12 -4
  47. package/build/lib/commands/execute.d.ts.map +1 -1
  48. package/build/lib/commands/execute.js +83 -78
  49. package/build/lib/commands/execute.js.map +1 -1
  50. package/build/lib/commands/file-actions.d.ts +42 -5
  51. package/build/lib/commands/file-actions.d.ts.map +1 -1
  52. package/build/lib/commands/file-actions.js +230 -194
  53. package/build/lib/commands/file-actions.js.map +1 -1
  54. package/build/lib/commands/find.d.ts +5 -4
  55. package/build/lib/commands/find.d.ts.map +1 -1
  56. package/build/lib/commands/find.js +7 -10
  57. package/build/lib/commands/find.js.map +1 -1
  58. package/build/lib/commands/geolocation.d.ts +45 -0
  59. package/build/lib/commands/geolocation.d.ts.map +1 -0
  60. package/build/lib/commands/geolocation.js +182 -0
  61. package/build/lib/commands/geolocation.js.map +1 -0
  62. package/build/lib/commands/ime.d.ts +25 -5
  63. package/build/lib/commands/ime.d.ts.map +1 -1
  64. package/build/lib/commands/ime.js +59 -42
  65. package/build/lib/commands/ime.js.map +1 -1
  66. package/build/lib/commands/intent.d.ts +56 -5
  67. package/build/lib/commands/intent.d.ts.map +1 -1
  68. package/build/lib/commands/intent.js +135 -83
  69. package/build/lib/commands/intent.js.map +1 -1
  70. package/build/lib/commands/keyboard.d.ts +58 -4
  71. package/build/lib/commands/keyboard.d.ts.map +1 -1
  72. package/build/lib/commands/keyboard.js +119 -17
  73. package/build/lib/commands/keyboard.js.map +1 -1
  74. package/build/lib/commands/lock/exports.d.ts +301 -0
  75. package/build/lib/commands/lock/exports.d.ts.map +1 -0
  76. package/build/lib/commands/lock/exports.js +121 -0
  77. package/build/lib/commands/lock/exports.js.map +1 -0
  78. package/build/lib/commands/lock/helpers.d.ts +349 -0
  79. package/build/lib/commands/lock/helpers.d.ts.map +1 -0
  80. package/build/lib/commands/lock/helpers.js +375 -0
  81. package/build/lib/commands/lock/helpers.js.map +1 -0
  82. package/build/lib/commands/log.d.ts +59 -5
  83. package/build/lib/commands/log.d.ts.map +1 -1
  84. package/build/lib/commands/log.js +150 -140
  85. package/build/lib/commands/log.js.map +1 -1
  86. package/build/lib/commands/media-projection.d.ts +16 -5
  87. package/build/lib/commands/media-projection.d.ts.map +1 -1
  88. package/build/lib/commands/media-projection.js +69 -58
  89. package/build/lib/commands/media-projection.js.map +1 -1
  90. package/build/lib/commands/memory.d.ts +9 -5
  91. package/build/lib/commands/memory.d.ts.map +1 -1
  92. package/build/lib/commands/memory.js +19 -24
  93. package/build/lib/commands/memory.js.map +1 -1
  94. package/build/lib/commands/misc.d.ts +42 -0
  95. package/build/lib/commands/misc.d.ts.map +1 -0
  96. package/build/lib/commands/misc.js +100 -0
  97. package/build/lib/commands/misc.js.map +1 -0
  98. package/build/lib/commands/network.d.ts +61 -5
  99. package/build/lib/commands/network.d.ts.map +1 -1
  100. package/build/lib/commands/network.js +196 -189
  101. package/build/lib/commands/network.js.map +1 -1
  102. package/build/lib/commands/performance.d.ts +67 -27
  103. package/build/lib/commands/performance.d.ts.map +1 -1
  104. package/build/lib/commands/performance.js +105 -80
  105. package/build/lib/commands/performance.js.map +1 -1
  106. package/build/lib/commands/permissions.d.ts +12 -6
  107. package/build/lib/commands/permissions.d.ts.map +1 -1
  108. package/build/lib/commands/permissions.js +65 -62
  109. package/build/lib/commands/permissions.js.map +1 -1
  110. package/build/lib/commands/recordscreen.d.ts +44 -5
  111. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  112. package/build/lib/commands/recordscreen.js +131 -126
  113. package/build/lib/commands/recordscreen.js.map +1 -1
  114. package/build/lib/commands/resources.d.ts +16 -0
  115. package/build/lib/commands/resources.d.ts.map +1 -0
  116. package/build/lib/commands/resources.js +91 -0
  117. package/build/lib/commands/resources.js.map +1 -0
  118. package/build/lib/commands/shell.d.ts +8 -5
  119. package/build/lib/commands/shell.d.ts.map +1 -1
  120. package/build/lib/commands/shell.js +29 -33
  121. package/build/lib/commands/shell.js.map +1 -1
  122. package/build/lib/commands/streamscreen.d.ts +34 -6
  123. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  124. package/build/lib/commands/streamscreen.js +166 -162
  125. package/build/lib/commands/streamscreen.js.map +1 -1
  126. package/build/lib/commands/system-bars.d.ts +18 -13
  127. package/build/lib/commands/system-bars.d.ts.map +1 -1
  128. package/build/lib/commands/system-bars.js +68 -64
  129. package/build/lib/commands/system-bars.js.map +1 -1
  130. package/build/lib/commands/time.d.ts +14 -0
  131. package/build/lib/commands/time.d.ts.map +1 -0
  132. package/build/lib/commands/time.js +39 -0
  133. package/build/lib/commands/time.js.map +1 -0
  134. package/build/lib/commands/touch.d.ts +99 -6
  135. package/build/lib/commands/touch.d.ts.map +1 -1
  136. package/build/lib/commands/touch.js +399 -280
  137. package/build/lib/commands/touch.js.map +1 -1
  138. package/build/lib/commands/types.d.ts +110 -2
  139. package/build/lib/commands/types.d.ts.map +1 -1
  140. package/build/lib/doctor/checks.d.ts.map +1 -1
  141. package/build/lib/doctor/checks.js +4 -4
  142. package/build/lib/doctor/checks.js.map +1 -1
  143. package/build/lib/driver.d.ts +224 -27
  144. package/build/lib/driver.d.ts.map +1 -1
  145. package/build/lib/driver.js +232 -7
  146. package/build/lib/driver.js.map +1 -1
  147. package/build/lib/index.d.ts +1 -4
  148. package/build/lib/index.d.ts.map +1 -1
  149. package/build/lib/index.js +1 -13
  150. package/build/lib/index.js.map +1 -1
  151. package/build/lib/logger.js.map +1 -1
  152. package/build/lib/method-map.d.ts +0 -23
  153. package/build/lib/method-map.d.ts.map +1 -1
  154. package/build/lib/method-map.js +0 -11
  155. package/build/lib/method-map.js.map +1 -1
  156. package/build/lib/utils.d.ts +12 -0
  157. package/build/lib/utils.d.ts.map +1 -1
  158. package/build/lib/utils.js +38 -2
  159. package/build/lib/utils.js.map +1 -1
  160. package/lib/commands/app-management.js +470 -145
  161. package/lib/commands/appearance.js +29 -36
  162. package/lib/commands/context/cache.js +29 -0
  163. package/lib/commands/context/exports.js +379 -0
  164. package/lib/commands/context/helpers.js +802 -0
  165. package/lib/commands/device/common.js +264 -0
  166. package/lib/commands/device/emulator-actions.js +194 -0
  167. package/lib/commands/device/emulator-console.js +24 -0
  168. package/lib/commands/device/utils.js +285 -0
  169. package/lib/commands/deviceidle.js +31 -44
  170. package/lib/commands/element.js +149 -142
  171. package/lib/commands/execute.js +86 -87
  172. package/lib/commands/file-actions.js +249 -222
  173. package/lib/commands/find.ts +13 -19
  174. package/lib/commands/geolocation.js +179 -0
  175. package/lib/commands/ime.js +53 -45
  176. package/lib/commands/intent.js +149 -91
  177. package/lib/commands/keyboard.js +114 -17
  178. package/lib/commands/lock/exports.js +139 -0
  179. package/lib/commands/lock/helpers.js +379 -0
  180. package/lib/commands/log.js +170 -166
  181. package/lib/commands/media-projection.js +75 -70
  182. package/lib/commands/memory.js +17 -29
  183. package/lib/commands/misc.js +94 -0
  184. package/lib/commands/network.js +209 -223
  185. package/lib/commands/performance.js +88 -73
  186. package/lib/commands/permissions.js +83 -84
  187. package/lib/commands/recordscreen.js +171 -170
  188. package/lib/commands/resources.js +96 -0
  189. package/lib/commands/shell.js +28 -42
  190. package/lib/commands/streamscreen.js +207 -206
  191. package/lib/commands/system-bars.js +76 -77
  192. package/lib/commands/time.js +36 -0
  193. package/lib/commands/touch.js +442 -346
  194. package/lib/commands/types.ts +123 -2
  195. package/lib/doctor/checks.js +24 -16
  196. package/lib/driver.ts +454 -12
  197. package/lib/index.ts +1 -13
  198. package/lib/logger.js +1 -1
  199. package/lib/method-map.js +0 -11
  200. package/lib/utils.js +40 -3
  201. package/package.json +2 -2
  202. package/build/lib/commands/actions.d.ts +0 -8
  203. package/build/lib/commands/actions.d.ts.map +0 -1
  204. package/build/lib/commands/actions.js +0 -207
  205. package/build/lib/commands/actions.js.map +0 -1
  206. package/build/lib/commands/alert.d.ts +0 -8
  207. package/build/lib/commands/alert.d.ts.map +0 -1
  208. package/build/lib/commands/alert.js +0 -29
  209. package/build/lib/commands/alert.js.map +0 -1
  210. package/build/lib/commands/context.d.ts +0 -10
  211. package/build/lib/commands/context.d.ts.map +0 -1
  212. package/build/lib/commands/context.js +0 -431
  213. package/build/lib/commands/context.js.map +0 -1
  214. package/build/lib/commands/emu-console.d.ts +0 -7
  215. package/build/lib/commands/emu-console.d.ts.map +0 -1
  216. package/build/lib/commands/emu-console.js +0 -27
  217. package/build/lib/commands/emu-console.js.map +0 -1
  218. package/build/lib/commands/general.d.ts +0 -9
  219. package/build/lib/commands/general.d.ts.map +0 -1
  220. package/build/lib/commands/general.js +0 -293
  221. package/build/lib/commands/general.js.map +0 -1
  222. package/build/lib/commands/index.d.ts +0 -28
  223. package/build/lib/commands/index.d.ts.map +0 -1
  224. package/build/lib/commands/index.js +0 -57
  225. package/build/lib/commands/index.js.map +0 -1
  226. package/build/lib/commands/mixins.d.ts +0 -747
  227. package/build/lib/commands/mixins.d.ts.map +0 -1
  228. package/build/lib/commands/mixins.js +0 -19
  229. package/build/lib/commands/mixins.js.map +0 -1
  230. package/build/lib/helpers/android.d.ts +0 -163
  231. package/build/lib/helpers/android.d.ts.map +0 -1
  232. package/build/lib/helpers/android.js +0 -818
  233. package/build/lib/helpers/android.js.map +0 -1
  234. package/build/lib/helpers/index.d.ts +0 -7
  235. package/build/lib/helpers/index.d.ts.map +0 -1
  236. package/build/lib/helpers/index.js +0 -29
  237. package/build/lib/helpers/index.js.map +0 -1
  238. package/build/lib/helpers/types.d.ts +0 -122
  239. package/build/lib/helpers/types.d.ts.map +0 -1
  240. package/build/lib/helpers/types.js +0 -3
  241. package/build/lib/helpers/types.js.map +0 -1
  242. package/build/lib/helpers/unlock.d.ts +0 -32
  243. package/build/lib/helpers/unlock.d.ts.map +0 -1
  244. package/build/lib/helpers/unlock.js +0 -273
  245. package/build/lib/helpers/unlock.js.map +0 -1
  246. package/build/lib/helpers/webview.d.ts +0 -74
  247. package/build/lib/helpers/webview.d.ts.map +0 -1
  248. package/build/lib/helpers/webview.js +0 -448
  249. package/build/lib/helpers/webview.js.map +0 -1
  250. package/lib/commands/actions.js +0 -244
  251. package/lib/commands/alert.js +0 -34
  252. package/lib/commands/context.js +0 -507
  253. package/lib/commands/emu-console.js +0 -31
  254. package/lib/commands/general.js +0 -343
  255. package/lib/commands/index.ts +0 -54
  256. package/lib/commands/mixins.ts +0 -976
  257. package/lib/helpers/android.ts +0 -1153
  258. package/lib/helpers/index.ts +0 -6
  259. package/lib/helpers/types.ts +0 -136
  260. package/lib/helpers/unlock.ts +0 -329
  261. package/lib/helpers/webview.ts +0 -610
@@ -2,9 +2,8 @@
2
2
  import {retryInterval} from 'asyncbox';
3
3
  import _ from 'lodash';
4
4
  import {requireArgs} from '../utils';
5
- import {mixin} from './mixins';
6
5
 
7
- const NETWORK_KEYS = [
6
+ export const NETWORK_KEYS = [
8
7
  [
9
8
  'bucketStart',
10
9
  'activeTime',
@@ -17,9 +16,9 @@ const NETWORK_KEYS = [
17
16
  ],
18
17
  ['st', 'activeTime', 'rb', 'rp', 'tb', 'tp', 'op', 'bucketDuration'],
19
18
  ];
20
- const CPU_KEYS = /** @type {const} */ (['user', 'kernel']);
21
- const BATTERY_KEYS = ['power'];
22
- const MEMORY_KEYS = [
19
+ export const CPU_KEYS = /** @type {const} */ (['user', 'kernel']);
20
+ export const BATTERY_KEYS = ['power'];
21
+ export const MEMORY_KEYS = [
23
22
  'totalPrivateDirty',
24
23
  'nativePrivateDirty',
25
24
  'dalvikPrivateDirty',
@@ -36,7 +35,7 @@ const MEMORY_KEYS = [
36
35
  'dalvikRss',
37
36
  'totalRss',
38
37
  ];
39
- const SUPPORTED_PERFORMANCE_DATA_TYPES = Object.freeze({
38
+ export const SUPPORTED_PERFORMANCE_DATA_TYPES = Object.freeze({
40
39
  cpuinfo:
41
40
  'the amount of cpu by user and kernel process - cpu information for applications on real devices and simulators',
42
41
  memoryinfo:
@@ -46,7 +45,7 @@ const SUPPORTED_PERFORMANCE_DATA_TYPES = Object.freeze({
46
45
  networkinfo:
47
46
  'the network statistics - network rx/tx information for applications on real devices and simulators',
48
47
  });
49
- const MEMINFO_TITLES = Object.freeze({
48
+ export const MEMINFO_TITLES = Object.freeze({
50
49
  NATIVE: 'Native',
51
50
  DALVIK: 'Dalvik',
52
51
  EGL: 'EGL',
@@ -57,6 +56,81 @@ const MEMINFO_TITLES = Object.freeze({
57
56
  });
58
57
  const RETRY_PAUSE_MS = 1000;
59
58
 
59
+ /**
60
+ * @this {AndroidDriver}
61
+ * @returns {Promise<import('./types').PerformanceDataType[]>}
62
+ */
63
+ export async function getPerformanceDataTypes() {
64
+ return /** @type {import('./types').PerformanceDataType[]} */ (
65
+ _.keys(SUPPORTED_PERFORMANCE_DATA_TYPES)
66
+ );
67
+ }
68
+
69
+ /**
70
+ * @this {AndroidDriver}
71
+ * @param {string} packageName
72
+ * @param {string} dataType
73
+ * @param {number} [retries=2]
74
+ * @returns {Promise<any[][]>}
75
+ */
76
+ export async function getPerformanceData(packageName, dataType, retries = 2) {
77
+ let result;
78
+ switch (_.toLower(dataType)) {
79
+ case 'batteryinfo':
80
+ result = await getBatteryInfo.call(this, retries);
81
+ break;
82
+ case 'cpuinfo':
83
+ result = await getCPUInfo.call(this, packageName, retries);
84
+ break;
85
+ case 'memoryinfo':
86
+ result = await getMemoryInfo.call(this, packageName, retries);
87
+ break;
88
+ case 'networkinfo':
89
+ result = await getNetworkTrafficInfo.call(this, retries);
90
+ break;
91
+ default:
92
+ throw new Error(
93
+ `No performance data of type '${dataType}' found. ` +
94
+ `Only the following values are supported: ${JSON.stringify(
95
+ SUPPORTED_PERFORMANCE_DATA_TYPES,
96
+ [' '],
97
+ 2,
98
+ )}`,
99
+ );
100
+ }
101
+ return /** @type {any[][]} */ (result);
102
+ }
103
+
104
+ /**
105
+ * Retrieves performance data about the given Android subsystem.
106
+ * The data is parsed from the output of the dumpsys utility.
107
+ *
108
+ * The output depends on the selected subsystem.
109
+ * It is orginized into a table, where the first row represent column names
110
+ * and the following rows represent the sampled data for each column.
111
+ * Example output for different data types:
112
+ * - batteryinfo: [[power], [23]]
113
+ * - memory info: [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty, totalPss,
114
+ * nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize], [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]]
115
+ * - networkinfo: [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,],
116
+ * [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000], [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]]
117
+ *
118
+ * [[st, activeTime, rb, rp, tb, tp, op, bucketDuration], [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600],
119
+ * [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600], [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
120
+ * [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
121
+ * - cpuinfo: [[user, kernel], [0.9, 1.3]]
122
+ *
123
+ * @this {AndroidDriver}
124
+ * @param {import('./types').PerformanceDataOpts} opts
125
+ * @returns {Promise<any[][]>}
126
+ */
127
+ export async function mobileGetPerformanceData(opts) {
128
+ const {packageName, dataType} = requireArgs(['packageName', 'dataType'], opts);
129
+ return await this.getPerformanceData(packageName, dataType);
130
+ }
131
+
132
+ // #region Internal helpers
133
+
60
134
  /**
61
135
  * API level between 18 and 30
62
136
  * ['<System Type>', '<Memory Type>', <pss total>, <private dirty>, <private clean>, <swapPss dirty>, <heap size>, <heap alloc>, <heap free>]
@@ -151,7 +225,7 @@ function parseMeminfoForApiAbove29(entries, valDict) {
151
225
  * @param {string} packageName
152
226
  * @param {number} retries
153
227
  */
154
- async function getMemoryInfo(packageName, retries = 2) {
228
+ export async function getMemoryInfo(packageName, retries = 2) {
155
229
  return await retryInterval(retries, RETRY_PAUSE_MS, async () => {
156
230
  const cmd = [
157
231
  'dumpsys',
@@ -193,7 +267,7 @@ async function getMemoryInfo(packageName, retries = 2) {
193
267
  * @this {AndroidDriver}
194
268
  * @param {number} retries
195
269
  */
196
- async function getNetworkTrafficInfo(retries = 2) {
270
+ export async function getNetworkTrafficInfo(retries = 2) {
197
271
  return await retryInterval(retries, RETRY_PAUSE_MS, async () => {
198
272
  let returnValue = [];
199
273
  let bucketDuration, bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations;
@@ -376,7 +450,7 @@ async function getNetworkTrafficInfo(retries = 2) {
376
450
  * '14.3' is usage by the user (%), '28.2' is usage by the kernel (%)
377
451
  * @throws {Error} If it failed to parse the result of dumpsys, or no package name exists.
378
452
  */
379
- async function getCPUInfo(packageName, retries = 2) {
453
+ export async function getCPUInfo(packageName, retries = 2) {
380
454
  // TODO: figure out why this is
381
455
  // sometimes, the function of 'adb.shell' fails. when I tested this function on the target of 'Galaxy Note5',
382
456
  // adb.shell(dumpsys cpuinfo) returns cpu datas for other application packages, but I can't find the data for packageName.
@@ -401,13 +475,13 @@ async function getCPUInfo(packageName, retries = 2) {
401
475
  // +0% 2209/io.appium.android.apis: 0.1% user + 0.2% kernel / faults: 70 minor
402
476
  const usagesPattern = new RegExp(
403
477
  `^.+\\/${_.escapeRegExp(packageName)}:\\D+([\\d.]+)%\\s+user\\s+\\+\\s+([\\d.]+)%\\s+kernel`,
404
- 'm'
478
+ 'm',
405
479
  );
406
480
  const match = usagesPattern.exec(output);
407
481
  if (!match) {
408
482
  this.log.debug(output);
409
483
  throw new Error(
410
- `Unable to parse cpu usage data for '${packageName}'. Check the server log for more details`
484
+ `Unable to parse cpu usage data for '${packageName}'. Check the server log for more details`,
411
485
  );
412
486
  }
413
487
  const user = /** @type {string} */ (match[1]);
@@ -420,7 +494,7 @@ async function getCPUInfo(packageName, retries = 2) {
420
494
  * @this {AndroidDriver}
421
495
  * @param {number} retries
422
496
  */
423
- async function getBatteryInfo(retries = 2) {
497
+ export async function getBatteryInfo(retries = 2) {
424
498
  return await retryInterval(retries, RETRY_PAUSE_MS, async () => {
425
499
  let cmd = ['dumpsys', 'battery', '|', 'grep', 'level'];
426
500
  let data = await this.adb.shell(cmd);
@@ -436,66 +510,7 @@ async function getBatteryInfo(retries = 2) {
436
510
  });
437
511
  }
438
512
 
439
- /**
440
- * @type {import('./mixins').PerformanceMixin & ThisType<import('../driver').AndroidDriver>}
441
- * @satisfies {import('@appium/types').ExternalDriver}
442
- */
443
- const PerformanceMixin = {
444
- async getPerformanceDataTypes() {
445
- return /** @type {import('./types').PerformanceDataType[]} */ (
446
- _.keys(SUPPORTED_PERFORMANCE_DATA_TYPES)
447
- );
448
- },
449
-
450
- async getPerformanceData(packageName, dataType, retries = 2) {
451
- let result;
452
- switch (_.toLower(dataType)) {
453
- case 'batteryinfo':
454
- result = await getBatteryInfo.call(this, retries);
455
- break;
456
- case 'cpuinfo':
457
- result = await getCPUInfo.call(this, packageName, retries);
458
- break;
459
- case 'memoryinfo':
460
- result = await getMemoryInfo.call(this, packageName, retries);
461
- break;
462
- case 'networkinfo':
463
- result = await getNetworkTrafficInfo.call(this, retries);
464
- break;
465
- default:
466
- throw new Error(
467
- `No performance data of type '${dataType}' found. ` +
468
- `Only the following values are supported: ${JSON.stringify(
469
- SUPPORTED_PERFORMANCE_DATA_TYPES,
470
- [' '],
471
- 2
472
- )}`
473
- );
474
- }
475
- return /** @type {any[][]} */ (result);
476
- },
477
-
478
- async mobileGetPerformanceData(opts) {
479
- const {packageName, dataType} = requireArgs(['packageName', 'dataType'], opts);
480
- return await this.getPerformanceData(packageName, dataType);
481
- },
482
- };
483
-
484
- mixin(PerformanceMixin);
485
-
486
- export {
487
- BATTERY_KEYS,
488
- CPU_KEYS,
489
- MEMORY_KEYS,
490
- NETWORK_KEYS,
491
- SUPPORTED_PERFORMANCE_DATA_TYPES,
492
- getBatteryInfo,
493
- getCPUInfo,
494
- getMemoryInfo,
495
- getNetworkTrafficInfo,
496
- };
497
-
498
- export default PerformanceMixin;
513
+ // #endregion
499
514
 
500
515
  /**
501
516
  * @typedef {import('../driver').AndroidDriver} AndroidDriver
@@ -1,10 +1,7 @@
1
- // @ts-check
2
-
3
1
  import {errors} from 'appium/driver';
4
2
  import B from 'bluebird';
5
3
  import _ from 'lodash';
6
4
  import {ADB_SHELL_FEATURE} from '../utils';
7
- import {mixin} from './mixins';
8
5
 
9
6
  const ALL_PERMISSIONS_MAGIC = 'all';
10
7
  const PM_ACTION = Object.freeze({
@@ -27,23 +24,92 @@ const PERMISSIONS_TYPE = Object.freeze({
27
24
  REQUESTED: 'requested',
28
25
  });
29
26
 
27
+ /**
28
+ * @this {import('../driver').AndroidDriver}
29
+ * @param {import('./types').ChangePermissionsOpts} opts
30
+ * @returns {Promise<void>}
31
+ */
32
+ export async function mobileChangePermissions(opts) {
33
+ const {
34
+ permissions,
35
+ appPackage = this.opts.appPackage,
36
+ action = _.toLower(opts.target) === PERMISSION_TARGET.APPOPS
37
+ ? APPOPS_ACTION.ALLOW
38
+ : PM_ACTION.GRANT,
39
+ target = PERMISSION_TARGET.PM,
40
+ } = opts;
41
+ if (_.isNil(permissions)) {
42
+ throw new errors.InvalidArgumentError(`'permissions' argument is required`);
43
+ }
44
+ if (_.isEmpty(permissions)) {
45
+ throw new errors.InvalidArgumentError(`'permissions' argument must not be empty`);
46
+ }
47
+
48
+ switch (_.toLower(target)) {
49
+ case PERMISSION_TARGET.PM:
50
+ return await changePermissionsViaPm.bind(this)(permissions, appPackage, _.toLower(action));
51
+ case PERMISSION_TARGET.APPOPS:
52
+ this.ensureFeatureEnabled(ADB_SHELL_FEATURE);
53
+ return await changePermissionsViaAppops.bind(this)(
54
+ permissions,
55
+ appPackage,
56
+ _.toLower(action),
57
+ );
58
+ default:
59
+ throw new errors.InvalidArgumentError(
60
+ `'target' argument must be one of: ${_.values(PERMISSION_TARGET)}`,
61
+ );
62
+ }
63
+ }
64
+
65
+ /**
66
+ * @this {import('../driver').AndroidDriver}
67
+ * @param {import('./types').GetPermissionsOpts} [opts={}]
68
+ * @returns {Promise<string[]>}
69
+ */
70
+ export async function mobileGetPermissions(opts = {}) {
71
+ const {type = PERMISSIONS_TYPE.REQUESTED, appPackage = this.opts.appPackage} = opts;
72
+ /**
73
+ * @type {(pkg: string) => Promise<string[]>}
74
+ */
75
+ let actionFunc;
76
+ switch (_.toLower(type)) {
77
+ case PERMISSIONS_TYPE.REQUESTED:
78
+ actionFunc = (pkg) => this.adb.getReqPermissions(pkg);
79
+ break;
80
+ case PERMISSIONS_TYPE.GRANTED:
81
+ actionFunc = (pkg) => this.adb.getGrantedPermissions(pkg);
82
+ break;
83
+ case PERMISSIONS_TYPE.DENIED:
84
+ actionFunc = (pkg) => this.adb.getDeniedPermissions(pkg);
85
+ break;
86
+ default:
87
+ throw new errors.InvalidArgumentError(
88
+ `Unknown permissions type '${type}'. ` +
89
+ `Only ${JSON.stringify(_.values(PERMISSIONS_TYPE))} types are supported`,
90
+ );
91
+ }
92
+ return await actionFunc(/** @type {string} */ (appPackage));
93
+ }
94
+
95
+ // #region Internal helpers
96
+
30
97
  /**
31
98
  * @this {AndroidDriver}
32
- * @param {*} permissions
33
- * @param {*} appPackage
34
- * @param {*} action
35
- * @todo FIXME: type this
99
+ * @param {string|string[]} permissions
100
+ * @param {string} appPackage
101
+ * @param {import('type-fest').ValueOf<PM_ACTION>} action
36
102
  */
37
103
  async function changePermissionsViaPm(permissions, appPackage, action) {
38
104
  if (!_.values(PM_ACTION).includes(action)) {
39
105
  throw new errors.InvalidArgumentError(
40
106
  `Unknown action '${action}'. ` +
41
- `Only ${JSON.stringify(_.values(PM_ACTION))} actions are supported`
107
+ `Only ${JSON.stringify(_.values(PM_ACTION))} actions are supported`,
42
108
  );
43
109
  }
44
110
 
45
111
  let affectedPermissions = _.isArray(permissions) ? permissions : [permissions];
46
- if (_.toLower(permissions) === ALL_PERMISSIONS_MAGIC) {
112
+ if (_.isString(permissions) && _.toLower(permissions) === ALL_PERMISSIONS_MAGIC) {
47
113
  const dumpsys = await this.adb.shell(['dumpsys', 'package', appPackage]);
48
114
  const grantedPermissions = await this.adb.getGrantedPermissions(appPackage, dumpsys);
49
115
  if (action === PM_ACTION.GRANT) {
@@ -66,99 +132,32 @@ async function changePermissionsViaPm(permissions, appPackage, action) {
66
132
  }
67
133
  /**
68
134
  * @this {AndroidDriver}
69
- * @param {*} permissions
70
- * @param {*} appPackage
71
- * @param {*} action
72
- * @todo FIXME: type this
135
+ * @param {string|string[]} permissions
136
+ * @param {string} appPackage
137
+ * @param {import('type-fest').ValueOf<APPOPS_ACTION>} action
73
138
  */
74
139
  async function changePermissionsViaAppops(permissions, appPackage, action) {
75
140
  if (!_.values(APPOPS_ACTION).includes(action)) {
76
141
  throw new errors.InvalidArgumentError(
77
142
  `Unknown action '${action}'. ` +
78
- `Only ${JSON.stringify(_.values(APPOPS_ACTION))} actions are supported`
143
+ `Only ${JSON.stringify(_.values(APPOPS_ACTION))} actions are supported`,
79
144
  );
80
145
  }
81
- if (_.toLower(permissions) === ALL_PERMISSIONS_MAGIC) {
146
+ if (_.isString(permissions) && _.toLower(permissions) === ALL_PERMISSIONS_MAGIC) {
82
147
  throw new errors.InvalidArgumentError(
83
148
  `'${ALL_PERMISSIONS_MAGIC}' permission is only supported for ` +
84
149
  `'${PERMISSION_TARGET.PM}' target. ` +
85
- `Check AppOpsManager.java from Android platform sources to get the full list of supported AppOps permissions`
150
+ `Check AppOpsManager.java from Android platform sources to get the full list of supported AppOps permissions`,
86
151
  );
87
152
  }
88
153
 
89
154
  const promises = (_.isArray(permissions) ? permissions : [permissions]).map((permission) =>
90
- this.adb.shell(['appops', 'set', appPackage, permission, action])
155
+ this.adb.shell(['appops', 'set', appPackage, permission, action]),
91
156
  );
92
157
  await B.all(promises);
93
158
  }
94
159
 
95
- /**
96
- * @type {import('./mixins').PermissionsMixin & ThisType<import('../driver').AndroidDriver>}
97
- * @satisfies {import('@appium/types').ExternalDriver}
98
- */
99
- const PermissionsMixin = {
100
- async mobileChangePermissions(opts) {
101
- const {
102
- permissions,
103
- appPackage = this.opts.appPackage,
104
- action = _.toLower(opts.target) === PERMISSION_TARGET.APPOPS
105
- ? APPOPS_ACTION.ALLOW
106
- : PM_ACTION.GRANT,
107
- target = PERMISSION_TARGET.PM,
108
- } = opts;
109
- if (_.isNil(permissions)) {
110
- throw new errors.InvalidArgumentError(`'permissions' argument is required`);
111
- }
112
- if (_.isEmpty(permissions)) {
113
- throw new errors.InvalidArgumentError(`'permissions' argument must not be empty`);
114
- }
115
-
116
- switch (_.toLower(target)) {
117
- case PERMISSION_TARGET.PM:
118
- return await changePermissionsViaPm.bind(this)(permissions, appPackage, _.toLower(action));
119
- case PERMISSION_TARGET.APPOPS:
120
- this.ensureFeatureEnabled(ADB_SHELL_FEATURE);
121
- return await changePermissionsViaAppops.bind(this)(
122
- permissions,
123
- appPackage,
124
- _.toLower(action)
125
- );
126
- default:
127
- throw new errors.InvalidArgumentError(
128
- `'target' argument must be one of: ${_.values(PERMISSION_TARGET)}`
129
- );
130
- }
131
- },
132
-
133
- async mobileGetPermissions(opts = {}) {
134
- const {type = PERMISSIONS_TYPE.REQUESTED, appPackage = this.opts.appPackage} = opts;
135
- /**
136
- * @type {(pkg: string) => Promise<string[]>}
137
- */
138
- let actionFunc;
139
- switch (_.toLower(type)) {
140
- case PERMISSIONS_TYPE.REQUESTED:
141
- actionFunc = (pkg) => this.adb.getReqPermissions(pkg);
142
- break;
143
- case PERMISSIONS_TYPE.GRANTED:
144
- actionFunc = (pkg) => this.adb.getGrantedPermissions(pkg);
145
- break;
146
- case PERMISSIONS_TYPE.DENIED:
147
- actionFunc = (pkg) => this.adb.getDeniedPermissions(pkg);
148
- break;
149
- default:
150
- throw new errors.InvalidArgumentError(
151
- `Unknown permissions type '${type}'. ` +
152
- `Only ${JSON.stringify(_.values(PERMISSIONS_TYPE))} types are supported`
153
- );
154
- }
155
- return await actionFunc(/** @type {string} */ (appPackage));
156
- },
157
- };
158
-
159
- mixin(PermissionsMixin);
160
-
161
- export default PermissionsMixin;
160
+ // #endregion
162
161
 
163
162
  /**
164
163
  * @typedef {import('appium-adb').ADB} ADB