[-]
[+]
|
Changed |
_service:tar_git:qtconnectivity.spec
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://github.com/sailfishos-chum/qtconnectivity.git</param>
<param name="branch"></param>
- <param name="revision">5.15.9+kde5</param>
+ <param name="revision">5.15.10+kde4</param>
</service>
</services>
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/.qmake.conf
^
|
@@ -2,4 +2,4 @@
DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS QT_NO_LINKED_LIST
-MODULE_VERSION = 5.15.9
+MODULE_VERSION = 5.15.10
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java
^
|
@@ -61,8 +61,15 @@
@SuppressWarnings("WeakerAccess")
static Context qtContext = null;
- private static final int TURN_BT_ON = 3330;
+ // These are opaque tokens that could be used to match the completed action
+ private static final int TURN_BT_ENABLED = 3330;
private static final int TURN_BT_DISCOVERABLE = 3331;
+ private static final int TURN_BT_DISABLED = 3332;
+
+ // The 'Disable' action identifier is hidden in the public APIs so we define it here
+ public static final String ACTION_REQUEST_DISABLE =
+ "android.bluetooth.adapter.action.REQUEST_DISABLE";
+
private static final String TAG = "QtBluetoothBroadcastReceiver";
public void onReceive(Context context, Intent intent)
@@ -90,35 +97,61 @@
qtContext = context;
}
- static public void setDiscoverable()
+ static public boolean setDisabled()
+ {
+ if (!(qtContext instanceof android.app.Activity)) {
+ Log.w(TAG, "Bluetooth cannot be disabled from a service.");
+ return false;
+ }
+ // The 'disable' is hidden in the public API and as such
+ // there are no availability guarantees; may throw an "ActivityNotFoundException"
+ Intent intent = new Intent(ACTION_REQUEST_DISABLE);
+
+ try {
+ ((Activity)qtContext).startActivityForResult(intent, TURN_BT_DISABLED);
+ } catch (Exception ex) {
+ Log.w(TAG, "setDisabled() failed to initiate Bluetooth disablement");
+ ex.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ static public boolean setDiscoverable()
{
if (!(qtContext instanceof android.app.Activity)) {
Log.w(TAG, "Discovery mode cannot be enabled from a service.");
- return;
+ return false;
}
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
try {
- ((Activity)qtContext).startActivityForResult(intent, TURN_BT_ON);
+ ((Activity)qtContext).startActivityForResult(intent, TURN_BT_DISCOVERABLE);
} catch (Exception ex) {
+ Log.w(TAG, "setDisabled() failed to initiate Bluetooth discoverability change");
ex.printStackTrace();
+ return false;
}
+ return true;
}
- static public void setConnectable()
+ static public boolean setEnabled()
{
if (!(qtContext instanceof android.app.Activity)) {
- Log.w(TAG, "Connectable mode cannot be enabled from a service.");
- return;
+ Log.w(TAG, "Bluetooth cannot be enabled from a service.");
+ return false;
}
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
try {
- ((Activity)qtContext).startActivityForResult(intent, TURN_BT_DISCOVERABLE);
+ ((Activity)qtContext).startActivityForResult(intent, TURN_BT_ENABLED);
} catch (Exception ex) {
+ Log.w(TAG, "setEnabled() failed to initiate Bluetooth enablement");
ex.printStackTrace();
+ return false;
}
+ return true;
}
static public boolean setPairingMode(String address, boolean isPairing)
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java
^
|
@@ -106,6 +106,9 @@
return;
}
+ if (isInterrupted()) // close() may have been called
+ return;
+
BluetoothSocket s;
if (m_serverSocket != null) {
try {
@@ -131,6 +134,24 @@
Log.d(TAG, "Leaving server socket thread.");
}
+ // This function closes the socket server
+ //
+ // A note on threading behavior
+ // 1. This function is called from Qt thread which is different from the Java thread (run())
+ // 2. The caller of this function expects the Java thread to be finished upon return
+ //
+ // First we mark the Java thread as interrupted, then call close() on the
+ // listening socket if it had been created, and lastly wait for the thread to finish.
+ // The close() method of the socket is intended to be used to abort the accept() from
+ // another thread, as per the accept() documentation.
+ //
+ // If the Java thread was in the middle of creating a socket with the non-blocking
+ // listen* call, the run() will notice after the returning from the listen* that it has
+ // been interrupted and returns early from the run().
+ //
+ // If the Java thread was in the middle of the blocking accept() call, it will get
+ // interrupated by the close() call on the socket. After returning the run() will
+ // notice it has been interrupted and return from the run()
public void close()
{
if (!isAlive())
@@ -143,7 +164,9 @@
//interrupts accept() call above
if (m_serverSocket != null)
m_serverSocket.close();
- } catch (IOException ex) {
+ // Wait for the thread to finish
+ join(20); // Maximum wait in ms, typically takes < 1ms
+ } catch (Exception ex) {
Log.d(TAG, "Closing server socket close() failed:" + ex.toString());
ex.printStackTrace();
}
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/android/android.pri
^
|
@@ -6,7 +6,8 @@
android/localdevicebroadcastreceiver_p.h \
android/serveracceptancethread_p.h \
android/jni_android_p.h \
- android/lowenergynotificationhub_p.h
+ android/lowenergynotificationhub_p.h \
+ android/androidutils_p.h
SOURCES += \
@@ -17,4 +18,5 @@
android/androidbroadcastreceiver.cpp \
android/localdevicebroadcastreceiver.cpp \
android/serveracceptancethread.cpp \
- android/lowenergynotificationhub.cpp
+ android/lowenergynotificationhub.cpp \
+ android/androidutils.cpp
|
[-]
[+]
|
Added |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/android/androidutils.cpp
^
|
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2023 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "androidutils_p.h"
+
+#include <QtCore/QLoggingCategory>
+#include <QtAndroidExtras/QAndroidJniEnvironment>
+#include <QtCore/private/qjnihelpers_p.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
+
+static QString androidPermissionString(BluetoothPermission permission)
+{
+ switch (permission) {
+ case BluetoothPermission::Scan:
+ return {QStringLiteral("android.permission.BLUETOOTH_SCAN")};
+ case BluetoothPermission::Advertise:
+ return {QStringLiteral("android.permission.BLUETOOTH_ADVERTISE")};
+ case BluetoothPermission::Connect:
+ return {QStringLiteral("android.permission.BLUETOOTH_CONNECT")};
+ }
+ return {};
+}
+
+bool ensureAndroidPermission(BluetoothPermission permission)
+{
+ // The current set of permissions are only applicable with 31+
+ if (QtAndroidPrivate::androidSdkVersion() < 31)
+ return true;
+
+ const auto permString = androidPermissionString(permission);
+
+ // First check if we have the permission already
+ if (QtAndroidPrivate::checkPermission(permString)
+ == QtAndroidPrivate::PermissionsResult::Granted) {
+ return true;
+ }
+
+ // If we didn't have the permission, request it
+ QAndroidJniEnvironment env;
+ auto result = QtAndroidPrivate::requestPermissionsSync(env, QStringList() << permString);
+ if (result.contains(permString)
+ && result[permString] == QtAndroidPrivate::PermissionsResult::Granted) {
+ return true;
+ }
+
+ qCWarning(QT_BT_ANDROID) << "Permission not authorized:" << permString;
+ return false;
+}
+
+QT_END_NAMESPACE
|
[-]
[+]
|
Added |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/android/androidutils_p.h
^
|
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2023 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QANDROIDBLUETOOTHUTILS_H
+#define QANDROIDBLUETOOTHUTILS_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <qglobal.h>
+#include <QtCore/QString>
+
+QT_BEGIN_NAMESPACE
+
+enum class BluetoothPermission {
+ Scan,
+ Advertise,
+ Connect
+};
+
+// Checks if a permssion is already authorized and requests if not.
+// Returns true if permission is successfully authorized
+bool ensureAndroidPermission(BluetoothPermission permission);
+
+QT_END_NAMESPACE
+
+#endif // QANDROIDBLUETOOTHUTILS_H
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/bluetooth.pro
^
|
@@ -46,7 +46,6 @@
qbluetoothlocaldevice_p.h \
qlowenergycontrollerbase_p.h \
qlowenergyserviceprivate_p.h \
- qleadvertiser_p.h \
lecmaccalculator_p.h
SOURCES += \
@@ -116,8 +115,10 @@
lecmaccalculator.cpp \
qlowenergycontroller_bluezdbus.cpp
- HEADERS += qlowenergycontroller_bluezdbus_p.h \
- qlowenergycontroller_bluez_p.h
+ HEADERS += \
+ qleadvertiser_bluez_p.h \
+ qlowenergycontroller_bluezdbus_p.h \
+ qlowenergycontroller_bluez_p.h
qtConfig(linux_crypto_api): DEFINES += CONFIG_LINUX_CRYPTO_API
} else {
@@ -138,7 +139,10 @@
android.permission.BLUETOOTH \
android.permission.BLUETOOTH_ADMIN \
android.permission.ACCESS_FINE_LOCATION \
- android.permission.ACCESS_COARSE_LOCATION # since Android 6.0 (API lvl 23)
+ android.permission.ACCESS_COARSE_LOCATION \ # since Android 6.0 (API lvl 23)
+ android.permission.BLUETOOTH_SCAN \ # since Android 12.0 (API lvl 31)
+ android.permission.BLUETOOTH_ADVERTISE \ # since Android 12.0 (API lvl 31)
+ android.permission.BLUETOOTH_CONNECT # since Android 12.0 (API lvl 31)
ANDROID_BUNDLED_JAR_DEPENDENCIES = \
jar/QtAndroidBluetooth.jar:org.qtproject.qt5.android.bluetooth.QtBluetoothBroadcastReceiver
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/bluez/bluetoothmanagement.cpp
^
|
@@ -313,3 +313,5 @@
QT_END_NAMESPACE
+
+#include "moc_bluetoothmanagement_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/bluez/bluez5_helper.cpp
^
|
@@ -577,3 +577,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_bluez5_helper_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/bluez/hcimanager.cpp
^
|
@@ -599,3 +599,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_hcimanager_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/bluez/profile1context.cpp
^
|
@@ -70,3 +70,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_profile1context_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/bluez/remotedevicemanager.cpp
^
|
@@ -171,3 +171,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_remotedevicemanager_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
^
|
@@ -38,6 +38,7 @@
**
****************************************************************************/
+#include "android/androidutils_p.h"
#include "qbluetoothdevicediscoveryagent_p.h"
#include <QtCore/QLoggingCategory>
#include <QtBluetooth/QBluetoothAddress>
@@ -220,6 +221,15 @@
qCDebug(QT_BT_ANDROID) << "Location turned on";
+ if (!(ensureAndroidPermission(BluetoothPermission::Scan) &&
+ ensureAndroidPermission(BluetoothPermission::Connect))) {
+ qCWarning(QT_BT_ANDROID) << "Device discovery start() failed due to missing permissions";
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("Bluetooth adapter error");
+ lastError = QBluetoothDeviceDiscoveryAgent::UnknownError;
+ emit q->error(lastError);
+ return;
+ }
+
// install Java BroadcastReceiver
if (!receiver) {
// SDP based device discovery
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp
^
|
@@ -90,3 +90,5 @@
QT_END_NAMESPACE
+
+#include "moc_qbluetoothdevicediscoveryagent_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothlocaldevice.cpp
^
|
@@ -104,6 +104,16 @@
be connectable and powered on, if required. This mode is is not supported on Android.
On \macos, it is not possible to set the \l hostMode() to HostConnectable or HostPoweredOff.
+ \note Starting from Android 13 (API level 33) the HostPoweredOff state relies on
+ non-public Android API as the public one has been deprecated, see
+ (\l {https://developer.android.com/reference/android/bluetooth/BluetoothAdapter#disable()}
+ {disable()}). This may change in a future version of Android.
+
+ \note At least on Android 12 the device's Bluetooth visibility setting may dictate the result
+ of setting either HostDiscoverable or HostConnectable. For example if the visibility is set
+ \e off, it may not be possible to enter the HostDiscoverable mode, but HostConnectable will be
+ used instead. This may change in future version of Android.
+
*/
void registerQBluetoothLocalDeviceMetaType()
@@ -137,6 +147,13 @@
remains invalid even if the same Bluetooth adapter is returned to
the system.
+//! [android-permissions-valid]
+ \note Starting from Android 12 (API level 31), the construction of this class requires
+ \l {https://developer.android.com/guide/topics/connectivity/bluetooth/permissions}
+ {bluetooth runtime permissions} (\e BLUETOOTH_SCAN and \e BLUETOOTH_CONNECT). If the
+ permissions are not granted, the device will not be valid.
+//! [android-permissions-valid]
+
\sa allDevices()
*/
bool QBluetoothLocalDevice::isValid() const
@@ -206,6 +223,9 @@
/*!
\fn QBluetoothLocalDevice::QBluetoothLocalDevice(QObject *parent)
Constructs a QBluetoothLocalDevice with \a parent.
+
+ \include qbluetoothlocaldevice.cpp android-permissions-valid
+ \sa isValid()
*/
/*!
@@ -324,6 +344,9 @@
Construct new QBluetoothLocalDevice for \a address. If \a address is default constructed
the resulting local device selects the local default device.
+
+ \include qbluetoothlocaldevice.cpp android-permissions-valid
+ \sa isValid()
*/
QT_END_NAMESPACE
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/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 @@
return;
}
+ if (!(ensureAndroidPermission(BluetoothPermission::Scan) &&
+ ensureAndroidPermission(BluetoothPermission::Connect))) {
+ qCWarning(QT_BT_ANDROID) << "Local device initialize() failed due to missing permissions";
+ return;
+ }
+
obj = new QAndroidJniObject(adapter);
if (!address.isNull()) {
const QString localAddress
@@ -129,19 +135,26 @@
void QBluetoothLocalDevicePrivate::processHostModeChange(QBluetoothLocalDevice::HostMode newMode)
{
- if (!pendingHostModeTransition) {
- // if not in transition -> pass data on
+ qCDebug(QT_BT_ANDROID) << "Processing host mode change:" << newMode
+ << ", pending transition:" << pendingConnectableHostModeTransition;
+ if (!pendingConnectableHostModeTransition) {
+ // If host mode is not in transition -> pass data on
emit q_ptr->hostModeStateChanged(newMode);
return;
}
+ // Host mode is in transition: check if the new mode is 'off' in which state
+ // we can enter the targeted 'Connectable' state
if (isValid() && newMode == QBluetoothLocalDevice::HostPoweredOff) {
- bool success = (bool)obj->callMethod<jboolean>("enable", "()Z");
- if (!success)
+ const bool success = (bool)QAndroidJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setEnabled");
+ if (!success) {
+ qCWarning(QT_BT_ANDROID) << "Transitioning Bluetooth from OFF to ON failed";
emit q_ptr->error(QBluetoothLocalDevice::UnknownError);
+ }
}
-
- pendingHostModeTransition = false;
+ pendingConnectableHostModeTransition = false;
}
// Return -1 if address is not part of a pending pairing request
@@ -245,44 +258,87 @@
return;
if (d_ptr->adapter()) {
- bool ret = (bool)d_ptr->adapter()->callMethod<jboolean>("enable", "()Z");
- if (!ret)
+ bool success(false);
+ if (QtAndroidPrivate::androidSdkVersion() >= 31) {
+ success = (bool)QAndroidJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setEnabled");
+ } else {
+ success = (bool)d_ptr->adapter()->callMethod<jboolean>("enable", "()Z");
+ }
+ if (!success) {
+ qCWarning(QT_BT_ANDROID) << "Enabling bluetooth failed";
emit error(QBluetoothLocalDevice::UnknownError);
+ }
}
}
void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode requestedMode)
{
- QBluetoothLocalDevice::HostMode mode = requestedMode;
+ QBluetoothLocalDevice::HostMode nextMode = requestedMode;
if (requestedMode == HostDiscoverableLimitedInquiry)
- mode = HostDiscoverable;
+ nextMode = HostDiscoverable;
- if (mode == hostMode())
+ if (nextMode == hostMode())
return;
- if (mode == QBluetoothLocalDevice::HostPoweredOff) {
- bool success = false;
- if (d_ptr->adapter())
- success = (bool)d_ptr->adapter()->callMethod<jboolean>("disable", "()Z");
+ switch (nextMode) {
- if (!success)
+ case QBluetoothLocalDevice::HostPoweredOff: {
+ bool success = false;
+ if (d_ptr->adapter()) {
+ if (QtAndroidPrivate::androidSdkVersion() >= 31) {
+ success = (bool)QAndroidJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setDisabled");
+ } else {
+ success = (bool)d_ptr->adapter()->callMethod<jboolean>("disable", "()Z");
+ }
+ }
+ if (!success) {
+ qCWarning(QT_BT_ANDROID) << "Unable to power off the adapter";
emit error(QBluetoothLocalDevice::UnknownError);
- } else if (mode == QBluetoothLocalDevice::HostConnectable) {
- if (hostMode() == QBluetoothLocalDevice::HostDiscoverable) {
- // cannot directly go from Discoverable to Connectable
- // we need to go to disabled mode and enable once disabling came through
+ }
+ break;
+ }
+ case QBluetoothLocalDevice::HostConnectable: {
+ if (hostMode() == QBluetoothLocalDevice::HostDiscoverable) {
+ // On Android 'Discoverable' is actually 'CONNECTABLE_DISCOVERABLE', and
+ // it seems we cannot go directly from "Discoverable" to "Connectable". Instead
+ // we need to go to disabled mode first and then to the 'Connectable' mode
setHostMode(QBluetoothLocalDevice::HostPoweredOff);
- d_ptr->pendingHostModeTransition = true;
+ d_ptr->pendingConnectableHostModeTransition = true;
} else {
- QAndroidJniObject::callStaticMethod<void>(
- "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
- "setConnectable");
- }
- } else if (mode == QBluetoothLocalDevice::HostDiscoverable
- || mode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry) {
- QAndroidJniObject::callStaticMethod<void>(
- "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver", "setDiscoverable");
+ const bool success = (bool)QAndroidJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setEnabled");
+ if (!success) {
+ qCWarning(QT_BT_ANDROID) << "Unable to enable the Bluetooth";
+ emit error(QBluetoothLocalDevice::UnknownError);
+ }
+ }
+ break;
+ }
+
+ case QBluetoothLocalDevice::HostDiscoverable: {
+ if (!ensureAndroidPermission(BluetoothPermission::Advertise)) {
+ qCWarning(QT_BT_ANDROID) << "Local device setHostMode() failed due to"
+ "missing permissions";
+ return;
+ }
+ const bool success = (bool)QAndroidJniObject::callStaticMethod<jboolean>(
+ "org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver",
+ "setDiscoverable");
+ if (!success) {
+ qCWarning(QT_BT_ANDROID) << "Unable to set Bluetooth as discoverable";
+ emit error(QBluetoothLocalDevice::UnknownError);
+ }
+ break;
+ }
+ default:
+ qCWarning(QT_BT_ANDROID) << "setHostMode() unsupported host mode:" << nextMode;
+ break;
}
}
@@ -308,6 +364,12 @@
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) << "Local device allDevices() failed due to"
+ "missing permissions";
+ return {};
+ }
// Android only supports max of one device (so far)
QList<QBluetoothHostInfo> localDevices;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothlocaldevice_p.h
^
|
@@ -138,7 +138,7 @@
public:
LocalDeviceBroadcastReceiver *receiver;
- bool pendingHostModeTransition = false;
+ bool pendingConnectableHostModeTransition = false;
QList<QPair<QBluetoothAddress, bool> > pendingPairings;
QList<QBluetoothAddress> connectedDevices;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothserver_android.cpp
^
|
@@ -37,15 +37,16 @@
**
****************************************************************************/
-#include <QtCore/QLoggingCategory>
+#include "android/serveracceptancethread_p.h"
+#include "android/androidutils_p.h"
#include "qbluetoothserver.h"
#include "qbluetoothserver_p.h"
#include "qbluetoothsocket.h"
#include "qbluetoothsocket_android_p.h"
#include "qbluetoothlocaldevice.h"
-#include "android/serveracceptancethread_p.h"
#include <QCoreApplication>
+#include <QtCore/QLoggingCategory>
QT_BEGIN_NAMESPACE
@@ -132,6 +133,13 @@
emit error(d->m_lastError);
return false;
}
+
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ qCWarning(QT_BT_ANDROID) << "Bluetooth server listen() failed due to missing permissions";
+ d->m_lastError = QBluetoothServer::UnknownError;
+ emit error(d->m_lastError);
+ return false;
+ }
const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
if (!localDevices.count()) {
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
^
|
@@ -37,6 +37,13 @@
**
****************************************************************************/
+
+#include "qbluetoothservicediscoveryagent_p.h"
+#include "qbluetoothsocket_android_p.h"
+#include "android/servicediscoverybroadcastreceiver_p.h"
+#include "android/localdevicebroadcastreceiver_p.h"
+#include "android/androidutils_p.h"
+
#include <QtCore/qcoreapplication.h>
#include <QtCore/QLoggingCategory>
#include <QtCore/QTimer>
@@ -46,11 +53,6 @@
#include <QtBluetooth/QBluetoothLocalDevice>
#include <QtBluetooth/QBluetoothServiceDiscoveryAgent>
-#include "qbluetoothservicediscoveryagent_p.h"
-#include "qbluetoothsocket_android_p.h"
-#include "android/servicediscoverybroadcastreceiver_p.h"
-#include "android/localdevicebroadcastreceiver_p.h"
-
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
@@ -123,6 +125,15 @@
{
Q_Q(QBluetoothServiceDiscoveryAgent);
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ qCWarning(QT_BT_ANDROID) << "Service discovery start() failed due to missing permissions";
+ error = QBluetoothServiceDiscoveryAgent::UnknownError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Unable to perform SDP scan");
+ emit q->error(error);
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
if (!btAdapter.isValid()) {
if (m_deviceAdapterAddress.isNull()) {
error = QBluetoothServiceDiscoveryAgent::UnknownError;
@@ -252,9 +263,11 @@
discoveredDevices.clear();
//kill receiver to limit load of signals
- receiver->unregisterReceiver();
- receiver->deleteLater();
- receiver = nullptr;
+ if (receiver) {
+ receiver->unregisterReceiver();
+ receiver->deleteLater();
+ receiver = nullptr;
+ }
Q_Q(QBluetoothServiceDiscoveryAgent);
emit q->canceled();
@@ -469,8 +482,11 @@
//don't include the service if we already discovered it before
if (!isDuplicatedService(serviceInfo)) {
discoveredServices << serviceInfo;
- //qCDebug(QT_BT_ANDROID) << serviceInfo;
- emit q->serviceDiscovered(serviceInfo);
+ // Use queued connection to allow us finish the service discovery reporting;
+ // the application might call stop() when it has detected the service-of-interest,
+ // which in turn can cause the use of already released resources
+ QMetaObject::invokeMethod(q, "serviceDiscovered", Qt::QueuedConnection,
+ Q_ARG(QBluetoothServiceInfo, serviceInfo));
}
}
}
@@ -490,9 +506,11 @@
Q_ASSERT(sdpCache.isEmpty());
//kill receiver to limit load of signals
- receiver->unregisterReceiver();
- receiver->deleteLater();
- receiver = nullptr;
+ if (receiver) {
+ receiver->unregisterReceiver();
+ receiver->deleteLater();
+ receiver = nullptr;
+ }
_q_serviceDiscoveryFinished();
}
@@ -507,9 +525,11 @@
errorString = QBluetoothServiceDiscoveryAgent::tr("Device is powered off");
//kill receiver to limit load of signals
- receiver->unregisterReceiver();
- receiver->deleteLater();
- receiver = nullptr;
+ if (receiver) {
+ receiver->unregisterReceiver();
+ receiver->deleteLater();
+ receiver = nullptr;
+ }
Q_Q(QBluetoothServiceDiscoveryAgent);
emit q->error(error);
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothservicediscoveryagent_p.cpp
^
|
@@ -73,3 +73,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qbluetoothservicediscoveryagent_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothserviceinfo_android.cpp
^
|
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#include <QtCore/QLoggingCategory>
+#include "android/androidutils_p.h"
#include "qbluetoothhostinfo.h"
#include "qbluetoothlocaldevice.h"
#include "qbluetoothserviceinfo.h"
@@ -46,6 +46,8 @@
#include "qbluetoothserver_p.h"
#include "qbluetoothserver.h"
+#include <QtCore/QLoggingCategory>
+
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
@@ -89,6 +91,12 @@
bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress& localAdapter)
{
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ qCWarning(QT_BT_ANDROID) << "Serviceinfo registerService() failed due to"
+ "missing permissions";
+ return false;
+ }
+
const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
if (!localDevices.count())
return false; //no Bluetooth device
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothserviceinfo_p.cpp
^
|
@@ -73,3 +73,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qbluetoothserviceinfo_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothsocket_android.cpp
^
|
@@ -43,6 +43,7 @@
#include "qbluetoothaddress.h"
#include "qbluetoothdeviceinfo.h"
#include "qbluetoothserviceinfo.h"
+#include "android/androidutils_p.h"
#include <QtCore/QLoggingCategory>
#include <QtCore/QThread>
#include <QtCore/QTime>
@@ -407,7 +408,15 @@
qCDebug(QT_BT_ANDROID) << "connectToServiceHelper()" << address.toString() << uuid.toString();
- q->setSocketState(QBluetoothSocket::ConnectingState);
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ qCWarning(QT_BT_ANDROID) << "Bluetooth socket connect failed due to missing permissions";
+ errorString = QBluetoothSocket::tr("Unknown socket error");
+ q->setSocketError(QBluetoothSocket::SocketError::UnknownSocketError);
+ q->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
+ return;
+ }
+
+ q->setSocketState(QBluetoothSocket::SocketState::ConnectingState);
if (!adapter.isValid()) {
qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
@@ -419,7 +428,7 @@
const int state = adapter.callMethod<jint>("getState");
if (state != 12 ) { //BluetoothAdapter.STATE_ON
- qCWarning(QT_BT_ANDROID) << "Bt device offline";
+ qCWarning(QT_BT_ANDROID) << "Bluetooth device offline";
errorString = QBluetoothSocket::tr("Device is powered off");
q->setSocketError(QBluetoothSocket::NetworkError);
q->setSocketState(QBluetoothSocket::UnconnectedState);
@@ -457,7 +466,7 @@
"(Ljava/util/UUID;)Landroid/bluetooth/BluetoothSocket;",
uuidObject.object<jobject>());
} else {
- qCDebug(QT_BT_ANDROID) << "Connnecting via secure rfcomm";
+ qCDebug(QT_BT_ANDROID) << "Connecting via secure rfcomm";
socketObject = remoteDevice.callObjectMethod("createRfcommSocketToServiceRecord",
"(Ljava/util/UUID;)Landroid/bluetooth/BluetoothSocket;",
uuidObject.object<jobject>());
@@ -724,8 +733,12 @@
QString QBluetoothSocketPrivateAndroid::localName() const
{
- if (adapter.isValid())
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ qCWarning(QT_BT_ANDROID) << "Bluetooth socket localName() failed due to"
+ "missing permissions";
+ } else if (adapter.isValid()) {
return adapter.callObjectMethod<jstring>("getName").toString();
+ }
return QString();
}
@@ -733,8 +746,13 @@
QBluetoothAddress QBluetoothSocketPrivateAndroid::localAddress() const
{
QString result;
- if (adapter.isValid())
+
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ qCWarning(QT_BT_ANDROID) << "Bluetooth socket localAddress() failed due to"
+ "missing permissions";
+ } else if (adapter.isValid()) {
result = adapter.callObjectMethod("getAddress", "()Ljava/lang/String;").toString();
+ }
return QBluetoothAddress(result);
}
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothsocket_bluez.cpp
^
|
@@ -717,3 +717,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qbluetoothsocket_bluez_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothsocket_bluezdbus.cpp
^
|
@@ -627,3 +627,5 @@
profilePath.clear();
}
QT_END_NAMESPACE
+
+#include "moc_qbluetoothsocket_bluezdbus_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothsocket_osx.mm
^
|
@@ -393,7 +393,6 @@
// Connected, setOpenMode on a QBluetoothSocket.
q_ptr->setOpenMode(openMode);
q_ptr->setSocketState(QBluetoothSocket::ConnectedState);
- emit q_ptr->connected();
if (buffer.size()) // We also have some data already ...
emit q_ptr->readyRead();
} else if (state == QBluetoothSocket::UnconnectedState) {
@@ -521,7 +520,6 @@
if (!isConnecting) {
q_ptr->setOpenMode(openMode);
q_ptr->setSocketState(QBluetoothSocket::ConnectedState);
- emit q_ptr->connected();
} else {
state = QBluetoothSocket::ConnectedState;
// We are still in connectToService, it'll care
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qbluetoothsocketbase.cpp
^
|
@@ -52,3 +52,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qbluetoothsocketbase_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qleadvertiser_bluez.cpp
^
|
@@ -37,7 +37,7 @@
**
****************************************************************************/
-#include "qleadvertiser_p.h"
+#include "qleadvertiser_bluez_p.h"
#include "bluez/bluez_data_p.h"
#include "bluez/hcimanager_p.h"
@@ -460,3 +460,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qleadvertiser_bluez_p.cpp"
|
[-]
[+]
|
Added |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qleadvertiser_bluez_p.h
^
|
@@ -0,0 +1,152 @@
+/***************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLEADVERTISER_BLUEZ_P_H
+#define QLEADVERTISER_BLUEZ_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qlowenergyadvertisingdata.h"
+#include "qlowenergyadvertisingparameters.h"
+
+QT_REQUIRE_CONFIG(bluez);
+
+#include "bluez/bluez_data_p.h"
+
+#include <QtCore/qobject.h>
+#include <QtCore/qvector.h>
+
+QT_BEGIN_NAMESPACE
+
+class QLeAdvertiser : public QObject
+{
+ Q_OBJECT
+public:
+ void startAdvertising() { doStartAdvertising(); }
+ void stopAdvertising() { doStopAdvertising(); }
+
+signals:
+ void errorOccurred();
+
+public:
+ QLeAdvertiser(const QLowEnergyAdvertisingParameters ¶ms,
+ const QLowEnergyAdvertisingData &advData,
+ const QLowEnergyAdvertisingData &responseData, QObject *parent)
+ : QObject(parent), m_params(params), m_advData(advData), m_responseData(responseData) {}
+ virtual ~QLeAdvertiser() { }
+
+protected:
+ const QLowEnergyAdvertisingParameters ¶meters() const { return m_params; }
+ const QLowEnergyAdvertisingData &advertisingData() const { return m_advData; }
+ const QLowEnergyAdvertisingData &scanResponseData() const { return m_responseData; }
+
+private:
+ virtual void doStartAdvertising() = 0;
+ virtual void doStopAdvertising() = 0;
+
+ const QLowEnergyAdvertisingParameters m_params;
+ const QLowEnergyAdvertisingData m_advData;
+ const QLowEnergyAdvertisingData m_responseData;
+};
+
+struct AdvData;
+struct AdvParams;
+class HciManager;
+
+class QLeAdvertiserBluez : public QLeAdvertiser
+{
+ Q_OBJECT
+public:
+ QLeAdvertiserBluez(const QLowEnergyAdvertisingParameters ¶ms,
+ const QLowEnergyAdvertisingData &advertisingData,
+ const QLowEnergyAdvertisingData &scanResponseData, HciManager &hciManager,
+ QObject *parent = nullptr);
+ ~QLeAdvertiserBluez() override;
+
+private:
+ void doStartAdvertising() override;
+ void doStopAdvertising() override;
+
+ void setPowerLevel(AdvData &advData);
+ void setFlags(AdvData &advData);
+ void setServicesData(const QLowEnergyAdvertisingData &src, AdvData &dest);
+ void setManufacturerData(const QLowEnergyAdvertisingData &src, AdvData &dest);
+ void setLocalNameData(const QLowEnergyAdvertisingData &src, AdvData &dest);
+
+ void queueCommand(OpCodeCommandField ocf, const QByteArray &advertisingData);
+ void sendNextCommand();
+ void queueAdvertisingCommands();
+ void queueReadTxPowerLevelCommand();
+ void toggleAdvertising(bool enable);
+ void setAdvertisingParams();
+ void setAdvertisingInterval(AdvParams ¶ms);
+ void setData(bool isScanResponseData);
+ void setAdvertisingData();
+ void setScanResponseData();
+ void setWhiteList();
+
+ void handleCommandCompleted(quint16 opCode, quint8 status, const QByteArray &advertisingData);
+ void handleError();
+
+ HciManager &m_hciManager;
+
+ struct Command {
+ Command() {}
+ Command(OpCodeCommandField ocf, const QByteArray &data) : ocf(ocf), data(data) { }
+ OpCodeCommandField ocf;
+ QByteArray data;
+ };
+ QVector<Command> m_pendingCommands;
+
+ quint8 m_powerLevel;
+ bool m_sendPowerLevel;
+};
+
+QT_END_NAMESPACE
+
+#endif // Include guard.
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergyadvertisingdata.h
^
|
@@ -84,7 +84,7 @@
void setRawData(const QByteArray &data);
QByteArray rawData() const;
- void swap(QLowEnergyAdvertisingData &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ void swap(QLowEnergyAdvertisingData &other) noexcept { d.swap(other.d); }
private:
QSharedDataPointer<QLowEnergyAdvertisingDataPrivate> d;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergyadvertisingparameters.h
^
|
@@ -90,7 +90,7 @@
// TODO: own address type
// TODO: For ADV_DIRECT_IND: peer address + peer address type
- void swap(QLowEnergyAdvertisingParameters &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ void swap(QLowEnergyAdvertisingParameters &other) noexcept { d.swap(other.d); }
private:
QSharedDataPointer<QLowEnergyAdvertisingParametersPrivate> d;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergycharacteristicdata.h
^
|
@@ -82,7 +82,7 @@
bool isValid() const;
- void swap(QLowEnergyCharacteristicData &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ void swap(QLowEnergyCharacteristicData &other) noexcept { d.swap(other.d); }
private:
QSharedDataPointer<QLowEnergyCharacteristicDataPrivate> d;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergyconnectionparameters.h
^
|
@@ -69,7 +69,7 @@
void setSupervisionTimeout(int timeout);
int supervisionTimeout() const;
- void swap(QLowEnergyConnectionParameters &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ void swap(QLowEnergyConnectionParameters &other) noexcept { d.swap(other.d); }
private:
QSharedDataPointer<QLowEnergyConnectionParametersPrivate> d;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergycontroller.cpp
^
|
@@ -54,6 +54,7 @@
#include "qlowenergycontroller_bluez_p.h"
#elif defined(QT_ANDROID_BLUETOOTH)
#include "qlowenergycontroller_android_p.h"
+#include "android/androidutils_p.h"
#elif defined(QT_WINRT_BLUETOOTH)
#include "qtbluetoothglobal_p.h"
#include "qlowenergycontroller_winrt_p.h"
@@ -74,6 +75,9 @@
Q_DECLARE_LOGGING_CATEGORY(QT_BT)
Q_DECLARE_LOGGING_CATEGORY(QT_BT_WINRT)
+#if defined(QT_ANDROID_BLUETOOTH)
+Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
+#endif
/*!
\class QLowEnergyController
@@ -212,7 +216,7 @@
\sa QLowEnergyController::createCentral()
\sa QLowEnergyController::createPeripheral()
\since 5.7
- \note The peripheral role is currently only supported on Linux. In addition, handling the
+ \note The peripheral role is not supported on Windows. In addition on Linux, handling the
"Signed Write" ATT command on the server side requires BlueZ 5 and kernel version 3.7
or newer.
*/
@@ -635,6 +639,7 @@
}
if (!d->isValidLocalAdapter()) {
+ qCWarning(QT_BT) << "connectToDevice() LE controller has invalid adapter";
d->setError(QLowEnergyController::InvalidBluetoothAdapterError);
return;
}
@@ -842,6 +847,13 @@
return nullptr;
}
+#if defined(QT_ANDROID_BLUETOOTH)
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ qCWarning(QT_BT_ANDROID) << "addService() failed due to missing permissions";
+ return nullptr;
+ }
+#endif
+
Q_D(QLowEnergyController);
QLowEnergyService *newService = d->addServiceHelper(service);
if (newService)
@@ -916,3 +928,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qlowenergycontroller.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergycontroller_android.cpp
^
|
@@ -37,6 +37,7 @@
**
****************************************************************************/
+#include "android/androidutils_p.h"
#include "qlowenergycontroller_android_p.h"
#include <QtCore/QLoggingCategory>
#include <QtAndroidExtras/QAndroidJniEnvironment>
@@ -144,8 +145,17 @@
void QLowEnergyControllerPrivateAndroid::connectToDevice()
{
- if (!hub)
- return; // Android version below v18
+ if (!hub) {
+ qCCritical(QT_BT_ANDROID) << "connectToDevice() LE controller has not been initialized";
+ return;
+ }
+
+ if (!ensureAndroidPermission(BluetoothPermission::Connect)) {
+ // This is unlikely to happen as a valid local adapter is a precondition
+ setError(QLowEnergyController::AuthorizationError);
+ qCWarning(QT_BT_ANDROID) << "connectToDevice() failed due to missing permissions";
+ return;
+ }
// required to pass unit test on default backend
if (remoteDevice.isNull()) {
@@ -195,6 +205,8 @@
void QLowEnergyControllerPrivateAndroid::discoverServices()
{
+ // No need to check bluetooth permissions here as 'connected' is a precondition
+
if (hub && hub->javaObject().callMethod<jboolean>("discoverServices")) {
qCDebug(QT_BT_ANDROID) << "Service discovery initiated";
} else {
@@ -1013,7 +1025,15 @@
{
setState(QLowEnergyController::AdvertisingState);
- if (!hub->javaObject().isValid()) {
+ if (!(ensureAndroidPermission(BluetoothPermission::Advertise) &&
+ ensureAndroidPermission(BluetoothPermission::Connect))) {
+ qCWarning(QT_BT_ANDROID) << "startAdvertising() failed due to missing permissions";
+ setError(QLowEnergyController::AdvertisingError);
+ setState(QLowEnergyController::UnconnectedState);
+ return;
+ }
+
+ if (!hub || !hub->javaObject().isValid()) {
qCWarning(QT_BT_ANDROID) << "Cannot initiate QtBluetoothLEServer";
setError(QLowEnergyController::AdvertisingError);
setState(QLowEnergyController::UnconnectedState);
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergycontroller_android_p.h
^
|
@@ -74,8 +74,6 @@
extern void registerQLowEnergyControllerMetaType();
-class QLeAdvertiser;
-
class QLowEnergyControllerPrivateAndroid final : public QLowEnergyControllerPrivate
{
Q_OBJECT
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergycontroller_bluez.cpp
^
|
@@ -42,7 +42,7 @@
#include "qlowenergycontroller_bluez_p.h"
#include "qbluetoothsocketbase_p.h"
#include "qbluetoothsocket_bluez_p.h"
-#include "qleadvertiser_p.h"
+#include "qleadvertiser_bluez_p.h"
#include "bluez/bluez_data_p.h"
#include "bluez/hcimanager_p.h"
#include "bluez/objectmanager_p.h"
@@ -3543,3 +3543,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qlowenergycontroller_bluez_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergycontroller_bluezdbus.cpp
^
|
@@ -476,7 +476,7 @@
for (auto const& uuid :
battIter.value()[QStringLiteral("UUIDs")].toStringList()) {
if (QBluetoothUuid(uuid) ==
- QBluetoothUuid::BatteryService) {
+ QBluetoothUuid::ServiceClassUuid::BatteryService) {
qCDebug(QT_BT_BLUEZ) << "Battery service listed as available service";
batteryServicePath = it.key().path();
break;
@@ -498,7 +498,7 @@
QStringLiteral("org.bluez"),it.key().path(),
QDBusConnection::systemBus(), this));
if (QBluetoothUuid(service->uUID()) ==
- QBluetoothUuid::BatteryService) {
+ QBluetoothUuid::ServiceClassUuid::BatteryService) {
qCDebug(QT_BT_BLUEZ) << "Using battery service via GattService1 interface";
gattBatteryService = true;
}
@@ -512,7 +512,7 @@
if (!gattBatteryService && !batteryServicePath.isEmpty()) {
setupServicePrivate(QLowEnergyService::PrimaryService,
- QBluetoothUuid::BatteryService,
+ QBluetoothUuid::ServiceClassUuid::BatteryService,
batteryServicePath, true);
}
@@ -1345,3 +1345,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qlowenergycontroller_bluezdbus_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergycontrollerbase.cpp
^
|
@@ -329,3 +329,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qlowenergycontrollerbase_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergydescriptordata.h
^
|
@@ -80,7 +80,7 @@
bool isWritable() const;
QBluetooth::AttAccessConstraints writeConstraints() const;
- void swap(QLowEnergyDescriptorData &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ void swap(QLowEnergyDescriptorData &other) noexcept { d.swap(other.d); }
private:
QSharedDataPointer<QLowEnergyDescriptorDataPrivate> d;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergyservice.cpp
^
|
@@ -836,3 +836,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qlowenergyservice.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergyservicedata.h
^
|
@@ -78,7 +78,7 @@
bool isValid() const;
- void swap(QLowEnergyServiceData &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
+ void swap(QLowEnergyServiceData &other) noexcept { d.swap(other.d); }
private:
QSharedDataPointer<QLowEnergyServiceDataPrivate> d;
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/bluetooth/qlowenergyserviceprivate.cpp
^
|
@@ -83,3 +83,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qlowenergyserviceprivate_p.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/nfc/qnearfieldmanager.cpp
^
|
@@ -440,3 +440,7 @@
}
QT_END_NAMESPACE
+
+#include "moc_qnearfieldmanager_p.cpp"
+
+#include "moc_qnearfieldmanager.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/src/nfc/qnearfieldtarget.cpp
^
|
@@ -551,3 +551,5 @@
}
QT_END_NAMESPACE
+
+#include "moc_qnearfieldtarget.cpp"
|
[-]
[+]
|
Changed |
_service:tar_git:opt-qt5-qtconnectivity-5.15.10+kde4.tar.bz2/upstream/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
^
|
@@ -121,10 +121,8 @@
QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished()));
QSignalSpy errorSpy(&discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
QSignalSpy discoveredSpy(&discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)));
- // connect(&discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
- // this, SLOT(deviceDiscoveryDebug(QBluetoothDeviceInfo)));
- discoveryAgent.start();
+ discoveryAgent.start(QBluetoothDeviceDiscoveryAgent::ClassicMethod);
// Wait for up to MaxScanTime for the scan to finish
int scanTime = MaxScanTime;
@@ -132,7 +130,6 @@
QTest::qWait(1000);
scanTime -= 1000;
}
- // qDebug() << "Scan time left:" << scanTime;
// Expect finished signal with no error
QVERIFY(finishedSpy.count() == 1);
@@ -386,7 +383,7 @@
QFETCH(QBluetoothServiceDiscoveryAgent::Error, serviceDiscoveryError);
QBluetoothLocalDevice localDevice;
- qDebug() << "Scanning address" << deviceInfo.address().toString();
+ qDebug() << "Scanning address" << deviceInfo.address().toString() << deviceInfo.name();
QBluetoothServiceDiscoveryAgent discoveryAgent(localDevice.address());
bool setAddress = discoveryAgent.setRemoteAddress(deviceInfo.address());
@@ -405,10 +402,8 @@
QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished()));
QSignalSpy errorSpy(&discoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)));
QSignalSpy discoveredSpy(&discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)));
-// connect(&discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
-// this, SLOT(serviceDiscoveryDebug(QBluetoothServiceInfo)));
- connect(&discoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)),
- this, SLOT(serviceError(QBluetoothServiceDiscoveryAgent::Error)));
+ connect(&discoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)), this,
+ SLOT(serviceError(QBluetoothServiceDiscoveryAgent::Error)));
discoveryAgent.start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
@@ -419,7 +414,7 @@
QVERIFY(discoveryAgent.isActive() || !finishedSpy.isEmpty());
// Wait for up to MaxScanTime for the scan to finish
- int scanTime = MaxScanTime;
+ int scanTime = 20000;
while (finishedSpy.count() == 0 && scanTime > 0) {
QTest::qWait(1000);
scanTime -= 1000;
@@ -434,7 +429,9 @@
QVERIFY(discoveryAgent.errorString() == QString());
// Expect finished signal with no error
- QVERIFY(finishedSpy.count() == 1);
+ if (scanTime)
+ QVERIFY(finishedSpy.count() == 1);
+
QVERIFY(errorSpy.isEmpty());
//if (discoveryAgent.discoveredServices().count() && expected_failures++ <2){
|
[-]
[+]
|
Deleted |
_service:tar_git:opt-qt5-qtconnectivity-5.15.9+kde5.tar.bz2/upstream/src/bluetooth/qleadvertiser_p.h
^
|
@@ -1,154 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtBluetooth module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QLEADVERTISER_P_H
-#define QLEADVERTISER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qlowenergyadvertisingdata.h"
-#include "qlowenergyadvertisingparameters.h"
-
-#if QT_CONFIG(bluez)
-#include "bluez/bluez_data_p.h"
-#endif
-
-#include <QtCore/qobject.h>
-#include <QtCore/qvector.h>
-
-QT_BEGIN_NAMESPACE
-
-class QLeAdvertiser : public QObject
-{
- Q_OBJECT
-public:
- void startAdvertising() { doStartAdvertising(); }
- void stopAdvertising() { doStopAdvertising(); }
-
-signals:
- void errorOccurred();
-
-public:
- QLeAdvertiser(const QLowEnergyAdvertisingParameters ¶ms,
- const QLowEnergyAdvertisingData &advData,
- const QLowEnergyAdvertisingData &responseData, QObject *parent)
- : QObject(parent), m_params(params), m_advData(advData), m_responseData(responseData) {}
- virtual ~QLeAdvertiser() { }
-
-protected:
- const QLowEnergyAdvertisingParameters ¶meters() const { return m_params; }
- const QLowEnergyAdvertisingData &advertisingData() const { return m_advData; }
- const QLowEnergyAdvertisingData &scanResponseData() const { return m_responseData; }
-
-private:
- virtual void doStartAdvertising() = 0;
- virtual void doStopAdvertising() = 0;
-
- const QLowEnergyAdvertisingParameters m_params;
- const QLowEnergyAdvertisingData m_advData;
- const QLowEnergyAdvertisingData m_responseData;
-};
-
-
-#if QT_CONFIG(bluez)
-struct AdvData;
-struct AdvParams;
-class HciManager;
-
-class QLeAdvertiserBluez : public QLeAdvertiser
-{
-public:
- QLeAdvertiserBluez(const QLowEnergyAdvertisingParameters ¶ms,
- const QLowEnergyAdvertisingData &advertisingData,
- const QLowEnergyAdvertisingData &scanResponseData, HciManager &hciManager,
- QObject *parent = nullptr);
- ~QLeAdvertiserBluez() override;
-
-private:
- void doStartAdvertising() override;
- void doStopAdvertising() override;
-
- void setPowerLevel(AdvData &advData);
- void setFlags(AdvData &advData);
- void setServicesData(const QLowEnergyAdvertisingData &src, AdvData &dest);
- void setManufacturerData(const QLowEnergyAdvertisingData &src, AdvData &dest);
- void setLocalNameData(const QLowEnergyAdvertisingData &src, AdvData &dest);
-
- void queueCommand(OpCodeCommandField ocf, const QByteArray &advertisingData);
- void sendNextCommand();
- void queueAdvertisingCommands();
- void queueReadTxPowerLevelCommand();
- void toggleAdvertising(bool enable);
- void setAdvertisingParams();
- void setAdvertisingInterval(AdvParams ¶ms);
- void setData(bool isScanResponseData);
- void setAdvertisingData();
- void setScanResponseData();
- void setWhiteList();
-
- void handleCommandCompleted(quint16 opCode, quint8 status, const QByteArray &advertisingData);
- void handleError();
-
- HciManager &m_hciManager;
-
- struct Command {
- Command() {}
- Command(OpCodeCommandField ocf, const QByteArray &data) : ocf(ocf), data(data) { }
- OpCodeCommandField ocf;
- QByteArray data;
- };
- QVector<Command> m_pendingCommands;
-
- quint8 m_powerLevel;
- bool m_sendPowerLevel;
-};
-#endif // QT_CONFIG(bluez)
-
-QT_END_NAMESPACE
-
-#endif // Include guard.
|