appium-android-driver 7.8.2 → 8.0.0
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 +115 -3
- 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 +142 -10
- 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 +1 -1
- 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 -442
- 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 -604
package/lib/commands/network.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {mixin} from './mixins';
|
|
2
1
|
import _ from 'lodash';
|
|
3
2
|
import {errors} from 'appium/driver';
|
|
4
3
|
import {util} from 'appium/support';
|
|
@@ -7,12 +6,6 @@ import B from 'bluebird';
|
|
|
7
6
|
const AIRPLANE_MODE_MASK = 0b001;
|
|
8
7
|
const WIFI_MASK = 0b010;
|
|
9
8
|
const DATA_MASK = 0b100;
|
|
10
|
-
// The value close to zero, but not zero, is needed
|
|
11
|
-
// to trick JSON generation and send a float value instead of an integer,
|
|
12
|
-
// This allows strictly-typed clients, like Java, to properly
|
|
13
|
-
// parse it. Otherwise float 0.0 is always represented as integer 0 in JS.
|
|
14
|
-
// The value must not be greater than DBL_EPSILON (https://opensource.apple.com/source/Libc/Libc-498/include/float.h)
|
|
15
|
-
const GEO_EPSILON = Number.MIN_VALUE;
|
|
16
9
|
const WIFI_KEY_NAME = 'wifi';
|
|
17
10
|
const DATA_KEY_NAME = 'data';
|
|
18
11
|
const AIRPLANE_MODE_KEY_NAME = 'airplaneMode';
|
|
@@ -23,239 +16,232 @@ const SUPPORTED_SERVICE_NAMES = /** @type {const} */ ([
|
|
|
23
16
|
]);
|
|
24
17
|
|
|
25
18
|
/**
|
|
26
|
-
* @
|
|
27
|
-
* @
|
|
19
|
+
* @this {import('../driver').AndroidDriver}
|
|
20
|
+
* @returns {Promise<number>}
|
|
28
21
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
export async function getNetworkConnection() {
|
|
23
|
+
this.log.info('Getting network connection');
|
|
24
|
+
let airplaneModeOn = await this.adb.isAirplaneModeOn();
|
|
25
|
+
let connection = airplaneModeOn ? AIRPLANE_MODE_MASK : 0;
|
|
26
|
+
|
|
27
|
+
// no need to check anything else if we are in airplane mode
|
|
28
|
+
if (!airplaneModeOn) {
|
|
29
|
+
let wifiOn = await this.isWifiOn();
|
|
30
|
+
connection |= wifiOn ? WIFI_MASK : 0;
|
|
31
|
+
let dataOn = await this.adb.isDataOn();
|
|
32
|
+
connection |= dataOn ? DATA_MASK : 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return connection;
|
|
36
|
+
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return connection;
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
async isWifiOn() {
|
|
47
|
-
return await this.adb.isWifiOn();
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
async mobileSetConnectivity(opts = {}) {
|
|
51
|
-
const {wifi, data, airplaneMode} = opts;
|
|
52
|
-
if (_.every([wifi, data, airplaneMode], _.isUndefined)) {
|
|
53
|
-
throw new errors.InvalidArgumentError(
|
|
54
|
-
`Either one of ${JSON.stringify(SUPPORTED_SERVICE_NAMES)} options must be provided`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const currentState = await this.mobileGetConnectivity({
|
|
59
|
-
services: /** @type {import('./types').ServiceType[]} */ ([
|
|
60
|
-
...(_.isUndefined(wifi) ? [] : [WIFI_KEY_NAME]),
|
|
61
|
-
...(_.isUndefined(data) ? [] : [DATA_KEY_NAME]),
|
|
62
|
-
...(_.isUndefined(airplaneMode) ? [] : [AIRPLANE_MODE_KEY_NAME]),
|
|
63
|
-
]),
|
|
64
|
-
});
|
|
65
|
-
/** @type {(Promise<any>|(() => Promise<any>))[]} */
|
|
66
|
-
const setters = [];
|
|
67
|
-
if (!_.isUndefined(wifi) && currentState.wifi !== Boolean(wifi)) {
|
|
68
|
-
setters.push(this.setWifiState(wifi));
|
|
69
|
-
}
|
|
70
|
-
if (!_.isUndefined(data) && currentState.data !== Boolean(data)) {
|
|
71
|
-
setters.push(this.setDataState(data));
|
|
72
|
-
}
|
|
73
|
-
if (!_.isUndefined(airplaneMode) && currentState.airplaneMode !== Boolean(airplaneMode)) {
|
|
74
|
-
setters.push(async () => {
|
|
75
|
-
await this.adb.setAirplaneMode(airplaneMode);
|
|
76
|
-
if ((await this.adb.getApiLevel()) < 30) {
|
|
77
|
-
await this.adb.broadcastAirplaneMode(airplaneMode);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (!_.isEmpty(setters)) {
|
|
82
|
-
await B.all(setters);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
async mobileGetConnectivity(opts = {}) {
|
|
87
|
-
let {services = SUPPORTED_SERVICE_NAMES} = opts;
|
|
88
|
-
const svcs = _.castArray(services);
|
|
89
|
-
const unsupportedServices = _.difference(services, SUPPORTED_SERVICE_NAMES);
|
|
90
|
-
if (!_.isEmpty(unsupportedServices)) {
|
|
91
|
-
throw new errors.InvalidArgumentError(
|
|
92
|
-
`${util.pluralize(
|
|
93
|
-
'Service name',
|
|
94
|
-
unsupportedServices.length,
|
|
95
|
-
false
|
|
96
|
-
)} ${unsupportedServices} ` +
|
|
97
|
-
`${
|
|
98
|
-
unsupportedServices.length === 1 ? 'is' : 'are'
|
|
99
|
-
} not known. Only the following services are ` +
|
|
100
|
-
`suported: ${SUPPORTED_SERVICE_NAMES}`
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const statePromises = {
|
|
105
|
-
wifi: B.resolve(svcs.includes(WIFI_KEY_NAME) ? this.adb.isWifiOn() : undefined),
|
|
106
|
-
data: B.resolve(svcs.includes(DATA_KEY_NAME) ? this.adb.isDataOn() : undefined),
|
|
107
|
-
airplaneMode: B.resolve(
|
|
108
|
-
svcs.includes(AIRPLANE_MODE_KEY_NAME) ? this.adb.isAirplaneModeOn() : undefined
|
|
109
|
-
),
|
|
110
|
-
};
|
|
111
|
-
await B.all(_.values(statePromises));
|
|
112
|
-
return {
|
|
113
|
-
wifi: Boolean(statePromises.wifi.value()),
|
|
114
|
-
data: Boolean(statePromises.data.value()),
|
|
115
|
-
airplaneMode: Boolean(statePromises.airplaneMode.value()),
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
async setNetworkConnection(type) {
|
|
120
|
-
this.log.info('Setting network connection');
|
|
121
|
-
// decode the input
|
|
122
|
-
const shouldEnableAirplaneMode = (type & AIRPLANE_MODE_MASK) !== 0;
|
|
123
|
-
const shouldEnableWifi = (type & WIFI_MASK) !== 0;
|
|
124
|
-
const shouldEnableDataConnection = (type & DATA_MASK) !== 0;
|
|
125
|
-
|
|
126
|
-
const currentState = await this.getNetworkConnection();
|
|
127
|
-
const isAirplaneModeEnabled = (currentState & AIRPLANE_MODE_MASK) !== 0;
|
|
128
|
-
const isWiFiEnabled = (currentState & WIFI_MASK) !== 0;
|
|
129
|
-
const isDataEnabled = (currentState & DATA_MASK) !== 0;
|
|
38
|
+
/**
|
|
39
|
+
* @this {import('../driver').AndroidDriver}
|
|
40
|
+
* @returns {Promise<boolean>}
|
|
41
|
+
*/
|
|
42
|
+
export async function isWifiOn() {
|
|
43
|
+
return await this.adb.isWifiOn();
|
|
44
|
+
}
|
|
130
45
|
|
|
131
|
-
|
|
132
|
-
|
|
46
|
+
/**
|
|
47
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
48
|
+
* @this {import('../driver').AndroidDriver}
|
|
49
|
+
* @param {import('./types').SetConnectivityOpts} [opts={}]
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
export async function mobileSetConnectivity(opts = {}) {
|
|
53
|
+
const {wifi, data, airplaneMode} = opts;
|
|
54
|
+
if (_.every([wifi, data, airplaneMode], _.isUndefined)) {
|
|
55
|
+
throw new errors.InvalidArgumentError(
|
|
56
|
+
`Either one of ${JSON.stringify(SUPPORTED_SERVICE_NAMES)} options must be provided`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const currentState = await this.mobileGetConnectivity({
|
|
61
|
+
services: /** @type {import('./types').ServiceType[]} */ ([
|
|
62
|
+
...(_.isUndefined(wifi) ? [] : [WIFI_KEY_NAME]),
|
|
63
|
+
...(_.isUndefined(data) ? [] : [DATA_KEY_NAME]),
|
|
64
|
+
...(_.isUndefined(airplaneMode) ? [] : [AIRPLANE_MODE_KEY_NAME]),
|
|
65
|
+
]),
|
|
66
|
+
});
|
|
67
|
+
/** @type {(Promise<any>|(() => Promise<any>))[]} */
|
|
68
|
+
const setters = [];
|
|
69
|
+
if (!_.isUndefined(wifi) && currentState.wifi !== Boolean(wifi)) {
|
|
70
|
+
setters.push(this.setWifiState(wifi));
|
|
71
|
+
}
|
|
72
|
+
if (!_.isUndefined(data) && currentState.data !== Boolean(data)) {
|
|
73
|
+
setters.push(this.setDataState(data));
|
|
74
|
+
}
|
|
75
|
+
if (!_.isUndefined(airplaneMode) && currentState.airplaneMode !== Boolean(airplaneMode)) {
|
|
76
|
+
setters.push(async () => {
|
|
77
|
+
await this.adb.setAirplaneMode(airplaneMode);
|
|
133
78
|
if ((await this.adb.getApiLevel()) < 30) {
|
|
134
|
-
await this.adb.broadcastAirplaneMode(
|
|
79
|
+
await this.adb.broadcastAirplaneMode(airplaneMode);
|
|
135
80
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (shouldEnableWifi === isWiFiEnabled && shouldEnableDataConnection === isDataEnabled) {
|
|
145
|
-
this.log.info(
|
|
146
|
-
'Not changing data connection/Wi-Fi states, since they are already set to expected values'
|
|
147
|
-
);
|
|
148
|
-
if (await this.adb.isAirplaneModeOn()) {
|
|
149
|
-
return AIRPLANE_MODE_MASK | currentState;
|
|
150
|
-
}
|
|
151
|
-
return ~AIRPLANE_MODE_MASK & currentState;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (shouldEnableWifi !== isWiFiEnabled) {
|
|
155
|
-
await this.setWifiState(shouldEnableWifi);
|
|
156
|
-
} else {
|
|
157
|
-
this.log.info(
|
|
158
|
-
`Not changing Wi-Fi state, since it is already ` +
|
|
159
|
-
`${shouldEnableWifi ? 'enabled' : 'disabled'}`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (shouldEnableAirplaneMode) {
|
|
164
|
-
this.log.info('Not changing data connection state, because airplane mode is enabled');
|
|
165
|
-
} else if (shouldEnableDataConnection === isDataEnabled) {
|
|
166
|
-
this.log.info(
|
|
167
|
-
`Not changing data connection state, since it is already ` +
|
|
168
|
-
`${shouldEnableDataConnection ? 'enabled' : 'disabled'}`
|
|
169
|
-
);
|
|
170
|
-
} else {
|
|
171
|
-
await this.setDataState(shouldEnableDataConnection);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return await this.getNetworkConnection();
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
async setWifiState(isOn) {
|
|
178
|
-
await this.settingsApp.setWifiState(isOn, this.isEmulator());
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
async setDataState(isOn) {
|
|
182
|
-
await this.settingsApp.setDataState(isOn, this.isEmulator());
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
async toggleData() {
|
|
186
|
-
const isOn = await this.adb.isDataOn();
|
|
187
|
-
this.log.info(`Turning network data ${!isOn ? 'on' : 'off'}`);
|
|
188
|
-
await this.setDataState(!isOn);
|
|
189
|
-
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!_.isEmpty(setters)) {
|
|
84
|
+
await B.all(setters);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
190
87
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
88
|
+
/**
|
|
89
|
+
* @this {import('../driver').AndroidDriver}
|
|
90
|
+
* @param {import('./types').GetConnectivityOpts} [opts={}]
|
|
91
|
+
* @returns {Promise<import('./types').GetConnectivityResult>}
|
|
92
|
+
*/
|
|
93
|
+
export async function mobileGetConnectivity(opts = {}) {
|
|
94
|
+
let {services = SUPPORTED_SERVICE_NAMES} = opts;
|
|
95
|
+
const svcs = _.castArray(services);
|
|
96
|
+
const unsupportedServices = _.difference(services, SUPPORTED_SERVICE_NAMES);
|
|
97
|
+
if (!_.isEmpty(unsupportedServices)) {
|
|
98
|
+
throw new errors.InvalidArgumentError(
|
|
99
|
+
`${util.pluralize(
|
|
100
|
+
'Service name',
|
|
101
|
+
unsupportedServices.length,
|
|
102
|
+
false,
|
|
103
|
+
)} ${unsupportedServices} ` +
|
|
104
|
+
`${
|
|
105
|
+
unsupportedServices.length === 1 ? 'is' : 'are'
|
|
106
|
+
} not known. Only the following services are ` +
|
|
107
|
+
`suported: ${SUPPORTED_SERVICE_NAMES}`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const statePromises = {
|
|
112
|
+
wifi: B.resolve(svcs.includes(WIFI_KEY_NAME) ? this.adb.isWifiOn() : undefined),
|
|
113
|
+
data: B.resolve(svcs.includes(DATA_KEY_NAME) ? this.adb.isDataOn() : undefined),
|
|
114
|
+
airplaneMode: B.resolve(
|
|
115
|
+
svcs.includes(AIRPLANE_MODE_KEY_NAME) ? this.adb.isAirplaneModeOn() : undefined,
|
|
116
|
+
),
|
|
117
|
+
};
|
|
118
|
+
await B.all(_.values(statePromises));
|
|
119
|
+
return {
|
|
120
|
+
wifi: Boolean(statePromises.wifi.value()),
|
|
121
|
+
data: Boolean(statePromises.data.value()),
|
|
122
|
+
airplaneMode: Boolean(statePromises.airplaneMode.value()),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
196
125
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
126
|
+
/**
|
|
127
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
128
|
+
* @this {import('../driver').AndroidDriver}
|
|
129
|
+
* @param {number} type
|
|
130
|
+
* @returns {Promise<number>}
|
|
131
|
+
*/
|
|
132
|
+
export async function setNetworkConnection(type) {
|
|
133
|
+
this.log.info('Setting network connection');
|
|
134
|
+
// decode the input
|
|
135
|
+
const shouldEnableAirplaneMode = (type & AIRPLANE_MODE_MASK) !== 0;
|
|
136
|
+
const shouldEnableWifi = (type & WIFI_MASK) !== 0;
|
|
137
|
+
const shouldEnableDataConnection = (type & DATA_MASK) !== 0;
|
|
138
|
+
|
|
139
|
+
const currentState = await this.getNetworkConnection();
|
|
140
|
+
const isAirplaneModeEnabled = (currentState & AIRPLANE_MODE_MASK) !== 0;
|
|
141
|
+
const isWiFiEnabled = (currentState & WIFI_MASK) !== 0;
|
|
142
|
+
const isDataEnabled = (currentState & DATA_MASK) !== 0;
|
|
143
|
+
|
|
144
|
+
if (shouldEnableAirplaneMode !== isAirplaneModeEnabled) {
|
|
145
|
+
await this.adb.setAirplaneMode(shouldEnableAirplaneMode);
|
|
205
146
|
if ((await this.adb.getApiLevel()) < 30) {
|
|
206
|
-
await this.adb.broadcastAirplaneMode(
|
|
147
|
+
await this.adb.broadcastAirplaneMode(shouldEnableAirplaneMode);
|
|
207
148
|
}
|
|
208
|
-
}
|
|
149
|
+
} else {
|
|
150
|
+
this.log.info(
|
|
151
|
+
`Not changing airplane mode, since it is already ${
|
|
152
|
+
shouldEnableAirplaneMode ? 'enabled' : 'disabled'
|
|
153
|
+
}`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
209
156
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
`Could not get the current geolocation info: ${/** @type {Error} */ (e).message}`
|
|
217
|
-
);
|
|
218
|
-
this.log.warn(`Returning the default zero'ed values`);
|
|
219
|
-
return {
|
|
220
|
-
latitude: GEO_EPSILON,
|
|
221
|
-
longitude: GEO_EPSILON,
|
|
222
|
-
altitude: GEO_EPSILON,
|
|
223
|
-
};
|
|
157
|
+
if (shouldEnableWifi === isWiFiEnabled && shouldEnableDataConnection === isDataEnabled) {
|
|
158
|
+
this.log.info(
|
|
159
|
+
'Not changing data connection/Wi-Fi states, since they are already set to expected values',
|
|
160
|
+
);
|
|
161
|
+
if (await this.adb.isAirplaneModeOn()) {
|
|
162
|
+
return AIRPLANE_MODE_MASK | currentState;
|
|
224
163
|
}
|
|
225
|
-
|
|
164
|
+
return ~AIRPLANE_MODE_MASK & currentState;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (shouldEnableWifi !== isWiFiEnabled) {
|
|
168
|
+
await this.setWifiState(shouldEnableWifi);
|
|
169
|
+
} else {
|
|
170
|
+
this.log.info(
|
|
171
|
+
`Not changing Wi-Fi state, since it is already ` +
|
|
172
|
+
`${shouldEnableWifi ? 'enabled' : 'disabled'}`,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (shouldEnableAirplaneMode) {
|
|
177
|
+
this.log.info('Not changing data connection state, because airplane mode is enabled');
|
|
178
|
+
} else if (shouldEnableDataConnection === isDataEnabled) {
|
|
179
|
+
this.log.info(
|
|
180
|
+
`Not changing data connection state, since it is already ` +
|
|
181
|
+
`${shouldEnableDataConnection ? 'enabled' : 'disabled'}`,
|
|
182
|
+
);
|
|
183
|
+
} else {
|
|
184
|
+
await this.setDataState(shouldEnableDataConnection);
|
|
185
|
+
}
|
|
226
186
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
await this.settingsApp.refreshGeoLocationCache(timeoutMs);
|
|
230
|
-
},
|
|
187
|
+
return await this.getNetworkConnection();
|
|
188
|
+
}
|
|
231
189
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
190
|
+
/**
|
|
191
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
192
|
+
* @this {import('../driver').AndroidDriver}
|
|
193
|
+
* @param {boolean} isOn
|
|
194
|
+
* @returns {Promise<void>}
|
|
195
|
+
*/
|
|
196
|
+
export async function setWifiState(isOn) {
|
|
197
|
+
await this.settingsApp.setWifiState(isOn, this.isEmulator());
|
|
198
|
+
}
|
|
240
199
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
200
|
+
/**
|
|
201
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
202
|
+
* @this {import('../driver').AndroidDriver}
|
|
203
|
+
* @param {boolean} isOn
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*/
|
|
206
|
+
export async function setDataState(isOn) {
|
|
207
|
+
await this.settingsApp.setDataState(isOn, this.isEmulator());
|
|
208
|
+
}
|
|
244
209
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
210
|
+
/**
|
|
211
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
212
|
+
* @this {import('../driver').AndroidDriver}
|
|
213
|
+
* @returns {Promise<void>}
|
|
214
|
+
*/
|
|
215
|
+
export async function toggleData() {
|
|
216
|
+
const isOn = await this.adb.isDataOn();
|
|
217
|
+
this.log.info(`Turning network data ${!isOn ? 'on' : 'off'}`);
|
|
218
|
+
await this.setDataState(!isOn);
|
|
219
|
+
}
|
|
255
220
|
|
|
256
|
-
|
|
221
|
+
/**
|
|
222
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
223
|
+
* @this {import('../driver').AndroidDriver}
|
|
224
|
+
* @returns {Promise<void>}
|
|
225
|
+
*/
|
|
226
|
+
export async function toggleWiFi() {
|
|
227
|
+
const isOn = await this.adb.isWifiOn();
|
|
228
|
+
this.log.info(`Turning WiFi ${!isOn ? 'on' : 'off'}`);
|
|
229
|
+
await this.setWifiState(!isOn);
|
|
230
|
+
}
|
|
257
231
|
|
|
258
|
-
|
|
232
|
+
/**
|
|
233
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
234
|
+
* @this {import('../driver').AndroidDriver}
|
|
235
|
+
* @returns {Promise<void>}
|
|
236
|
+
*/
|
|
237
|
+
export async function toggleFlightMode() {
|
|
238
|
+
let flightMode = !(await this.adb.isAirplaneModeOn());
|
|
239
|
+
this.log.info(`Turning flight mode ${flightMode ? 'on' : 'off'}`);
|
|
240
|
+
await this.adb.setAirplaneMode(flightMode);
|
|
241
|
+
if ((await this.adb.getApiLevel()) < 30) {
|
|
242
|
+
await this.adb.broadcastAirplaneMode(flightMode);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
259
245
|
|
|
260
246
|
/**
|
|
261
247
|
* @typedef {import('appium-adb').ADB} ADB
|