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;
|
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.
|
Sets the socket state to \a state.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -36,12 +36,13 @@
|
||||||
|
|
||||||
#include <QtBluetooth/qbluetoothglobal.h>
|
#include <QtBluetooth/qbluetoothglobal.h>
|
||||||
|
|
||||||
#include <QtBluetooth/QBluetoothAddress>
|
#include <QtBluetooth/qbluetooth.h>
|
||||||
#include <QtBluetooth/QBluetoothUuid>
|
#include <QtBluetooth/qbluetoothaddress.h>
|
||||||
#include <QtBluetooth/QBluetoothServiceInfo>
|
#include <QtBluetooth/qbluetoothuuid.h>
|
||||||
|
#include <QtBluetooth/qbluetoothserviceinfo.h>
|
||||||
|
|
||||||
#include <QtCore/QIODevice>
|
#include <QtCore/qiodevice.h>
|
||||||
#include <QtNetwork/QAbstractSocket>
|
#include <QtNetwork/qabstractsocket.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
@ -129,6 +130,9 @@ public:
|
||||||
//bool waitForDisconnected(int msecs = 30000);
|
//bool waitForDisconnected(int msecs = 30000);
|
||||||
//virtual bool waitForReadyRead(int msecs = 30000);
|
//virtual bool waitForReadyRead(int msecs = 30000);
|
||||||
|
|
||||||
|
void setPreferredSecurityFlags(QBluetooth::SecurityFlags flags);
|
||||||
|
QBluetooth::SecurityFlags preferredSecurityFlags() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void connected();
|
void connected();
|
||||||
void disconnected();
|
void disconnected();
|
||||||
|
|
|
@ -173,6 +173,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
|
||||||
socketError(QBluetoothSocket::NoSocketError),
|
socketError(QBluetoothSocket::NoSocketError),
|
||||||
connecting(false),
|
connecting(false),
|
||||||
discoveryAgent(0),
|
discoveryAgent(0),
|
||||||
|
secFlags(QBluetooth::Secure),
|
||||||
inputThread(0)
|
inputThread(0)
|
||||||
{
|
{
|
||||||
adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
|
adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
|
||||||
|
|
|
@ -64,6 +64,7 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
|
||||||
connectWriteNotifier(0),
|
connectWriteNotifier(0),
|
||||||
connecting(false),
|
connecting(false),
|
||||||
discoveryAgent(0),
|
discoveryAgent(0),
|
||||||
|
secFlags(QBluetooth::Authorization),
|
||||||
lowEnergySocketType(0)
|
lowEnergySocketType(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -712,6 +712,18 @@ int QBluetoothSocket::socketDescriptor() const
|
||||||
return -1;
|
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
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
|
QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
|
||||||
|
|
|
@ -40,7 +40,8 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
|
||||||
: socket(-1),
|
: socket(-1),
|
||||||
socketType(QBluetoothServiceInfo::UnknownProtocol),
|
socketType(QBluetoothServiceInfo::UnknownProtocol),
|
||||||
state(QBluetoothSocket::UnconnectedState),
|
state(QBluetoothSocket::UnconnectedState),
|
||||||
socketError(QBluetoothSocket::NoSocketError)
|
socketError(QBluetoothSocket::NoSocketError),
|
||||||
|
secFlags(QBluetooth::NoSecurity)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,7 @@ public:
|
||||||
|
|
||||||
QBluetoothServiceDiscoveryAgent *discoveryAgent;
|
QBluetoothServiceDiscoveryAgent *discoveryAgent;
|
||||||
QBluetoothSocket::OpenMode openMode;
|
QBluetoothSocket::OpenMode openMode;
|
||||||
|
QBluetooth::SecurityFlags secFlags;
|
||||||
|
|
||||||
|
|
||||||
// QByteArray rxBuffer;
|
// QByteArray rxBuffer;
|
||||||
|
|
Loading…
Reference in New Issue