in idb_companion/Server/FBIDBServiceHandler.mm [1388:1435]
Status FBIDBServiceHandler::describe(ServerContext *context, const idb::TargetDescriptionRequest *request, idb::TargetDescriptionResponse *response)
{@autoreleasepool{
// Populate the default values
idb::TargetDescription *description = response->mutable_target_description();
FBiOSTargetScreenInfo *screenInfo = _target.screenInfo;
if (screenInfo) {
idb::ScreenDimensions *dimensions = description->mutable_screen_dimensions();
dimensions->set_width(screenInfo.widthPixels);
dimensions->set_height(screenInfo.heightPixels);
dimensions->set_height_points(screenInfo.heightPixels/screenInfo.scale);
dimensions->set_width_points(screenInfo.widthPixels/screenInfo.scale);
dimensions->set_density(screenInfo.scale);
}
description->set_udid(_target.udid.UTF8String);
description->set_name(_target.name.UTF8String);
description->set_state(FBiOSTargetStateStringFromState(_target.state).UTF8String);
description->set_target_type(FBiOSTargetTypeStringFromTargetType(_target.targetType).lowercaseString.UTF8String);
description->set_os_version(_target.osVersion.name.UTF8String);
description->set_architecture(_target.architecture.UTF8String);
// Add extended information
NSDictionary<NSString *, id> *extendedInformation = _target.extendedInformation;
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:extendedInformation options:0 error:&error];
if (!data) {
return Status(grpc::StatusCode::INTERNAL, error.localizedDescription.UTF8String);
}
description->set_extended(data.bytes, data.length);
// Also attach the companion metadata
populate_companion_info(response->mutable_companion(), _eventReporter, _target);
// Only fetch diagnostic information when requested.
if (!request->fetch_diagnostics()) {
return Status::OK;
}
NSDictionary<NSString *, id> *diagnosticInformation = [[_commandExecutor diagnostic_information] block:&error];
if (!diagnosticInformation) {
return Status(grpc::StatusCode::INTERNAL, error.localizedDescription.UTF8String);
}
data = [NSJSONSerialization dataWithJSONObject:diagnosticInformation options:0 error:&error];
if (!data) {
return Status(grpc::StatusCode::INTERNAL, error.localizedDescription.UTF8String);
}
description->set_diagnostics(data.bytes, data.length);
return Status::OK;
}}