Bug 477633

Summary: After waking from sleep via lid close and re-open, Bluetooth tray applet doesn't show any devices even if KCM does
Product: [Unmaintained] Bluedevil Reporter: Bharadwaj Raju <bharadwaj.raju777>
Component: system trayAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: agurenko, me, nate, nowrep
Priority: NOR Keywords: qt6
Version First Reported In: master   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Bharadwaj Raju 2023-11-27 19:15:16 UTC
SUMMARY
Bluetooth tray applet sometimes doesn't show any devices even if KCM does. Restarting plasmashell makes it work fine.

There doesn't seem to be anything directly relevant in Plasmashell logs.



STEPS TO REPRODUCE
I'm not exactly sure what causes this, I'll try some experiments (turning it off and on) and see if anything consistent emerges.

SOFTWARE/OS VERSIONS
Operating System: Fedora Linux 39
KDE Plasma Version: 5.81.80
KDE Frameworks Version: 5.245.0
Qt Version: 6.6.0
Kernel Version: 6.5.11-300.fc39.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 5625U with Radeon Graphics
Memory: 7.1 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Comment 1 Bharadwaj Raju 2023-11-27 22:04:39 UTC
Observation: when this happens and Bluetooth is off at that moment, I don't see the enable switch. I just see the enable button.
Comment 2 Bharadwaj Raju 2023-11-27 22:06:04 UTC
OK, I can reproduce it consistently by waking my laptop from suspend (close lid and reopen).
Comment 3 Bharadwaj Raju 2023-12-15 15:03:54 UTC
Interestingly it doesn't seem to affect plasmawindowed.
Comment 4 Bharadwaj Raju 2024-02-08 20:20:20 UTC
Observing output with kf.bluez debug logs turned on:

For plasmawindowed (where it works), the output goes like:

kf.bluezqt: Rfkill global state changed: BluezQt::Rfkill::Unblocked
kf.bluezqt: Setting usable adapter QSharedPointer(BluezQt::Adapter(0xf5b5b0))
<sleep>
kf.bluezqt: Rfkill global state changed: BluezQt::Rfkill::Unblocked
kf.bluezqt: Setting usable adapter QSharedPointer(QObject(0x0))
kf.bluezqt: Unhandled property change "org.bluez.Adapter1" QMap(("Class", QVariant(uint, 0))("Discovering", QVariant(bool, false))("PowerState", QVariant(QString, "on"))("Powered", QVariant(bool, false))) QList()
kf.bluezqt: Setting usable adapter QSharedPointer(BluezQt::Adapter(0x14ba950))

Notice how a non-null adapter was set.

For KCM (where it doesn't), the output is:

kf.bluezqt: Rfkill global state changed: BluezQt::Rfkill::Unblocked
kf.bluezqt: Setting usable adapter QSharedPointer(BluezQt::Adapter(0x25b8b40))
qt.dbus.integration: Could not connect "org.freedesktop.DBus.ObjectManager" to "InterfacesAdded"
<sleep>
kf.bluezqt: Rfkill global state changed: BluezQt::Rfkill::Unblocked
kf.bluezqt: Setting usable adapter QSharedPointer(QObject(0x0))
kf.bluezqt: Unhandled property change "org.bluez.Adapter1" QMap(("Pairable", QVariant(bool, true))) QList()
kf.bluezqt: Unhandled property change "org.bluez.Adapter1" QMap(("UUIDs", QVariant(QStringList, QList("0000110e-0000-1000-8000-00805f9b34fb", "0000111f-0000-1000-8000-00805f9b34fb", "00001200-0000-1000-8000-00805f9b34fb", "00001132-0000-1000-8000-00805f9b34fb", "00001133-0000-1000-8000-00805f9b34fb", "0000110c-0000-1000-8000-00805f9b34fb", "00001800-0000-1000-8000-00805f9b34fb", "0000112f-0000-1000-8000-00805f9b34fb", "00001801-0000-1000-8000-00805f9b34fb", "00001106-0000-1000-8000-00805f9b34fb", "0000180a-0000-1000-8000-00805f9b34fb", "00001104-0000-1000-8000-00805f9b34fb", "0000111e-0000-1000-8000-00805f9b34fb", "00001105-0000-1000-8000-00805f9b34fb", "00005005-0000-1000-8000-0002ee000001")))) QList()
[lots more lines]

A non-null adapter was never set again.

I wonder if `qt.dbus.integration: Could not connect "org.freedesktop.DBus.ObjectManager" to "InterfacesAdded"` is relevant at all?
Comment 5 Bharadwaj Raju 2024-02-10 13:48:26 UTC
Found a "fix", but it's too strange. Connecting to the signal like this works:

void ManagerPrivate::interfacesAdded2(const QDBusObjectPath &objectPath, const QMap<QString, QMap<QString, QVariant>> &interfaces);
// ...
QDBusConnection::systemBus().connect(QStringLiteral("org.bluez"),
                                         QStringLiteral("/"),
                                         QStringLiteral("org.freedesktop.DBus.ObjectManager"),
                                         QStringLiteral("InterfacesAdded"),
                                         this,
                                         SLOT(interfacesAdded2(QDBusObjectPath, QMap<QString, QMap<QString, QVariant>>)));

But not if I use a method with QVariantMapMap in the signature, even though QVariantMapMap is typedef'd to be exactly that. It's already Q_DECLARE_METATYPE'd as well.

And for some reason the same QVariantMapMap connect call works in plasmawindowed but not plasmashell or systemsettings. What could possibly be different?
Comment 6 Bug Janitor Service 2024-02-10 14:34:52 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/bluez-qt/-/merge_requests/55
Comment 7 Bharadwaj Raju 2024-02-15 10:49:00 UTC
Git commit 3c60d9e3db6f9d236f1e6a166303f51cc6374119 by Bharadwaj Raju.
Committed on 15/02/2024 at 10:48.
Pushed by bharadwaj-raju into branch 'master'.

Fix connecting to org.freedesktop.DBus.ObjectManager InterfacesAdded

The metatype also needs to be qRegisterMetaType'd in addition to
qDBusRegisterMetaType and Q_DECLARE_METATYPE.

I still don't know why it worked in plasmawindowed though…

M  +1    -0    src/manager_p.cpp

https://invent.kde.org/frameworks/bluez-qt/-/commit/3c60d9e3db6f9d236f1e6a166303f51cc6374119