Check power saver when plugged in state changes

Changes in plugged in state could also change power save, but they are
notified by two separate broadcasts. In order to obtain the information
early, check the power save state if the plugged in state changes and
update it before notifying callbacks.

Before this, the tile (and statusbar icon) will briefly go through
no-power save state when going between power save and plugged in (and
back), while we waited for the second broadcast.

With this solution, there's still a small instant of INACTIVE observed
(in logs), but we go from >50ms to <1ms.

We only check power save if the plugged in state changes, to prevent
frequent calls to system_server.

Test: atest BatteryControllerTest
Test: manual, observe tile logs
Fixes: 331755756
Flag: EXEMPT BUGFIX
Change-Id: I37c4d9890f02a072b345bcb165e09fcdce8ad313
2 files changed