Skip to content

components/batterycontrol: Re-use battery names correctly

Oliver Beard requested to merge work/olib/battery-names into master

Previously, if a battery was seen twice, it would not re-use the existing name, leading to the user seeing a single battery called "Battery 2".

The code has also been re-written to be more intelligible.

Reason for the change

When, for some reason, a battery's name was updated twice, the previous name was not used.

Test plan

️ This has not been tested! I do not have the ability to test the changes myself - ideally we'd need someone with multiple removable batteries to validate the behaviour.

The original bug reporter has confirmed that these changes work for them, but that doesn't test battery removal/replug - only that previous names are now remembered.

i.e. it only tests the code path where no batteries are known (m_namedBatteries.isEmpty()), and where the same battery name is reused (m_namedBatteries.contains(deviceBattery.udi()), but not trying to use an unused index (i.e. you have batteries 1, 2 and 3, and remove battery 2 and plug a new one in - it should be known as battery 2.)

Bugs fixed

BUG: 492480

Edited by Oliver Beard

Merge request reports

Loading