I tested KDE Connect Android 1.35.17 on a OnePlus 13 running Android 16 and OxygenOS 16.0.10.600. In a local debug build, I removed only the explicit WifiManager.MulticastLock creation, acquisition and release from MdnsDiscovery.kt. I left NsdManager discovery and registration, UDP discovery and TCP connections unchanged. Normal paired-device use has continued to work. The patched app no longer holds KDE's multicast lock, and the phone can restore APF multicast filtering when no other app requires multicast reception. I have not established a measurable battery saving. Other background activity and test conditions changed between measurements. I also have not separately verified discovery of new peers while filtering is active, or compatibility with other Android versions and OEMs. Is this additional app-owned lock required for NsdManager discovery on all supported devices? If it is only needed in some cases, could KDE avoid holding it continuously where unnecessary? I can provide the small patch and redacted lock/filter diagnostics.
Description KDE Connect Android holds kdeConnectMdnsMulticastLock for long periods while its background discovery service runs. This enables blanket Wi-Fi multicast reception, including traffic unrelated to KDE Connect. On my OnePlus 13, the original build accumulated 16 hours 38 minutes of multicast-lock time during a statistics period with about 18 hours of foreground-service time. Steps to reproduce 1. Run KDE Connect Android 1.35.17 on a Wi-Fi network permitted by its trusted-network settings. 2. Pair it with a desktop and leave the background service running. 3. Turn the phone's screen off and leave it connected to Wi-Fi. 4. Inspect the active multicast locks and accumulated battery statistics: adb shell dumpsys wifi adb shell dumpsys batterystats --charged Look for kdeConnectMdnsMulticastLock in the Wi-Fi dump and the WiFi Multicast Wakelock entry under KDE Connect's UID in the battery statistics. Observed result KDE Connect keeps its multicast lock while mDNS discovery runs. The lock lifetime follows discovery, rather than a short discovery transaction. This report concerns that long-running behavior, not a lock that fails to release after discovery stops. Expected result KDE Connect should remain available for background connections and discovery while allowing normal Wi-Fi multicast filtering wherever the platform can provide those functions without blanket multicast reception. Software versions - OnePlus 13, CPH2653 - Android 16 - KDE Connect Android 1.35.17 - Initial observations on OxygenOS 16.0.10.501; later patched-build observations on 16.0.10.600 Additional observations and limits I tested a local build that removes only KDE Connect's explicit multicast-lock creation, acquisition and release in MdnsDiscovery.kt. NsdManager discovery and registration, UDP discovery and TCP connections remain unchanged. Normal paired-device use has continued to work. The patched app has no multicast-lock attribution in the collected statistics. Separate packet-filter logs show mcast: DROP during screen-off operation when no other app requires multicast reception. These observations do not establish a battery saving. The captures come from different periods, and firmware, access-point conditions and other background activity changed. I have not separately verified discovery of a new peer while filtering is active, or behavior on other Android versions and OEMs. The evidence therefore does not justify removing the lock unconditionally on every supported device. Requested severity: wishlist.
Created attachment 197058 [details] Sanitized multicast-lock and packet-filter diagnostic excerpts
Albert, I'm addressing this to you as the component maintainer: I have a patch for this that I can't open as a merge request upstream, so I'm posting it here for review. I ran into the same problem. A few weeks ago I forked the app and patched it, and I've been using the patched build since then with no issues. My patch keeps the lock but bounds how long it is held, instead of removing it. Device: OnePlus 12 (CPH2573), Android 16, OxygenOS 16.0.10.501. Paired with a Linux desktop. Disclosure: I used AI assistants (OpenAI Codex and Anthropic Claude) to help analyse battery statistics, write the patch and tests, and run the on-device checks below. I reviewed the changes and the results myself. FIX Branch: https://invent.kde.org/noah/kdeconnect-android/-/tree/fix-battery-multicast-drain Based on master 4d317ee (1.37.0 Beta): 1. Bound mDNS discovery to a 30 second window https://invent.kde.org/noah/kdeconnect-android/-/commit/202764369c957be891426806019a401dcc803c26 2. Rate limit connection refreshes on screen on https://invent.kde.org/noah/kdeconnect-android/-/commit/f238c4f658cdc751398a19f1c9211a56eaee3cbc CAUSE `MdnsDiscovery.startDiscovering()` acquires `kdeConnectMdnsMulticastLock` and only releases it in `stopDiscovering()`. That runs when the service stops, or on the next network change (`LanLinkProvider.onNetworkChange()` calls stop and then start). So the lock lives as long as the discovery session, which in practice means as long as the phone stays on one network. A second trigger makes it worse. `KdeConnectBroadcastReceiver` calls `BackgroundService.ForceRefreshConnections()` on every `ACTION_SCREEN_ON`. Each refresh sends a UDP identity broadcast and restarts mDNS discovery. `DELAY_BETWEEN_BROADCASTS` (200 ms) in `LanLinkProvider` does not limit this in practice. WHAT THE PATCH DOES 1. `startDiscovering()` schedules `stopDiscovering()` 30 s after it starts, which releases the lock. The lock is also released from `onDiscoveryStopped` and `onStartDiscoveryFailed`, and callbacks from an already stopped session are ignored. `MainActivity.onStart()` calls `ForceRefreshConnections()`, so opening the app opens a new window. 2. The `ACTION_SCREEN_ON` refresh is skipped when every paired device is already reachable. Otherwise it runs at most once per 5 minutes. Network changes and opening the app still refresh immediately. Robolectric tests are included (`MdnsDiscoveryTest`, `KdeConnectBroadcastReceiverTest`). The full unit test suite passes (144 tests). MEASUREMENTS (BATTERYSTATS, KDE CONNECT UID) With patch 1 only, over about 13 h on battery (about 11 h of that with the screen off): - WiFi multicast wakelock: 57 acquisitions, 19 min 50 s in total, each about 30 s. - Every lock session lined up with a screen-on. There were none while the screen stayed off. - CPU 7.9 s, no partial wakelocks. KDE Connect did not appear among the apps causing network wakeups. For comparison, the reporter above saw 16 h 38 min with the unpatched build. With patch 2 added, three screen-on events 6 s apart produced one 30 s discovery session (`durationMs=30023` in `dumpsys wifi`). The other two logged `Screen on: refreshed recently, skipping refresh`. Already paired devices stay connected over TCP, so the window does not affect them. Discovering a new device needs one of: opening the app, a network change, or a screen-on refresh. On the question in the original report: removing the lock entirely might work on some devices, but whether NsdManager receives multicast without it depends on the vendor's APF/offload implementation. Bounding the lock keeps discovery working everywhere and still lets the device return to multicast filtering most of the time. I'm happy to rework the patch if you prefer a different approach, for example a different window length or making the screen-on behaviour configurable.
I can confirm this on a second device and OS, with a measured battery cost. The current behaviour is a real drain, not just a theoretical one, and I don't think it should be the default. Device: Pixel 10 Pro, GrapheneOS 2026102101 (Android 17), KDE Connect Android 1.37.0 (installed via Obtainium), paired with one Linux desktop over home Wi-Fi. Run 1 (24 h 10 min on battery, default settings): - WiFi multicast wake lock under KDE Connect's UID: 87 acquisitions, held 24 h 9 min, i.e. the whole run. - Wi-Fi kernel active 83.5% of the time; 9,801 wakeups from the Wi-Fi chip (1238 dhdpcie_host_wake). - Wi-Fi rail drain 1,095 mAh (45 mAh/h). Screen-off drain 60 mAh/h. - KDE Connect itself is billed 0.58 mAh, because the cost lands on the Wi-Fi chip and not on the app. That makes the cause very hard for users to find from Android's battery screen. Run 2 (18 h 24 min, same phone and network): the only change was turning on Trusted networks with an empty list, which makes MdnsDiscovery.startDiscovering() return before acquiring the lock. - Multicast lock held about 2 min in total. `dumpsys wifi` shows no lock owners. - Wi-Fi kernel active 47.8%; Wi-Fi wakeups about 2,660 per 24 h (-73%). - Wi-Fi rail drain 33 mAh/h (-27%). Screen-off drain 47 mAh/h (-22%). - The already-paired laptop stayed connected while the phone stayed on the home network. The two days weren't identical (run 2 had more screen-on, GPS and cellular use, so I'm not quoting whole-phone totals), but the Wi-Fi and screen-off figures are directly comparable, and the change follows the lock. The workaround has two costs. Trusted networks need location permission to read the SSID, which is an awkward trade-off on a privacy-focused phone. And with discovery off, the phone no longer reconnects by itself after changing networks: I have to open KDE Connect on the phone before the laptop connects. That suits me, since I'd rather connect deliberately, but most users expect it to reconnect in the background, and many will never find the setting anyway, since they don't attribute the drain to KDE Connect. Current master (e1c3129) still acquires the lock in startDiscovering() and only releases it in stopDiscovering(), so it is held for as long as the phone stays on one network. Bounding discovery to a short window, as in Noah's patch in comment 3, looks like the right default: paired devices stay connected over TCP, and because a network change still triggers an immediate refresh, it keeps the automatic reconnection that the Trusted networks workaround loses. I'd be glad to test a build with that patch on this device and post the same before/after figures.
I'll merge Noah's patch "Bound mDNS discovery to a 30 second window".
> with discovery off, the phone no longer reconnects by itself after changing networks I think this isn't accurate, because in theory we do trigger a "network refresh" on network change.
Git commit 4de397e230f18d69cac8510d081e25cd3495d144 by Albert Vaca Cintora, on behalf of Noah Jon. Committed on 31/10/2026 at 19:45. Pushed by albertvaka into branch 'master'. Bound mDNS discovery to a 30 second window MdnsDiscovery held a WifiManager.MulticastLock for as long as discovery was running, and discovery was only stopped when the service stopped or the network changed. On busy networks this keeps the Wi-Fi chip waking the device for every multicast frame, long after the screen is off. Stop discovery and release the lock 30 seconds after it starts. Also release the lock when the system reports discovery stopped or failed, and ignore callbacks from an already stopped session. MainActivity now requests a refresh on start so opening the app reopens the window. M +41 -7 src/main/java/org/kde/kdeconnect/backends/lan/MdnsDiscovery.kt M +1 -1 src/main/java/org/kde/kdeconnect/ui/MainActivity.kt A +178 -0 src/test/java/org/kde/kdeconnect/backends/lan/MdnsDiscoveryTest.kt https://invent.kde.org/network/kdeconnect-android/-/commit/4de397e230f18d69cac8510d081e25cd3495d144