From e28adc19ed51006344c26bb46b92fa966ad903ed Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Wed, 14 Aug 2024 13:45:20 +0300 Subject: [PATCH] Decouple location and bluetooth permissions if API level >= 31 This is a manual cherry-pick from bb8cf72233e05c88424d525ca578cbf21d66c938 With minor documentation modification (6.8.1 instead of 6.9) Since Android-12 / API-level 31, the ACCESS_FINE_LOCATION is no longer mandatory for Bluetooth usage. Removing it will avoid unnecessary location permission query (user prompt). There are less common use cases to derive the location too. In these cases the user must override the BLUETOOTH_SCAN permission so that it no longer asserts neverForLocation, and also request the ACCESS_FINE_LOCATION permission separately (QLocationPermission). This change relates to QtBluetooth change, which adds android:usesPermissionFlags="neverForLocation" attribute to BLUETOOTH_SCAN permission (in default-generated AndroidManifest.xml) [ChangeLog][Important Behavior Changes][QBluetoothPermission] ACCESS_FINE_LOCATION is no longer requested if API-level >= 31 Task-number: QTBUG-129944 Task-number: QTBUG-117358 Task-number: QTBUG-112164 Change-Id: I774d0aada4c08829860d252a616fd0c3992a853d Reviewed-by: Ivan Solovev Reviewed-by: Assam Boudjelthia (cherry picked from commit bb8cf72233e05c88424d525ca578cbf21d66c938) --- src/corelib/doc/src/external-resources.qdoc | 4 ++++ src/corelib/kernel/qpermissions.cpp | 19 ++++++++----------- src/corelib/kernel/qpermissions_android.cpp | 6 ++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/corelib/doc/src/external-resources.qdoc b/src/corelib/doc/src/external-resources.qdoc index e6bd65d5b4c..7c3653aa711 100644 --- a/src/corelib/doc/src/external-resources.qdoc +++ b/src/corelib/doc/src/external-resources.qdoc @@ -177,3 +177,7 @@ \title Java arrays */ +/*! + \externalpage https://developer.android.com/develop/connectivity/bluetooth/bt-permissions + \title Android Bluetooth Permissions +*/ diff --git a/src/corelib/kernel/qpermissions.cpp b/src/corelib/kernel/qpermissions.cpp index 4089bee6935..6d295970550 100644 --- a/src/corelib/kernel/qpermissions.cpp +++ b/src/corelib/kernel/qpermissions.cpp @@ -371,16 +371,17 @@ QT_PERMISSION_IMPL_COMMON(QMicrophonePermission) \li \c android.permission.BLUETOOTH_ADVERTISE \li \c android.permission.BLUETOOTH_CONNECT \li \c android.permission.BLUETOOTH_SCAN - \li \c android.permission.ACCESS_FINE_LOCATION \endlist \include permissions.qdocinc end-usage-declarations - \note Currently on Android the \c android.permission.ACCESS_FINE_LOCATION - permission is requested together with Bluetooth permissions. This is - required for Bluetooth to work properly, unless the application provides a - strong assertion in the application manifest that it does not use Bluetooth - to derive a physical location. This permission coupling may change in - future. + \note Since Qt 6.8.1, the ACCESS_FINE_LOCATION permission is no longer + requested if API Level >= 31. This + \l {Android Bluetooth Permissions}{may limit some Bluetooth scan results}. + Users needing these results need + to request the location permission separately (see + \l {QLocationPermission::Precise}{precise location}) and ensure that + \c {BLUETOOTH_SCAN} permission doesn't have the + \c {android:usesPermissionFlags="neverForLocation"} attribute set. \include permissions.qdocinc permission-metadata */ @@ -403,10 +404,6 @@ QT_PERMISSION_IMPL_COMMON(QBluetoothPermission) \note The fine-grained permissions are currently supported only on Android 12 and newer. On older Android versions, as well as on Apple operating systems, any mode results in full Bluetooth access. - - \note For now the \c Access mode on Android also requests the - \l {QLocationPermission::Precise}{precise location} permission. - This permission coupling may change in the future. */ /*! diff --git a/src/corelib/kernel/qpermissions_android.cpp b/src/corelib/kernel/qpermissions_android.cpp index 6c21ded72cd..ded6c7ec8f0 100644 --- a/src/corelib/kernel/qpermissions_android.cpp +++ b/src/corelib/kernel/qpermissions_android.cpp @@ -56,13 +56,11 @@ static QStringList nativeBluetoothPermission(const QBluetoothPermission &permiss // API Level < 31 static QString bluetoothGeneral = u"android.permission.BLUETOOTH"_s; + static QString fineLocation = u"android.permission.ACCESS_FINE_LOCATION"_s; // API Level >= 31 static QString bluetoothScan = u"android.permission.BLUETOOTH_SCAN"_s; static QString bluetoothAdvertise = u"android.permission.BLUETOOTH_ADVERTISE"_s; static QString bluetoothConnect = u"android.permission.BLUETOOTH_CONNECT"_s; - // Fine location is currently required for ALL API levels, but that is not - // strictly necessary for API Level >= 31. See QTBUG-112164. - static QString fineLocation = u"android.permission.ACCESS_FINE_LOCATION"_s; if (QtAndroidPrivate::androidSdkVersion() < 31) { return {bluetoothGeneral, fineLocation}; @@ -72,7 +70,7 @@ static QStringList nativeBluetoothPermission(const QBluetoothPermission &permiss if (modes & QBluetoothPermission::Advertise) permissionList << bluetoothAdvertise; if (modes & QBluetoothPermission::Access) - permissionList << bluetoothScan << bluetoothConnect << fineLocation; + permissionList << bluetoothScan << bluetoothConnect; return permissionList; } }