Skip to content

Commit

Permalink
[powersavemode] Do not trigger psm during mce startup. JB#43843
Browse files Browse the repository at this point in the history
Booting device / restarting mce while charger is connected can cause
power save mode to get briefly activated while charger status is not
known.

Do not activate PSM while charger status is not known.

Do not disable forced-PSM setting if charger status makes
transition from "undefined" to "on" state.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Dec 21, 2018
1 parent 03fcbea commit 48f0cb0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions modules/powersavemode.c
Expand Up @@ -139,13 +139,21 @@ static void update_power_saving_mode(void)
activate = false;
}
else if( force_psm ) {
/* Forced PSM is triggered when charger is disconnected. */
activate = true;
/* Forced PSM is triggered when no charger is connected. */
if( charger_state == CHARGER_STATE_UNDEF )
mce_log(LL_DEBUG, "charger state unknown; "
"not activating forced-psm");
else
activate = true;
}
else if( power_saving_mode && battery_level <= psm_threshold ) {
/* Normally PSM is triggered when the feature is enabled and
* battery level is not over the threshold. */
activate = true;
if( charger_state == CHARGER_STATE_UNDEF )
mce_log(LL_DEBUG, "charger state unknown; "
"not activating psm");
else
activate = true;
}

if( active_power_saving_mode != activate ) {
Expand Down Expand Up @@ -196,7 +204,12 @@ static void charger_state_trigger(gconstpointer const data)
charger_state_repr(prev),
charger_state_repr(charger_state));

if( force_psm && charger_state == CHARGER_STATE_ON ) {
/* Disable forced-psm on charger connect - but ignore
* undef -> on transitions that are expected to happen
* on mce startup. */
if( force_psm &&
prev == CHARGER_STATE_OFF &&
charger_state == CHARGER_STATE_ON ) {
mce_log(LL_DEBUG, "autodisable forced-power-save-mode");
/* Change cached value before changing the setting
* value to avoid repeated state evaluation. */
Expand Down

0 comments on commit 48f0cb0

Please sign in to comment.