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,
|
usbDevice,
|
||||||
CFSTR(kUSBSerialNumberString),
|
CFSTR(kUSBSerialNumberString),
|
||||||
kCFAllocatorDefault, 0));
|
kCFAllocatorDefault, 0));
|
||||||
|
if (cfUid) {
|
||||||
QString uid = CFStringRef2QString(cfUid);
|
QString uid = CFStringRef2QString(cfUid);
|
||||||
CFRelease(cfUid);
|
CFRelease(cfUid);
|
||||||
|
qCDebug(detectLog) << "device UID is" << uid;
|
||||||
IosDeviceManager::instance()->deviceConnected(uid, name);
|
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
|
// Done with this USB device; release the reference added by IOIteratorNext
|
||||||
kr = IOObjectRelease(usbDevice);
|
kr = IOObjectRelease(usbDevice);
|
||||||
@@ -385,18 +390,22 @@ void deviceDisconnectedCallback(void *refCon, io_iterator_t iterator)
|
|||||||
|
|
||||||
// Get the USB device's name.
|
// Get the USB device's name.
|
||||||
kr = IORegistryEntryGetName(usbDevice, deviceName);
|
kr = IORegistryEntryGetName(usbDevice, deviceName);
|
||||||
if (KERN_SUCCESS != kr)
|
QString name;
|
||||||
deviceName[0] = '\0';
|
if (KERN_SUCCESS == kr)
|
||||||
qCDebug(detectLog) << "ios device " << deviceName << " in deviceDisconnectedCallback";
|
name = QString::fromLocal8Bit(deviceName);
|
||||||
|
qCDebug(detectLog) << "ios device " << name << " in deviceDisconnectedCallback";
|
||||||
|
|
||||||
{
|
CFStringRef cfUid = static_cast<CFStringRef>(
|
||||||
CFStringRef cfUid = static_cast<CFStringRef>(IORegistryEntryCreateCFProperty(
|
IORegistryEntryCreateCFProperty(usbDevice,
|
||||||
usbDevice,
|
|
||||||
CFSTR(kUSBSerialNumberString),
|
CFSTR(kUSBSerialNumberString),
|
||||||
kCFAllocatorDefault, 0));
|
kCFAllocatorDefault,
|
||||||
|
0));
|
||||||
|
if (cfUid) {
|
||||||
QString uid = CFStringRef2QString(cfUid);
|
QString uid = CFStringRef2QString(cfUid);
|
||||||
CFRelease(cfUid);
|
CFRelease(cfUid);
|
||||||
IosDeviceManager::instance()->deviceDisconnected(uid);
|
IosDeviceManager::instance()->deviceDisconnected(uid);
|
||||||
|
} else {
|
||||||
|
qCDebug(detectLog) << "failed to retrieve device's UID";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done with this USB device; release the reference added by IOIteratorNext
|
// Done with this USB device; release the reference added by IOIteratorNext
|
||||||
|
Reference in New Issue
Block a user