11#include <QCoreApplication>
12#include <QtCore/qcoreapplication.h>
13#include <QtCore/QLoggingCategory>
14#include <QtCore/QTimer>
15#include <QtCore/QJniEnvironment>
16#include <QtBluetooth/QBluetoothHostInfo>
17#include <QtBluetooth/QBluetoothLocalDevice>
18#include <QtBluetooth/QBluetoothServiceDiscoveryAgent>
29 m_deviceAdapterAddress(deviceAdapter),
40 bool createAdapter =
true;
41 if (!deviceAdapter.isNull()) {
44 createAdapter =
false;
47 return info.address() == deviceAdapter;
52 createAdapter =
false;
64 if (!btAdapter.isValid())
65 qCWarning(QT_BT_ANDROID) <<
"Platform does not support Bluetooth";
67 qRegisterMetaType<QList<QBluetoothUuid> >();
73 receiver->unregisterReceiver();
76 if (localDeviceReceiver) {
77 localDeviceReceiver->unregisterReceiver();
78 delete localDeviceReceiver;
87 qCWarning(QT_BT_ANDROID) <<
"Service discovery start() failed due to missing permissions";
90 "Failed to start service discovery due to missing permissions.");
96 if (!btAdapter.isValid()) {
99 errorString = QBluetoothServiceDiscoveryAgent::tr(
"Platform does not support Bluetooth");
104 errorString = QBluetoothServiceDiscoveryAgent::tr(
"Invalid Bluetooth adapter address");
117 btAdapter.callMethod<QtJniTypes::BluetoothDevice>(
"getRemoteDevice",
118 inputString.object<jstring>());
119 if (!remoteDevice.isValid()) {
124 errorString = QBluetoothServiceDiscoveryAgent::tr(
"Cannot create Android BluetoothDevice");
127 <<
"(" <<
address.toString() <<
")";
141 remoteDevice.callMethod<QtJniTypes::ParcelUuidArray>(
"getUuids");
143 if (!parcelUuidArray.isValid()) {
146 errorString = QBluetoothServiceDiscoveryAgent::tr(
"Cannot obtain service uuids");
150 <<
"(" <<
address.toString() <<
")";
168 this->_q_processFetchedUuids(
address, uuids);
172 if (!localDeviceReceiver) {
176 this->_q_hostModeStateChanged(state);
180 jboolean
result = remoteDevice.callMethod<jboolean>(
"fetchUuidsWithSdp");
183 receiver->unregisterReceiver();
184 receiver->deleteLater();
186 qCWarning(QT_BT_ANDROID) <<
"Cannot start dynamic fetch.";
192void QBluetoothServiceDiscoveryAgentPrivate::stop()
199 receiver->unregisterReceiver();
200 receiver->deleteLater();
209void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids(
221 this->_q_fetchUuidsTimeout();
229 if (QT_BT_ANDROID().isDebugEnabled()) {
231 <<
"\ncount: " << uuids.
size();
247 if (sdpCache.contains(
address)) {
252 populateDiscoveredServices(pair.first, uuids);
264 if (pair.first.address() !=
address)
274 this->_q_fetchUuidsTimeout();
303 bool haveSppClass =
false;
333 return profileSequence;
351 if (customUuids.
contains(
i) && haveSppClass) {
359 sppProfileDescriptorList());
367 serviceInfo.
setServiceName(QBluetoothServiceDiscoveryAgent::tr(
"Serial Port Profile"));
375 sppProfileDescriptorList());
403 for (
const auto &uuid :
std::as_const(uuidFilter)) {
413 if (!isDuplicatedService(serviceInfo)) {
424void QBluetoothServiceDiscoveryAgentPrivate::_q_fetchUuidsTimeout()
431 if (!sdpCache.isEmpty()) {
435 pair = sdpCache.take(
key);
436 populateDiscoveredServices(pair.first, pair.second);
444 receiver->unregisterReceiver();
445 receiver->deleteLater();
459 errorString = QBluetoothServiceDiscoveryAgent::tr(
"Device is powered off");
463 receiver->unregisterReceiver();
464 receiver->deleteLater();
QJniObject getDefaultBluetoothAdapter()
QT_BEGIN_NAMESPACE bool ensureAndroidPermission(QBluetoothPermission::CommunicationModes modes)
void hostModeStateChanged(QBluetoothLocalDevice::HostMode state)
QString name() const
Returns the name assigned to the device.
HostMode
This enum describes the most of the local Bluetooth device.
static QList< QBluetoothHostInfo > allDevices()
Returns a list of all available local Bluetooth devices.
~QBluetoothServiceDiscoveryAgentPrivate()
QList< QBluetoothServiceInfo > discoveredServices
void _q_serviceDiscoveryFinished()
QBluetoothServiceDiscoveryAgentPrivate(QBluetoothServiceDiscoveryAgent *qp, const QBluetoothAddress &deviceAdapter)
DiscoveryState discoveryState()
QList< QBluetoothDeviceInfo > discoveredDevices
QBluetoothServiceDiscoveryAgent::Error error
QBluetoothAddress m_deviceAdapterAddress
@ MissingPermissionsError
@ InvalidBluetoothAdapterError
void setServiceUuid(const QBluetoothUuid &uuid)
This is a convenience function.
QBluetoothUuid serviceUuid() const
This is a convenience function.
void setDevice(const QBluetoothDeviceInfo &info)
Sets the Bluetooth device that provides this service to device.
void setAttribute(quint16 attributeId, const QVariant &value)
Sets the attribute identified by attributeId to value.
@ BluetoothProfileDescriptorList
void setServiceName(const QString &name)
This is a convenience function.
QList< QBluetoothUuid > serviceClassUuids() const
Returns a list of UUIDs describing the service classes that this service conforms to.
static QBluetoothUuid reverseUuid(const QBluetoothUuid &serviceUuid)
quint16 toUInt16(bool *ok=nullptr) const
Returns the 16 bit representation of this UUID.
int minimumSize() const
Returns the minimum size in bytes that this UUID can be represented in.
ServiceClassUuid
This enum is a convienience type for Bluetooth service class and profile UUIDs.
static QString serviceClassToString(ServiceClassUuid uuid)
Returns a human-readable and translated name for the given service class represented by uuid.
qsizetype size() const noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool singleShot
whether the timer is a single-shot timer
bool isNull() const noexcept
Returns true if this is the null UUID {00000000-0000-0000-0000-000000000000}; otherwise returns false...
bool contains(const AT &t) const
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
void uuidFetchFinished(const QBluetoothAddress &addr, const QList< QBluetoothUuid > &serviceUuid)
static QList< QBluetoothUuid > convertParcelableArray(const QJniObject &obj)
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE constexpr auto uuidFetchTimeLimit
std::pair< T1, T2 > QPair
DBusConnection const char DBusError * error
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
#define Q_ARG(Type, data)
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
QFileInfo info(fileName)
[8]
char * toString(const MyType &t)
[31]
bool contains(const AT &t) const noexcept