summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2017-12-11 11:01:24 +0100
committerOliver Wolff <oliver.wolff@qt.io>2017-12-12 09:01:12 +0000
commite46cde935ee76eaa00e78af968121502e2406347 (patch)
treea52c0870a629350103479caaa8cf469403bd9f53
parent61cc3be31d750ecf32506ee585a4957e2c81dfe7 (diff)
winrt: Do not crash when trying to an unreachable paired LE device
As device discovery returns every paired device on winrt, it is possible that we try to connect to a device, that is paired but not available. When doing so the application should not crash but state that there was an error connecting to the device. Task-number: QTBUG-64480 Change-Id: I8d79f6da1de2b0bda7a51a7cfd068bb4a6057257 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Miguel Costa <miguel.costa@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp
index ed36790b..1e06dedb 100644
--- a/src/bluetooth/qlowenergycontroller_winrt.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt.cpp
@@ -400,7 +400,17 @@ void QLowEnergyControllerPrivate::connectToDevice()
Q_ASSERT_SUCCEEDED(hr);
ComPtr<IGattReadResult> result;
hr = QWinRTFunctions::await(op, result.GetAddressOf());
- Q_ASSERT_SUCCEEDED(hr);
+ if (hr == E_INVALIDARG) {
+ // E_INVALIDARG happens when user tries to connect to a device that was paired
+ // before but is not available.
+ qCDebug(QT_BT_WINRT) << "Could not obtain characteristic read result that triggers"
+ "device connection. Is the device reachable?";
+ setError(QLowEnergyController::ConnectionError);
+ setState(QLowEnergyController::UnconnectedState);
+ return;
+ } else {
+ Q_ASSERT_SUCCEEDED(hr);
+ }
ComPtr<ABI::Windows::Storage::Streams::IBuffer> buffer;
hr = result->get_Value(&buffer);
Q_ASSERT_SUCCEEDED(hr);