summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothlocaldevice_android.cpp
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2022-02-25 11:15:03 +0200
committerJuha Vuolle <juha.vuolle@insta.fi>2022-03-24 12:54:56 +0200
commit542984380435ff254e927cc6fff1e3b3bd8adb04 (patch)
tree6737b0fcbd6141f5215669ee110a5173b32ccb4f /src/bluetooth/qbluetoothlocaldevice_android.cpp
parent438f9ca628e03461102cf757230ee735c0feb0d3 (diff)
Introduce Android 12 / SDK 31+ bluetooth permissions
The Android 12 introduces three new bluetooth runtime permissions which are required to use bluetooth. This commit introduces these permissions. The permission requirements are sprinkled throughout the Android bluetooth APIs, and we need to make sure all user codepaths are covered. As next step we can also reduce the < 31 permissions when building for 31+ target, but this possibly requires some buildsystem related support as well. Task-number: QTBUG-99590 Change-Id: Iab4b7d6d9935509e669265ed6851990d49a3a7e1 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit a0542cff15d58db83a835f1a378a55a0ec117c9c) Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qbluetoothlocaldevice_android.cpp')
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_android.cpp17
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;