appium-adb 9.10.13 → 9.10.14

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.
@@ -45,6 +45,8 @@ const commands = {};
45
45
  * @typedef {Object} SettingsAppStartupOptions
46
46
  * @property {number} timeout [5000] The maximum number of milliseconds
47
47
  * to wait until the app has started
48
+ * @property {boolean} shouldRestoreCurrentApp [false] Whether to restore
49
+ * the activity which was the current one before Settings startup
48
50
  */
49
51
 
50
52
  /**
@@ -63,7 +65,16 @@ commands.requireRunningSettingsApp = async function requireRunningSettingsApp (o
63
65
  log.debug('Starting Appium Settings app');
64
66
  const {
65
67
  timeout = 5000,
68
+ shouldRestoreCurrentApp = false,
66
69
  } = opts;
70
+ let appPackage;
71
+ if (shouldRestoreCurrentApp) {
72
+ try {
73
+ ({appPackage} = await this.getFocusedPackageAndActivity());
74
+ } catch (e) {
75
+ log.warn(`The current application can not be restored: ${e.message}`);
76
+ }
77
+ }
67
78
  await this.startApp({
68
79
  pkg: SETTINGS_HELPER_ID,
69
80
  activity: SETTINGS_HELPER_MAIN_ACTIVITY,
@@ -77,6 +88,13 @@ commands.requireRunningSettingsApp = async function requireRunningSettingsApp (o
77
88
  waitMs: timeout,
78
89
  intervalMs: 300,
79
90
  });
91
+ if (shouldRestoreCurrentApp && appPackage) {
92
+ try {
93
+ await this.activateApp(appPackage);
94
+ } catch (e) {
95
+ log.warn(`The current application can not be restored: ${e.message}`);
96
+ }
97
+ }
80
98
  return this;
81
99
  } catch (err) {
82
100
  throw new Error(`Appium Settings app is not running after ${timeout}ms`);
@@ -97,6 +115,8 @@ commands.setWifiState = async function setWifiState (on, isEmulator = false) {
97
115
  privileged: await this.getApiLevel() < 26,
98
116
  });
99
117
  } else {
118
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
119
+
100
120
  await this.shell([
101
121
  'am', 'broadcast',
102
122
  '-a', WIFI_CONNECTION_SETTING_ACTION,
@@ -120,6 +140,8 @@ commands.setDataState = async function setDataState (on, isEmulator = false) {
120
140
  privileged: await this.getApiLevel() < 26,
121
141
  });
122
142
  } else {
143
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
144
+
123
145
  await this.shell([
124
146
  'am', 'broadcast',
125
147
  '-a', DATA_CONNECTION_SETTING_ACTION,
@@ -269,6 +291,8 @@ commands.setGeoLocation = async function setGeoLocation (location, isEmulator =
269
291
  * @throws {Error} If the current location cannot be retrieved
270
292
  */
271
293
  commands.getGeoLocation = async function getGeoLocation () {
294
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
295
+
272
296
  let output;
273
297
  try {
274
298
  output = await this.shell([
@@ -309,6 +333,8 @@ commands.getGeoLocation = async function getGeoLocation () {
309
333
  * @throws {Error} If the GPS cache cannot be refreshed.
310
334
  */
311
335
  commands.refreshGeoLocationCache = async function refreshGeoLocationCache (timeoutMs = 20000) {
336
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
337
+
312
338
  let logcatMonitor;
313
339
  let monitoringPromise;
314
340
 
@@ -396,6 +422,7 @@ commands.performEditorAction = async function performEditorAction (action) {
396
422
  */
397
423
  commands.getClipboard = async function getClipboard () {
398
424
  log.debug('Getting the clipboard content');
425
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
399
426
  const retrieveClipboard = async () => await this.shell([
400
427
  'am', 'broadcast',
401
428
  '-n', CLIPBOARD_RECEIVER,
@@ -472,7 +499,7 @@ commands.getNotifications = async function getNotifications () {
472
499
  // renders the broadcast to fail instead of starting the
473
500
  // Appium Settings app. This only happens to the notifications
474
501
  // receiver
475
- await this.requireRunningSettingsApp();
502
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
476
503
  let output;
477
504
  try {
478
505
  output = await this.shell([
@@ -535,6 +562,7 @@ commands.getNotifications = async function getNotifications () {
535
562
  */
536
563
  commands.getSmsList = async function getSmsList (opts = {}) {
537
564
  log.debug('Retrieving the recent SMS messages');
565
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
538
566
  const args = [
539
567
  'am', 'broadcast',
540
568
  '-n', SMS_LIST_RECEIVER,
@@ -588,6 +616,7 @@ commands.typeUnicode = async function typeUnicode (text) {
588
616
  */
589
617
  commands.scanMedia = async function scanMedia (destination) {
590
618
  log.debug(`Scanning '${destination}' for media files`);
619
+ await this.requireRunningSettingsApp({shouldRestoreCurrentApp: true});
591
620
  const output = await this.shell([
592
621
  'am', 'broadcast',
593
622
  '-n', MEDIA_SCAN_RECEIVER,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appium-adb",
3
- "version": "9.10.13",
3
+ "version": "9.10.14",
4
4
  "description": "Android Debug Bridge interface",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {