summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2021-07-09 11:20:16 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-07-12 09:42:28 +0000
commit3041fc43f13ae46040ba8ffb7ed1719644be76d5 (patch)
treeeebf7d0b79c857341553bcfcec4954330c5e68d5 /src
parentaa6e808640d8c2b5084a3e94aa27ee726bb62a77 (diff)
Improve detection of enabled location service on SDK<28
Bluetooth seems to be non-functional when location services are disabled. This is not documented in Android's documentations, but several bug entries exist about this which are closed as "works as intended". See the linked bug entry for details. Our code thus tries to detect whether location services are enabled. This patch improves the detection of enabled location services. While the previous code did only check for GPS and Network location providers, the new code should detect any enabled location provider. Fixes: QTBUG-90760 Change-Id: I0c670296d0af62161dbc3fca40889996fa91f0ca Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 4fdcd2d8d2c2b47ec142b744ad291c1e134db7d4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index 823fd62e..088355df 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -166,18 +166,15 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
if (QNativeInterface::QAndroidApplication::sdkVersion() >= 28) {
locationTurnedOn = bool(locService.callMethod<jboolean>("isLocationEnabled"));
} else {
- // try GPS and network provider
- QJniObject provider = QJniObject::getStaticObjectField(
- "android/location/LocationManager", "GPS_PROVIDER", "Ljava/lang/String;");
- bool gpsTurnedOn = bool(locService.callMethod<jboolean>("isProviderEnabled",
- "(Ljava/lang/String;)Z", provider.object<jstring>()));
-
- provider = QJniObject::getStaticObjectField(
- "android/location/LocationManager", "NETWORK_PROVIDER", "Ljava/lang/String;");
- bool providerTurnedOn = bool(locService.callMethod<jboolean>("isProviderEnabled",
- "(Ljava/lang/String;)Z", provider.object<jstring>()));
-
- locationTurnedOn = gpsTurnedOn || providerTurnedOn;
+ // check whether there is any enabled provider
+ QJniObject listOfEnabledProviders =
+ locService.callObjectMethod("getProviders", "(Z)Ljava/util/List;", true);
+
+ if (listOfEnabledProviders.isValid()) {
+ int size = listOfEnabledProviders.callMethod<jint>("size", "()I");
+ locationTurnedOn = size > 0;
+ qCDebug(QT_BT_ANDROID) << size << "enabled location providers detected.";
+ }
}
}