util: invert ac_power() source type check
authorLennart Poettering <lennart@poettering.net>
Mon, 11 Oct 2021 08:54:31 +0000 (10:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 11 Oct 2021 09:31:52 +0000 (11:31 +0200)
commitc19a51bec40ae5e5073464e72411e7920d05d683
tree26425939b9c77aa11a8ac808ad8378091a609dec
parent6bfd44ee04515ce0a506ab88b91ca332ca35dedd
util: invert ac_power() source type check

So far we assumed every power source was a battery except for the ones
which definitely are not. I think this logic makes little sense, as
"battery" is kinda the exceptional case here, not the other way round.
Hence let's invert the type check, and denylist "Battery" devices rather
than allowlist "Mains" devices.

This should increase compatibility with alternative types of power
sources, in particular USB ones.

This takes into account that additional power types have been added
since we wrote the original code, and in particular should cover the
siutation discussed here OK:

https://sources.debian.org/src/powermgmt-base/1.36/power_supply.txt/#L31
https://sources.debian.org/src/powermgmt-base/1.36/on_ac_power/#L25

Also, modernizes the code in various was ways.

Inspired by and fixes: #20964
src/basic/util.c