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.
Files changed (261) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/build/lib/commands/app-management.d.ts +129 -5
  3. package/build/lib/commands/app-management.d.ts.map +1 -1
  4. package/build/lib/commands/app-management.js +433 -128
  5. package/build/lib/commands/app-management.js.map +1 -1
  6. package/build/lib/commands/appearance.d.ts +17 -4
  7. package/build/lib/commands/appearance.d.ts.map +1 -1
  8. package/build/lib/commands/appearance.js +32 -33
  9. package/build/lib/commands/appearance.js.map +1 -1
  10. package/build/lib/commands/context/cache.d.ts +19 -0
  11. package/build/lib/commands/context/cache.d.ts.map +1 -0
  12. package/build/lib/commands/context/cache.js +32 -0
  13. package/build/lib/commands/context/cache.js.map +1 -0
  14. package/build/lib/commands/context/exports.d.ts +141 -0
  15. package/build/lib/commands/context/exports.d.ts.map +1 -0
  16. package/build/lib/commands/context/exports.js +351 -0
  17. package/build/lib/commands/context/exports.js.map +1 -0
  18. package/build/lib/commands/context/helpers.d.ts +98 -0
  19. package/build/lib/commands/context/helpers.d.ts.map +1 -0
  20. package/build/lib/commands/context/helpers.js +715 -0
  21. package/build/lib/commands/context/helpers.js.map +1 -0
  22. package/build/lib/commands/device/common.d.ts +23 -0
  23. package/build/lib/commands/device/common.d.ts.map +1 -0
  24. package/build/lib/commands/device/common.js +230 -0
  25. package/build/lib/commands/device/common.js.map +1 -0
  26. package/build/lib/commands/device/emulator-actions.d.ts +114 -0
  27. package/build/lib/commands/device/emulator-actions.d.ts.map +1 -0
  28. package/build/lib/commands/device/emulator-actions.js +197 -0
  29. package/build/lib/commands/device/emulator-actions.js.map +1 -0
  30. package/build/lib/commands/device/emulator-console.d.ts +7 -0
  31. package/build/lib/commands/device/emulator-console.d.ts.map +1 -0
  32. package/build/lib/commands/device/emulator-console.js +24 -0
  33. package/build/lib/commands/device/emulator-console.js.map +1 -0
  34. package/build/lib/commands/device/utils.d.ts +50 -0
  35. package/build/lib/commands/device/utils.d.ts.map +1 -0
  36. package/build/lib/commands/device/utils.js +238 -0
  37. package/build/lib/commands/device/utils.js.map +1 -0
  38. package/build/lib/commands/deviceidle.d.ts +8 -5
  39. package/build/lib/commands/deviceidle.d.ts.map +1 -1
  40. package/build/lib/commands/deviceidle.js +31 -37
  41. package/build/lib/commands/deviceidle.js.map +1 -1
  42. package/build/lib/commands/element.d.ts +99 -5
  43. package/build/lib/commands/element.d.ts.map +1 -1
  44. package/build/lib/commands/element.js +152 -116
  45. package/build/lib/commands/element.js.map +1 -1
  46. package/build/lib/commands/execute.d.ts +12 -4
  47. package/build/lib/commands/execute.d.ts.map +1 -1
  48. package/build/lib/commands/execute.js +83 -78
  49. package/build/lib/commands/execute.js.map +1 -1
  50. package/build/lib/commands/file-actions.d.ts +42 -5
  51. package/build/lib/commands/file-actions.d.ts.map +1 -1
  52. package/build/lib/commands/file-actions.js +230 -194
  53. package/build/lib/commands/file-actions.js.map +1 -1
  54. package/build/lib/commands/find.d.ts +5 -4
  55. package/build/lib/commands/find.d.ts.map +1 -1
  56. package/build/lib/commands/find.js +7 -10
  57. package/build/lib/commands/find.js.map +1 -1
  58. package/build/lib/commands/geolocation.d.ts +45 -0
  59. package/build/lib/commands/geolocation.d.ts.map +1 -0
  60. package/build/lib/commands/geolocation.js +182 -0
  61. package/build/lib/commands/geolocation.js.map +1 -0
  62. package/build/lib/commands/ime.d.ts +25 -5
  63. package/build/lib/commands/ime.d.ts.map +1 -1
  64. package/build/lib/commands/ime.js +59 -42
  65. package/build/lib/commands/ime.js.map +1 -1
  66. package/build/lib/commands/intent.d.ts +56 -5
  67. package/build/lib/commands/intent.d.ts.map +1 -1
  68. package/build/lib/commands/intent.js +135 -83
  69. package/build/lib/commands/intent.js.map +1 -1
  70. package/build/lib/commands/keyboard.d.ts +58 -4
  71. package/build/lib/commands/keyboard.d.ts.map +1 -1
  72. package/build/lib/commands/keyboard.js +119 -17
  73. package/build/lib/commands/keyboard.js.map +1 -1
  74. package/build/lib/commands/lock/exports.d.ts +301 -0
  75. package/build/lib/commands/lock/exports.d.ts.map +1 -0
  76. package/build/lib/commands/lock/exports.js +121 -0
  77. package/build/lib/commands/lock/exports.js.map +1 -0
  78. package/build/lib/commands/lock/helpers.d.ts +349 -0
  79. package/build/lib/commands/lock/helpers.d.ts.map +1 -0
  80. package/build/lib/commands/lock/helpers.js +375 -0
  81. package/build/lib/commands/lock/helpers.js.map +1 -0
  82. package/build/lib/commands/log.d.ts +59 -5
  83. package/build/lib/commands/log.d.ts.map +1 -1
  84. package/build/lib/commands/log.js +150 -140
  85. package/build/lib/commands/log.js.map +1 -1
  86. package/build/lib/commands/media-projection.d.ts +16 -5
  87. package/build/lib/commands/media-projection.d.ts.map +1 -1
  88. package/build/lib/commands/media-projection.js +69 -58
  89. package/build/lib/commands/media-projection.js.map +1 -1
  90. package/build/lib/commands/memory.d.ts +9 -5
  91. package/build/lib/commands/memory.d.ts.map +1 -1
  92. package/build/lib/commands/memory.js +19 -24
  93. package/build/lib/commands/memory.js.map +1 -1
  94. package/build/lib/commands/misc.d.ts +42 -0
  95. package/build/lib/commands/misc.d.ts.map +1 -0
  96. package/build/lib/commands/misc.js +100 -0
  97. package/build/lib/commands/misc.js.map +1 -0
  98. package/build/lib/commands/network.d.ts +61 -5
  99. package/build/lib/commands/network.d.ts.map +1 -1
  100. package/build/lib/commands/network.js +196 -189
  101. package/build/lib/commands/network.js.map +1 -1
  102. package/build/lib/commands/performance.d.ts +67 -27
  103. package/build/lib/commands/performance.d.ts.map +1 -1
  104. package/build/lib/commands/performance.js +105 -80
  105. package/build/lib/commands/performance.js.map +1 -1
  106. package/build/lib/commands/permissions.d.ts +12 -6
  107. package/build/lib/commands/permissions.d.ts.map +1 -1
  108. package/build/lib/commands/permissions.js +65 -62
  109. package/build/lib/commands/permissions.js.map +1 -1
  110. package/build/lib/commands/recordscreen.d.ts +44 -5
  111. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  112. package/build/lib/commands/recordscreen.js +131 -126
  113. package/build/lib/commands/recordscreen.js.map +1 -1
  114. package/build/lib/commands/resources.d.ts +16 -0
  115. package/build/lib/commands/resources.d.ts.map +1 -0
  116. package/build/lib/commands/resources.js +91 -0
  117. package/build/lib/commands/resources.js.map +1 -0
  118. package/build/lib/commands/shell.d.ts +8 -5
  119. package/build/lib/commands/shell.d.ts.map +1 -1
  120. package/build/lib/commands/shell.js +29 -33
  121. package/build/lib/commands/shell.js.map +1 -1
  122. package/build/lib/commands/streamscreen.d.ts +34 -6
  123. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  124. package/build/lib/commands/streamscreen.js +166 -162
  125. package/build/lib/commands/streamscreen.js.map +1 -1
  126. package/build/lib/commands/system-bars.d.ts +18 -13
  127. package/build/lib/commands/system-bars.d.ts.map +1 -1
  128. package/build/lib/commands/system-bars.js +68 -64
  129. package/build/lib/commands/system-bars.js.map +1 -1
  130. package/build/lib/commands/time.d.ts +14 -0
  131. package/build/lib/commands/time.d.ts.map +1 -0
  132. package/build/lib/commands/time.js +39 -0
  133. package/build/lib/commands/time.js.map +1 -0
  134. package/build/lib/commands/touch.d.ts +99 -6
  135. package/build/lib/commands/touch.d.ts.map +1 -1
  136. package/build/lib/commands/touch.js +399 -280
  137. package/build/lib/commands/touch.js.map +1 -1
  138. package/build/lib/commands/types.d.ts +115 -3
  139. package/build/lib/commands/types.d.ts.map +1 -1
  140. package/build/lib/doctor/checks.d.ts.map +1 -1
  141. package/build/lib/doctor/checks.js +4 -4
  142. package/build/lib/doctor/checks.js.map +1 -1
  143. package/build/lib/driver.d.ts +224 -27
  144. package/build/lib/driver.d.ts.map +1 -1
  145. package/build/lib/driver.js +232 -7
  146. package/build/lib/driver.js.map +1 -1
  147. package/build/lib/index.d.ts +1 -4
  148. package/build/lib/index.d.ts.map +1 -1
  149. package/build/lib/index.js +1 -13
  150. package/build/lib/index.js.map +1 -1
  151. package/build/lib/logger.js.map +1 -1
  152. package/build/lib/method-map.d.ts +0 -23
  153. package/build/lib/method-map.d.ts.map +1 -1
  154. package/build/lib/method-map.js +0 -11
  155. package/build/lib/method-map.js.map +1 -1
  156. package/build/lib/utils.d.ts +12 -0
  157. package/build/lib/utils.d.ts.map +1 -1
  158. package/build/lib/utils.js +38 -2
  159. package/build/lib/utils.js.map +1 -1
  160. package/lib/commands/app-management.js +470 -145
  161. package/lib/commands/appearance.js +29 -36
  162. package/lib/commands/context/cache.js +29 -0
  163. package/lib/commands/context/exports.js +379 -0
  164. package/lib/commands/context/helpers.js +802 -0
  165. package/lib/commands/device/common.js +264 -0
  166. package/lib/commands/device/emulator-actions.js +194 -0
  167. package/lib/commands/device/emulator-console.js +24 -0
  168. package/lib/commands/device/utils.js +285 -0
  169. package/lib/commands/deviceidle.js +31 -44
  170. package/lib/commands/element.js +149 -142
  171. package/lib/commands/execute.js +86 -87
  172. package/lib/commands/file-actions.js +249 -222
  173. package/lib/commands/find.ts +13 -19
  174. package/lib/commands/geolocation.js +179 -0
  175. package/lib/commands/ime.js +53 -45
  176. package/lib/commands/intent.js +149 -91
  177. package/lib/commands/keyboard.js +114 -17
  178. package/lib/commands/lock/exports.js +139 -0
  179. package/lib/commands/lock/helpers.js +379 -0
  180. package/lib/commands/log.js +170 -166
  181. package/lib/commands/media-projection.js +75 -70
  182. package/lib/commands/memory.js +17 -29
  183. package/lib/commands/misc.js +94 -0
  184. package/lib/commands/network.js +209 -223
  185. package/lib/commands/performance.js +88 -73
  186. package/lib/commands/permissions.js +83 -84
  187. package/lib/commands/recordscreen.js +171 -170
  188. package/lib/commands/resources.js +96 -0
  189. package/lib/commands/shell.js +28 -42
  190. package/lib/commands/streamscreen.js +207 -206
  191. package/lib/commands/system-bars.js +76 -77
  192. package/lib/commands/time.js +36 -0
  193. package/lib/commands/touch.js +442 -346
  194. package/lib/commands/types.ts +142 -10
  195. package/lib/doctor/checks.js +24 -16
  196. package/lib/driver.ts +454 -12
  197. package/lib/index.ts +1 -13
  198. package/lib/logger.js +1 -1
  199. package/lib/method-map.js +0 -11
  200. package/lib/utils.js +40 -3
  201. package/package.json +1 -1
  202. package/build/lib/commands/actions.d.ts +0 -8
  203. package/build/lib/commands/actions.d.ts.map +0 -1
  204. package/build/lib/commands/actions.js +0 -207
  205. package/build/lib/commands/actions.js.map +0 -1
  206. package/build/lib/commands/alert.d.ts +0 -8
  207. package/build/lib/commands/alert.d.ts.map +0 -1
  208. package/build/lib/commands/alert.js +0 -29
  209. package/build/lib/commands/alert.js.map +0 -1
  210. package/build/lib/commands/context.d.ts +0 -10
  211. package/build/lib/commands/context.d.ts.map +0 -1
  212. package/build/lib/commands/context.js +0 -431
  213. package/build/lib/commands/context.js.map +0 -1
  214. package/build/lib/commands/emu-console.d.ts +0 -7
  215. package/build/lib/commands/emu-console.d.ts.map +0 -1
  216. package/build/lib/commands/emu-console.js +0 -27
  217. package/build/lib/commands/emu-console.js.map +0 -1
  218. package/build/lib/commands/general.d.ts +0 -9
  219. package/build/lib/commands/general.d.ts.map +0 -1
  220. package/build/lib/commands/general.js +0 -293
  221. package/build/lib/commands/general.js.map +0 -1
  222. package/build/lib/commands/index.d.ts +0 -28
  223. package/build/lib/commands/index.d.ts.map +0 -1
  224. package/build/lib/commands/index.js +0 -57
  225. package/build/lib/commands/index.js.map +0 -1
  226. package/build/lib/commands/mixins.d.ts +0 -747
  227. package/build/lib/commands/mixins.d.ts.map +0 -1
  228. package/build/lib/commands/mixins.js +0 -19
  229. package/build/lib/commands/mixins.js.map +0 -1
  230. package/build/lib/helpers/android.d.ts +0 -163
  231. package/build/lib/helpers/android.d.ts.map +0 -1
  232. package/build/lib/helpers/android.js +0 -818
  233. package/build/lib/helpers/android.js.map +0 -1
  234. package/build/lib/helpers/index.d.ts +0 -7
  235. package/build/lib/helpers/index.d.ts.map +0 -1
  236. package/build/lib/helpers/index.js +0 -29
  237. package/build/lib/helpers/index.js.map +0 -1
  238. package/build/lib/helpers/types.d.ts +0 -122
  239. package/build/lib/helpers/types.d.ts.map +0 -1
  240. package/build/lib/helpers/types.js +0 -3
  241. package/build/lib/helpers/types.js.map +0 -1
  242. package/build/lib/helpers/unlock.d.ts +0 -32
  243. package/build/lib/helpers/unlock.d.ts.map +0 -1
  244. package/build/lib/helpers/unlock.js +0 -273
  245. package/build/lib/helpers/unlock.js.map +0 -1
  246. package/build/lib/helpers/webview.d.ts +0 -74
  247. package/build/lib/helpers/webview.d.ts.map +0 -1
  248. package/build/lib/helpers/webview.js +0 -442
  249. package/build/lib/helpers/webview.js.map +0 -1
  250. package/lib/commands/actions.js +0 -244
  251. package/lib/commands/alert.js +0 -34
  252. package/lib/commands/context.js +0 -507
  253. package/lib/commands/emu-console.js +0 -31
  254. package/lib/commands/general.js +0 -343
  255. package/lib/commands/index.ts +0 -54
  256. package/lib/commands/mixins.ts +0 -976
  257. package/lib/helpers/android.ts +0 -1153
  258. package/lib/helpers/index.ts +0 -6
  259. package/lib/helpers/types.ts +0 -136
  260. package/lib/helpers/unlock.ts +0 -329
  261. package/lib/helpers/webview.ts +0 -604
@@ -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
- * @type {import('./mixins').NetworkMixin & ThisType<import('../driver').AndroidDriver>}
27
- * @satisfies {import('@appium/types').ExternalDriver}
19
+ * @this {import('../driver').AndroidDriver}
20
+ * @returns {Promise<number>}
28
21
  */
29
- const NetworkMixin = {
30
- async getNetworkConnection() {
31
- this.log.info('Getting network connection');
32
- let airplaneModeOn = await this.adb.isAirplaneModeOn();
33
- let connection = airplaneModeOn ? AIRPLANE_MODE_MASK : 0;
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
- // no need to check anything else if we are in airplane mode
36
- if (!airplaneModeOn) {
37
- let wifiOn = await this.isWifiOn();
38
- connection |= wifiOn ? WIFI_MASK : 0;
39
- let dataOn = await this.adb.isDataOn();
40
- connection |= dataOn ? DATA_MASK : 0;
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
- if (shouldEnableAirplaneMode !== isAirplaneModeEnabled) {
132
- await this.adb.setAirplaneMode(shouldEnableAirplaneMode);
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(shouldEnableAirplaneMode);
79
+ await this.adb.broadcastAirplaneMode(airplaneMode);
135
80
  }
136
- } else {
137
- this.log.info(
138
- `Not changing airplane mode, since it is already ${
139
- shouldEnableAirplaneMode ? 'enabled' : 'disabled'
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
- async toggleWiFi() {
192
- const isOn = await this.adb.isWifiOn();
193
- this.log.info(`Turning WiFi ${!isOn ? 'on' : 'off'}`);
194
- await this.setWifiState(!isOn);
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
- async toggleFlightMode() {
198
- /*
199
- * TODO: Implement isRealDevice(). This method fails on
200
- * real devices, it should throw a NotYetImplementedError
201
- */
202
- let flightMode = !(await this.adb.isAirplaneModeOn());
203
- this.log.info(`Turning flight mode ${flightMode ? 'on' : 'off'}`);
204
- await this.adb.setAirplaneMode(flightMode);
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(flightMode);
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
- async setGeoLocation(location) {
211
- await this.settingsApp.setGeoLocation(location, this.isEmulator());
212
- try {
213
- return await this.getGeoLocation();
214
- } catch (e) {
215
- this.log.warn(
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
- async mobileRefreshGpsCache(opts = {}) {
228
- const {timeoutMs} = opts;
229
- await this.settingsApp.refreshGeoLocationCache(timeoutMs);
230
- },
187
+ return await this.getNetworkConnection();
188
+ }
231
189
 
232
- async getGeoLocation() {
233
- const {latitude, longitude, altitude} = await this.settingsApp.getGeoLocation();
234
- return {
235
- latitude: parseFloat(String(latitude)) || GEO_EPSILON,
236
- longitude: parseFloat(String(longitude)) || GEO_EPSILON,
237
- altitude: parseFloat(String(altitude)) || GEO_EPSILON,
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
- async isLocationServicesEnabled() {
242
- return (await this.adb.getLocationProviders()).includes('gps');
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
- async toggleLocationServices() {
246
- this.log.info('Toggling location services');
247
- const isGpsEnabled = await this.isLocationServicesEnabled();
248
- this.log.debug(
249
- `Current GPS state: ${isGpsEnabled}. ` +
250
- `The service is going to be ${isGpsEnabled ? 'disabled' : 'enabled'}`
251
- );
252
- await this.adb.toggleGPSLocationProvider(!isGpsEnabled);
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
- mixin(NetworkMixin);
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
- export default NetworkMixin;
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