Skip to content

Commit 9479651

Browse files
authored
Handle missing Sole service with FTMS fallback (#4574)
1 parent 77f2059 commit 9479651

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/devices/solebike/solebike.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "keepawakehelper.h"
44
#endif
55
#include "virtualdevices/virtualbike.h"
6+
#include "homeform.h"
7+
#include "qzsettings.h"
68
#include <QBluetoothLocalDevice>
79
#include <QDateTime>
810
#include <QFile>
@@ -515,6 +517,25 @@ void solebike::serviceScanDone(void) {
515517
QBluetoothUuid _gattCommunicationChannelServiceId(QStringLiteral("49535343-fe7d-4ae5-8fa9-9fafd205e455"));
516518

517519
gattCommunicationChannelService = m_control->createServiceObject(_gattCommunicationChannelServiceId);
520+
521+
if (!gattCommunicationChannelService) {
522+
// Main Sole service not found, try FTMS service as a fallback to avoid crashes.
523+
QBluetoothUuid ftmsServiceId((quint16)0x1826);
524+
QLowEnergyService *ftmsService = m_control->createServiceObject(ftmsServiceId);
525+
if (ftmsService) {
526+
QSettings settings;
527+
settings.setValue(QZSettings::ftms_bike, bluetoothDevice.name());
528+
qDebug() << "forcing FTMS bike since Sole main service is missing but FTMS service is available";
529+
if (homeform::singleton()) {
530+
homeform::singleton()->setToastRequested("FTMS bike found, restart the app to apply the change");
531+
}
532+
delete ftmsService;
533+
} else {
534+
qDebug() << "Sole main service and FTMS service not found, skipping service init to avoid crash";
535+
}
536+
return;
537+
}
538+
518539
connect(gattCommunicationChannelService, &QLowEnergyService::stateChanged, this, &solebike::stateChanged);
519540
gattCommunicationChannelService->discoverDetails();
520541
}

0 commit comments

Comments
 (0)