Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qbluetoothserviceinfo_android.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
10#include "qbluetoothserver_p.h"
11#include "qbluetoothserver.h"
12
13#include <QtCore/QLoggingCategory>
14
16
17Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
18
19extern QHash<QBluetoothServerPrivate*, int> __fakeServerPorts;
20
25
29
31{
32 return registered;
33}
34
36{
37 if (!registered)
38 return false;
39
41 if (!sPriv) {
42 //QBluetoothServer::close() was called without prior call to unregisterService().
43 //Now it is unregistered anyway.
44 registered = false;
45 return true;
46 }
47
48 bool result = sPriv->deactivateActiveListening();
49 if (!result)
50 return false;
51
52 registered = false;
53 return true;
54}
55
57{
59 qCWarning(QT_BT_ANDROID) << "Serviceinfo registerService() failed due to"
60 "missing permissions";
61 return false;
62 }
63
64 const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
65 if (localDevices.isEmpty())
66 return false; //no Bluetooth device
67
68 if (!localAdapter.isNull()) {
69 bool found = false;
70 for (const QBluetoothHostInfo &hostInfo : localDevices) {
71 if (hostInfo.address() == localAdapter) {
72 found = true;
73 break;
74 }
75 }
76
77 if (!found) {
78 qCWarning(QT_BT_ANDROID) << localAdapter.toString() << "is not a valid local Bt adapter";
79 return false;
80 }
81 }
82
83 //already registered on local adapter => nothing to do
84 if (registered)
85 return false;
86
88 qCWarning(QT_BT_ANDROID) << Q_FUNC_INFO << "Only RFCOMM services can be registered on Android";
89 return false;
90 }
91
93 if (!sPriv)
94 return false;
95
96 //tell the server what service name and uuid our listener should have
97 //and start the real listener
98 bool result = sPriv->initiateActiveListening(
101 if (!result) {
102 return false;
103 }
104
105
106 registered = true;
107 return true;
108}
109
QT_BEGIN_NAMESPACE bool ensureAndroidPermission(QBluetoothPermission::CommunicationModes modes)
\inmodule QtBluetooth
\inmodule QtBluetooth
static QList< QBluetoothHostInfo > allDevices()
Returns a list of all available local Bluetooth devices.
QBluetoothServiceInfo::Sequence protocolDescriptor(QBluetoothUuid::ProtocolUuid protocol) const
QMap< quint16, QVariant > attributes
bool registerService(const QBluetoothAddress &localAdapter=QBluetoothAddress())
\inmodule QtBluetooth
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
T value() const &
Definition qvariant.h:516
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE QHash< QBluetoothServerPrivate *, int > __fakeServerPorts
QT_BEGIN_NAMESPACE QHash< QBluetoothServerPrivate *, int > __fakeServerPorts
#define Q_FUNC_INFO
#define qCWarning(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLuint64EXT * result
[6]