Skip to content

fix(battery): consider every line power device, not just the first - #187

Merged
mmstick merged 1 commit into
pop-os:masterfrom
chris-010:fix/all-line-power-devices
Aug 28, 2026
Merged

mmstick merged 1 commit into
pop-os:masterfrom
chris-010:fix/all-line-power-devices

Conversation

@chris-010

Copy link
Copy Markdown
Contributor

watch_battery_plug_events watches only the first upower device whose name starts with line_power. Where a stale ACPI AC device is enumerated ahead of the supplies that actually work, the daemon watches that one forever and never sees a plug event.

On a ThinkPad T490 (Pop!_OS 24.04) with the charger connected, line_power_AC reports Online = false and never changes, while line_power_ucsi_source_psy_USBC000o001 reports true and /sys/class/power_supply/AC/online reads 1. line_power_AC is enumerated first, so is_on_battery stays true and no plug event arrives — among other things the critical battery alert can then never be stopped by plugging in.

This collects every line_power device and treats the machine as on mains power when any of them is online, recomputing across all of them when one changes. The debounce and the returned watch function are unchanged.

Measured by logging the daemon's own pw-play calls while unplugging and replugging:

unplug plug
before nothing played nothing played
after power-unplug in the same second power-plug in the same second

line_power_AC.Online stayed false throughout, so this works around the stale device rather than depending on it.

Closes #182

  • I have disclosed use of any AI generated code in my commit messages.
  • I understand these changes in full and will be able to respond to review comments.
  • My change is accurately described in the commit message.
  • My contribution is tested and working as described.
  • I have read the Developer Certificate of Origin and certify my contribution under its conditions.

`watch_battery_plug_events` took the first upower device whose name starts with
`line_power` and watched only that one. Where a stale ACPI AC device is
enumerated ahead of the supplies that actually work, the daemon reads its
`Online` forever and never sees a plug event.

On a ThinkPad T490 running Pop!_OS 24.04, upower enumerates `line_power_AC`,
`line_power_ucsi_source_psy_USBC000o001` and
`line_power_ucsi_source_psy_USBC000o002`. With the charger connected,
`/sys/class/power_supply/AC/online` reads 1 and the first `ucsi` device reports
`Online = true`, while `line_power_AC` stays `false` and never emits a change.
`line_power_AC` is enumerated first, so `is_on_battery` is stuck at `true` and no
plug event ever arrives. The critical battery alert therefore cannot be stopped
by plugging in; it ends only once charging carries the level back over 10%.

Collect every `line_power` device instead, treat the machine as on mains power
when any of them is online, and recompute across all of them whenever one
changes. The 500ms debounce and the semantics of the returned watch function are
unchanged.

Measured on that machine by logging the daemon's own `pw-play` invocations while
unplugging and replugging. Unpatched, neither `power-unplug` nor `power-plug` was
played. Patched, both were played in the same second as the sysfs transition.
`line_power_AC.Online` remained `false` throughout, so the change works around
the stale device rather than depending on it.

Drafted with AI assistance (Claude Code). I understand the change, built it and
measured it on real hardware as described.

Closes pop-os#182

Signed-off-by: chris-010 <10660568+chris-010@users.noreply.github.com>
@mmstick
mmstick requested a review from a team August 28, 2026 15:25
@jklgrasso jklgrasso self-assigned this Aug 28, 2026

@jklgrasso jklgrasso left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sound plays after connecting or disconnecting the AC adapter.

@mmstick
mmstick merged commit f015ca8 into pop-os:master Aug 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AC detection since #180 can latch to a upower line_power device that never updates

3 participants