Bttestui is a manual bluetooth test application with which one can
manually test different bluetooth features. This commit adds Low Energy
support for the application.
The support is logically simple and flat meaning that it does not
on purpose implement automated state flows. Rather one can manually
trigger each action and modify them locally as needed for testing
purposes.
The commit adds base support for both central and peripheral roles and
their basic functionalities: discovery, advertisement, read and write.
In addition few changes:
- Make the main.qml flickable to be able to use on small screens
- Remove QML import numbering
- Add nullptr checks in some of the functions, sometimes it is
intentional to eg. disable localDevice creation
Fixes: QTBUG-103827
Change-Id: I57c88912803eab8e777c9e6ef3bcaa5401709381
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
At least for testing on Android it's easier to have an out-of-tree
build.
Task-number: QTBUG-103827
Change-Id: I4f89a1c96d65542a1317a6f223f8bd00720ef3cb
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
When disconnecting from a device, a message about the MTU size
might be handled after the pointer to the GATT session is already
set to zero. This leads to a warning message.
This patch improves the message to highlight that the
GATT session might be just outdated. When triggered during
disconnection, the user might infer that it's not that bad.
Task-number: QTBUG-96530
Change-Id: I05f93e535e649ac182e45fc6e89ed525dd4b5fc6
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
The function is not implemented, so it must return false according to
the documentation.
[ChangeLog][QtBluetooth][macOS] QBluetoothSocket::setSocketDescriptor
now always returns false on Darwin backend. That is the correct behavior
because this method is not implemented.
Change-Id: Ibebf9ef69b59ff6e9784b81c3cdd708a71299db9
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Because of QTBUG-98651 and QTBUG-97482 a QPushButton with a dropdown
menu was not working properly neither on iOS nor on Android.
This patch fixes the issue, but it's not optimal, because it re-creates
the menu every time.
Ideally we should provide QML-based GUI for the example.
Task-number: QTBUG-103949
Pick-to: 6.3 6.2
Change-Id: Icd1e00f27f5c4864a33fa7f1f7755c0e919183cb
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
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>
The key is needed for iOS applications accessing NFC hardware
Change-Id: Icbdd605504b2392934d7edc7f1daa192ffdef1c3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
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>
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: d58d134d25
Fixes: QTBUG-103388
Change-Id: I96de202e9ac8c33e51bc126389f62091d03eab70
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
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 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>
Instead of manually writing something like
"this value was introduced by <Qt version>"
Change-Id: I64ab419d034c2b01217670d0a09c9cd9ae79b6df
Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi>
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>
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>
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>
On Android 12 device it seems that the Connectable/Discoverable hostmode
is governed by the UI bluetooth visibility setting. This commit makes
the test pass and assumes the visibility setting is 'true'.
Fixes: QTBUG-102874
Change-Id: Ic772cb4e5a76cef7b512b5d87f2f8842599d1fd5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
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>
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>
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>
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>
[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>
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>
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>
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>
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>
... 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>
... in anticipation of a future deprecation of yet another synonym of
size().
Change-Id: Id2bc51df7583f7157317bd768accc7dbf4dcd0a5
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
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>
Yes, they're identical, but I had to look that up first.
Change-Id: I5a3f72e79556575e48a33f2f16b8dbef460adac0
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
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>
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>
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>
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>
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>
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>
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>
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>
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>