Add preferredSecurityFlags to QBluetoothSocket
This permits the API user to determine the security parameters for the connect attempt to the remote SPP service. Task-number: QTBUG-46377 Change-Id: I1ed5ea0f5a32aa08dcedc46a34b0377654e420b2 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
This commit is contained in:
parent
f870501469
commit
c9af4c90ee
|
@ -486,6 +486,60 @@ QString QBluetoothSocket::errorString() const
|
|||
return d->errorString;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the preferred security parameter for the connection attempt to
|
||||
\a flags. This value is incorporated when calling \l connectToService().
|
||||
Therefore it is required to reconnect to change this parameter for an
|
||||
existing connection.
|
||||
|
||||
On Bluez this property is set to QBluetooth::Authorization by default.
|
||||
|
||||
On OS X, this value is ignored as the platform does not permit access
|
||||
to the security parameter of the socket. By default the platform prefers
|
||||
secure/encrypted connections though and therefore this function always
|
||||
returns \l QBluetooth::Secure.
|
||||
|
||||
Android only supports two levels of security (secure and non-secure). If this flag is set to
|
||||
\l QBluetooth::NoSecurity the socket object will not employ any authentication or encryption.
|
||||
Any other security flag combination will trigger a secure Bluetooth connection.
|
||||
This flag is set to \l QBluetooth::Secure by default.
|
||||
|
||||
\note A secure connection requires a pairing between the two devices. On
|
||||
some platforms, the pairing is automatically initiated during the establishment
|
||||
of the connection. Other platforms require the application to manually trigger
|
||||
the pairing before attempting to connect.
|
||||
|
||||
\sa preferredSecurityFlags()
|
||||
|
||||
\since 5.5
|
||||
*/
|
||||
void QBluetoothSocket::setPreferredSecurityFlags(QBluetooth::SecurityFlags flags)
|
||||
{
|
||||
Q_D(QBluetoothSocket);
|
||||
if (d->secFlags != flags)
|
||||
d->secFlags = flags;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the security parameters used for the initial connection
|
||||
attempt.
|
||||
|
||||
The security parameters may be renegotiated between the two parties
|
||||
during or after the connection has been established. If such a change happens
|
||||
it is not reflected in the value of this flag.
|
||||
|
||||
On OS X, this flag is always set to \l QBluetooth::Secure.
|
||||
|
||||
\sa setPreferredSecurityFlags()
|
||||
|
||||
\since 5.5
|
||||
*/
|
||||
QBluetooth::SecurityFlags QBluetoothSocket::preferredSecurityFlags() const
|
||||
{
|
||||
Q_D(const QBluetoothSocket);
|
||||
return d->secFlags;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the socket state to \a state.
|
||||
*/
|
||||
|
|
|
@ -36,12 +36,13 @@
|
|||
|
||||
#include <QtBluetooth/qbluetoothglobal.h>
|
||||
|
||||
#include <QtBluetooth/QBluetoothAddress>
|
||||
#include <QtBluetooth/QBluetoothUuid>
|
||||
#include <QtBluetooth/QBluetoothServiceInfo>
|
||||
#include <QtBluetooth/qbluetooth.h>
|
||||
#include <QtBluetooth/qbluetoothaddress.h>
|
||||
#include <QtBluetooth/qbluetoothuuid.h>
|
||||
#include <QtBluetooth/qbluetoothserviceinfo.h>
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtNetwork/QAbstractSocket>
|
||||
#include <QtCore/qiodevice.h>
|
||||
#include <QtNetwork/qabstractsocket.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -129,6 +130,9 @@ public:
|
|||
//bool waitForDisconnected(int msecs = 30000);
|
||||
//virtual bool waitForReadyRead(int msecs = 30000);
|
||||
|
||||
void setPreferredSecurityFlags(QBluetooth::SecurityFlags flags);
|
||||
QBluetooth::SecurityFlags preferredSecurityFlags() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void connected();
|
||||
void disconnected();
|
||||
|
|
|
@ -173,6 +173,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
|
|||
socketError(QBluetoothSocket::NoSocketError),
|
||||
connecting(false),
|
||||
discoveryAgent(0),
|
||||
secFlags(QBluetooth::Secure),
|
||||
inputThread(0)
|
||||
{
|
||||
adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
|
||||
|
|
|
@ -64,6 +64,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
|
|||
connectWriteNotifier(0),
|
||||
connecting(false),
|
||||
discoveryAgent(0),
|
||||
secFlags(QBluetooth::Authorization),
|
||||
lowEnergySocketType(0)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -712,6 +712,18 @@ int QBluetoothSocket::socketDescriptor() const
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* not supported on OS X */
|
||||
void QBluetoothSocket::setPreferredSecurityFlags(QBluetooth::SecurityFlags flags)
|
||||
{
|
||||
Q_UNUSED(flags)
|
||||
}
|
||||
|
||||
/* not supported on OS X - platform always uses encryption */
|
||||
QBluetooth::SecurityFlags QBluetoothSocket::preferredSecurityFlags() const
|
||||
{
|
||||
return QBluetooth::Secure;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
||||
QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
|
||||
|
|
|
@ -40,7 +40,8 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
|
|||
: socket(-1),
|
||||
socketType(QBluetoothServiceInfo::UnknownProtocol),
|
||||
state(QBluetoothSocket::UnconnectedState),
|
||||
socketError(QBluetoothSocket::NoSocketError)
|
||||
socketError(QBluetoothSocket::NoSocketError),
|
||||
secFlags(QBluetooth::NoSecurity)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ public:
|
|||
|
||||
QBluetoothServiceDiscoveryAgent *discoveryAgent;
|
||||
QBluetoothSocket::OpenMode openMode;
|
||||
QBluetooth::SecurityFlags secFlags;
|
||||
|
||||
|
||||
// QByteArray rxBuffer;
|
||||
|
|
Loading…
Reference in New Issue