diff options
Diffstat (limited to 'src/bluetooth/qbluetoothlocaldevice_android.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_android.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_android.cpp b/src/bluetooth/qbluetoothlocaldevice_android.cpp index ef7e4074..002d699f 100644 --- a/src/bluetooth/qbluetoothlocaldevice_android.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_android.cpp @@ -38,6 +38,9 @@ ** ****************************************************************************/ +#include "android/androidutils_p.h" +#include "android/localdevicebroadcastreceiver_p.h" +#include "qbluetoothlocaldevice_p.h" #include <QtCore/QLoggingCategory> #include <QtCore/private/qjnihelpers_p.h> #include <QtAndroidExtras/QAndroidJniEnvironment> @@ -45,9 +48,6 @@ #include <QtBluetooth/QBluetoothLocalDevice> #include <QtBluetooth/QBluetoothAddress> -#include "qbluetoothlocaldevice_p.h" -#include "android/localdevicebroadcastreceiver_p.h" - QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID) @@ -110,6 +110,12 @@ void QBluetoothLocalDevicePrivate::initialize(const QBluetoothAddress &address) return; } + if (!(ensureAndroidPermission(BluetoothPermission::Scan) && + ensureAndroidPermission(BluetoothPermission::Connect))) { + qCWarning(QT_BT_ANDROID) << "Local device unable to get permissions."; + return; + } + obj = new QAndroidJniObject(adapter); if (!address.isNull()) { const QString localAddress @@ -308,6 +314,11 @@ QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices() { + // As a static class function we need to ensure permissions here (in addition to initialize()) + if (!ensureAndroidPermission(BluetoothPermission::Connect)) { + qCWarning(QT_BT_ANDROID) << "allDevices() unable to get permission."; + return {}; + } // Android only supports max of one device (so far) QList<QBluetoothHostInfo> localDevices; |