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