Skip to content

Commit f36ec2b

Browse files
Add a command to check whether a device has enabled developer mode. D… (#563)
Retry of #556 that guards the developer mode check by a preprocessor define so that it is not build by default. Developer mode requires a MobileDevice method introduced with Xcode 14 so including it by default will break builds where Xcode 14 is unavailable.
1 parent b325443 commit f36ec2b

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ python -m py_compile src/scripts/*.py && xcodebuild -target ios-deploy && xcodeb
6666
-m, --noinstall directly start debugging without app install (-d not required)
6767
-A, --app_deltas incremental install. must specify a directory to store app deltas to determine what needs to be installed
6868
-p, --port <number> port used for device, default: dynamic
69-
-r, --uninstall uninstall the app before install (do not use with -m; app cache and data are cleared)
70-
-9, --uninstall_only uninstall the app ONLY. Use only with -1 <bundle_id>
69+
-r, --uninstall uninstall the app before install (do not use with -m; app cache and data are cleared)
70+
-9, --uninstall_only uninstall the app ONLY. Use only with -1 <bundle_id>
7171
-1, --bundle_id <bundle id> specify bundle id for list and upload
7272
-l, --list[=<dir>] list all app files or the specified directory
7373
-o, --upload <file> upload file
@@ -76,18 +76,28 @@ python -m py_compile src/scripts/*.py && xcodebuild -target ios-deploy && xcodeb
7676
-D, --mkdir <dir> make directory on device
7777
-R, --rm <path> remove file or directory on device (directories must be empty)
7878
-X, --rmtree <path> remove directory and all contained files recursively on device
79-
-V, --version print the executable version
80-
-e, --exists check if the app with given bundle_id is installed or not
81-
-B, --list_bundle_id list bundle_id
79+
-V, --version print the executable version
80+
-e, --exists check if the app with given bundle_id is installed or not
81+
-B, --list_bundle_id list bundle_id
8282
-W, --no-wifi ignore wifi devices
83-
-C, --get_battery_level get battery current capacity
83+
-C, --get_battery_level get battery current capacity
8484
-O, --output <file> write stdout to this file
8585
-E, --error_output <file> write stderr to this file
8686
--detect_deadlocks <sec> start printing backtraces for all threads periodically after specific amount of seconds
8787
-f, --file_system specify file system for mkdir / list / upload / download / rm
88-
-k, --key keys for the properties of the bundle. Joined by ',' and used only with -B <list_bundle_id> and -j <json>
8988
-F, --non-recursively specify non-recursively walk directory
89+
-S, --symbols download OS symbols. must specify a directory to store the downloaded symbols
9090
-j, --json format output as JSON
91+
-k, --key keys for the properties of the bundle. Joined by ',' and used only with -B <list_bundle_id> and -j <json>
92+
--custom-script <script> path to custom python script to execute in lldb
93+
--custom-command <command> specify additional lldb commands to execute
94+
--faster-path-search use alternative logic to find the device support paths faster
95+
-P, --list_profiles list all provisioning profiles on device
96+
--profile-uuid <uuid> the UUID of the provisioning profile to target, use with other profile commands
97+
--profile-download <path> download a provisioning profile (requires --profile-uuid)
98+
--profile-install <file> install a provisioning profile
99+
--profile-uninstall uninstall a provisioning profile (requires --profile-uuid <UUID>)
100+
--check-developer-mode checks whether the given device has developer mode enabled (Requires Xcode 14 or newer)
91101

92102
## Examples
93103

src/ios-deploy/ios-deploy.m

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@
9191
mach_error_t AMDeviceLookupApplications(AMDeviceRef device, CFDictionaryRef options, CFDictionaryRef *result);
9292
int AMDeviceGetInterfaceType(AMDeviceRef device);
9393
AMDeviceRef AMDeviceCopyPairedCompanion(AMDeviceRef device);
94+
#if defined(IOS_DEPLOY_FEATURE_DEVELOPER_MODE)
95+
unsigned int AMDeviceCopyDeveloperModeStatus(AMDeviceRef device, uint32_t *error_code);
96+
#endif
9497

9598
int AMDServiceConnectionSend(ServiceConnRef con, const void * data, size_t size);
9699
int AMDServiceConnectionReceive(ServiceConnRef con, void * data, size_t size);
@@ -2289,6 +2292,34 @@ void uninstall_app(AMDeviceRef device) {
22892292
}
22902293
}
22912294

2295+
#if defined(IOS_DEPLOY_FEATURE_DEVELOPER_MODE)
2296+
void check_developer_mode(AMDeviceRef device) {
2297+
unsigned int error_code = 0;
2298+
bool is_enabled = AMDeviceCopyDeveloperModeStatus(device, &error_code);
2299+
2300+
if (error_code) {
2301+
const char *mobdev_error = get_error_message(error_code);
2302+
NSString *error_description = mobdev_error ? [NSString stringWithUTF8String:mobdev_error] : @"unknown.";
2303+
if (_json_output) {
2304+
NSLogJSON(@{
2305+
@"Event": @"DeveloperMode",
2306+
@"IsEnabled": @(is_enabled),
2307+
@"Code": @(error_code),
2308+
@"Status": error_description,
2309+
});
2310+
} else {
2311+
NSLogOut(@"Encountered error checking developer mode status: %@", error_description);
2312+
}
2313+
} else {
2314+
if (_json_output) {
2315+
NSLogJSON(@{@"Event": @"DeveloperMode", @"IsEnabled": @(is_enabled)});
2316+
} else {
2317+
NSLogOut(@"Developer mode is%s enabled.", is_enabled ? "" : " not");
2318+
}
2319+
}
2320+
}
2321+
#endif
2322+
22922323
void start_symbols_service_with_command(AMDeviceRef device, uint32_t command) {
22932324
connect_and_start_session(device);
22942325
check_error(AMDeviceSecureStartService(device, symbols_service_name,
@@ -2608,7 +2639,11 @@ void handle_device(AMDeviceRef device) {
26082639
uninstall_provisioning_profile(device);
26092640
} else if (strcmp("download_profile", command) == 0) {
26102641
download_provisioning_profile(device);
2611-
}
2642+
#if defined(IOS_DEPLOY_FEATURE_DEVELOPER_MODE)
2643+
} else if (strcmp("check_developer_mode", command) == 0) {
2644+
check_developer_mode(device);
2645+
#endif
2646+
}
26122647
exit(0);
26132648
}
26142649

@@ -2874,7 +2909,12 @@ void usage(const char* app) {
28742909
@" --profile-uuid <uuid> the UUID of the provisioning profile to target, use with other profile commands\n"
28752910
@" --profile-download <path> download a provisioning profile (requires --profile-uuid)\n"
28762911
@" --profile-install <file> install a provisioning profile\n"
2877-
@" --profile-uninstall uninstall a provisioning profile (requires --profile-uuid <UUID>)\n",
2912+
@" --profile-uninstall uninstall a provisioning profile (requires --profile-uuid <UUID>)\n"
2913+
#if defined(IOS_DEPLOY_FEATURE_DEVELOPER_MODE)
2914+
@" --check-developer-mode checks whether the given device has developer mode enabled (requires Xcode 14 or newer)\n",
2915+
#else
2916+
,
2917+
#endif
28782918
[NSString stringWithUTF8String:app]);
28792919
}
28802920

@@ -2940,6 +2980,9 @@ int main(int argc, char *argv[]) {
29402980
{ "profile-uninstall", no_argument, NULL, 1005},
29412981
{ "profile-download", required_argument, NULL, 1006},
29422982
{ "profile-uuid", required_argument, NULL, 1007},
2983+
#if defined(IOS_DEPLOY_FEATURE_DEVELOPER_MODE)
2984+
{ "check-developer-mode", no_argument, NULL, 1008},
2985+
#endif
29432986
{ NULL, 0, NULL, 0 },
29442987
};
29452988
int ch;
@@ -3115,6 +3158,12 @@ int main(int argc, char *argv[]) {
31153158
case 1007:
31163159
profile_uuid = optarg;
31173160
break;
3161+
#if defined(IOS_DEPLOY_FEATURE_DEVELOPER_MODE)
3162+
case 1008:
3163+
command_only = true;
3164+
command = "check_developer_mode";
3165+
break;
3166+
#endif
31183167
case 'P':
31193168
command_only = true;
31203169
command = "list_profiles";

0 commit comments

Comments
 (0)