Skip to content

on_ac_power: Fix incorrect AC state on some machines with USB type-C ports

On some machines, on_ac_power will incorrectly report the power state due to USB-C ports.

The current implementation of on_ac_power only checks if the USB-C port is in the connected state without checking first if any of the ports are running in sink or source mode. With this patch, on_ac_power will first make sure that there is at least a USB port operating in sink mode before considering the USB* type as a possible power supply source. If no source mode USB-C devices are found assume that there are USB-C ports in sink mode.

This implementation mimics what is already present in systemd with the systemd-ac-power command, where if a USB-C port in source mode is found, USB-C ports are ignored when determining the current power state.

The source code for the systemd implementation can be found here: https://github.com/systemd/systemd/blob/main/src/shared/battery-util.c#L12

Launchpad bug: https://bugs.launchpad.net/bugs/1980991 Debian bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1025141

Merge request reports

Loading