Commit 3e41f3d2 authored by spiiroin's avatar spiiroin

[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: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 67ce4384
......@@ -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>
......@@ -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);
......
......@@ -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>
*
......@@ -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;
......
......@@ -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>
......@@ -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
{
......
......@@ -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>
......@@ -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,
......@@ -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,
......
......@@ -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>
......@@ -57,6 +58,7 @@
#include <fcntl.h>
#include <mce/dbus-names.h>
#include <mce/mode-names.h>
#include <gmodule.h>
......@@ -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;
......
......@@ -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>
......@@ -32,6 +33,7 @@
#include "../mce-dbus.h"
#include <mce/dbus-names.h>
#include <mce/mode-names.h>
#include <gmodule.h>
......@@ -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;
......@@ -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. */
......
/** @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>
......@@ -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;
}
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment