appium-android-driver 7.8.3 → 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 +25 -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 +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 -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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @this {import('../driver').AndroidDriver}
|
|
3
|
+
* @returns {Promise<import('@appium/types').Size>}
|
|
4
|
+
*/
|
|
5
|
+
export function getWindowSize(this: import("../driver").AndroidDriver): Promise<import('@appium/types').Size>;
|
|
6
|
+
/**
|
|
7
|
+
* @this {import('../driver').AndroidDriver}
|
|
8
|
+
* @returns {Promise<import('@appium/types').Rect>}
|
|
9
|
+
*/
|
|
10
|
+
export function getWindowRect(this: import("../driver").AndroidDriver): Promise<import('@appium/types').Rect>;
|
|
11
|
+
/**
|
|
12
|
+
* we override setUrl to take an android URI which can be used for deep-linking
|
|
13
|
+
* inside an app, similar to starting an intent
|
|
14
|
+
*
|
|
15
|
+
* @this {import('../driver').AndroidDriver}
|
|
16
|
+
* @param {string} uri
|
|
17
|
+
* @returns {Promise<void>}
|
|
18
|
+
*/
|
|
19
|
+
export function setUrl(this: import("../driver").AndroidDriver, uri: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* @this {import('../driver').AndroidDriver}
|
|
22
|
+
* @returns {Promise<number>}
|
|
23
|
+
*/
|
|
24
|
+
export function getDisplayDensity(this: import("../driver").AndroidDriver): Promise<number>;
|
|
25
|
+
/**
|
|
26
|
+
* @this {import('../driver').AndroidDriver}
|
|
27
|
+
* @returns {Promise<StringRecord>}
|
|
28
|
+
*/
|
|
29
|
+
export function mobileGetNotifications(this: import("../driver").AndroidDriver): Promise<StringRecord>;
|
|
30
|
+
/**
|
|
31
|
+
* @this {import('../driver').AndroidDriver}
|
|
32
|
+
* @returns {Promise<import('./types').SmsListResult>}
|
|
33
|
+
*/
|
|
34
|
+
export function mobileListSms(this: import("../driver").AndroidDriver, opts: any): Promise<import('./types').SmsListResult>;
|
|
35
|
+
/**
|
|
36
|
+
* @this {import('../driver').AndroidDriver}
|
|
37
|
+
* @returns {Promise<void>}
|
|
38
|
+
*/
|
|
39
|
+
export function openNotifications(this: import("../driver").AndroidDriver): Promise<void>;
|
|
40
|
+
export type ADB = import('appium-adb').ADB;
|
|
41
|
+
export type StringRecord = import('@appium/types').StringRecord;
|
|
42
|
+
//# sourceMappingURL=misc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../lib/commands/misc.js"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wEAFa,QAAQ,OAAO,eAAe,EAAE,IAAI,CAAC,CAIjD;AAED;;;GAGG;AACH,wEAFa,QAAQ,OAAO,eAAe,EAAE,IAAI,CAAC,CAUjD;AAED;;;;;;;GAOG;AACH,qEAHW,MAAM,GACJ,QAAQ,IAAI,CAAC,CAIzB;AAED;;;GAGG;AACH,4EAFa,QAAQ,MAAM,CAAC,CAwB3B;AAED;;;GAGG;AACH,iFAFa,QAAQ,YAAY,CAAC,CAIjC;AAED;;;GAGG;AACH,mFAFa,QAAQ,OAAO,SAAS,EAAE,aAAa,CAAC,CAIpD;AAED;;;GAGG;AACH,4EAFa,QAAQ,IAAI,CAAC,CAIzB;kBAGY,OAAO,YAAY,EAAE,GAAG;2BACxB,OAAO,eAAe,EAAE,YAAY"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.openNotifications = exports.mobileListSms = exports.mobileGetNotifications = exports.getDisplayDensity = exports.setUrl = exports.getWindowRect = exports.getWindowSize = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const driver_1 = require("appium/driver");
|
|
10
|
+
/**
|
|
11
|
+
* @this {import('../driver').AndroidDriver}
|
|
12
|
+
* @returns {Promise<import('@appium/types').Size>}
|
|
13
|
+
*/
|
|
14
|
+
async function getWindowSize() {
|
|
15
|
+
throw new driver_1.errors.NotImplementedError('Not implemented');
|
|
16
|
+
}
|
|
17
|
+
exports.getWindowSize = getWindowSize;
|
|
18
|
+
/**
|
|
19
|
+
* @this {import('../driver').AndroidDriver}
|
|
20
|
+
* @returns {Promise<import('@appium/types').Rect>}
|
|
21
|
+
*/
|
|
22
|
+
async function getWindowRect() {
|
|
23
|
+
const { width, height } = await this.getWindowSize();
|
|
24
|
+
return {
|
|
25
|
+
width,
|
|
26
|
+
height,
|
|
27
|
+
x: 0,
|
|
28
|
+
y: 0,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.getWindowRect = getWindowRect;
|
|
32
|
+
/**
|
|
33
|
+
* we override setUrl to take an android URI which can be used for deep-linking
|
|
34
|
+
* inside an app, similar to starting an intent
|
|
35
|
+
*
|
|
36
|
+
* @this {import('../driver').AndroidDriver}
|
|
37
|
+
* @param {string} uri
|
|
38
|
+
* @returns {Promise<void>}
|
|
39
|
+
*/
|
|
40
|
+
async function setUrl(uri) {
|
|
41
|
+
await this.adb.startUri(uri, /** @type {string} */ (this.opts.appPackage));
|
|
42
|
+
}
|
|
43
|
+
exports.setUrl = setUrl;
|
|
44
|
+
/**
|
|
45
|
+
* @this {import('../driver').AndroidDriver}
|
|
46
|
+
* @returns {Promise<number>}
|
|
47
|
+
*/
|
|
48
|
+
async function getDisplayDensity() {
|
|
49
|
+
// first try the property for devices
|
|
50
|
+
let out = await this.adb.shell(['getprop', 'ro.sf.lcd_density']);
|
|
51
|
+
if (out) {
|
|
52
|
+
let val = parseInt(out, 10);
|
|
53
|
+
// if the value is NaN, try getting the emulator property
|
|
54
|
+
if (!isNaN(val)) {
|
|
55
|
+
return val;
|
|
56
|
+
}
|
|
57
|
+
this.log.debug(`Parsed density value was NaN: "${out}"`);
|
|
58
|
+
}
|
|
59
|
+
// fallback to trying property for emulators
|
|
60
|
+
out = await this.adb.shell(['getprop', 'qemu.sf.lcd_density']);
|
|
61
|
+
if (out) {
|
|
62
|
+
let val = parseInt(out, 10);
|
|
63
|
+
if (!isNaN(val)) {
|
|
64
|
+
return val;
|
|
65
|
+
}
|
|
66
|
+
this.log.debug(`Parsed density value was NaN: "${out}"`);
|
|
67
|
+
}
|
|
68
|
+
// couldn't get anything, so error out
|
|
69
|
+
throw this.log.errorAndThrow('Failed to get display density property.');
|
|
70
|
+
}
|
|
71
|
+
exports.getDisplayDensity = getDisplayDensity;
|
|
72
|
+
/**
|
|
73
|
+
* @this {import('../driver').AndroidDriver}
|
|
74
|
+
* @returns {Promise<StringRecord>}
|
|
75
|
+
*/
|
|
76
|
+
async function mobileGetNotifications() {
|
|
77
|
+
return await this.settingsApp.getNotifications();
|
|
78
|
+
}
|
|
79
|
+
exports.mobileGetNotifications = mobileGetNotifications;
|
|
80
|
+
/**
|
|
81
|
+
* @this {import('../driver').AndroidDriver}
|
|
82
|
+
* @returns {Promise<import('./types').SmsListResult>}
|
|
83
|
+
*/
|
|
84
|
+
async function mobileListSms(opts) {
|
|
85
|
+
return await this.settingsApp.getSmsList(opts);
|
|
86
|
+
}
|
|
87
|
+
exports.mobileListSms = mobileListSms;
|
|
88
|
+
/**
|
|
89
|
+
* @this {import('../driver').AndroidDriver}
|
|
90
|
+
* @returns {Promise<void>}
|
|
91
|
+
*/
|
|
92
|
+
async function openNotifications() {
|
|
93
|
+
throw new driver_1.errors.NotImplementedError('Not implemented');
|
|
94
|
+
}
|
|
95
|
+
exports.openNotifications = openNotifications;
|
|
96
|
+
/**
|
|
97
|
+
* @typedef {import('appium-adb').ADB} ADB
|
|
98
|
+
* @typedef {import('@appium/types').StringRecord} StringRecord
|
|
99
|
+
*/
|
|
100
|
+
//# sourceMappingURL=misc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../../lib/commands/misc.js"],"names":[],"mappings":";;;;;;AAAA,sDAAsD;AACtD,oDAAuB;AACvB,0CAAqC;AAErC;;;GAGG;AACI,KAAK,UAAU,aAAa;IACjC,MAAM,IAAI,eAAM,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;AAC1D,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACI,KAAK,UAAU,aAAa;IACjC,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;IACnD,OAAO;QACL,KAAK;QACL,MAAM;QACN,CAAC,EAAE,CAAC;QACJ,CAAC,EAAE,CAAC;KACL,CAAC;AACJ,CAAC;AARD,sCAQC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,MAAM,CAAC,GAAG;IAC9B,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;AAC7E,CAAC;AAFD,wBAEC;AAED;;;GAGG;AACI,KAAK,UAAU,iBAAiB;IACrC,qCAAqC;IACrC,IAAI,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC;IACjE,IAAI,GAAG,EAAE;QACP,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC5B,yDAAyD;QACzD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;YACf,OAAO,GAAG,CAAC;SACZ;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kCAAkC,GAAG,GAAG,CAAC,CAAC;KAC1D;IACD,4CAA4C;IAC5C,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAC/D,IAAI,GAAG,EAAE;QACP,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;YACf,OAAO,GAAG,CAAC;SACZ;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kCAAkC,GAAG,GAAG,CAAC,CAAC;KAC1D;IACD,sCAAsC;IACtC,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,yCAAyC,CAAC,CAAC;AAC1E,CAAC;AAtBD,8CAsBC;AAED;;;GAGG;AACI,KAAK,UAAU,sBAAsB;IAC1C,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC;AACnD,CAAC;AAFD,wDAEC;AAED;;;GAGG;AACI,KAAK,UAAU,aAAa,CAAC,IAAI;IACtC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACI,KAAK,UAAU,iBAAiB;IACrC,MAAM,IAAI,eAAM,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;AAC1D,CAAC;AAFD,8CAEC;AAED;;;GAGG"}
|
|
@@ -1,8 +1,64 @@
|
|
|
1
|
-
export default NetworkMixin;
|
|
2
|
-
export type ADB = import('appium-adb').ADB;
|
|
3
1
|
/**
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
2
|
+
* @this {import('../driver').AndroidDriver}
|
|
3
|
+
* @returns {Promise<number>}
|
|
4
|
+
*/
|
|
5
|
+
export function getNetworkConnection(this: import("../driver").AndroidDriver): Promise<number>;
|
|
6
|
+
/**
|
|
7
|
+
* @this {import('../driver').AndroidDriver}
|
|
8
|
+
* @returns {Promise<boolean>}
|
|
9
|
+
*/
|
|
10
|
+
export function isWifiOn(this: import("../driver").AndroidDriver): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
13
|
+
* @this {import('../driver').AndroidDriver}
|
|
14
|
+
* @param {import('./types').SetConnectivityOpts} [opts={}]
|
|
15
|
+
* @returns {Promise<void>}
|
|
16
|
+
*/
|
|
17
|
+
export function mobileSetConnectivity(this: import("../driver").AndroidDriver, opts?: import("./types").SetConnectivityOpts | undefined): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* @this {import('../driver').AndroidDriver}
|
|
20
|
+
* @param {import('./types').GetConnectivityOpts} [opts={}]
|
|
21
|
+
* @returns {Promise<import('./types').GetConnectivityResult>}
|
|
22
|
+
*/
|
|
23
|
+
export function mobileGetConnectivity(this: import("../driver").AndroidDriver, opts?: import("./types").GetConnectivityOpts | undefined): Promise<import('./types').GetConnectivityResult>;
|
|
24
|
+
/**
|
|
25
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
26
|
+
* @this {import('../driver').AndroidDriver}
|
|
27
|
+
* @param {number} type
|
|
28
|
+
* @returns {Promise<number>}
|
|
29
|
+
*/
|
|
30
|
+
export function setNetworkConnection(this: import("../driver").AndroidDriver, type: number): Promise<number>;
|
|
31
|
+
/**
|
|
32
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
33
|
+
* @this {import('../driver').AndroidDriver}
|
|
34
|
+
* @param {boolean} isOn
|
|
35
|
+
* @returns {Promise<void>}
|
|
36
|
+
*/
|
|
37
|
+
export function setWifiState(this: import("../driver").AndroidDriver, isOn: boolean): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
40
|
+
* @this {import('../driver').AndroidDriver}
|
|
41
|
+
* @param {boolean} isOn
|
|
42
|
+
* @returns {Promise<void>}
|
|
43
|
+
*/
|
|
44
|
+
export function setDataState(this: import("../driver").AndroidDriver, isOn: boolean): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
47
|
+
* @this {import('../driver').AndroidDriver}
|
|
48
|
+
* @returns {Promise<void>}
|
|
6
49
|
*/
|
|
7
|
-
|
|
50
|
+
export function toggleData(this: import("../driver").AndroidDriver): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
53
|
+
* @this {import('../driver').AndroidDriver}
|
|
54
|
+
* @returns {Promise<void>}
|
|
55
|
+
*/
|
|
56
|
+
export function toggleWiFi(this: import("../driver").AndroidDriver): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
59
|
+
* @this {import('../driver').AndroidDriver}
|
|
60
|
+
* @returns {Promise<void>}
|
|
61
|
+
*/
|
|
62
|
+
export function toggleFlightMode(this: import("../driver").AndroidDriver): Promise<void>;
|
|
63
|
+
export type ADB = import('appium-adb').ADB;
|
|
8
64
|
//# sourceMappingURL=network.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../lib/commands/network.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../lib/commands/network.js"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,+EAFa,QAAQ,MAAM,CAAC,CAgB3B;AAED;;;GAGG;AACH,mEAFa,QAAQ,OAAO,CAAC,CAI5B;AAED;;;;;GAKG;AACH,0IAFa,QAAQ,IAAI,CAAC,CAoCzB;AAED;;;;GAIG;AACH,0IAFa,QAAQ,OAAO,SAAS,EAAE,qBAAqB,CAAC,CAiC5D;AAED;;;;;GAKG;AACH,oFAHW,MAAM,GACJ,QAAQ,MAAM,CAAC,CA0D3B;AAED;;;;;GAKG;AACH,4EAHW,OAAO,GACL,QAAQ,IAAI,CAAC,CAIzB;AAED;;;;;GAKG;AACH,4EAHW,OAAO,GACL,QAAQ,IAAI,CAAC,CAIzB;AAED;;;;GAIG;AACH,qEAFa,QAAQ,IAAI,CAAC,CAMzB;AAED;;;;GAIG;AACH,qEAFa,QAAQ,IAAI,CAAC,CAMzB;AAED;;;;GAIG;AACH,2EAFa,QAAQ,IAAI,CAAC,CASzB;kBAGY,OAAO,YAAY,EAAE,GAAG"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
exports.toggleFlightMode = exports.toggleWiFi = exports.toggleData = exports.setDataState = exports.setWifiState = exports.setNetworkConnection = exports.mobileGetConnectivity = exports.mobileSetConnectivity = exports.isWifiOn = exports.getNetworkConnection = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const driver_1 = require("appium/driver");
|
|
9
9
|
const support_1 = require("appium/support");
|
|
@@ -11,12 +11,6 @@ const bluebird_1 = __importDefault(require("bluebird"));
|
|
|
11
11
|
const AIRPLANE_MODE_MASK = 0b001;
|
|
12
12
|
const WIFI_MASK = 0b010;
|
|
13
13
|
const DATA_MASK = 0b100;
|
|
14
|
-
// The value close to zero, but not zero, is needed
|
|
15
|
-
// to trick JSON generation and send a float value instead of an integer,
|
|
16
|
-
// This allows strictly-typed clients, like Java, to properly
|
|
17
|
-
// parse it. Otherwise float 0.0 is always represented as integer 0 in JS.
|
|
18
|
-
// The value must not be greater than DBL_EPSILON (https://opensource.apple.com/source/Libc/Libc-498/include/float.h)
|
|
19
|
-
const GEO_EPSILON = Number.MIN_VALUE;
|
|
20
14
|
const WIFI_KEY_NAME = 'wifi';
|
|
21
15
|
const DATA_KEY_NAME = 'data';
|
|
22
16
|
const AIRPLANE_MODE_KEY_NAME = 'airplaneMode';
|
|
@@ -26,192 +20,205 @@ const SUPPORTED_SERVICE_NAMES = /** @type {const} */ ([
|
|
|
26
20
|
AIRPLANE_MODE_KEY_NAME,
|
|
27
21
|
]);
|
|
28
22
|
/**
|
|
29
|
-
* @
|
|
30
|
-
* @
|
|
23
|
+
* @this {import('../driver').AndroidDriver}
|
|
24
|
+
* @returns {Promise<number>}
|
|
31
25
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const svcs = lodash_1.default.castArray(services);
|
|
84
|
-
const unsupportedServices = lodash_1.default.difference(services, SUPPORTED_SERVICE_NAMES);
|
|
85
|
-
if (!lodash_1.default.isEmpty(unsupportedServices)) {
|
|
86
|
-
throw new driver_1.errors.InvalidArgumentError(`${support_1.util.pluralize('Service name', unsupportedServices.length, false)} ${unsupportedServices} ` +
|
|
87
|
-
`${unsupportedServices.length === 1 ? 'is' : 'are'} not known. Only the following services are ` +
|
|
88
|
-
`suported: ${SUPPORTED_SERVICE_NAMES}`);
|
|
89
|
-
}
|
|
90
|
-
const statePromises = {
|
|
91
|
-
wifi: bluebird_1.default.resolve(svcs.includes(WIFI_KEY_NAME) ? this.adb.isWifiOn() : undefined),
|
|
92
|
-
data: bluebird_1.default.resolve(svcs.includes(DATA_KEY_NAME) ? this.adb.isDataOn() : undefined),
|
|
93
|
-
airplaneMode: bluebird_1.default.resolve(svcs.includes(AIRPLANE_MODE_KEY_NAME) ? this.adb.isAirplaneModeOn() : undefined),
|
|
94
|
-
};
|
|
95
|
-
await bluebird_1.default.all(lodash_1.default.values(statePromises));
|
|
96
|
-
return {
|
|
97
|
-
wifi: Boolean(statePromises.wifi.value()),
|
|
98
|
-
data: Boolean(statePromises.data.value()),
|
|
99
|
-
airplaneMode: Boolean(statePromises.airplaneMode.value()),
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
async setNetworkConnection(type) {
|
|
103
|
-
this.log.info('Setting network connection');
|
|
104
|
-
// decode the input
|
|
105
|
-
const shouldEnableAirplaneMode = (type & AIRPLANE_MODE_MASK) !== 0;
|
|
106
|
-
const shouldEnableWifi = (type & WIFI_MASK) !== 0;
|
|
107
|
-
const shouldEnableDataConnection = (type & DATA_MASK) !== 0;
|
|
108
|
-
const currentState = await this.getNetworkConnection();
|
|
109
|
-
const isAirplaneModeEnabled = (currentState & AIRPLANE_MODE_MASK) !== 0;
|
|
110
|
-
const isWiFiEnabled = (currentState & WIFI_MASK) !== 0;
|
|
111
|
-
const isDataEnabled = (currentState & DATA_MASK) !== 0;
|
|
112
|
-
if (shouldEnableAirplaneMode !== isAirplaneModeEnabled) {
|
|
113
|
-
await this.adb.setAirplaneMode(shouldEnableAirplaneMode);
|
|
26
|
+
async function getNetworkConnection() {
|
|
27
|
+
this.log.info('Getting network connection');
|
|
28
|
+
let airplaneModeOn = await this.adb.isAirplaneModeOn();
|
|
29
|
+
let connection = airplaneModeOn ? AIRPLANE_MODE_MASK : 0;
|
|
30
|
+
// no need to check anything else if we are in airplane mode
|
|
31
|
+
if (!airplaneModeOn) {
|
|
32
|
+
let wifiOn = await this.isWifiOn();
|
|
33
|
+
connection |= wifiOn ? WIFI_MASK : 0;
|
|
34
|
+
let dataOn = await this.adb.isDataOn();
|
|
35
|
+
connection |= dataOn ? DATA_MASK : 0;
|
|
36
|
+
}
|
|
37
|
+
return connection;
|
|
38
|
+
}
|
|
39
|
+
exports.getNetworkConnection = getNetworkConnection;
|
|
40
|
+
/**
|
|
41
|
+
* @this {import('../driver').AndroidDriver}
|
|
42
|
+
* @returns {Promise<boolean>}
|
|
43
|
+
*/
|
|
44
|
+
async function isWifiOn() {
|
|
45
|
+
return await this.adb.isWifiOn();
|
|
46
|
+
}
|
|
47
|
+
exports.isWifiOn = isWifiOn;
|
|
48
|
+
/**
|
|
49
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
50
|
+
* @this {import('../driver').AndroidDriver}
|
|
51
|
+
* @param {import('./types').SetConnectivityOpts} [opts={}]
|
|
52
|
+
* @returns {Promise<void>}
|
|
53
|
+
*/
|
|
54
|
+
async function mobileSetConnectivity(opts = {}) {
|
|
55
|
+
const { wifi, data, airplaneMode } = opts;
|
|
56
|
+
if (lodash_1.default.every([wifi, data, airplaneMode], lodash_1.default.isUndefined)) {
|
|
57
|
+
throw new driver_1.errors.InvalidArgumentError(`Either one of ${JSON.stringify(SUPPORTED_SERVICE_NAMES)} options must be provided`);
|
|
58
|
+
}
|
|
59
|
+
const currentState = await this.mobileGetConnectivity({
|
|
60
|
+
services: /** @type {import('./types').ServiceType[]} */ ([
|
|
61
|
+
...(lodash_1.default.isUndefined(wifi) ? [] : [WIFI_KEY_NAME]),
|
|
62
|
+
...(lodash_1.default.isUndefined(data) ? [] : [DATA_KEY_NAME]),
|
|
63
|
+
...(lodash_1.default.isUndefined(airplaneMode) ? [] : [AIRPLANE_MODE_KEY_NAME]),
|
|
64
|
+
]),
|
|
65
|
+
});
|
|
66
|
+
/** @type {(Promise<any>|(() => Promise<any>))[]} */
|
|
67
|
+
const setters = [];
|
|
68
|
+
if (!lodash_1.default.isUndefined(wifi) && currentState.wifi !== Boolean(wifi)) {
|
|
69
|
+
setters.push(this.setWifiState(wifi));
|
|
70
|
+
}
|
|
71
|
+
if (!lodash_1.default.isUndefined(data) && currentState.data !== Boolean(data)) {
|
|
72
|
+
setters.push(this.setDataState(data));
|
|
73
|
+
}
|
|
74
|
+
if (!lodash_1.default.isUndefined(airplaneMode) && currentState.airplaneMode !== Boolean(airplaneMode)) {
|
|
75
|
+
setters.push(async () => {
|
|
76
|
+
await this.adb.setAirplaneMode(airplaneMode);
|
|
114
77
|
if ((await this.adb.getApiLevel()) < 30) {
|
|
115
|
-
await this.adb.broadcastAirplaneMode(
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this.log.info(`Not changing airplane mode, since it is already ${shouldEnableAirplaneMode ? 'enabled' : 'disabled'}`);
|
|
120
|
-
}
|
|
121
|
-
if (shouldEnableWifi === isWiFiEnabled && shouldEnableDataConnection === isDataEnabled) {
|
|
122
|
-
this.log.info('Not changing data connection/Wi-Fi states, since they are already set to expected values');
|
|
123
|
-
if (await this.adb.isAirplaneModeOn()) {
|
|
124
|
-
return AIRPLANE_MODE_MASK | currentState;
|
|
78
|
+
await this.adb.broadcastAirplaneMode(airplaneMode);
|
|
125
79
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (!lodash_1.default.isEmpty(setters)) {
|
|
83
|
+
await bluebird_1.default.all(setters);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.mobileSetConnectivity = mobileSetConnectivity;
|
|
87
|
+
/**
|
|
88
|
+
* @this {import('../driver').AndroidDriver}
|
|
89
|
+
* @param {import('./types').GetConnectivityOpts} [opts={}]
|
|
90
|
+
* @returns {Promise<import('./types').GetConnectivityResult>}
|
|
91
|
+
*/
|
|
92
|
+
async function mobileGetConnectivity(opts = {}) {
|
|
93
|
+
let { services = SUPPORTED_SERVICE_NAMES } = opts;
|
|
94
|
+
const svcs = lodash_1.default.castArray(services);
|
|
95
|
+
const unsupportedServices = lodash_1.default.difference(services, SUPPORTED_SERVICE_NAMES);
|
|
96
|
+
if (!lodash_1.default.isEmpty(unsupportedServices)) {
|
|
97
|
+
throw new driver_1.errors.InvalidArgumentError(`${support_1.util.pluralize('Service name', unsupportedServices.length, false)} ${unsupportedServices} ` +
|
|
98
|
+
`${unsupportedServices.length === 1 ? 'is' : 'are'} not known. Only the following services are ` +
|
|
99
|
+
`suported: ${SUPPORTED_SERVICE_NAMES}`);
|
|
100
|
+
}
|
|
101
|
+
const statePromises = {
|
|
102
|
+
wifi: bluebird_1.default.resolve(svcs.includes(WIFI_KEY_NAME) ? this.adb.isWifiOn() : undefined),
|
|
103
|
+
data: bluebird_1.default.resolve(svcs.includes(DATA_KEY_NAME) ? this.adb.isDataOn() : undefined),
|
|
104
|
+
airplaneMode: bluebird_1.default.resolve(svcs.includes(AIRPLANE_MODE_KEY_NAME) ? this.adb.isAirplaneModeOn() : undefined),
|
|
105
|
+
};
|
|
106
|
+
await bluebird_1.default.all(lodash_1.default.values(statePromises));
|
|
107
|
+
return {
|
|
108
|
+
wifi: Boolean(statePromises.wifi.value()),
|
|
109
|
+
data: Boolean(statePromises.data.value()),
|
|
110
|
+
airplaneMode: Boolean(statePromises.airplaneMode.value()),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
exports.mobileGetConnectivity = mobileGetConnectivity;
|
|
114
|
+
/**
|
|
115
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
116
|
+
* @this {import('../driver').AndroidDriver}
|
|
117
|
+
* @param {number} type
|
|
118
|
+
* @returns {Promise<number>}
|
|
119
|
+
*/
|
|
120
|
+
async function setNetworkConnection(type) {
|
|
121
|
+
this.log.info('Setting network connection');
|
|
122
|
+
// decode the input
|
|
123
|
+
const shouldEnableAirplaneMode = (type & AIRPLANE_MODE_MASK) !== 0;
|
|
124
|
+
const shouldEnableWifi = (type & WIFI_MASK) !== 0;
|
|
125
|
+
const shouldEnableDataConnection = (type & DATA_MASK) !== 0;
|
|
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;
|
|
130
|
+
if (shouldEnableAirplaneMode !== isAirplaneModeEnabled) {
|
|
131
|
+
await this.adb.setAirplaneMode(shouldEnableAirplaneMode);
|
|
171
132
|
if ((await this.adb.getApiLevel()) < 30) {
|
|
172
|
-
await this.adb.broadcastAirplaneMode(
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
exports.
|
|
133
|
+
await this.adb.broadcastAirplaneMode(shouldEnableAirplaneMode);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
this.log.info(`Not changing airplane mode, since it is already ${shouldEnableAirplaneMode ? 'enabled' : 'disabled'}`);
|
|
138
|
+
}
|
|
139
|
+
if (shouldEnableWifi === isWiFiEnabled && shouldEnableDataConnection === isDataEnabled) {
|
|
140
|
+
this.log.info('Not changing data connection/Wi-Fi states, since they are already set to expected values');
|
|
141
|
+
if (await this.adb.isAirplaneModeOn()) {
|
|
142
|
+
return AIRPLANE_MODE_MASK | currentState;
|
|
143
|
+
}
|
|
144
|
+
return ~AIRPLANE_MODE_MASK & currentState;
|
|
145
|
+
}
|
|
146
|
+
if (shouldEnableWifi !== isWiFiEnabled) {
|
|
147
|
+
await this.setWifiState(shouldEnableWifi);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
this.log.info(`Not changing Wi-Fi state, since it is already ` +
|
|
151
|
+
`${shouldEnableWifi ? 'enabled' : 'disabled'}`);
|
|
152
|
+
}
|
|
153
|
+
if (shouldEnableAirplaneMode) {
|
|
154
|
+
this.log.info('Not changing data connection state, because airplane mode is enabled');
|
|
155
|
+
}
|
|
156
|
+
else if (shouldEnableDataConnection === isDataEnabled) {
|
|
157
|
+
this.log.info(`Not changing data connection state, since it is already ` +
|
|
158
|
+
`${shouldEnableDataConnection ? 'enabled' : 'disabled'}`);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
await this.setDataState(shouldEnableDataConnection);
|
|
162
|
+
}
|
|
163
|
+
return await this.getNetworkConnection();
|
|
164
|
+
}
|
|
165
|
+
exports.setNetworkConnection = setNetworkConnection;
|
|
166
|
+
/**
|
|
167
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
168
|
+
* @this {import('../driver').AndroidDriver}
|
|
169
|
+
* @param {boolean} isOn
|
|
170
|
+
* @returns {Promise<void>}
|
|
171
|
+
*/
|
|
172
|
+
async function setWifiState(isOn) {
|
|
173
|
+
await this.settingsApp.setWifiState(isOn, this.isEmulator());
|
|
174
|
+
}
|
|
175
|
+
exports.setWifiState = setWifiState;
|
|
176
|
+
/**
|
|
177
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
178
|
+
* @this {import('../driver').AndroidDriver}
|
|
179
|
+
* @param {boolean} isOn
|
|
180
|
+
* @returns {Promise<void>}
|
|
181
|
+
*/
|
|
182
|
+
async function setDataState(isOn) {
|
|
183
|
+
await this.settingsApp.setDataState(isOn, this.isEmulator());
|
|
184
|
+
}
|
|
185
|
+
exports.setDataState = setDataState;
|
|
186
|
+
/**
|
|
187
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
188
|
+
* @this {import('../driver').AndroidDriver}
|
|
189
|
+
* @returns {Promise<void>}
|
|
190
|
+
*/
|
|
191
|
+
async function toggleData() {
|
|
192
|
+
const isOn = await this.adb.isDataOn();
|
|
193
|
+
this.log.info(`Turning network data ${!isOn ? 'on' : 'off'}`);
|
|
194
|
+
await this.setDataState(!isOn);
|
|
195
|
+
}
|
|
196
|
+
exports.toggleData = toggleData;
|
|
197
|
+
/**
|
|
198
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
199
|
+
* @this {import('../driver').AndroidDriver}
|
|
200
|
+
* @returns {Promise<void>}
|
|
201
|
+
*/
|
|
202
|
+
async function toggleWiFi() {
|
|
203
|
+
const isOn = await this.adb.isWifiOn();
|
|
204
|
+
this.log.info(`Turning WiFi ${!isOn ? 'on' : 'off'}`);
|
|
205
|
+
await this.setWifiState(!isOn);
|
|
206
|
+
}
|
|
207
|
+
exports.toggleWiFi = toggleWiFi;
|
|
208
|
+
/**
|
|
209
|
+
* @since Android 12 (only real devices, emulators work in all APIs)
|
|
210
|
+
* @this {import('../driver').AndroidDriver}
|
|
211
|
+
* @returns {Promise<void>}
|
|
212
|
+
*/
|
|
213
|
+
async function toggleFlightMode() {
|
|
214
|
+
let flightMode = !(await this.adb.isAirplaneModeOn());
|
|
215
|
+
this.log.info(`Turning flight mode ${flightMode ? 'on' : 'off'}`);
|
|
216
|
+
await this.adb.setAirplaneMode(flightMode);
|
|
217
|
+
if ((await this.adb.getApiLevel()) < 30) {
|
|
218
|
+
await this.adb.broadcastAirplaneMode(flightMode);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.toggleFlightMode = toggleFlightMode;
|
|
215
222
|
/**
|
|
216
223
|
* @typedef {import('appium-adb').ADB} ADB
|
|
217
224
|
*/
|