https://bugs.kde.org/show_bug.cgi?id=528848

            Bug ID: 528848
           Summary: Notifications plugin sends all active notifications on
                    every connection and again on request (since 1.37.1)
    Classification: Applications
           Product: kdeconnect
      Version First unspecified
       Reported In:
          Platform: Android
                OS: Unspecified
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: android-application
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

Since 1.37.1 the Android app pushes the complete set of active notifications to
the desktop
whenever the notifications plugin is created, i.e. on every (re)connection, and
it also
answers the desktop's kdeconnect.notification.request with the complete set. So
one
reconnect — for example after the desktop resumes from suspend while the phone
stays awake —
can deliver the full set twice, and the pushed set consists of notifications
the desktop
already has. With many notifications on the phone this is a burst of N "update"
packets.

On the desktop each such update makes the Plasma applet re-read notification
properties over
synchronous D-Bus; on KDE Connect desktop 25.12.3 this froze plasmashell for
several minutes
after resume. The desktop side is analysed in bug 527798; this report is only
about the
amount of traffic the phone sends.

STEPS TO REPRODUCE
1. Pair the Android app (1.37.1 or later) with a desktop; notification sync
enabled.
2. Have many notifications on the phone (here: 136).
3. Make the connection drop and come back, e.g. suspend and resume the desktop
while the
   phone stays awake.

OBSERVED RESULT
The phone sends the full set when the plugin is created and again in reply to
the desktop's
request. The desktop receives packets for ids it already knows (silent: true,
no isCancel).
Measured on the desktop after resume: plasmashell made 5803
org.freedesktop.DBus.Properties.Get
calls to kdeconnectd within 5 seconds, with 136 mirrored notifications, and
stayed
unresponsive for minutes.

EXPECTED RESULT
One full synchronisation per connection. The desktop clients I checked already
ask for one on
connect: kdeconnect-kde, GSConnect and Valent all send "request".

CODE REFERENCES (kdeconnect-android v1.37.3, f82d035d; unchanged on master
510471b6)
- onCreate → addListener:
 
https://invent.kde.org/network/kdeconnect-android/-/blob/f82d035ddc93d41aa45bea3988a6db4265c5554f/src/main/java/org/kde/kdeconnect/plugins/notifications/NotificationsPlugin.kt#L79-86
- addListener calls onListenerConnected immediately when the service is already
bound
  (a74d7a56, 1.37.1):
 
https://invent.kde.org/network/kdeconnect-android/-/blob/f82d035ddc93d41aa45bea3988a6db4265c5554f/src/main/java/org/kde/kdeconnect/plugins/notifications/NotificationReceiver.kt#L32-41
- onListenerConnected → sendCurrentNotifications (9ebd3ee5, 1.35.16):
 
https://invent.kde.org/network/kdeconnect-android/-/blob/f82d035ddc93d41aa45bea3988a6db4265c5554f/src/main/java/org/kde/kdeconnect/plugins/notifications/NotificationsPlugin.kt#L104-109
- the reply to "request" sends the full set again:
 
https://invent.kde.org/network/kdeconnect-android/-/blob/f82d035ddc93d41aa45bea3988a6db4265c5554f/src/main/java/org/kde/kdeconnect/plugins/notifications/NotificationsPlugin.kt#L520-524
- plugins are recreated on the first link:
 
https://invent.kde.org/network/kdeconnect-android/-/blob/f82d035ddc93d41aa45bea3988a6db4265c5554f/src/main/java/org/kde/kdeconnect/Device.kt#L361-362
- onDestroy clears notificationsIcons, so the first set after a reconnect
carries every icon
  payload again:
 
https://invent.kde.org/network/kdeconnect-android/-/blob/f82d035ddc93d41aa45bea3988a6db4265c5554f/src/main/java/org/kde/kdeconnect/plugins/notifications/NotificationsPlugin.kt#L88-90
- the desktop requests on every plugin reload:
 
https://invent.kde.org/network/kdeconnect-kde/-/blob/a97984ebce1d31917aa002b8753a05de42968db7/plugins/notifications/notificationsplugin.cpp#L27-31
  and
https://invent.kde.org/network/kdeconnect-kde/-/blob/a97984ebce1d31917aa002b8753a05de42968db7/core/device.cpp#L204

HISTORY
The same push on listener connection was removed in 2019 by e3e4fc65 ("Don't
sync
notification on connection", 1.13.1), because the desktop requests the list
itself. 9ebd3ee5
(1.35.16) brought it back — I guess for bug 524438 (listener rebind) and for a
request that
arrives before serviceReady and is dropped (NotificationsPlugin.kt#L521); the
commit has no
description, so this is my reading. a74d7a56 (1.37.1) made it fire on every
plugin creation.

PROPOSAL (lowest risk first)
1. At most one full sync per short window per plugin instance: skip the reply
to "request"
   if sendCurrentNotifications ran a few seconds ago. A time window, not a
per-connection
   flag, because the desktop sends "request" on every plugin reload and a
re-enabled plugin
   needs the full set.
2. Remember a "request" that arrived while !serviceReady and answer it in
   onListenerConnected, instead of pushing unconditionally; keep the
unconditional push only
   for a real rebind by the system.
3. Longer term: the desktop also sends "request" after a LAN link socket reset
   (lanlinkprovider.cpp reuses the link without reloading plugins), so the
phone would not
   need to push at all.

The desktop should also ignore unchanged updates; that part is in bug 527798.

Not verified: which of the two paths wins the race on a given reconnect (one
set or two),
and the Bluetooth backend.

SOFTWARE
KDE Connect Android 1.37.3; KDE Connect desktop 25.12.3; Plasma 6.6.6; Qt
6.10.2; Wayland.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to