summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_android.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-01-04 11:14:30 +0100
committerAlex Blasche <alexander.blasche@qt.io>2017-01-23 11:09:26 +0000
commiteaec158cf7ea2a62e79afd87701384830dee599d (patch)
tree7a56c42df37391a5e752a8e05e490dce8c4fbf01 /src/bluetooth/qlowenergycontroller_android.cpp
parentd66b34100ad3e5ddd226ba85c4e974ad08e22205 (diff)
Android: Keep track of peripheral advertisement errors
If advertisement fails then we drop back into the unconnected state and provide a more detailed error message for individual advertisement errors. Change-Id: Ic9de02b456409cd1a2dec11e53c884fe368ae267 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_android.cpp')
-rw-r--r--src/bluetooth/qlowenergycontroller_android.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index 8654fe71..0d63faf1 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -88,6 +88,8 @@ void QLowEnergyControllerPrivate::init()
// TODO add connections as they get added later on
connect(hub, &LowEnergyNotificationHub::connectionUpdated,
this, &QLowEnergyControllerPrivate::connectionUpdated);
+ connect(hub, &LowEnergyNotificationHub::advertisementError,
+ this, &QLowEnergyControllerPrivate::advertisementError);
} else {
if (version < 18) {
qWarning() << "Qt Bluetooth LE Central/Client support not available"
@@ -678,6 +680,54 @@ void QLowEnergyControllerPrivate::serviceError(
service->setError(errorCode);
}
+void QLowEnergyControllerPrivate::advertisementError(int errorCode)
+{
+ Q_Q(QLowEnergyController);
+
+ switch (errorCode)
+ {
+ case 1: // AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE
+ errorString = QLowEnergyController::tr("Advertisement data is larger than 31 bytes");
+ break;
+ case 2: // AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED
+ errorString = QLowEnergyController::tr("Advertisement feature not supported on the platform");
+ break;
+ case 3: // AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR
+ errorString = QLowEnergyController::tr("Error occurred trying to start advertising");
+ break;
+ case 4: // AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
+ errorString = QLowEnergyController::tr("Failed due to too many advertisers");
+ break;
+ default:
+ errorString = QLowEnergyController::tr("Unknown advertisment error");
+ break;
+ }
+
+ error = QLowEnergyController::AdvertisingError;
+ emit q->error(error);
+
+ // not relevant states in peripheral mode
+ Q_ASSERT(state != QLowEnergyController::DiscoveredState);
+ Q_ASSERT(state != QLowEnergyController::DiscoveringState);
+
+ switch (state)
+ {
+ case QLowEnergyController::UnconnectedState:
+ case QLowEnergyController::ConnectingState:
+ case QLowEnergyController::ConnectedState:
+ case QLowEnergyController::ClosingState:
+ // noop as remote is already connected or about to disconnect.
+ // when connection drops we reset to unconnected anyway
+ break;
+
+ case QLowEnergyController::AdvertisingState:
+ setState(QLowEnergyController::UnconnectedState);
+ break;
+ default:
+ break;
+ }
+}
+
static QAndroidJniObject javaParcelUuidfromQtUuid(const QBluetoothUuid& uuid)
{
QString output = uuid.toString();