summaryrefslogtreecommitdiffstats
path: root/bluetooth/bluetooth.cpp
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2020-06-23 13:59:15 +0200
committerRaquel Medina <raquel.medina@konsulko.com>2020-06-23 18:47:24 +0200
commit14c3bea3a90d54577ae1f6a124f61e90fb05c731 (patch)
treef6e3b04f7fdf5cd31f8f7f48926b6cb0e87fe3a4 /bluetooth/bluetooth.cpp
parentae208a6a303982535c44a7f124f38b4252528ab4 (diff)
add checks to avoid duplicates in qtappfw-bt modeljellyfish_9.99.1jellyfish/9.99.19.99.1
Duplicate bluetooth entries have been seen on settings app' bluetooth page, following disconnect/connect cycles. They were caused by multiple connected events associated to the same device on the same adapter. This patch avoids the duplicates in the model when only one bluetooth adapter is present on the target, duplicates in the model when more than one bluetooth adapter is present is to be covered by SPEC-3294. The current patch: - tests the device id present on "device_changes" events data, as this id is used to index devices in the model. - treats "device_changes added" events on an existing device in the model as if a "changed" action was received for it. Bug-AGL: SPEC-3424 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: Ia5f273f456383880b2d855e567bdf6b41ed98352
Diffstat (limited to 'bluetooth/bluetooth.cpp')
-rw-r--r--bluetooth/bluetooth.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/bluetooth/bluetooth.cpp b/bluetooth/bluetooth.cpp
index cea89ad..fe1212f 100644
--- a/bluetooth/bluetooth.cpp
+++ b/bluetooth/bluetooth.cpp
@@ -228,16 +228,23 @@ void Bluetooth::processDeviceChangesEvent(QJsonObject data)
QString action = data.value("action").toString();
QString id = data.value("device").toString();
- if (action == "added") {
- BluetoothDevice *device = m_bluetooth->updateDeviceProperties(nullptr, data);
- m_bluetooth->addDevice(device);
- } else if (action == "changed") {
- BluetoothDevice *device = m_bluetooth->getDevice(id);
- m_bluetooth->updateDeviceProperties(device, data);
- } else if (action == "removed") {
- BluetoothDevice *device = m_bluetooth->getDevice(id);
- m_bluetooth->removeDevice(device);
+ if (id.isEmpty())
+ return;
+
+ BluetoothDevice *device = m_bluetooth->getDevice(id);
+ if (action == "removed") {
+ if (device != nullptr)
+ m_bluetooth->removeDevice(device);
+ return;
+ }
+
+ BluetoothDevice *ndevice = m_bluetooth->updateDeviceProperties(device, data);
+ if (ndevice == nullptr) {
+ qDebug() << "bt - failed to create device object with id: " << id;
+ return;
}
+ if (device == nullptr) //device not previously in model
+ m_bluetooth->addDevice(ndevice);
}
void Bluetooth::processAdapterChangesEvent(QJsonObject data)