From 759ece64f113cccd93a1c58f770366c84e3093f5 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 20 Dec 2021 12:20:12 +0100 Subject: IOBluetooth: tweak a couple of classes 1. Connection monitor: instead of asserting on 'monitor != nullptr' - issue a warning and bail-out early. Despite of us unregistering from connection notifications and trying to release the monitor, IOBluetooth seems to keep references and sometimes it's possible to trigger this assert in our autotests. 2. IOBluetoothDeviceInquiry - stop reporting errors completely, they are not mapped to any error in QtBluetooth and give nothing but failing auto-tests. Change-Id: I8fc2e23d3685b912759df91c65b02537f39d1b5f Reviewed-by: Juha Vuolle (cherry picked from commit ba38f64e22c98ba6b0d3bdccbd00ea5a643404f8) Reviewed-by: Qt Cherry-pick Bot --- src/bluetooth/darwin/btconnectionmonitor.mm | 9 +++++++++ src/bluetooth/darwin/btdeviceinquiry.mm | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bluetooth/darwin/btconnectionmonitor.mm b/src/bluetooth/darwin/btconnectionmonitor.mm index 548fec9c..a9f038f5 100644 --- a/src/bluetooth/darwin/btconnectionmonitor.mm +++ b/src/bluetooth/darwin/btconnectionmonitor.mm @@ -89,6 +89,15 @@ using namespace QT_NAMESPACE; if (!device) return; + if (!monitor) { + // Rather surprising: monitor == nullptr means we stopped monitoring. + // So apparently this thingie is still alive and keeps receiving + // notifications. + qCWarning(QT_BT_DARWIN, + "Connection notification received in a monitor that was cancelled"); + return; + } + QT_BT_MAC_AUTORELEASEPOOL; // All Obj-C objects are autoreleased. diff --git a/src/bluetooth/darwin/btdeviceinquiry.mm b/src/bluetooth/darwin/btdeviceinquiry.mm index db8c778b..536db35d 100644 --- a/src/bluetooth/darwin/btdeviceinquiry.mm +++ b/src/bluetooth/darwin/btdeviceinquiry.mm @@ -158,11 +158,11 @@ const uint8_t IOBlueoothInquiryLengthS = 15; if (error != kIOReturnSuccess && !aborted) { // QtBluetooth has not too many error codes, 'UnknownError' is not really - // useful, report the actual error code here: + // useful, log the actual error code here: qCWarning(QT_BT_DARWIN) << "IOKit error code: " << error; - m_delegate->error(error); // Let watchDog to stop it, calling -stop at timeout, otherwise, - // it looks like inquiry continues and keeps reporting new devices found. + // it looks like inquiry continues even after this error and + // keeps reporting new devices found. } else { // Either a normal completion or from a timer slot. watchDog.reset(); -- cgit v1.2.3