summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Fix bluetooth service discovery not finishing on AndroidJuha Vuolle2022-06-282-10/+22
| | | | | | | | | | | | | | | | | | | The service discovery finished signal is not emitted when the SDP cache is empty when last device inquiry of services finishes. This commit changes the logic so that the the inquiry is finished independent of whether actual services were discovered on (any) of the devices. As a related drive-by: - Document the role of sdpCache to ease understanding - Change raw timeout limits into a variable Fixes: QTBUG-104479 Change-Id: Ifc9e8587a66769a1fc7959a8154f2be72ffd7461 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 7c7d860ca52dc19e994a1166b6e2d0f5fa869455) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix documentation issues and enable documentation testing in CITopi Reinio2022-06-283-5/+13
| | | | | | | | | | | This will fail the integration of changes that introduce new documentation warnings. Change-Id: I503b123417308f7ba264422a78850e6188a10a48 Reviewed-by: Luca Di Sera <luca.disera@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 74215aeed1c27b56acd266673ba4447b287c145d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix Bluez LE advertiser crash on large advertisement dataJuha Vuolle2022-06-281-1/+2
| | | | | | | | | | | | | The calculation to count the number of service UUIDs that fit the 31 bytes resulted in choosing a number of services that doesn't fit, ultimately leading to a memset() crash a bit later. Fixes: QTBUG-104060 Change-Id: Iad170cfded7363f820a92230df27cdb57bce3814 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit efc4541af0f02d254cabf82b3db0412e7b83682e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix spelling errors in debug outputKai Köhne2022-06-242-4/+4
| | | | | | | | Task-number: QTBUG-97092 Change-Id: I5a5289915d0f3e68327e0414b83f824614f31e07 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi> (cherry picked from commit 66947141e75aeca89e1f68abbc15fbef09404ecf) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Add a timeout guard for Android BT device discovery not startingJuha Vuolle2022-06-215-25/+95
| | | | | | | | | | | | | | | | | In some bluetooth environments, after a full SDP service discovery, the device discovery can get stuck indefinitely. Everything seems to be starting fine but we do not get the DISCOVERY_STARTED action. In the normal case this action is received in < 1 second. This commit adds a timeout guard for this. If we don't get the DISCOVERY_STARTED action in time, we silently restart the query. Typically the discovery starts working after 10..20 seconds. Task-number: QTBUG-101066 Change-Id: Id6032ebeec97d1ad9eec07a946bc623c92500fd5 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit eedaaca9634d56dce27601749049c81b201ab625) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Repair tst_QBluetoothDeviceDiscoveryAgent unit test on AndroidAndreas Buhr2022-06-211-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | tst_QBluetoothDeviceDiscoveryAgent::tst_startStopDeviceDiscoveries was broken on Android. The sequence QBluetoothDeviceDiscoveryAgent::start() QBluetoothDeviceDiscoveryAgent::stop() QBluetoothDeviceDiscoveryAgent::start() QBluetoothDeviceDiscoveryAgent::stop() is called rather quickly. The first stop() results in the state pendingCancel=true, pendingStart=false. The second start() results in the state pendingCancel=true, pendingStart=true. The second stop() then did nothing because pendingCancel=true. Then, after the whole sequence, discovery started because pendingStart=true. This patch repairs it by setting pendingStart=false in the stop() method. Change-Id: I55486b5b494265c90149e72461a1d0529adaa2f0 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 32b859dc9c83c7fb440e53335917021ef7eab15d) Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Android BT LE advertisement start to fail when bluetooth is OFFJuha Vuolle2022-06-211-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When we start a BT LE advertisement while bluetooth is OFF, the advertisement should fail to start, and on the other hand when bluetooth is switched back ON, starting the advertisement should be possible again. This commit adds offline/online check to the startAdvertising function. In addition the creation of the advertiser is delayed until the first advertisement request. This delaying is done for the case when the bluetooth is OFF when the LE controller is created => we don't want the creation of advertisement to fail once during construction and therefore become unusable even if bluetooth is later switched ON. For completeness it should be mentioned that Android documentation mentions that the getBluetoothLeAdvertiser() returns 'null' if the bluetooth is offline. However on all the devices I've tried this, it returns a valid instance. This means that the creation delay of this commit would not be strictly speaking necessary. But we shouldn't rely on it: on some Android devices the advertiser might be returned as null when bluetooth is offline, as documented. Fixes: QTBUG-104106 Change-Id: Ia016e4534c29fac23f42785d68bc95d568c41def Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 4292b32d57f7b6dc2f644ee75403ce8b26f9e1e5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix Bluez LE advertiser delete crashJuha Vuolle2022-06-216-17/+22
| | | | | | | | | | | | | | | | | | | | | | Bluez LE advertiser and Bluez LE controller use/share an instance of HCI manager, and in some circumstances the deletion of the LE controller leads to a crash. This is because: 1) LE advertiser and HCI manager are parented to the LE controller 2) LE advertiser uses HCI manager in its destructor => When LE controller is deleted, its QObject children are deleted. If the HCI manager happens to be deleted first, the advertiser uses a by-now deleted HCI manager in its destructor This commit makes the HCI manager a shared resource so that the exact destruction order does not matter. As a drive-by set deleted cmacCalculator pointer to nullptr. Fixes: QTBUG-104105 Change-Id: I1c5e319af2fc59c4d5bb1fed33b8824eb3c4cb29 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit f1ff9f4d17b82b5e597e28118de62beab705519e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QtNfc: Fix iOS session invalidation/restartMike Achtelik2022-06-151-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix a problem where the user is able to get into a state, where iOS NFC implementation deadlocks itself, so the whole app has to be restarted to get it working again. Basically, if we (or the user) abort a scan sessionStoppedByApplication will be set, preventing a new scan until the session is invalidated by the system and sessionStoppedByApplication is cleared. The problem is that sometimes the invalidation by the system takes some time, especially if the sessions is transmitting and waiting for a timeout. In that case, the user is able to quickly start a new scan, which will of course wait for the flag to be cleared. However, if that scan is immediately stopped again self.session will be set to nil. This then becomes a problem, when the original session finally invalidates and we now think it's an unexpected session and return. This means self.sessionStoppedByApplication will never be cleared, preventing any start of the scan. To fix this we should always wait for the system to invalidate the session and not just clear it ourselves. Similarly, if we already have a session don't just to restartPolling, since it has no effect on an invalidated session, so invalidate it to make sure and wait for it to clear and start a new one. Change-Id: I341a114d6ba5c761aa3c61df66b1a17636ec3946 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit a113cea72806e3b1302d36532df3a8a58c6640fe) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix an Android bluetooth logging typoJuha Vuolle2022-06-131-1/+1
| | | | | | | | Task-number: QTBUG-102442 Change-Id: I70909a219d8aa08ebf187e4f0f22e8a79f79498c Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit bfa47d68ecad0345a8080862f3f6a3993e2129c9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Use SPDX license identifiersLucie Gérard2022-06-13264-9928/+559
| | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Ifc22d8ae24532e9a1093ca613ed6590a1992bc39 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 664d2a1cf019f76adf433d41b1418e515ffce86c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Port QtConnectivity configure check reporting from Qt 5Juha Vuolle2022-06-021-2/+23
| | | | | | | | | | In addition reintroduce the 'bluez' compilation test which was omitted in the original Qt 6 port. Pick-to: 6.2 6.3 Fixes: QTBUG-103209 Change-Id: If82e85615f0b85f055d42f3de7662f05f2cbcd08 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Remove QScopedPointer related deprecation warnings on macOSJuha Vuolle2022-05-314-17/+14
| | | | | | | | | | | The QScopedPointer::take() has been deprecated since Qt 6.1 and the suggestion is to use std::unique_ptr instead. Pick-to: 6.2 6.3 Fixes: QTBUG-103826 Change-Id: If40b1dd82f231b07607d1a6bfc6c06e7d3b055e7 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Use the new "permissions error" code on macOSJuha Vuolle2022-05-309-17/+46
| | | | | | | | | | | | | | | | | | | | | | Qt 6.4 introduces new error code for permission errors (QTBUG-102373). This commit makes use of the new error code. This consists of two parts: 1) If the bluetooth permission key is missing from the application's Info.plist and we know it's needed => permission error. This is limited to Low Energy because classic bluetooth does not need it on macOS, and iOS does not support classic bluetooth. If the key is missing, it is an application development/deployment error and we should not make too many of these checks - few places is enough. 2) At runtime the platform prompts for bluetooth permission and the user may disallow it => permission error. Amends: d58d134d25695dd044fc13d57a4d754b1dfb4e4a Fixes: QTBUG-103388 Change-Id: I96de202e9ac8c33e51bc126389f62091d03eab70 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Close socket descriptor when QBluetoothSocketBluez is destroyedJuha Vuolle2022-05-302-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | There are two private QBluetoothSocket backends on Linux: - QBluetoothSocketBluez is native linux socket implementation It is always used by the linux QBluetoothServer, and by QBluetoothSocket if Bluez version is < 5.46 - QBluetoothSocketBluezDbus used by QBluetoothSocket when Bluez >= 5.46 Leaving the native socket unclosed leaks the resource and eventually we may run out of descriptors. This is reproducible by creating and destroying QBluetoothServer instances in a loop. As a related drive-by: - Fix bluetooth socket autotest version check. DBus socket is used with bluez 5.46+ (for clarity: DBus lowenergycontroller is used with bluez 5.42+). This is needed for the test to pass with Bluez < 5.46 - Add a clarifying comment on socket close() Fixes: QTBUG-103067 Pick-to: 5.15 6.2 6.3 Change-Id: Idc38c743be09e559ea82bf09c2f9e44e4b80d666 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* QNdefMessage: un-export the classIevgenii Meshcheriakov2022-05-201-12/+24
| | | | | | | | | | | | | | | | | | | QNdefMessage inherits QList publically, but QList isn't designed to be inherited by an exported class, because we make changes to QList API assuming that its an inline-only class and not exported. However, exporting a derived class means QList API is exported, too. Fix by un-exporting the class, exporting individual functions instead, the inline ones only for Qt 6. This is BiC, too, because the previously-exported QList API no longer is exported, but at least this will prevent further BC breaks going forward. Pick-to: 6.3 6.2 Fixes: QTBUG-102367 Change-Id: I4d0073c9769e50d9c62c11ecc3e3937cce092fa1 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Properly use 'since' qdoc command in enum values documentationIvan Solovev2022-05-195-46/+38
| | | | | | | | Instead of manually writing something like "this value was introduced by <Qt version>" Change-Id: I64ab419d034c2b01217670d0a09c9cd9ae79b6df Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* Introduce error codes for missing permissionsIvan Solovev2022-05-1918-13/+41
| | | | | | | | | | | | | | | | | Some operating systems might request special permissions while working with Bluetooth. Previously if the permissions were missing, we were returning an UnknownError, and the error description, when available, was not very good as well. [ChangeLog][QtBluetooth] Various error enums are extended with new error codes that represent missing permissions error. Error descriptions are also updated, when available. This patch also applies new error codes to Android implementation. Fixes: QTBUG-102373 Change-Id: I247371de6b1eb8d39f0f99c50269d2b1f3bf21c2 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* QtNfc: create "Supported Features" doc pageIvan Solovev2022-05-182-0/+89
| | | | | | | | | | To provide information which access methods and tag types are supported for different platforms Fixes: QTBUG-94792 Change-Id: I85cf94f3108cbb341d98b0ef93c0e11f0f7316ee Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* QtNfc docs: add PC/SC documentation page to the list of articlesIvan Solovev2022-05-181-0/+1
| | | | | | | | So making it easier to navigate to this page from main module documentation page. Change-Id: Ie9b5f5db54746d8ff0ee4d71c49df286b02e3580 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* Android bluetooth local device always to use "Paired"Juha Vuolle2022-05-171-1/+1
| | | | | | | | | | | | | | | | | | QBluetoothLocalDevice on Android doesn't distinguish between "AuthorizedPaired" and "Paired" but regresses to "Paired". This commit changes one place where the code echoes back whatever pairing mode the user requested, instead of "Paired". This caused the sent pairingFinished() signal to have different value than what a call to pairingStatus() gives. In addition this commit fixes the related autotest when run in "manual mode" ie. the BT_TEST_DEVICE and live counterpart device is used. Task-number: QTBUG-102874 Change-Id: I24c76b03ad1d0b27b8afeaf94f146393e4547712 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QtNfc: Get rid of NearFieldTarget classIevgenii Meshcheriakov2022-05-167-15/+8
| | | | | | | | | | Use QNearFieldTarget class directly after making QNearFieldManagerPrivateImpl a friend. Task-number: QTBUG-103357 Change-Id: I3488c7c23e3a050f3f74cbd3edd39e39bf851ea8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QNearFieldTargetPrivate: Use same types in declarations and definitionsIevgenii Meshcheriakov2022-05-161-6/+9
| | | | | | | | | Replace NearFieldTarget in method definitions by QNearFieldTarget used in method declarations. Task-number: QTBUG-103357 Change-Id: I506e1ef558dacc8a38fa3577124e3b5eb2fe657d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Doc: Use find_package(Qt6 REQUIRED COMPONENTS ...) idiomKai Köhne2022-05-132-2/+2
| | | | | | | | | | | Using REQUIRED as a prefix instead of suffix works better with OPTIONAL_COMPONENTS, and is also the order in the CMake manual. Task-number: QTBUG-98867 Pick-to: 6.3 Change-Id: Id019afe67edccdff477569a483ec61393e57602b Reviewed-by: Rui Oliveira Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Windows: implement the missing APIs for QBluetoothLocalDeviceIvan Solovev2022-05-123-13/+121
| | | | | | | | | | | | | | | | [ChangeLog][QBluetoothLocalDevice][Windows] Add support for correctly emitting deviceConnected() and deviceDisconnected() signals, as well as return a valid list of connectedDevices(). The implementation has one assumption - it considers that Windows always has only one local adapter available. This is correct for now, and is unlikely to change, but we need to keep it in mind. Fixes: QTBUG-98942 Change-Id: If7c5ce2237a60754965f485d8fe54159f071a3f0 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Windows: refactor QBluetoothLocalDevice private implementationIvan Solovev2022-05-121-39/+71
| | | | | | | | | | | | | | | | | | | We are using DeviceWatcher instance to track Bluetooth adapter state. To implement the tracking of connected Bluetooth devices, we will need to create 2 more device watchers - one for BTLE, and one for BT Classic devices. To avoid code duplication, this patch introduces a wrapper around DeviceWatcher and applies it to the existing Bluetooth adapter watcher. The callbacks in the wrapper are executed in separate threads, so the wrapper uses signals to interact with AdapterWatcher, and std::enable_shared_from_this to make sure, that the wrapper instance if valid even if the AdapterWatcher is already destroyed. Task-number: QTBUG-98942 Pick-to: 6.3 Change-Id: Icc1e4a01dd333d55c771cbfa6002633575c70881 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* Remove unsupported Android bluetooth codepaths part 2Juha Vuolle2022-05-121-35/+17
| | | | | | | | | | | | | Minimum Android level supported on Qt 6 is Android 6 / API Level 23. This commit removes older unsupported code in order to simplify. This commit completes the cleanup by removing the Java reflection in QtBluetoothBroadcastReceiver::getConnectedDevices() Fixes: QTBUG-102497 Pick-to: 6.2 6.3 Change-Id: Id1b9f900041e8c43c911cfc21102506616537a29 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Remove unsupported Android bluetooth codepathsJuha Vuolle2022-05-1210-261/+51
| | | | | | | | | | | | | | | Minimum Android level supported on Qt 6 is Android 6 / API Level 23. This commit removes older unsupported code in order to simplify. This concerns primarily: - sdkVersion() checks - Java reflections (API availability was uncertain) Task-number: QTBUG-102497 Pick-to: 6.2 6.3 Change-Id: Ia90248a0a8f8e32130b8394998c2676c97a02eb5 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* bluez dbus files: work around qdbusxml2cpp's inability to includemocsMarc Mutz2022-05-1111-0/+25
| | | | | | | | | | | Since we generate these files using a script, anyway, and until qdbusxml2cpp learns how to do it automatically, just append the moc-files manually. Task-number: QTBUG-103313 Task-number: QTBUG-103207 Change-Id: Ia8b95981029cdc65ee513e6fd1acfbf1aac4e006 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* bluez dbus files: adapt the generate script to recent changesMarc Mutz2022-05-1121-69/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... and re-generate We're now supposed to include the qglobal_p.h file in every _p.h file, so pass that as an (additional) -i to qdbusxml2cpp. To DRY, wrap that in a function. There were some changes that I had to remove after the script ran: - qdbusxml2cpp tries to generate properties called 'class', which have been renamed to 'classProperty' in the checked-in files, and I left it as such, for obvious reasons. - The PropertiesChanged() signal in the newly-generated properties_p.h is missing the trailing QDBusMessage parameter, compared to the checked-in version. The slot connected to the signal uses the argument, with no obvious (to this author) way to get the info elsewhere. The includes generated from -i options always use "", not <>, so I guess we need to live with that, or fix qdbusxml2cpp. Task-number: QTBUG-103207 Task-number: QTBUG-103313 Change-Id: Ifee3e74126e9a4fc72e6040d667aa2bb85bbd768 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* Assorted int/qsizetype fixesMarc Mutz2022-05-105-7/+7
| | | | | | | Pick-to: 6.3 6.2 Fixes: QTBUG-102463 Change-Id: I270ef1d3f50d9393b0850e27adca077acffc8511 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Replace some length() calls with size()Marc Mutz2022-05-104-6/+6
| | | | | | | | ... in anticipation of a future deprecation of yet another synonym of size(). Change-Id: Id2bc51df7583f7157317bd768accc7dbf4dcd0a5 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Fix some signed/unsigned mismatchesMarc Mutz2022-05-102-4/+4
| | | | | | | | | | | | In jni_android.cpp, the qstrlen() function returns size_t, the QByteArray ctor takes qsizetype, so int was wrong for both. In QBluetoothserviceInfo/WinRT, compare quint32 to size_t, not qsizetype. Pick-to: 6.3 Change-Id: I4922d3c678d539b5f0ef9c80b50bf10b04e9f32d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Port length() == 0 to isEmpty()Marc Mutz2022-05-103-6/+6
| | | | | Change-Id: I5f317ac857ce44c75f0351287d26d36e1813607d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* ServiceDiscoveryBroadcastReceiver: fix int/jint mismatchMarc Mutz2022-05-101-1/+1
| | | | | | | Yes, they're identical, but I had to look that up first. Change-Id: I5a3f72e79556575e48a33f2f16b8dbef460adac0 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QtConnectivity: replace qSwap with std::swap/member-swap where possibleMarc Mutz2022-05-096-6/+6
| | | | | | | | | | | | | | | | | | | | | qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by using our hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. As a drive-by, port Q_DECL_NOTHROW to noexcept, which has been available to us since Qt 5.7. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 5.15 Change-Id: I08ef8e0c252854e4a9905da77448f280681cc7a3 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Fix crash when service discovery agent (SDA) is stopped on AndroidJuha Vuolle2022-05-071-11/+20
| | | | | | | | | | | | | | | | | | | | | The SDA emits serviceDiscovered() signals for found services while processing them. The application code receiving the signal may call stop() on the SDA when it has received a service-of-interest, which in turn can lead to use of already released resources once the service processing resumes. While the signal is emitted in the populateDiscoveredServices(), the immediate crash was in _q_fetchUuidsTimeout() which calls it. That function unregisters the broadcast receiver, which was already released in stop(). This commit fixes this by making the serviceDiscovered() emission queued so that the service discovery reporting can finish before allowing further SDA calls. Pick-to: 5.15 6.2 6.3 Fixes: QTBUG-102319 Change-Id: I0059c1eaf3756e49b06b12da9e9f332602aa956e Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Replace deprecated bluetooth disable/enable methods on AndroidJuha Vuolle2022-05-074-36/+126
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Starting from Android 13 (API level 33) the BluetoothAdapter enable() and disable() methods have been deprecated. In addition both methods are strongly discouraged as they do not necessarily trigger a permission dialogue to turn the bluetooth ON/OFF. The methods are replaced with preferred 'action requests' which are available since API level 5 and have the benefit of triggering a user dialogue when powering Bluetooth ON/OFF. The calls to these replacing APIs are surrounded by sdkVersion checks with one exception: it appears that the old enable() call does not work well when performing a multi-state transition from Discoverable => PoweredOff => Connectable. The replacing API fairs better there and hence it is replaced unconditionally. Elsewhere the sdkVersion check is for >= 31 in order to be able to test with devices available at the moment (API level 31 corresponds with Android 12). As a drive-by few related code changes: - handle hostmode enum in a switch-case instead of if-elseif - rename the opaque tokens and setConnectable() method in the broadcast receiver to better reflect their role Fixes: QTBUG-102442 Pick-to: 5.15 6.2 6.3 Change-Id: I5d9395ce9e5ecd28b1f8e2f37d13e8aea7cfcdd3 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Android: Use string based permission APITor Arne Vestbø2022-05-061-1/+1
| | | | | | | Preparation for refactoring permission API. Change-Id: I74f41793a7b2fc847139d7fcb50e70ec8c897a40 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Fix Bluez BT LE battery readingJuha Vuolle2022-05-061-11/+51
| | | | | | | | | | | | | | | | | | | | | | This commit addresses two related issues: - From Bluez 5.55 onwards the battery service is available through both GattService1 and Battery1 interface. This broke the current implementation in a way that the battery level was always '0'. This patch uses the GattService1 interface if available - The Battery1 interface is not always available during the service discovery, it's not generated yet. This causes the service to be missed. This patch also checks if the battery remote service is available also from 'Device1' interface This commit has been tested with Bluez versions 5.42..5.63 with Qt6, and with few selected versions with Qt5 Fixes: QTBUG-70222 Pick-to: 5.15 6.2 6.3 Change-Id: I963947937cf85c8082fb044afe223f41e141b7c0 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* DeviceDiscoveryBroadcastReceiver: fix potential integer overflowMarc Mutz2022-05-051-1/+1
| | | | | | | | | | | | | | | | | The old code added two signed integers together, comparing the result with the length of a buffer. While harmless for the expected small values, this is not the kind of code you want to see. Signed integer overflow is UB, so the compiler may assume it doesn't happen. Fix by comparing the index variable to the difference between the buffer length and the current chunk size. The former is known to be >= 0 and the latter < 256 (because its value was sourced from a char variable), so the subtraction cannot overflow. Pick-to: 6.3 6.2 Change-Id: I36f1e8ce5b30058ca2ff4f03299f3bb3e1ec7493 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLeAdvertizerBluez: add missing Q_OBJECT macroMarc Mutz2022-05-041-0/+1
| | | | | | | | | | | | The class doesn't have signals, slots or Q_PROPERTYs, but adding Q_OBJECT is idiomatic, and makes sure qobject_cast and metaObject()->className() work as expected. Pick-to: 6.3 6.2 5.15 Change-Id: I6819605a26f5bd8b41ba68e74e03b03a177da3ea Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* De-inline QLeAdvertizer dtorMarc Mutz2022-05-042-1/+4
| | | | | | | | | | | Destructors of polymorphic classes should be out-of-line to pin vtable and type_info objects to a single TU. Task-number: QTBUG-45582 Change-Id: I54bd07330b41490af6b6696bc6c3c4ed5da29d2a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* includemocsMarc Mutz2022-05-0422-0/+46
| | | | | | | | | | | | | Including moc files directly into their classes' TU tends to improve codegen and enables extended compiler warnings, e.g. about unused private functions or fields. Pick-to: 6.3 6.2 5.15 Fixes: QTBUG-103207 Change-Id: I1811aaef25fe4c1dbc66ebd2354cbf2308ede6dc Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* Rename qleadvertiser_p.h → qleadvertiser_bluez_p.hMarc Mutz2022-05-044-11/+7
| | | | | | | | | | | It's only used by the bluez code, so a) let the name reflect that (as the .cpp file already did) and b) remove the header from non-bluez builds. Pick-to: 6.3 6.2 5.15 Change-Id: Idc9cabcf24b8f639e6e2b9e25f8c92ce10198e8a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
* Add a separate TU for bluez_data_p.hMarc Mutz2022-05-032-1/+47
| | | | | | | | | | | | | The header contains moc-able content, and it's the last moc-file included in the module's mocs_compilation.cpp, so add a bluez_data.cpp and include the moc file there. No moc-able content in 5.15, so just Pick-to: 6.3 6.2 Task-number: QTBUG-103207 Change-Id: Icac94ba5b85fd22d20372b4b691dd66b75fbb6e8 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QLowEnergyControllerPrivateAndroid: remove unused forward declarationMarc Mutz2022-05-031-2/+0
| | | | | | | Pick-to: 6.3 6.2 5.15 Change-Id: I7c95c177ab1e8ed6a0767d77f9500b1daf723857 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Bluetooth pairing mode improvements on WindowsJuha Vuolle2022-05-022-6/+25
| | | | | | | | | | | | | | | | | | | | Windows QBluetoothLocalDevice does not distinguish between "Paired" and "AuthorizedPaired" pairing modes as there does not seem to be APIs to do it. The current implementation has few shortcomings addressed by this commit: - Document the behavior - Use the actual pairing mode as signal value instead of using what was requested. On current implementation the "pairingFinished()" signal and "pairingStatus()" method call may give different values - Perform pairing/unparing only if this could mean a change; requesting 'Paired' is same as requesting 'AuthorizedPaired' Fixes: QTBUG-102412 Change-Id: I57801744432978c70cfdba5e58e8f85acfab92f2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Remove extra ".lib" suffix from Windows library linkageJuha Vuolle2022-05-021-2/+2
| | | | | | | | | | The extra ".lib" can introduce trouble with static linking as the lib can become of the form <>.lib.lib in the Makefile Task-number: QTBUG-102994 Pick-to: 6.2 6.3 Change-Id: I6b74efe535d9a85b4483d04d5952f75c62b735b5 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QBluetoothServiceDiscoveryAgentPrivate: de-pessimize readAttributeValue()Marc Mutz2022-04-281-16/+15
| | | | | | | | | | | | | - drop unneeded toString() calls - use QLatin1String as the key into QXmlStreamAttributes::value() Saves more than one KiB in TEXT size on optimized Linux AMD64 Clang builds - in (basically) _one_ function! Pick-to: 6.3 Change-Id: If6767e3905ba54287096b4d6df85ad7c6be64167 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>