Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[battery] Do not report 100% when battery level is unknown. JB#48562
Using 100% as default initial value can lead to clients seeing what
looks like genuine battery level drop during mce startup.

Use MCE_BATTERY_LEVEL_UNKNOWN (-1) - which is documented in mce-dev
headers as placeholder value used while battery level is unknown.

Adapt battery level tracking withing mce to expect and deal with
unknown/negative initial state.

To allow debugging of battery level unknown states, expand value
range allowed by mcetool --set-battery-level=<percent> to include
also -1.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Feb 4, 2020
1 parent 67ce438 commit 3e41f3d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
8 changes: 4 additions & 4 deletions datapipe.c
Expand Up @@ -3,9 +3,9 @@
* This file implements the sinmple datapipe framework;
* this can be used to filter data and to setup data triggers
* <p>
* Copyright © 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2007 - 2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2014 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
Expand Down Expand Up @@ -744,7 +744,7 @@ datapipe_t battery_status_pipe = DATAPIPE_INIT(battery_status,
datapipe_t battery_state_pipe = DATAPIPE_INIT(battery_state, battery_state, BATTERY_STATE_UNKNOWN, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);

/** Battery charge level; read only */
datapipe_t battery_level_pipe = DATAPIPE_INIT(battery_level, int, BATTERY_LEVEL_INITIAL, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
datapipe_t battery_level_pipe = DATAPIPE_INIT(battery_level, int, MCE_BATTERY_LEVEL_UNKNOWN, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);

/** Topmost window PID; read only */
datapipe_t topmost_window_pid_pipe = DATAPIPE_INIT(topmost_window_pid, int, -1, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
Expand Down
8 changes: 4 additions & 4 deletions mce-common.c
Expand Up @@ -2,8 +2,8 @@
* @file mce-common.c
* Common state logic for Mode Control Entity
* <p>
* Copyright (C) 2017-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2017 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
Expand Down Expand Up @@ -133,8 +133,8 @@ static battery_status_t battery_status = BATTERY_STATUS_UNDEF;
/** Battery state; assume unknown */
static battery_state_t battery_state = BATTERY_STATE_UNKNOWN;

/** Battery charge level: assume 100% */
static gint battery_level = BATTERY_LEVEL_INITIAL;
/** Battery charge level: assume unknown */
static gint battery_level = MCE_BATTERY_LEVEL_UNKNOWN;

/** Cached (raw) proximity sensor state */
static cover_state_t proximity_sensor_actual = COVER_UNDEF;
Expand Down
9 changes: 3 additions & 6 deletions mce.h
Expand Up @@ -2,9 +2,9 @@
* @file mce.h
* Generic headers for Mode Control Entity
* <p>
* Copyright © 2004-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2004 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Irina Bezruk <ext-irina.bezruk@nokia.com>
Expand Down Expand Up @@ -310,9 +310,6 @@ const char *tklock_request_repr(tklock_request_t state);

const char *tklock_status_repr(int status);

/** Assumed initial battery level */
#define BATTERY_LEVEL_INITIAL 100

/** Raw udev battery status */
typedef enum
{
Expand Down
8 changes: 4 additions & 4 deletions modules/battery-udev.c
Expand Up @@ -2,8 +2,8 @@
* @file battery-udev.c
* Battery module -- this implements battery and charger logic for MCE
* <p>
* Copyright (C) 2018-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2018 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
* <p>
Expand Down Expand Up @@ -296,7 +296,7 @@ G_MODULE_EXPORT module_info_struct module_info =
* sync with default values held in the relevant datapipes.
*/
static mcebat_t mcebat_datapipe = {
.battery_level = BATTERY_LEVEL_INITIAL,
.battery_level = MCE_BATTERY_LEVEL_UNKNOWN,
.battery_status = BATTERY_STATUS_UNDEF,
.battery_state = BATTERY_STATE_UNKNOWN,
.charger_state = CHARGER_STATE_UNDEF,
Expand All @@ -306,7 +306,7 @@ static mcebat_t mcebat_datapipe = {
/** Cached battery state as derived from udev
*/
static mcebat_t mcebat_actual = {
.battery_level = BATTERY_LEVEL_INITIAL,
.battery_level = MCE_BATTERY_LEVEL_UNKNOWN,
.battery_status = BATTERY_STATUS_UNDEF,
.battery_state = BATTERY_STATE_UNKNOWN,
.charger_state = CHARGER_STATE_UNDEF,
Expand Down
10 changes: 6 additions & 4 deletions modules/led.c
Expand Up @@ -2,8 +2,9 @@
* @file led.c
* LED module -- this handles the LED logic for MCE
* <p>
* Copyright © 2006-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2006 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Tapio Rantala <ext-tapio.rantala@nokia.com>
Expand Down Expand Up @@ -57,6 +58,7 @@
#include <fcntl.h>

#include <mce/dbus-names.h>
#include <mce/mode-names.h>

#include <gmodule.h>

Expand Down Expand Up @@ -2888,8 +2890,8 @@ static gboolean init_patterns(void)
/** Flag for: charger connected */
static charger_state_t charger_state = CHARGER_STATE_UNDEF;

/** Current battery percent level */
static int battery_level = 0;
/** Current battery percent level: assume unknown */
static int battery_level = MCE_BATTERY_LEVEL_UNKNOWN;

/** Setting: sw breathing allowed */
static gboolean sw_breathing_enabled = MCE_DEFAULT_LED_SW_BREATH_ENABLED;
Expand Down
16 changes: 11 additions & 5 deletions modules/powersavemode.c
Expand Up @@ -3,8 +3,9 @@
* Power saving mode module -- this handles the power saving mode
* for MCE
* <p>
* Copyright © 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2010 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2014 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Tapio Rantala <ext-tapio.rantala@nokia.com>
Expand Down Expand Up @@ -32,6 +33,7 @@
#include "../mce-dbus.h"

#include <mce/dbus-names.h>
#include <mce/mode-names.h>

#include <gmodule.h>

Expand All @@ -51,8 +53,9 @@ G_MODULE_EXPORT module_info_struct module_info = {
.priority = 250
};

/** Battery charge level */
static gint battery_level = 100;
/** Battery charge level: assume unknown == -1 */
static gint battery_level = MCE_BATTERY_LEVEL_UNKNOWN;

/** Charger state */
static charger_state_t charger_state = CHARGER_STATE_UNDEF;

Expand Down Expand Up @@ -138,9 +141,12 @@ static void update_power_saving_mode(void)
* of other settings and states. */
activate = true;
}
else if ( battery_level <= MCE_BATTERY_LEVEL_UNKNOWN ) {
/* Ignore triggers based on charger and battery
* info until battery level becomes known. */
}
else if( charger_state == CHARGER_STATE_ON ) {
/* If charger is connected, PSM should be deactivated. */
activate = false;
}
else if( force_psm ) {
/* Forced PSM is triggered when no charger is connected. */
Expand Down
12 changes: 7 additions & 5 deletions tools/mcetool.c
@@ -1,9 +1,9 @@
/** @file mcetool.c
* Tool to test and remote control the Mode Control Entity
* <p>
* Copyright © 2005-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* Copyright (c) 2005 - 2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2012 - 2020 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
Expand Down Expand Up @@ -2727,7 +2727,7 @@ static bool mcetool_do_set_charger_state(const char *arg)
static bool mcetool_do_set_battery_level(const char *arg)
{
int level = xmce_parse_integer(arg);
if( level < 0 || level > 100 ) {
if( level < -1 || level > 100 ) {
errorf("%s: invalid battery level\n", arg);
return false;
}
Expand Down Expand Up @@ -7999,7 +7999,9 @@ static const char version_text[] =
PROG_NAME" v"G_STRINGIFY(PRG_VERSION)"\n"
"Written by David Weinehall.\n"
"\n"
"Copyright (C) 2005-2011 Nokia Corporation. All rights reserved.\n"
"Copyright (c) 2005 - 2011 Nokia Corporation. All rights reserved.\n"
"Copyright (c) 2012 - 2020 Jolla Ltd.\n"
"Copyright (c) 2019 - 2020 Open Mobile Platform LLC.\n"
;

static __attribute__((__noreturn__)) bool mcetool_do_version(const char *arg)
Expand Down

0 comments on commit 3e41f3d

Please sign in to comment.