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.
- package/CHANGELOG.md +32 -0
- package/build/lib/commands/app-management.d.ts +129 -5
- package/build/lib/commands/app-management.d.ts.map +1 -1
- package/build/lib/commands/app-management.js +433 -128
- package/build/lib/commands/app-management.js.map +1 -1
- package/build/lib/commands/appearance.d.ts +17 -4
- package/build/lib/commands/appearance.d.ts.map +1 -1
- package/build/lib/commands/appearance.js +32 -33
- package/build/lib/commands/appearance.js.map +1 -1
- package/build/lib/commands/context/cache.d.ts +19 -0
- package/build/lib/commands/context/cache.d.ts.map +1 -0
- package/build/lib/commands/context/cache.js +32 -0
- package/build/lib/commands/context/cache.js.map +1 -0
- package/build/lib/commands/context/exports.d.ts +141 -0
- package/build/lib/commands/context/exports.d.ts.map +1 -0
- package/build/lib/commands/context/exports.js +351 -0
- package/build/lib/commands/context/exports.js.map +1 -0
- package/build/lib/commands/context/helpers.d.ts +98 -0
- package/build/lib/commands/context/helpers.d.ts.map +1 -0
- package/build/lib/commands/context/helpers.js +715 -0
- package/build/lib/commands/context/helpers.js.map +1 -0
- package/build/lib/commands/device/common.d.ts +23 -0
- package/build/lib/commands/device/common.d.ts.map +1 -0
- package/build/lib/commands/device/common.js +230 -0
- package/build/lib/commands/device/common.js.map +1 -0
- package/build/lib/commands/device/emulator-actions.d.ts +114 -0
- package/build/lib/commands/device/emulator-actions.d.ts.map +1 -0
- package/build/lib/commands/device/emulator-actions.js +197 -0
- package/build/lib/commands/device/emulator-actions.js.map +1 -0
- package/build/lib/commands/device/emulator-console.d.ts +7 -0
- package/build/lib/commands/device/emulator-console.d.ts.map +1 -0
- package/build/lib/commands/device/emulator-console.js +24 -0
- package/build/lib/commands/device/emulator-console.js.map +1 -0
- package/build/lib/commands/device/utils.d.ts +50 -0
- package/build/lib/commands/device/utils.d.ts.map +1 -0
- package/build/lib/commands/device/utils.js +238 -0
- package/build/lib/commands/device/utils.js.map +1 -0
- package/build/lib/commands/deviceidle.d.ts +8 -5
- package/build/lib/commands/deviceidle.d.ts.map +1 -1
- package/build/lib/commands/deviceidle.js +31 -37
- package/build/lib/commands/deviceidle.js.map +1 -1
- package/build/lib/commands/element.d.ts +99 -5
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +152 -116
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/execute.d.ts +12 -4
- package/build/lib/commands/execute.d.ts.map +1 -1
- package/build/lib/commands/execute.js +83 -78
- package/build/lib/commands/execute.js.map +1 -1
- package/build/lib/commands/file-actions.d.ts +42 -5
- package/build/lib/commands/file-actions.d.ts.map +1 -1
- package/build/lib/commands/file-actions.js +230 -194
- package/build/lib/commands/file-actions.js.map +1 -1
- package/build/lib/commands/find.d.ts +5 -4
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +7 -10
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/geolocation.d.ts +45 -0
- package/build/lib/commands/geolocation.d.ts.map +1 -0
- package/build/lib/commands/geolocation.js +182 -0
- package/build/lib/commands/geolocation.js.map +1 -0
- package/build/lib/commands/ime.d.ts +25 -5
- package/build/lib/commands/ime.d.ts.map +1 -1
- package/build/lib/commands/ime.js +59 -42
- package/build/lib/commands/ime.js.map +1 -1
- package/build/lib/commands/intent.d.ts +56 -5
- package/build/lib/commands/intent.d.ts.map +1 -1
- package/build/lib/commands/intent.js +135 -83
- package/build/lib/commands/intent.js.map +1 -1
- package/build/lib/commands/keyboard.d.ts +58 -4
- package/build/lib/commands/keyboard.d.ts.map +1 -1
- package/build/lib/commands/keyboard.js +119 -17
- package/build/lib/commands/keyboard.js.map +1 -1
- package/build/lib/commands/lock/exports.d.ts +301 -0
- package/build/lib/commands/lock/exports.d.ts.map +1 -0
- package/build/lib/commands/lock/exports.js +121 -0
- package/build/lib/commands/lock/exports.js.map +1 -0
- package/build/lib/commands/lock/helpers.d.ts +349 -0
- package/build/lib/commands/lock/helpers.d.ts.map +1 -0
- package/build/lib/commands/lock/helpers.js +375 -0
- package/build/lib/commands/lock/helpers.js.map +1 -0
- package/build/lib/commands/log.d.ts +59 -5
- package/build/lib/commands/log.d.ts.map +1 -1
- package/build/lib/commands/log.js +150 -140
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/media-projection.d.ts +16 -5
- package/build/lib/commands/media-projection.d.ts.map +1 -1
- package/build/lib/commands/media-projection.js +69 -58
- package/build/lib/commands/media-projection.js.map +1 -1
- package/build/lib/commands/memory.d.ts +9 -5
- package/build/lib/commands/memory.d.ts.map +1 -1
- package/build/lib/commands/memory.js +19 -24
- package/build/lib/commands/memory.js.map +1 -1
- package/build/lib/commands/misc.d.ts +42 -0
- package/build/lib/commands/misc.d.ts.map +1 -0
- package/build/lib/commands/misc.js +100 -0
- package/build/lib/commands/misc.js.map +1 -0
- package/build/lib/commands/network.d.ts +61 -5
- package/build/lib/commands/network.d.ts.map +1 -1
- package/build/lib/commands/network.js +196 -189
- package/build/lib/commands/network.js.map +1 -1
- package/build/lib/commands/performance.d.ts +67 -27
- package/build/lib/commands/performance.d.ts.map +1 -1
- package/build/lib/commands/performance.js +105 -80
- package/build/lib/commands/performance.js.map +1 -1
- package/build/lib/commands/permissions.d.ts +12 -6
- package/build/lib/commands/permissions.d.ts.map +1 -1
- package/build/lib/commands/permissions.js +65 -62
- package/build/lib/commands/permissions.js.map +1 -1
- package/build/lib/commands/recordscreen.d.ts +44 -5
- package/build/lib/commands/recordscreen.d.ts.map +1 -1
- package/build/lib/commands/recordscreen.js +131 -126
- package/build/lib/commands/recordscreen.js.map +1 -1
- package/build/lib/commands/resources.d.ts +16 -0
- package/build/lib/commands/resources.d.ts.map +1 -0
- package/build/lib/commands/resources.js +91 -0
- package/build/lib/commands/resources.js.map +1 -0
- package/build/lib/commands/shell.d.ts +8 -5
- package/build/lib/commands/shell.d.ts.map +1 -1
- package/build/lib/commands/shell.js +29 -33
- package/build/lib/commands/shell.js.map +1 -1
- package/build/lib/commands/streamscreen.d.ts +34 -6
- package/build/lib/commands/streamscreen.d.ts.map +1 -1
- package/build/lib/commands/streamscreen.js +166 -162
- package/build/lib/commands/streamscreen.js.map +1 -1
- package/build/lib/commands/system-bars.d.ts +18 -13
- package/build/lib/commands/system-bars.d.ts.map +1 -1
- package/build/lib/commands/system-bars.js +68 -64
- package/build/lib/commands/system-bars.js.map +1 -1
- package/build/lib/commands/time.d.ts +14 -0
- package/build/lib/commands/time.d.ts.map +1 -0
- package/build/lib/commands/time.js +39 -0
- package/build/lib/commands/time.js.map +1 -0
- package/build/lib/commands/touch.d.ts +99 -6
- package/build/lib/commands/touch.d.ts.map +1 -1
- package/build/lib/commands/touch.js +399 -280
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/commands/types.d.ts +110 -2
- package/build/lib/commands/types.d.ts.map +1 -1
- package/build/lib/doctor/checks.d.ts.map +1 -1
- package/build/lib/doctor/checks.js +4 -4
- package/build/lib/doctor/checks.js.map +1 -1
- package/build/lib/driver.d.ts +224 -27
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +232 -7
- package/build/lib/driver.js.map +1 -1
- package/build/lib/index.d.ts +1 -4
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +1 -13
- package/build/lib/index.js.map +1 -1
- package/build/lib/logger.js.map +1 -1
- package/build/lib/method-map.d.ts +0 -23
- package/build/lib/method-map.d.ts.map +1 -1
- package/build/lib/method-map.js +0 -11
- package/build/lib/method-map.js.map +1 -1
- package/build/lib/utils.d.ts +12 -0
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +38 -2
- package/build/lib/utils.js.map +1 -1
- package/lib/commands/app-management.js +470 -145
- package/lib/commands/appearance.js +29 -36
- package/lib/commands/context/cache.js +29 -0
- package/lib/commands/context/exports.js +379 -0
- package/lib/commands/context/helpers.js +802 -0
- package/lib/commands/device/common.js +264 -0
- package/lib/commands/device/emulator-actions.js +194 -0
- package/lib/commands/device/emulator-console.js +24 -0
- package/lib/commands/device/utils.js +285 -0
- package/lib/commands/deviceidle.js +31 -44
- package/lib/commands/element.js +149 -142
- package/lib/commands/execute.js +86 -87
- package/lib/commands/file-actions.js +249 -222
- package/lib/commands/find.ts +13 -19
- package/lib/commands/geolocation.js +179 -0
- package/lib/commands/ime.js +53 -45
- package/lib/commands/intent.js +149 -91
- package/lib/commands/keyboard.js +114 -17
- package/lib/commands/lock/exports.js +139 -0
- package/lib/commands/lock/helpers.js +379 -0
- package/lib/commands/log.js +170 -166
- package/lib/commands/media-projection.js +75 -70
- package/lib/commands/memory.js +17 -29
- package/lib/commands/misc.js +94 -0
- package/lib/commands/network.js +209 -223
- package/lib/commands/performance.js +88 -73
- package/lib/commands/permissions.js +83 -84
- package/lib/commands/recordscreen.js +171 -170
- package/lib/commands/resources.js +96 -0
- package/lib/commands/shell.js +28 -42
- package/lib/commands/streamscreen.js +207 -206
- package/lib/commands/system-bars.js +76 -77
- package/lib/commands/time.js +36 -0
- package/lib/commands/touch.js +442 -346
- package/lib/commands/types.ts +123 -2
- package/lib/doctor/checks.js +24 -16
- package/lib/driver.ts +454 -12
- package/lib/index.ts +1 -13
- package/lib/logger.js +1 -1
- package/lib/method-map.js +0 -11
- package/lib/utils.js +40 -3
- package/package.json +2 -2
- package/build/lib/commands/actions.d.ts +0 -8
- package/build/lib/commands/actions.d.ts.map +0 -1
- package/build/lib/commands/actions.js +0 -207
- package/build/lib/commands/actions.js.map +0 -1
- package/build/lib/commands/alert.d.ts +0 -8
- package/build/lib/commands/alert.d.ts.map +0 -1
- package/build/lib/commands/alert.js +0 -29
- package/build/lib/commands/alert.js.map +0 -1
- package/build/lib/commands/context.d.ts +0 -10
- package/build/lib/commands/context.d.ts.map +0 -1
- package/build/lib/commands/context.js +0 -431
- package/build/lib/commands/context.js.map +0 -1
- package/build/lib/commands/emu-console.d.ts +0 -7
- package/build/lib/commands/emu-console.d.ts.map +0 -1
- package/build/lib/commands/emu-console.js +0 -27
- package/build/lib/commands/emu-console.js.map +0 -1
- package/build/lib/commands/general.d.ts +0 -9
- package/build/lib/commands/general.d.ts.map +0 -1
- package/build/lib/commands/general.js +0 -293
- package/build/lib/commands/general.js.map +0 -1
- package/build/lib/commands/index.d.ts +0 -28
- package/build/lib/commands/index.d.ts.map +0 -1
- package/build/lib/commands/index.js +0 -57
- package/build/lib/commands/index.js.map +0 -1
- package/build/lib/commands/mixins.d.ts +0 -747
- package/build/lib/commands/mixins.d.ts.map +0 -1
- package/build/lib/commands/mixins.js +0 -19
- package/build/lib/commands/mixins.js.map +0 -1
- package/build/lib/helpers/android.d.ts +0 -163
- package/build/lib/helpers/android.d.ts.map +0 -1
- package/build/lib/helpers/android.js +0 -818
- package/build/lib/helpers/android.js.map +0 -1
- package/build/lib/helpers/index.d.ts +0 -7
- package/build/lib/helpers/index.d.ts.map +0 -1
- package/build/lib/helpers/index.js +0 -29
- package/build/lib/helpers/index.js.map +0 -1
- package/build/lib/helpers/types.d.ts +0 -122
- package/build/lib/helpers/types.d.ts.map +0 -1
- package/build/lib/helpers/types.js +0 -3
- package/build/lib/helpers/types.js.map +0 -1
- package/build/lib/helpers/unlock.d.ts +0 -32
- package/build/lib/helpers/unlock.d.ts.map +0 -1
- package/build/lib/helpers/unlock.js +0 -273
- package/build/lib/helpers/unlock.js.map +0 -1
- package/build/lib/helpers/webview.d.ts +0 -74
- package/build/lib/helpers/webview.d.ts.map +0 -1
- package/build/lib/helpers/webview.js +0 -448
- package/build/lib/helpers/webview.js.map +0 -1
- package/lib/commands/actions.js +0 -244
- package/lib/commands/alert.js +0 -34
- package/lib/commands/context.js +0 -507
- package/lib/commands/emu-console.js +0 -31
- package/lib/commands/general.js +0 -343
- package/lib/commands/index.ts +0 -54
- package/lib/commands/mixins.ts +0 -976
- package/lib/helpers/android.ts +0 -1153
- package/lib/helpers/index.ts +0 -6
- package/lib/helpers/types.ts +0 -136
- package/lib/helpers/unlock.ts +0 -329
- 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 {
|
|
33
|
-
* @param {
|
|
34
|
-
* @param {
|
|
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 {
|
|
70
|
-
* @param {
|
|
71
|
-
* @param {
|
|
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
|