Skip to content

Commit

Permalink
Update device detection json output to include the interface over whi…
Browse files Browse the repository at this point in the history
…ch the device was found (e.g. Wifi, USB, etc) and to correctly start a session before fetching device attributes. Previously without a session, devices connected over wifi would return null for some attributes including BuildVersion and DeviceClass.
  • Loading branch information
ivanhernandez13 committed May 25, 2022
1 parent 8670979 commit c86d933
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ device_desc get_device_desc(CFStringRef model) {
return res;
}

void connect_and_start_session(AMDeviceRef device) {
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
check_error(AMDeviceValidatePairing(device));
check_error(AMDeviceStartSession(device));
}

CFStringRef get_device_full_name(const AMDeviceRef device) {
CFStringRef full_name = NULL,
device_udid = AMDeviceCopyDeviceIdentifier(device),
Expand Down Expand Up @@ -521,7 +528,7 @@ CFStringRef get_device_full_name(const AMDeviceRef device) {

NSDictionary* get_device_json_dict(const AMDeviceRef device) {
NSMutableDictionary *json_dict = [NSMutableDictionary new];
AMDeviceConnect(device);
connect_and_start_session(device);

CFStringRef device_udid = AMDeviceCopyDeviceIdentifier(device);
if (device_udid) {
Expand Down Expand Up @@ -1214,13 +1221,6 @@ void fdvendor_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataR
CFRelease(s);
}

void connect_and_start_session(AMDeviceRef device) {
AMDeviceConnect(device);
assert(AMDeviceIsPaired(device));
check_error(AMDeviceValidatePairing(device));
check_error(AMDeviceStartSession(device));
}

void start_remote_debug_server(AMDeviceRef device) {

dbgServiceConnection = NULL;
Expand Down Expand Up @@ -2539,6 +2539,7 @@ void handle_device(AMDeviceRef device) {
if (detect_only) {
if (_json_output) {
NSLogJSON(@{@"Event": @"DeviceDetected",
@"Interface": (__bridge NSString *)device_interface_name,
@"Device": get_device_json_dict(device)
});
} else {
Expand Down Expand Up @@ -2770,6 +2771,7 @@ void device_callback(struct am_device_notification_callback_info *info, void *ar
NSLogVerbose(@"[....] Disconnected %@ from %@.", device_uuid, device_interface_name);
if (detect_only && _json_output) {
NSLogJSON(@{@"Event": @"DeviceDisconnected",
@"Interface": (__bridge NSString *)device_interface_name,
@"Device": get_device_json_dict(info->dev)
});
}
Expand Down

0 comments on commit c86d933

Please # to comment.