summaryrefslogtreecommitdiff
path: root/src/bluetooth/android/androidutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bluetooth/android/androidutils.cpp')
-rw-r--r--src/bluetooth/android/androidutils.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/bluetooth/android/androidutils.cpp b/src/bluetooth/android/androidutils.cpp
index b33275b2..7b7c9cc1 100644
--- a/src/bluetooth/android/androidutils.cpp
+++ b/src/bluetooth/android/androidutils.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "androidutils_p.h"
+#include "jni_android_p.h"
#include <QtCore/QLoggingCategory>
#include <QtCore/private/qandroidextras_p.h>
@@ -43,4 +44,27 @@ bool ensureAndroidPermission(BluetoothPermission permission)
return false;
}
+QJniObject getDefaultBluetoothAdapter()
+{
+ QJniObject service = QJniObject::getStaticField<QtJniTypes::AndroidContext, jstring>(
+ "BLUETOOTH_SERVICE");
+ QJniObject context = QNativeInterface::QAndroidApplication::context();
+ QJniObject manager =
+ context.callMethod<jobject>("getSystemService", service.object<jstring>());
+ QJniObject adapter;
+ if (manager.isValid())
+ adapter = manager.callMethod<QtJniTypes::BluetoothAdapter>("getAdapter");
+
+ // ### Qt 7 check if the below double-get of the adapter can be removed.
+ // It is a workaround for QTBUG-57489, fixed in 2016. According to the bug it occurred on
+ // a certain device running Android 6.0.1 (Qt 6 supports Android 6.0 as the minimum).
+ // For completeness: the original workaround was for the deprecated getDefaultAdapter()
+ // method, and it is thus unclear if this is needed even in Qt 6 anymore. In addition the
+ // impacted device is updateable to Android 8 which may also have fixed the issue.
+ if (!adapter.isValid())
+ adapter = manager.callMethod<QtJniTypes::BluetoothAdapter>("getAdapter");
+
+ return adapter;
+}
+
QT_END_NAMESPACE