rocknix: start the bluetooth agent with bluetoothd - #3230
Open
xiaodoudou wants to merge 1 commit into
Open
Conversation
bluetooth-agent.service declares PartOf=bluetooth.service so it follows bluetoothd down, and WantedBy=bluetooth.service so it comes back up with it. Only the first half is in effect: the unit is never passed to enable_service, so the bluetooth.service.wants symlink is absent from the image and nothing pulls the agent in. PartOf also propagates restarts, so systemctl restart bluetooth keeps the agent alive and hides this. What does not survive is a discrete stop followed later by a start, which is exactly the shape of the suspend path: sleep.sh stops bluetooth in its pre hook and starts it again in post. From the first resume onward bluetoothd runs with no agent behind it. Scanning still lists devices, so the adapter looks healthy, but pairing from the UI goes nowhere because nothing answers the confirmation request. rocknix-bluetooth enable, which starts both units by name, only runs from autostart at boot, so the gap lasts until the next reboot. Reproducible without suspending: systemctl stop bluetooth systemctl start bluetooth systemctl is-active bluetooth-agent # inactive Enable the unit so the WantedBy symlink ships. Note that systemctl is-enabled still reports disabled for units enabled this way, as it only looks at the config paths; the symlink under /usr/lib/systemd/system/bluetooth.service.wants is what matters.
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
Pair a bluetooth device, sleep the handheld, wake it up, then try to pair something else. Nothing happens. The device shows up in the list, you select it, and it just doesn't pair. No error anywhere. Reboot and it works again, until the next sleep.
The pairing agent is missing.
bluetooth-agent.servicehasPartOf=bluetooth.serviceso it stops with bluetoothd, andWantedBy=bluetooth.serviceso it should come back with it. ThatWantedBywas never installed: the unit isn't passed toenable_service, so there's nobluetooth.service.wantssymlink in the image and nothing pulls the agent back in. The only thing that starts it isrocknix-bluetooth enable, which runs once at boot from autostart.sleep.shhas always stopped bluetooth in itsprehook and started it again inpost, and nothing there changes here, so from the first resume onward bluetoothd is running with nothing behind it. The adapter still scans and lists devices, which is why it looks healthy, but pairing needs an agent to answer the confirmation request and there isn't one.This took a while to pin down because restarting doesn't reproduce it.
PartOfpropagates restarts as well as stops, sosystemctl restart bluetoothtakes the agent down and brings it straight back. Only a discrete stop followed later by a start loses it, which is exactly what the sleep hooks do.Testing
Built for SM8550 and flashed to an AYN Odin 2.
You don't need to sleep the device to see it, since the hooks amount to a stop and a start:
That prints
inactivebefore the change andactiveafter.On the flashed image, three suspend and resume cycles. The agent comes back one second after each resume with
NRestarts=0, so it's the new dependency pulling it in rather than something that survived from boot. Paired a controller after a resume, which is the case that silently did nothing before.One warning if you go poking: don't check this with
systemctl is-enabled, it reportsdisabledeither way. It only looks at the config paths, which is whysave-sysconfig.serviceandrocknix-memory-manager.servicesay the same thing today. The symlink under/usr/lib/systemd/system/bluetooth.service.wants/is what to look for.Could someone confirm this on a platform that ships with real suspend? SM8550 is the only hardware I have, and it runs fake suspend on
next, so I had to enable real suspend to see this at all (that is #3126, still open). I am going off the quirks for the rest: AMD64, RK3566, SM6115 and SM8750 all setsuspendmode memwith no device gate, andsleep.shis the same file everywhere, so they should all hit it. I have not run it on any of them.The check is just: sleep the device with bluetooth on, wake it, then
systemctl is-active bluetooth-agent. If that comes backinactive, this is a live bug for those users and the fix stands on its own. If it comes backactive, then I have this wrong and the only thing affected is SM8550 once real suspend is turned on, in which case this belongs with that work rather than as a separate change.Additional Context
The agent accepts pairing unconditionally:
NoInputNoOutput,RequestConfirmationandRequestAuthorizationboth return without raising, andmain.confcarriesJustWorksRepairing=always. So it is now resident more of the time than it was. It never touchesDiscoverableorPairableand only starts discovery from/run/bt_discovery_control, so I don't think this widens anything in practice, but you're better placed to judge that than I am.The call goes in the rocknix package rather than alongside the existing
enable_servicecalls in bluez, because rocknix is the package that ships the unit and itspost_installis therefore guaranteed to find it in$INSTALL. From bluez it would depend on which of the two installs first.AI Usage
Did you use AI tools to help write this code? PARTIALLY