appium-ios-simulator 5.4.0 → 5.5.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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [5.5.0](https://github.com/appium/appium-ios-simulator/compare/v5.4.0...v5.5.0) (2023-11-26)
2
+
3
+
4
+ ### Features
5
+
6
+ * use xcrun privacy instead of wix for location permission but keep using wix for rest ([#406](https://github.com/appium/appium-ios-simulator/issues/406)) ([6280527](https://github.com/appium/appium-ios-simulator/commit/628052753caaa68fd8afffe14956d180156dded9))
7
+
1
8
  ## [5.4.0](https://github.com/appium/appium-ios-simulator/compare/v5.3.10...v5.4.0) (2023-11-24)
2
9
 
3
10
 
package/README.md CHANGED
@@ -38,6 +38,7 @@ The following tools and utilities are not mandatory, but could be used by the ap
38
38
  - [Mobile Native Foundation](https://github.com/MobileNativeFoundation)
39
39
  - [IDB](https://github.com/facebook/idb)
40
40
  - [AppleSimulatorUtils](https://github.com/wix/AppleSimulatorUtils)
41
+ - For `contacts`, `camera`, `faceid`, `health`, `homekit`, `notifications`, `speech` and `userTracking` permissions
41
42
 
42
43
  ### Xcode and iOS versions
43
44
 
@@ -1,9 +1,8 @@
1
1
  export default extensions;
2
2
  declare namespace extensions {
3
3
  /**
4
- * Sets the particular permission to the application bundle. See
5
- * https://github.com/wix/AppleSimulatorUtils for more details on
6
- * the available service names and statuses.
4
+ * Sets the particular permission to the application bundle. See https://github.com/wix/AppleSimulatorUtils
5
+ * or `xcrun simctl privacy` for more details on the available service names and statuses.
7
6
  *
8
7
  * @param {string} bundleId - Application bundle identifier.
9
8
  * @param {string} permission - Service name to be set.
@@ -17,7 +16,7 @@ declare namespace extensions {
17
16
  * @param {string} bundleId - Application bundle identifier.
18
17
  * @param {Object} permissionsMapping - A mapping where kays
19
18
  * are service names and values are their corresponding status values.
20
- * See https://github.com/wix/AppleSimulatorUtils
19
+ * See https://github.com/wix/AppleSimulatorUtils or `xcrun simctl privacy`
21
20
  * for more details on available service names and statuses.
22
21
  * @throws {Error} If there was an error while changing permissions.
23
22
  */
@@ -1 +1 @@
1
- {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../../lib/extensions/permissions.js"],"names":[],"mappings":";;IAiJA;;;;;;;;;OASG;IACH,2FAEC;IAED;;;;;;;;;OASG;IACH,kFAGC;IAED;;;;;;OAMG;IACH,+EAIC"}
1
+ {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../../lib/extensions/permissions.js"],"names":[],"mappings":";;IA2NA;;;;;;;;OAQG;IACH,2FAEC;IAED;;;;;;;;;OASG;IACH,kFAGC;IAED;;;;;;OAMG;IACH,+EAIC"}
@@ -8,6 +8,7 @@ const lodash_1 = __importDefault(require("lodash"));
8
8
  const support_1 = require("@appium/support");
9
9
  const teen_process_1 = require("teen_process");
10
10
  const path_1 = __importDefault(require("path"));
11
+ const bluebird_1 = __importDefault(require("bluebird"));
11
12
  const STATUS = Object.freeze({
12
13
  UNSET: 'unset',
13
14
  NO: 'no',
@@ -15,6 +16,15 @@ const STATUS = Object.freeze({
15
16
  LIMITED: 'limited',
16
17
  });
17
18
  const WIX_SIM_UTILS = 'applesimutils';
19
+ // `location` permission does not work with WIX/applesimutils.
20
+ // Note that except for 'contacts', the Apple's privacy command sets
21
+ // permissions properly but it kills the app process while WIX/applesimutils does not.
22
+ // In the backward compatibility perspective,
23
+ // we'd like to keep the app process as possible.
24
+ const PERMISSIONS_APPLIED_VIA_SIMCTL = [
25
+ 'location',
26
+ 'location-always'
27
+ ];
18
28
  const SERVICES = Object.freeze({
19
29
  calendar: 'kTCCServiceCalendar',
20
30
  camera: 'kTCCServiceCamera',
@@ -76,22 +86,77 @@ async function execWix(args) {
76
86
  /**
77
87
  * Sets permissions for the given application
78
88
  *
89
+ * @param {import('node-simctl').Simctl} simctl - node-simctl object.
79
90
  * @param {string} udid - udid of the target simulator device.
80
91
  * @param {string} bundleId - bundle identifier of the target application.
81
- * @param {Object} permissionsMapping - An object, where keys ar service names
82
- * and values are corresponding state values. See https://github.com/wix/AppleSimulatorUtils
92
+ * @param {Object} permissionsMapping - An object, where keys are service names
93
+ * and values are corresponding state values. Services listed in PERMISSIONS_APPLIED_VIA_SIMCTL
94
+ * will be set with `xcrun simctl privacy` command by Apple otherwise AppleSimulatorUtils by WIX.
95
+ * See the result of `xcrun simctl privacy` and https://github.com/wix/AppleSimulatorUtils
83
96
  * for more details on available service names and statuses.
97
+ * Note that the `xcrun simctl privacy` command kill the app process.
84
98
  * @throws {Error} If there was an error while changing permissions.
85
99
  */
86
- async function setAccess(udid, bundleId, permissionsMapping) {
87
- const permissionsArg = lodash_1.default.toPairs(permissionsMapping)
88
- .map((x) => `${x[0]}=${formatStatus(x[1])}`)
89
- .join(',');
90
- return await execWix([
91
- '--byId', udid,
92
- '--bundle', bundleId,
93
- '--setPermissions', permissionsArg,
94
- ]);
100
+ async function setAccess(simctl, udid, bundleId, permissionsMapping) {
101
+ const /** @type {Record<string, string>} */ wixPermissions = {};
102
+ const /** @type {string[]} */ grantPermissions = [];
103
+ const /** @type {string[]} */ revokePermissions = [];
104
+ const /** @type {string[]} */ resetPermissions = [];
105
+ for (const serviceName in permissionsMapping) {
106
+ if (!PERMISSIONS_APPLIED_VIA_SIMCTL.includes(serviceName)) {
107
+ wixPermissions[serviceName] = permissionsMapping[serviceName];
108
+ }
109
+ else {
110
+ switch (permissionsMapping[serviceName]) {
111
+ case STATUS.YES:
112
+ grantPermissions.push(serviceName);
113
+ break;
114
+ case STATUS.NO:
115
+ revokePermissions.push(serviceName);
116
+ break;
117
+ case STATUS.UNSET:
118
+ resetPermissions.push(serviceName);
119
+ break;
120
+ default:
121
+ logger_1.default.errorAndThrow(`${serviceName} does not support ${permissionsMapping[serviceName]}. Please specify 'yes', 'no' or 'unset'.`);
122
+ }
123
+ ;
124
+ }
125
+ }
126
+ const /** @type {string[]} */ permissionPromises = [];
127
+ if (!lodash_1.default.isEmpty(grantPermissions)) {
128
+ logger_1.default.debug(`Granting ${support_1.util.pluralize('permission', grantPermissions.length, false)} for ${bundleId}: ${grantPermissions}`);
129
+ for (const action of grantPermissions) {
130
+ permissionPromises.push(simctl.grantPermission(bundleId, action));
131
+ }
132
+ }
133
+ if (!lodash_1.default.isEmpty(revokePermissions)) {
134
+ logger_1.default.debug(`Revoking ${support_1.util.pluralize('permission', revokePermissions.length, false)} for ${bundleId}: ${revokePermissions}`);
135
+ for (const action of revokePermissions) {
136
+ permissionPromises.push(simctl.revokePermission(bundleId, action));
137
+ }
138
+ }
139
+ if (!lodash_1.default.isEmpty(resetPermissions)) {
140
+ logger_1.default.debug(`Resetting ${support_1.util.pluralize('permission', resetPermissions.length, false)} for ${bundleId}: ${resetPermissions}`);
141
+ for (const action of resetPermissions) {
142
+ permissionPromises.push(simctl.resetPermission(bundleId, action));
143
+ }
144
+ }
145
+ if (!lodash_1.default.isEmpty(permissionPromises)) {
146
+ await bluebird_1.default.all(permissionPromises);
147
+ }
148
+ if (!lodash_1.default.isEmpty(wixPermissions)) {
149
+ logger_1.default.debug(`Setting permissions for ${bundleId} wit ${WIX_SIM_UTILS} as ${JSON.stringify(wixPermissions)}`);
150
+ const permissionsArg = lodash_1.default.toPairs(wixPermissions)
151
+ .map((x) => `${x[0]}=${formatStatus(x[1])}`)
152
+ .join(',');
153
+ await execWix([
154
+ '--byId', udid,
155
+ '--bundle', bundleId,
156
+ '--setPermissions', permissionsArg,
157
+ ]);
158
+ }
159
+ return true;
95
160
  }
96
161
  /**
97
162
  * Retrieves the current permission status for the given service and application.
@@ -129,9 +194,8 @@ async function getAccess(bundleId, serviceName, simDataRoot) {
129
194
  }
130
195
  const extensions = {};
131
196
  /**
132
- * Sets the particular permission to the application bundle. See
133
- * https://github.com/wix/AppleSimulatorUtils for more details on
134
- * the available service names and statuses.
197
+ * Sets the particular permission to the application bundle. See https://github.com/wix/AppleSimulatorUtils
198
+ * or `xcrun simctl privacy` for more details on the available service names and statuses.
135
199
  *
136
200
  * @param {string} bundleId - Application bundle identifier.
137
201
  * @param {string} permission - Service name to be set.
@@ -147,13 +211,13 @@ extensions.setPermission = async function setPermission(bundleId, permission, va
147
211
  * @param {string} bundleId - Application bundle identifier.
148
212
  * @param {Object} permissionsMapping - A mapping where kays
149
213
  * are service names and values are their corresponding status values.
150
- * See https://github.com/wix/AppleSimulatorUtils
214
+ * See https://github.com/wix/AppleSimulatorUtils or `xcrun simctl privacy`
151
215
  * for more details on available service names and statuses.
152
216
  * @throws {Error} If there was an error while changing permissions.
153
217
  */
154
218
  extensions.setPermissions = async function setPermissions(bundleId, permissionsMapping) {
155
219
  logger_1.default.debug(`Setting access for '${bundleId}': ${JSON.stringify(permissionsMapping, null, 2)}`);
156
- await setAccess(this.udid, bundleId, permissionsMapping);
220
+ await setAccess(this.simctl, this.udid, bundleId, permissionsMapping);
157
221
  };
158
222
  /**
159
223
  * Retrieves current permission status for the given application bundle.
@@ -1 +1 @@
1
- {"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../lib/extensions/permissions.js"],"names":[],"mappings":";;;;;AAAA,uDAA4B;AAC5B,oDAAuB;AACvB,6CAA2C;AAC3C,+CAAoC;AACpC,gDAAwB;AAExB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3B,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,KAAK;IACV,OAAO,EAAE,SAAS;CACnB,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,eAAe,CAAC;AACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,QAAQ,EAAE,qBAAqB;IAC/B,MAAM,EAAE,mBAAmB;IAC3B,QAAQ,EAAE,wBAAwB;IAClC,OAAO,EAAE,mBAAmB;IAC5B,UAAU,EAAE,uBAAuB;IACnC,MAAM,EAAE,mBAAmB;IAC3B,SAAS,EAAE,sBAAsB;IACjC,YAAY,EAAE,yBAAyB;IACvC,MAAM,EAAE,mBAAmB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EACrC,SAAS,CACV,CAAC;KACH;AACH,CAAC;AAED,MAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;;;;;;;GAQG;AACH,UAAU,CAAC,aAAa,GAAG,KAAK,UAAU,aAAa,CAAE,QAAQ,EAAE,UAAU,EAAE,KAAK;IAClF,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAC,CAAC,UAAU,CAAC,EAAE,KAAK,EAAC,CAAC,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,UAAU,CAAC,cAAc,GAAG,KAAK,UAAU,cAAc,CAAE,QAAQ,EAAE,kBAAkB;IACrF,gBAAG,CAAC,KAAK,CAAC,uBAAuB,QAAQ,MAAM,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9F,MAAM,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,UAAU,CAAC,aAAa,GAAG,KAAK,UAAU,aAAa,CAAE,QAAQ,EAAE,WAAW;IAC5E,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACrE,gBAAG,CAAC,KAAK,CAAC,OAAO,WAAW,uBAAuB,QAAQ,MAAM,MAAM,EAAE,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
@@ -3,6 +3,7 @@ import _ from 'lodash';
3
3
  import { fs, util } from '@appium/support';
4
4
  import { exec } from 'teen_process';
5
5
  import path from 'path';
6
+ import B from 'bluebird';
6
7
 
7
8
  const STATUS = Object.freeze({
8
9
  UNSET: 'unset',
@@ -12,6 +13,17 @@ const STATUS = Object.freeze({
12
13
  });
13
14
 
14
15
  const WIX_SIM_UTILS = 'applesimutils';
16
+
17
+ // `location` permission does not work with WIX/applesimutils.
18
+ // Note that except for 'contacts', the Apple's privacy command sets
19
+ // permissions properly but it kills the app process while WIX/applesimutils does not.
20
+ // In the backward compatibility perspective,
21
+ // we'd like to keep the app process as possible.
22
+ const PERMISSIONS_APPLIED_VIA_SIMCTL = [
23
+ 'location',
24
+ 'location-always'
25
+ ];
26
+
15
27
  const SERVICES = Object.freeze({
16
28
  calendar: 'kTCCServiceCalendar',
17
29
  camera: 'kTCCServiceCamera',
@@ -82,22 +94,84 @@ async function execWix (args) {
82
94
  /**
83
95
  * Sets permissions for the given application
84
96
  *
97
+ * @param {import('node-simctl').Simctl} simctl - node-simctl object.
85
98
  * @param {string} udid - udid of the target simulator device.
86
99
  * @param {string} bundleId - bundle identifier of the target application.
87
- * @param {Object} permissionsMapping - An object, where keys ar service names
88
- * and values are corresponding state values. See https://github.com/wix/AppleSimulatorUtils
100
+ * @param {Object} permissionsMapping - An object, where keys are service names
101
+ * and values are corresponding state values. Services listed in PERMISSIONS_APPLIED_VIA_SIMCTL
102
+ * will be set with `xcrun simctl privacy` command by Apple otherwise AppleSimulatorUtils by WIX.
103
+ * See the result of `xcrun simctl privacy` and https://github.com/wix/AppleSimulatorUtils
89
104
  * for more details on available service names and statuses.
105
+ * Note that the `xcrun simctl privacy` command kill the app process.
90
106
  * @throws {Error} If there was an error while changing permissions.
91
107
  */
92
- async function setAccess (udid, bundleId, permissionsMapping) {
93
- const permissionsArg = _.toPairs(permissionsMapping)
94
- .map((x) => `${x[0]}=${formatStatus(x[1])}`)
95
- .join(',');
96
- return await execWix([
97
- '--byId', udid,
98
- '--bundle', bundleId,
99
- '--setPermissions', permissionsArg,
100
- ]);
108
+ async function setAccess (simctl, udid, bundleId, permissionsMapping) {
109
+ const /** @type {Record<string, string>} */ wixPermissions = {};
110
+
111
+ const /** @type {string[]} */ grantPermissions = [];
112
+ const /** @type {string[]} */ revokePermissions = [];
113
+ const /** @type {string[]} */ resetPermissions = [];
114
+
115
+ for (const serviceName in permissionsMapping) {
116
+ if (!PERMISSIONS_APPLIED_VIA_SIMCTL.includes(serviceName)) {
117
+ wixPermissions[serviceName] = permissionsMapping[serviceName];
118
+ } else {
119
+ switch (permissionsMapping[serviceName]) {
120
+ case STATUS.YES:
121
+ grantPermissions.push(serviceName);
122
+ break;
123
+ case STATUS.NO:
124
+ revokePermissions.push(serviceName);
125
+ break;
126
+ case STATUS.UNSET:
127
+ resetPermissions.push(serviceName);
128
+ break;
129
+ default:
130
+ log.errorAndThrow(`${serviceName} does not support ${permissionsMapping[serviceName]}. Please specify 'yes', 'no' or 'unset'.`);
131
+ };
132
+ }
133
+ }
134
+
135
+ const /** @type {string[]} */ permissionPromises = [];
136
+
137
+ if (!_.isEmpty(grantPermissions)) {
138
+ log.debug(`Granting ${util.pluralize('permission', grantPermissions.length, false)} for ${bundleId}: ${grantPermissions}`);
139
+ for (const action of grantPermissions) {
140
+ permissionPromises.push(simctl.grantPermission(bundleId, action));
141
+ }
142
+ }
143
+
144
+ if (!_.isEmpty(revokePermissions)) {
145
+ log.debug(`Revoking ${util.pluralize('permission', revokePermissions.length, false)} for ${bundleId}: ${revokePermissions}`);
146
+ for (const action of revokePermissions) {
147
+ permissionPromises.push(simctl.revokePermission(bundleId, action));
148
+ }
149
+ }
150
+
151
+ if (!_.isEmpty(resetPermissions)) {
152
+ log.debug(`Resetting ${util.pluralize('permission', resetPermissions.length, false)} for ${bundleId}: ${resetPermissions}`);
153
+ for (const action of resetPermissions) {
154
+ permissionPromises.push(simctl.resetPermission(bundleId, action));
155
+ }
156
+ }
157
+
158
+ if (!_.isEmpty(permissionPromises)) {
159
+ await B.all(permissionPromises);
160
+ }
161
+
162
+ if (!_.isEmpty(wixPermissions)) {
163
+ log.debug(`Setting permissions for ${bundleId} wit ${WIX_SIM_UTILS} as ${JSON.stringify(wixPermissions)}`);
164
+ const permissionsArg = _.toPairs(wixPermissions)
165
+ .map((x) => `${x[0]}=${formatStatus(x[1])}`)
166
+ .join(',');
167
+ await execWix([
168
+ '--byId', udid,
169
+ '--bundle', bundleId,
170
+ '--setPermissions', permissionsArg,
171
+ ]);
172
+ }
173
+
174
+ return true;
101
175
  }
102
176
 
103
177
  /**
@@ -144,9 +218,8 @@ async function getAccess (bundleId, serviceName, simDataRoot) {
144
218
  const extensions = {};
145
219
 
146
220
  /**
147
- * Sets the particular permission to the application bundle. See
148
- * https://github.com/wix/AppleSimulatorUtils for more details on
149
- * the available service names and statuses.
221
+ * Sets the particular permission to the application bundle. See https://github.com/wix/AppleSimulatorUtils
222
+ * or `xcrun simctl privacy` for more details on the available service names and statuses.
150
223
  *
151
224
  * @param {string} bundleId - Application bundle identifier.
152
225
  * @param {string} permission - Service name to be set.
@@ -163,13 +236,13 @@ extensions.setPermission = async function setPermission (bundleId, permission, v
163
236
  * @param {string} bundleId - Application bundle identifier.
164
237
  * @param {Object} permissionsMapping - A mapping where kays
165
238
  * are service names and values are their corresponding status values.
166
- * See https://github.com/wix/AppleSimulatorUtils
239
+ * See https://github.com/wix/AppleSimulatorUtils or `xcrun simctl privacy`
167
240
  * for more details on available service names and statuses.
168
241
  * @throws {Error} If there was an error while changing permissions.
169
242
  */
170
243
  extensions.setPermissions = async function setPermissions (bundleId, permissionsMapping) {
171
244
  log.debug(`Setting access for '${bundleId}': ${JSON.stringify(permissionsMapping, null, 2)}`);
172
- await setAccess(this.udid, bundleId, permissionsMapping);
245
+ await setAccess(this.simctl, this.udid, bundleId, permissionsMapping);
173
246
  };
174
247
 
175
248
  /**
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "ios",
8
8
  "simctl"
9
9
  ],
10
- "version": "5.4.0",
10
+ "version": "5.5.0",
11
11
  "author": "Appium Contributors",
12
12
  "license": "Apache-2.0",
13
13
  "repository": {