Fix Android IP detection and multicast for OpenBikeControl (MyWhoosh Link) - #4864
Merged
Merged
Conversation
…Link) MyWhoosh Link's mDNS advertising and TCP server never receive incoming connections on Android because: - localipaddress::getIP() relied solely on the deprecated WifiManager.getConnectionInfo().getIpAddress() API, which returns 0 on modern Android, causing mDNS to publish 0.0.0.0 as the service address. Add a QNetworkInterface-based fallback (preferring wlan*) and validate the JNI-derived address before using it. - Android silently drops incoming WiFi multicast packets (including mDNS queries) unless the app holds a WifiManager.MulticastLock. Acquire one in ForegroundService alongside the new CHANGE_WIFI_MULTICAST_STATE permission. Ports forward two commits from the abandoned branch android-ipaddress-not-valid (closed PR #4357, never merged).
…id IP QNetworkInterface enumeration relies on netlink route sockets, which SELinux denies to untrusted (third-party) apps on modern Android (observed as nlmsg_readpriv AVC denials), so it was returning no usable interface at all on affected devices. Query the device's IPv4 address via ConnectivityManager.getLinkProperties() on the active network instead, which goes through the normal system service and isn't subject to that restriction. Falls back to the legacy WifiManager JNI path (still validated) on Android < 6.0 where getActiveNetwork() doesn't exist.
connManager's local reference was deleted right after getActiveNetwork() but then reused for getLinkProperties(), corrupting the JNI local reference table (observed as a SIGABRT: "jobject is an invalid local reference... popped reference at index 15 in a table of size 12", crashing inside QMdnsEngine::ProviderPrivate::publish() -> getIP()). Fix by only deleting local refs after their last use, and wrap the whole function in PushLocalFrame/PopLocalFrame so it doesn't depend on the calling thread's default local reference capacity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
localipaddress::getIP()only used the deprecatedWifiManager.getConnectionInfo().getIpAddress()API, which returns 0 on modern Android, so mDNS advertised0.0.0.0as the service address. Added aQNetworkInterface-based fallback (preferringwlan*) and stricter validation of the JNI-derived address.WifiManager.MulticastLock. AddedCHANGE_WIFI_MULTICAST_STATEpermission and acquire/release the lock inForegroundService.android-ipaddress-not-valid(closed PR Prefer wlan IPv4 and validate JNI IP #4357, never merged, no review comments, all CI green at the time).Relates to #4717 (Zwift Click steering via MyWhoosh not working — button routing was already fixed in 592c28e, but messages never reach MyWhoosh because no TCP client ever connects).
Test plan