forked from qt-creator/qt-creator
iOS: Guard against failure to retrieve device UID
It should not happen, but if it happens, Qt Creator should not crash. Task-number: QTCREATORBUG-23460 Change-Id: Id25b53ff24d7e1726efc344dc6318c32073ee75c Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -356,9 +356,14 @@ void deviceConnectedCallback(void *refCon, io_iterator_t iterator)
|
||||
usbDevice,
|
||||
CFSTR(kUSBSerialNumberString),
|
||||
kCFAllocatorDefault, 0));
|
||||
if (cfUid) {
|
||||
QString uid = CFStringRef2QString(cfUid);
|
||||
CFRelease(cfUid);
|
||||
qCDebug(detectLog) << "device UID is" << uid;
|
||||
IosDeviceManager::instance()->deviceConnected(uid, name);
|
||||
} else {
|
||||
qCDebug(detectLog) << "failed to retrieve device's UID";
|
||||
}
|
||||
|
||||
// Done with this USB device; release the reference added by IOIteratorNext
|
||||
kr = IOObjectRelease(usbDevice);
|
||||
@@ -385,18 +390,22 @@ void deviceDisconnectedCallback(void *refCon, io_iterator_t iterator)
|
||||
|
||||
// Get the USB device's name.
|
||||
kr = IORegistryEntryGetName(usbDevice, deviceName);
|
||||
if (KERN_SUCCESS != kr)
|
||||
deviceName[0] = '\0';
|
||||
qCDebug(detectLog) << "ios device " << deviceName << " in deviceDisconnectedCallback";
|
||||
QString name;
|
||||
if (KERN_SUCCESS == kr)
|
||||
name = QString::fromLocal8Bit(deviceName);
|
||||
qCDebug(detectLog) << "ios device " << name << " in deviceDisconnectedCallback";
|
||||
|
||||
{
|
||||
CFStringRef cfUid = static_cast<CFStringRef>(IORegistryEntryCreateCFProperty(
|
||||
usbDevice,
|
||||
CFStringRef cfUid = static_cast<CFStringRef>(
|
||||
IORegistryEntryCreateCFProperty(usbDevice,
|
||||
CFSTR(kUSBSerialNumberString),
|
||||
kCFAllocatorDefault, 0));
|
||||
kCFAllocatorDefault,
|
||||
0));
|
||||
if (cfUid) {
|
||||
QString uid = CFStringRef2QString(cfUid);
|
||||
CFRelease(cfUid);
|
||||
IosDeviceManager::instance()->deviceDisconnected(uid);
|
||||
} else {
|
||||
qCDebug(detectLog) << "failed to retrieve device's UID";
|
||||
}
|
||||
|
||||
// Done with this USB device; release the reference added by IOIteratorNext
|
||||
|
Reference in New Issue
Block a user