[-]
[+]
|
Changed |
_service:tar_git:mce.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:mce.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -1,7 +1,7 @@
<services>
<service name="tar_git">
<param name="url">https://github.com/sailfish-on-dontbeevil/mce-1.git</param>
- <param name="branch">1.109.2+pp</param>
+ <param name="branch">1.114.1+pp</param>
<param name="revision"></param>
<param name="token"/>
<param name="debian">N</param>
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/.depend
^
|
@@ -8,6 +8,7 @@
mce-log.h\
mce-setting.h\
mce.h\
+ modules/charging.h\
modules/display.h\
modules/doubletap.h\
modules/inactivity.h\
@@ -29,6 +30,7 @@
mce-log.h\
mce-setting.h\
mce.h\
+ modules/charging.h\
modules/display.h\
modules/doubletap.h\
modules/inactivity.h\
@@ -714,6 +716,32 @@
tklock.h\
modules/camera.h\
+modules/charging.o:\
+ modules/charging.c\
+ builtin-gconf.h\
+ datapipe.h\
+ datapipe.h\
+ mce-conf.h\
+ mce-dbus.h\
+ mce-log.h\
+ mce-setting.h\
+ mce.h\
+ musl-compatibility.h\
+ modules/charging.h\
+
+modules/charging.pic.o:\
+ modules/charging.c\
+ builtin-gconf.h\
+ datapipe.h\
+ datapipe.h\
+ mce-conf.h\
+ mce-dbus.h\
+ mce-log.h\
+ mce-setting.h\
+ mce.h\
+ musl-compatibility.h\
+ modules/charging.h\
+
modules/cpu-keepalive.o:\
modules/cpu-keepalive.c\
builtin-gconf.h\
@@ -1512,6 +1540,7 @@
mce-dbus.h\
mce-setting.h\
mce.h\
+ modules/charging.h\
modules/display.h\
modules/doubletap.h\
modules/inactivity.h\
@@ -1535,6 +1564,7 @@
mce-dbus.h\
mce-setting.h\
mce.h\
+ modules/charging.h\
modules/display.h\
modules/doubletap.h\
modules/inactivity.h\
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/Makefile
^
|
@@ -57,7 +57,7 @@
# CONFIGURATION
# ----------------------------------------------------------------------------
-VERSION := 1.109.2
+VERSION := 1.114.1
INSTALL_BIN := install --mode=755
INSTALL_DIR := install -d
@@ -156,6 +156,7 @@
MODULES += $(MODULE_DIR)/keypad.so
MODULES += $(MODULE_DIR)/inactivity.so
MODULES += $(MODULE_DIR)/camera.so
+MODULES += $(MODULE_DIR)/charging.so
MODULES += $(MODULE_DIR)/alarm.so
MODULES += $(MODULE_DIR)/memnotify.so
MODULES += $(MODULE_DIR)/mempressure.so
@@ -625,6 +626,8 @@
modules/callstate.c\
modules/callstate.h\
modules/camera.h\
+ modules/charging.c\
+ modules/charging.h\
modules/cpu-keepalive.c\
modules/display.c\
modules/display.h\
@@ -726,7 +729,7 @@
%.q : %.c ; $(CC) -o $@ -E $< $(PROTO_CPPFLAGS)
%.p : %.q ; cproto -s < $< | prettyproto.py | tee $@
-%.g : %.q ; cproto < $< | prettyproto.py | tee $@
+%.g : %.q ; cproto < $< | prettyproto.py -xg_module | tee $@
protos-q: $(patsubst %.c,%.q,$(wildcard *.c modules/*.c))
protos-p: $(patsubst %.c,%.p,$(wildcard *.c modules/*.c))
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/builtin-gconf.c
^
|
@@ -2,7 +2,7 @@
* @file builtin-gconf.c
* GConf compatibility module - for dynamic mce settings
* <p>
- * Copyright (C) 2012-2019 Jolla Ltd.
+ * Copyright (c) 2012 - 2022 Jolla Ltd.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
@@ -49,6 +49,7 @@
#include "modules/doubletap.h"
#include "modules/led.h"
#include "modules/inactivity.h"
+#include "modules/charging.h"
#include <stdlib.h>
#include <string.h>
@@ -1958,6 +1959,21 @@
.def = G_STRINGIFY(MCE_DEFAULT_BUTTONBACKLIGHT_OFF_DELAY),
},
{
+ .key = MCE_SETTING_CHARGING_MODE,
+ .type = "i",
+ .def = G_STRINGIFY(MCE_DEFAULT_CHARGING_MODE),
+ },
+ {
+ .key = MCE_SETTING_CHARGING_LIMIT_DISABLE,
+ .type = "i",
+ .def = G_STRINGIFY(MCE_DEFAULT_CHARGING_LIMIT_DISABLE),
+ },
+ {
+ .key = MCE_SETTING_CHARGING_LIMIT_ENABLE,
+ .type = "i",
+ .def = G_STRINGIFY(MCE_DEFAULT_CHARGING_LIMIT_ENABLE),
+ },
+ {
.key = NULL,
}
};
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/debian/changelog
^
|
@@ -1,3 +1,48 @@
+mce (1.114.1) precise; urgency=low
+
+ * [charging] Use literal number for charging enable limit. Fixes JB#59821
+
+ -- Simo Piiroinen <simo.piiroinen@jolla.com> Tue, 17 Jan 2023 09:14:59 +0200
+
+mce (1.114.0) precise; urgency=low
+
+ * [battery-udev] Optionally track also extcon devices. JB#59448
+
+ -- Simo Piiroinen <simo.piiroinen@jolla.com> Thu, 01 Dec 2022 08:59:36 +0200
+
+mce (1.113.0) precise; urgency=low
+
+ * [charging] Expose charging suspendable on D-Bus. JB#59152
+
+ -- Simo Piiroinen <simo.piiroinen@jolla.com> Tue, 22 Nov 2022 14:32:19 +0200
+
+mce (1.112.0) precise; urgency=low
+
+ * [battery-udev] Simulated battery differentiates between 100% and full
+ * [charging] Refactor setting charging limits
+ * [charging] Align default charging hysteresis with settings. JB#58372
+ * [charging] Add charge-once-to-full override. JB#58372
+
+ -- Simo Piiroinen <simo.piiroinen@jolla.com> Tue, 18 Oct 2022 11:08:21 +0300
+
+mce (1.111.1) precise; urgency=low
+
+ * [charging] Broadcast charging control state changes. JB#58812
+
+ -- Simo Piiroinen <simo.piiroinen@jolla.com> Tue, 11 Oct 2022 09:26:36 +0300
+
+mce (1.111.0) precise; urgency=low
+
+ * [charging] Auto-detect charging hysteresis controls. Fixes JB#57297
+
+ -- Simo Piiroinen <simo.piiroinen@jolla.com> Fri, 11 Mar 2022 09:12:52 +0200
+
+mce (1.110.0) precise; urgency=low
+
+ * [charging] Configurable charging hysteresis. Fixes JB#40062
+
+ -- Simo Piiroinen <simo.piiroinen@jolla.com> Tue, 22 Feb 2022 04:33:54 +0200
+
mce (1.109.2) precise; urgency=low
* [audiorouting] Add audio routing mapping for "bthfp" sink device
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/depend_filter.py
^
|
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- encoding: utf8 -*-
# ----------------------------------------------------------------------------
@@ -13,7 +13,7 @@
return not path.startswith("/")
def print_rule(dest, srce):
- print "%s\\\n" % "\\\n\t".join(["%s:" % dest] + srce)
+ print("%s\\\n" % "\\\n\t".join(["%s:" % dest] + srce))
def set_extension(path, ext):
return os.path.splitext(path)[0] + ext
@@ -29,7 +29,7 @@
if __name__ == "__main__":
data = sys.stdin.readlines()
- data = map(lambda x:x.rstrip(), data)
+ data = list(map(lambda x:x.rstrip(), data))
data.reverse()
deps = []
@@ -52,13 +52,13 @@
dest = fix_directory(dest, srce)
# remove secondary deps with absolute path
- temp = filter(is_local, temp)
+ temp = list(filter(is_local, temp))
# sort secondary sources
temp.sort()
srce = [srce] + temp
- srce = map(normalize_path, srce)
+ srce = list(map(normalize_path, srce))
deps.append((dest,srce))
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/inifiles/battery-udev-settings.ini
^
|
@@ -27,6 +27,21 @@
#
# RefreshOnNotify = false
+# For similar purposes mce can be instructed to track
+# USB state changes reported by extcon subsystem devices.
+#
+# On its own this is not overtly costly, but chances
+# are that when it is needed, also RefreshOnNotify=true
+# should be used.
+#
+# To enable:
+#
+# RefreshOnExtcon = true
+#
+# Default is:
+#
+# RefreshOnExtcon = false
+
# Many/most of devices do not send udev notifications
# on every battery capacity percent change. Most of the
# times this is harmless. However it can also cause
|
[-]
[+]
|
Added |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/inifiles/charging.ini
^
|
@@ -0,0 +1,34 @@
+# Configuration file for MCE - charging hysteresis control -*- mode: sh -*-
+#
+# Provided that battery kernel driver supports such operation,
+# mce can be instructed for example to cease charging when battery
+# level reaches 90% and restart charging when battery level drops
+# below 50%.
+#
+# While mce side state logic and settings are generic, how charging
+# is actually enabled/disabled can vary from one device type to
+# another depending on hw and related kernel drivers.
+
+[Charging]
+
+# Devices with kernels that utilize
+# - POWER_SUPPLY_PROP_CHARGING_ENABLED
+# - POWER_SUPPLY_PROP_INPUT_SUSPEND
+# are detected automatically and do not need to be configured.
+#
+# If configuration data is present, it takes precedence over
+# autodetect logic.
+
+# Devices where kernel utilizes POWER_SUPPLY_PROP_CHARGING_ENABLED
+# For example: f5121 (Xperia X), l500d (Jolla C)
+
+#ControlPath = /sys/class/power_supply/battery/charging_enabled
+#EnableValue = 1
+#DisableValue = 0
+
+# Devices where kernel utilizes POWER_SUPPLY_PROP_INPUT_SUSPEND
+# For example: h3113 (Xperia XA2), i4113 (Xperia 10)
+
+#ControlPath = /sys/class/power_supply/battery/input_suspend
+#EnableValue = 0
+#DisableValue = 1
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/inifiles/mce.ini
^
|
@@ -16,7 +16,7 @@
# to avoid unnecessary brightness fluctuations on mce startup
#
# Note: the name should not include the "lib"-prefix
-Modules=radiostates;filter-brightness-als;display;keypad;led;battery-udev;inactivity;alarm;callstate;audiorouting;proximity;powersavemode;cpu-keepalive;doubletap;packagekit;sensor-gestures;bluetooth;memnotify;mempressure;usbmode;buttonbacklight;fingerprint;
+Modules=radiostates;filter-brightness-als;display;keypad;led;battery-udev;inactivity;alarm;callstate;audiorouting;proximity;powersavemode;cpu-keepalive;doubletap;packagekit;sensor-gestures;bluetooth;memnotify;mempressure;usbmode;buttonbacklight;fingerprint;charging;
[KeyPad]
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/mce.conf
^
|
@@ -234,6 +234,19 @@
<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
send_member="get_charger_type"/>
+ <allow send_destination="com.nokia.mce"
+ send_interface="com.nokia.mce.request"
+ send_member="get_charging_state"/>
+ <allow send_destination="com.nokia.mce"
+ send_interface="com.nokia.mce.request"
+ send_member="get_charging_suspendable"/>
+
+ <allow send_destination="com.nokia.mce"
+ send_interface="com.nokia.mce.request"
+ send_member="get_forced_charging"/>
+ <allow send_destination="com.nokia.mce"
+ send_interface="com.nokia.mce.request"
+ send_member="req_forced_charging"/>
<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/modules/battery-udev.c
^
|
@@ -2,7 +2,7 @@
* @file battery-udev.c
* Battery module -- this implements battery and charger logic for MCE
* <p>
- * Copyright (c) 2018 - 2020 Jolla Ltd.
+ * Copyright (c) 2018 - 2022 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
@@ -82,6 +82,10 @@
#define MCE_CONF_BATTERY_UDEV_REFRESH_ON_NOTIFY "RefreshOnNotify"
#define DEFAULT_BATTERY_UDEV_REFRESH_ON_NOTIFY false
+/** Setting for forced refresh on USB state udev notify from extcon devices */
+#define MCE_CONF_BATTERY_UDEV_REFRESH_ON_EXTCON "RefreshOnExtcon"
+#define DEFAULT_BATTERY_UDEV_REFRESH_ON_EXTCON false
+
/** Setting for forced refresh on system heartbeat */
#define MCE_CONF_BATTERY_UDEV_REFRESH_ON_HEARTBEAT "RefreshOnHeartbeat"
#define DEFAULT_BATTERY_UDEV_REFRESH_ON_HEARTBEAT true
@@ -296,6 +300,17 @@
static void udevdevice_evaluate_battery_cb (gpointer key, gpointer value, gpointer aptr);
/* ------------------------------------------------------------------------- *
+ * UDEVEXTCON
+ * ------------------------------------------------------------------------- */
+
+static gchar *udevextcon_parse_usb_state(const char *state);
+static bool udevextcon_update_state (const char *syspath, const char *state);
+static void udevextcon_initialize_from(struct udev_device *dev);
+static bool udevextcon_update_from (struct udev_device *dev);
+static void udevextcon_init (void);
+static void udevextcon_quit (void);
+
+/* ------------------------------------------------------------------------- *
* UDEVTRACKER
* ------------------------------------------------------------------------- */
@@ -430,6 +445,9 @@
/** Cached MCE_CONF_BATTERY_UDEV_REFRESH_ON_NOTIFY value */
static bool mcebat_refresh_on_notify = DEFAULT_BATTERY_UDEV_REFRESH_ON_NOTIFY;
+/** Cached MCE_CONF_BATTERY_UDEV_REFRESH_ON_EXTCON value */
+static bool mcebat_refresh_on_extcon = DEFAULT_BATTERY_UDEV_REFRESH_ON_EXTCON;
+
/** Cached MCE_CONF_BATTERY_UDEV_REFRESH_ON_HEARTBEAT value */
static bool mcebat_refresh_on_heartbeat = DEFAULT_BATTERY_UDEV_REFRESH_ON_HEARTBEAT;
@@ -541,8 +559,9 @@
if( mcebat_simulated.charger_state == CHARGER_STATE_ON ) {
mcebat_simulated.battery_state = BATTERY_STATE_CHARGING;
- if( mcebat_simulated.battery_level >= 100 ) {
+ if( mcebat_simulated.battery_level > 100 ) {
/* Battery full reached */
+ mcebat_simulated.battery_level = 100;
mcebat_simulated.battery_status = BATTERY_STATUS_FULL;
mcebat_simulated.battery_state = BATTERY_STATE_FULL;
goto EXIT;
@@ -1776,6 +1795,131 @@
}
/* ========================================================================= *
+ * UDEVEXTCON
+ * ========================================================================= */
+
+/** Subsystem name for extcon devices */
+static const char udevextcon_subsystem[] = "extcon";
+
+/** USB state cache for extcon devices */
+static GHashTable *udevextcon_usb_state_lut = NULL;
+
+/** Parse USB entry from extcon state information
+ *
+ * When non-null value is returned, caller must release it with g_free().
+ *
+ * @param state Full state data for extcon device
+ *
+ * @return value for USB entry, or NULL
+ */
+static gchar *
+udevextcon_parse_usb_state(const char *state)
+{
+ gchar *res = NULL;
+ gchar *tmp = NULL;
+
+ if( (tmp = g_strdup(state)) ) {
+ for( char *pos = tmp; *pos; ) {
+ char *val = mce_slice_token(pos, &pos, NULL);
+ char *key = mce_slice_token(val, &val, "=");
+ if( !strcmp(key, "USB") ) {
+ res = g_strdup(val);
+ break;
+ }
+ }
+ g_free(tmp);
+ }
+
+ return res;
+}
+
+/** Update cached USB state for an extcon device
+ *
+ * @param syspath syspath for device to update
+ * @param state state reported for the device
+ *
+ * @return true if cached value changed, false otherwise
+ */
+static bool
+udevextcon_update_state(const char *syspath, const char *state)
+{
+ bool changed = false;
+ gchar *usb_state = NULL;
+ const gchar *old_state = NULL;
+
+ if( !syspath || !udevextcon_usb_state_lut )
+ goto EXIT;
+
+ usb_state = udevextcon_parse_usb_state(state);
+ old_state = g_hash_table_lookup(udevextcon_usb_state_lut, syspath);
+ if( g_strcmp0(old_state, usb_state) ) {
+ mce_log(LL_DEBUG, "%s.STATE / USB: %s -> %s",
+ basename(syspath), old_state ?: "null", usb_state ?: "null");
+ if( usb_state )
+ g_hash_table_replace(udevextcon_usb_state_lut, g_strdup(syspath),
+ usb_state), usb_state = NULL;
+ else
+ g_hash_table_remove(udevextcon_usb_state_lut, syspath);
+ changed = true;
+ }
+
+EXIT:
+ g_free(usb_state);
+
+ return changed;
+}
+
+/** Initialize cached USB state for an extcon device
+ *
+ * @param device device to initialize from
+ */
+static void
+udevextcon_initialize_from(struct udev_device *dev)
+{
+ const char *syspath = udev_device_get_syspath(dev);
+ const char *state = udev_device_get_sysattr_value(dev, "state");
+ udevextcon_update_state(syspath, state);
+}
+
+/** Update cached USB state for an extcon device
+ *
+ * @param device device to update from
+ *
+ * @return true if cached value changed, false otherwise
+ */
+static bool
+udevextcon_update_from(struct udev_device *dev)
+{
+ const char *syspath = udev_device_get_syspath(dev);
+ const char *state = udev_device_get_property_value(dev, "STATE");
+ return udevextcon_update_state(syspath, state);
+}
+
+/** Initialize USB state cache for extcon devices
+ */
+static void
+udevextcon_init(void)
+{
+ if( mcebat_refresh_on_extcon && !udevextcon_usb_state_lut ) {
+ udevextcon_usb_state_lut = g_hash_table_new_full(g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
+ }
+}
+
+/** Release USB state cache for extcon devices
+ */
+static void
+udevextcon_quit(void)
+{
+ if( udevextcon_usb_state_lut ) {
+ g_hash_table_unref(udevextcon_usb_state_lut),
+ udevextcon_usb_state_lut = NULL;
+ }
+}
+
+/* ========================================================================= *
* UDEVTRACKER
* ========================================================================= */
@@ -1970,6 +2114,8 @@
mce_log(LL_DEBUG, "ENTER - get initial state");
udev_enum = udev_enumerate_new(self->udt_udev_handle);
udev_enumerate_add_match_subsystem(udev_enum, udevtracker_subsystem);
+ if( mcebat_refresh_on_extcon )
+ udev_enumerate_add_match_subsystem(udev_enum, udevextcon_subsystem);
udev_enumerate_scan_devices(udev_enum);
for( struct udev_list_entry *iter =
|
[-]
[+]
|
Added |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/modules/charging.c
^
|
@@ -0,0 +1,1293 @@
+/**
+ * @file charging.c
+ *
+ * Charging -- this module handles user space charger enable/disable
+ * <p>
+ * Copyright (c) 2017 - 2022 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jolla.com>
+ *
+ * mce is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * mce is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mce. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "charging.h"
+
+#include "../mce.h"
+#include "../mce-conf.h"
+#include "../mce-log.h"
+#include "../datapipe.h"
+#include "../mce-setting.h"
+#include "../mce-dbus.h"
+
+#include <mce/dbus-names.h>
+#include <mce/mode-names.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include <gmodule.h>
+
+/* ========================================================================= *
+ * TYPES & CONSTANTS
+ * ========================================================================= */
+
+/** Module name */
+#define MODULE_NAME "charging"
+
+/** Minimum battery level where charging can be disabled [%]
+ *
+ * Having charger connected but not charging from it can delay (USER mode)
+ * or inhibit (ACTDEAD mode) battery empty shutdown -> allow charging when
+ * battery level is approaching battery empty shutdown level - regardless
+ * of possible user configured limits.
+ */
+#define MCH_MINIMUM_BATTERY_LEVEL 5
+
+/* ========================================================================= *
+ * Types
+ * ========================================================================= */
+
+/** Charging mode override */
+typedef enum {
+ /** Transient / placeholder value */
+ FORCED_CHARGING_UNKNOWN,
+ /** Charging mode is ignored and battery is charged until full */
+ FORCED_CHARGING_ENABLED,
+ /** Battery is charged according to charging mode settings */
+ FORCED_CHARGING_DISABLED,
+} forced_charging_t;
+
+/* ========================================================================= *
+ * Prototypes
+ * ========================================================================= */
+
+/* ------------------------------------------------------------------------- *
+ * FORCED_CHARGING
+ * ------------------------------------------------------------------------- */
+
+const char *forced_charging_repr (forced_charging_t value);
+forced_charging_t forced_charging_parse(const char *repr);
+
+/* ------------------------------------------------------------------------- *
+ * CHARGING_MODE
+ * ------------------------------------------------------------------------- */
+
+static const char *charging_mode_repr(charging_mode_t mode);
+
+/* ------------------------------------------------------------------------- *
+ * CHARGING_STATE
+ * ------------------------------------------------------------------------- */
+
+static const char *charging_state_repr(charging_state_t state);
+
+/* ------------------------------------------------------------------------- *
+ * UTILITY
+ * ------------------------------------------------------------------------- */
+
+static int mch_clamp(int value, int minval, int maxval);
+
+/* ------------------------------------------------------------------------- *
+ * MCH_SYSFS
+ * ------------------------------------------------------------------------- */
+
+static bool mch_sysfs_write(const char *path, const char *text);
+
+/* ------------------------------------------------------------------------- *
+ * MCH_POLICY
+ * ------------------------------------------------------------------------- */
+
+static void mch_policy_set_battery_full (bool battery_full);
+static void mch_policy_set_charging_state (charging_state_t charging_state);
+static void mch_policy_evaluate_charging_state(void);
+static void mch_policy_set_charging_mode (charging_mode_t charging_mode);
+static void mch_policy_set_limit_disable (int limit_disable);
+static void mch_policy_set_limit_enable (int limit_enable);
+static void mch_policy_set_forced_charging_ex (forced_charging_t forced_charging, bool evaluate_state);
+static void mch_policy_set_forced_charging (forced_charging_t forced_charging);
+
+/* ------------------------------------------------------------------------- *
+ * MCH_SETTINGS
+ * ------------------------------------------------------------------------- */
+
+static void mch_settings_cb (GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
+static void mch_settings_init(void);
+static void mch_settings_quit(void);
+
+/* ------------------------------------------------------------------------- *
+ * MCH_CONFIG
+ * ------------------------------------------------------------------------- */
+
+static void mch_config_init(void);
+static void mch_config_quit(void);
+
+/* ------------------------------------------------------------------------- *
+ * MCH_DATAPIPE
+ * ------------------------------------------------------------------------- */
+
+static void mch_datapipe_usb_cable_state_cb(gconstpointer data);
+static void mch_datapipe_charger_state_cb (gconstpointer data);
+static void mch_datapipe_battery_status_cb (gconstpointer data);
+static void mch_datapipe_battery_level_cb (gconstpointer data);
+static void mch_datapipe_init (void);
+static void mch_datapipe_quit (void);
+
+/* ------------------------------------------------------------------------- *
+ * MCH_DBUS
+ * ------------------------------------------------------------------------- */
+
+static void mch_dbus_send_charging_state (DBusMessage *const req);
+static gboolean mch_dbus_get_charging_state_cb (DBusMessage *const req);
+static void mch_dbus_send_forced_charging_state (DBusMessage *const req);
+static gboolean mch_dbus_get_forced_charging_state_cb(DBusMessage *const req);
+static gboolean mch_dbus_set_forced_charging_state_cb(DBusMessage *const req);
+static gboolean mch_dbus_get_charging_suspendable_cb (DBusMessage *const req);
+static gboolean mch_dbus_initial_cb (gpointer aptr);
+static void mch_dbus_init (void);
+static void mch_dbus_quit (void);
+
+/* ------------------------------------------------------------------------- *
+ * G_MODULE
+ * ------------------------------------------------------------------------- */
+
+const gchar *g_module_check_init(GModule *module);
+void g_module_unload (GModule *module);
+
+/* ========================================================================= *
+ * DATA
+ * ========================================================================= */
+
+/** Functionality provided by this module */
+static const gchar *const provides[] = { MODULE_NAME, NULL };
+
+/** Functionality that this module depends on */
+static const gchar *const depends[] = { NULL };
+
+/** Functionality that this module recommends */
+static const gchar *const recommends[] = { NULL };
+
+/** Module information */
+G_MODULE_EXPORT module_info_struct module_info = {
+ /** Name of the module */
+ .name = MODULE_NAME,
+ /** Module dependencies */
+ .depends = depends,
+ /** Module recommends */
+ .recommends = recommends,
+ /** Module provides */
+ .provides = provides,
+ /** Module priority */
+ .priority = 250
+};
+
+/** USB cable status; assume undefined */
+static usb_cable_state_t usb_cable_state = USB_CABLE_UNDEF;
+
+/** Charger state; assume undefined */
|
[-]
[+]
|
Added |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/modules/charging.h
^
|
@@ -0,0 +1,101 @@
+/**
+ * @file charging.h
+ *
+ * Charging -- this module handles user space charger enable/disable
+ * <p>
+ * Copyright (c) 2017 - 2022 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jolla.com>
+ *
+ * mce is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * mce is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mce. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CHARGING_H_
+# define CHARGING_H_
+
+/* ========================================================================= *
+ * Static configuration
+ * ========================================================================= */
+
+/** Group for charging configuration keys */
+# define MCE_CONF_CHARGING_GROUP "Charging"
+
+/** Control file where to write */
+# define MCE_CONF_CHARGING_CONTROL_PATH "ControlPath"
+# define DEFAULT_CHARGING_CONTROL_PATH NULL
+
+/* Value to write when enabling */
+# define MCE_CONF_CHARGING_ENABLE_VALUE "EnableValue"
+# define DEFAULT_CHARGING_ENABLE_VALUE "1"
+
+/* Value to write when disabling */
+# define MCE_CONF_CHARGING_DISABLE_VALUE "DisableValue"
+# define DEFAULT_CHARGING_DISABLE_VALUE "0"
+
+/* ========================================================================= *
+ * Dynamic settings
+ * ========================================================================= */
+
+/** Prefix for charging setting keys */
+# define MCE_SETTING_CHARGING_PATH "/system/osso/dsm/charging"
+
+/** Charging disable/enable mode */
+# define MCE_SETTING_CHARGING_MODE MCE_SETTING_CHARGING_PATH "/charging_mode"
+# define MCE_DEFAULT_CHARGING_MODE 1 // = CHARGING_MODE_ENABLE
+
+/** Battery level at which to disable charging
+ *
+ * The value is dictated by hardcoded expectations in settings ui.
+ */
+# define MCE_SETTING_CHARGING_LIMIT_DISABLE MCE_SETTING_CHARGING_PATH "/limit_disable"
+# define MCE_DEFAULT_CHARGING_LIMIT_DISABLE 90
+
+/** Battery level at which to enable charging
+ *
+ * The value is dictated by hardcoded expectations in settings ui.
+ */
+# define MCE_SETTING_CHARGING_LIMIT_ENABLE MCE_SETTING_CHARGING_PATH "/limit_enable"
+# define MCE_DEFAULT_CHARGING_LIMIT_ENABLE 87 // = MCE_DEFAULT_CHARGING_LIMIT_DISABLE - 3
+
+/* ========================================================================= *
+ * Types
+ * ========================================================================= */
+
+typedef enum
+{
+ /* Keep charger disabled */
+ CHARGING_MODE_DISABLE,
+
+ /* Keep charger enabled (default behavior) */
+ CHARGING_MODE_ENABLE,
+
+ /* Apply thresholds without waiting for battery full */
+ CHARGING_MODE_APPLY_THRESHOLDS,
+
+ /* Apply thresholds after battery full is reached */
+ CHARGING_MODE_APPLY_THRESHOLDS_AFTER_FULL,
+} charging_mode_t;
+
+typedef enum
+{
+ /** Battery should not be charged */
+ CHARGING_STATE_DISABLED,
+
+ /** Charging logic decides whether to charge or not */
+ CHARGING_STATE_ENABLED,
+
+ /** Placeholder values used during initialization */
+ CHARGING_STATE_UNKNOWN,
+} charging_state_t;
+
+#endif /* CHARGING_H_ */
|
[-]
[+]
|
Changed |
_service:tar_git:mce-1.114.1+pp1.tar.bz2/tools/mcetool.c
^
|
@@ -2,7 +2,7 @@
* Tool to test and remote control the Mode Control Entity
* <p>
* Copyright (c) 2005 - 2011 Nokia Corporation and/or its subsidiary(-ies).
- * Copyright (c) 2012 - 2020 Jolla Ltd.
+ * Copyright (c) 2012 - 2022 Jolla Ltd.
* Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
@@ -40,6 +40,7 @@
#include "../modules/proximity.h"
#include "../modules/memnotify.h"
#include "../modules/led.h"
+#include "../modules/charging.h"
#include "../systemui/dbus-names.h"
#include "../systemui/tklock-dbus-names.h"
@@ -137,6 +138,7 @@
static unsigned xmce_parse_radio_states (const char *args);
static gboolean xmce_parse_enabled (const char *args);
static int xmce_parse_integer (const char *args);
+static int xmce_parse_memory_limit (const char *args);
static double xmce_parse_double (const char *args);
static bool xmce_set_verbosity (const char *arg);
static void xmce_get_verbosity (void);
@@ -153,6 +155,14 @@
static void xmce_get_battery_status (void);
static void xmce_get_battery_state (void);
static void xmce_get_battery_level (void);
+static bool xmce_set_charging_enable_limit (const char *args);
+static void xmce_get_charging_enable_limit (void);
+static bool xmce_set_charging_disable_limit (const char *args);
+static void xmce_get_charging_disable_limit (void);
+static bool xmce_set_charging_mode (const char *args);
+static void xmce_get_charging_mode (void);
+static bool xmce_set_forced_charging_mode (const char *args);
+static void xmce_get_forced_charging_mode (void);
static void xmce_get_battery_info (void);
static void xmce_parse_notification_args (const char *args, char **title, dbus_int32_t *delay, dbus_int32_t *renew);
static bool xmce_notification_begin (const char *args);
@@ -2038,6 +2048,8 @@
{
{ "enabled", TRUE },
{ "disabled", FALSE },
+ { "enable", TRUE },
+ { "disable", FALSE },
{ 0, -1 }
};
@@ -2772,9 +2784,13 @@
static bool mcetool_do_set_battery_level(const char *arg)
{
int level = xmce_parse_integer(arg);
- if( level < -1 || level > 100 ) {
- errorf("%s: invalid battery level\n", arg);
- return false;
+ if( level < 0 ) {
+ /* Battery simulation takes this as: unknown */
+ level = -1;
+ }
+ else if( level > 100 ) {
+ /* Battery simulation takes this as: 100% + Full */
+ level = 101;
}
return xmce_set_battery_level(level);
}
@@ -2819,6 +2835,108 @@
printf("%-"PAD1"s %d\n","Battery level:", num);
}
+static bool xmce_set_charging_enable_limit(const char *args)
+{
+ int val = xmce_parse_integer(args);
+ if( val < 0 || val > 100 ) {
+ errorf("%d: invalid battery limit value\n", val);
+ exit(EXIT_FAILURE);
+ }
+ xmce_setting_set_int(MCE_SETTING_CHARGING_LIMIT_ENABLE, val);
+ return true;
+}
+
+static void xmce_get_charging_enable_limit(void)
+{
+ gint val = 0;
+ char txt[32];
+ strcpy(txt, "unknown");
+ if( xmce_setting_get_int(MCE_SETTING_CHARGING_LIMIT_ENABLE, &val) )
+ snprintf(txt, sizeof txt, "%d", (int)val);
+ printf("%-"PAD1"s %s (%%)\n", "Charging enable limit:", txt);
+}
+
+static bool xmce_set_charging_disable_limit(const char *args)
+{
+ int val = xmce_parse_integer(args);
+ if( val < 0 || val > 100 ) {
+ errorf("%d: invalid battery limit value\n", val);
+ exit(EXIT_FAILURE);
+ }
+ xmce_setting_set_int(MCE_SETTING_CHARGING_LIMIT_DISABLE, val);
+ return true;
+}
+
+static void xmce_get_charging_disable_limit(void)
+{
+ gint val = 0;
+ char txt[32];
+ strcpy(txt, "unknown");
+ if( xmce_setting_get_int(MCE_SETTING_CHARGING_LIMIT_DISABLE, &val) )
+ snprintf(txt, sizeof txt, "%d", (int)val);
+ printf("%-"PAD1"s %s (%%)\n", "Charging disable limit:", txt);
+}
+
+/** Lookuptable for enable/disable mode values */
+static const symbol_t charging_mode_lut[] =
+{
+ { "disable", CHARGING_MODE_DISABLE },
+ { "enable", CHARGING_MODE_ENABLE },
+ { "apply-thresholds", CHARGING_MODE_APPLY_THRESHOLDS },
+ { "apply-thresholds-after-full", CHARGING_MODE_APPLY_THRESHOLDS_AFTER_FULL },
+ { 0, -1 }
+};
+
+static bool xmce_set_charging_mode(const char *args)
+{
+ debugf("%s(%s)\n", __FUNCTION__, args);
+ int val = lookup(charging_mode_lut, args);
+ if( val == -1 ) {
+ errorf("%s: invalid charging mode\n", args);
+ exit(EXIT_FAILURE);
+ }
+ xmce_setting_set_int(MCE_SETTING_CHARGING_MODE, val);
+ return true;
+}
+
+static void xmce_get_charging_mode(void)
+{
+ gint val = 0;
+ const char *txt = 0;
+ if( xmce_setting_get_int(MCE_SETTING_CHARGING_MODE, &val) )
+ txt = rlookup(charging_mode_lut, val);
+ printf("%-"PAD1"s %s\n", "Charging mode:", txt ?: "unknown");
+}
+
+static bool xmce_set_forced_charging_mode(const char *args)
+{
+ static const char * const lut[] = {
+ MCE_FORCED_CHARGING_ENABLED,
+ MCE_FORCED_CHARGING_DISABLED,
+ NULL
+ };
+ for( size_t i = 0; ; ++i ) {
+ if( lut[i] == NULL ) {
+ errorf("%s: invalid charging override value\n", args);
+ exit(EXIT_FAILURE);
+ }
+ if( !strcmp(lut[i], args) )
+ break;
+ }
+ xmce_ipc_no_reply(MCE_FORCED_CHARGING_REQ,
+ DBUS_TYPE_STRING, &args,
+ DBUS_TYPE_INVALID);
+ return true;
+}
+
+static void xmce_get_forced_charging_mode(void)
+{
+ char *str = 0;
+ xmce_ipc_string_reply(MCE_FORCED_CHARGING_GET, &str, DBUS_TYPE_INVALID);
+ printf("%-"PAD1"s %s\n","Charging override:", str ?: "unknown");
+ free(str);
+}
+
static void xmce_get_battery_info(void)
{
xmce_get_cable_state();
@@ -2826,6 +2944,10 @@
xmce_get_battery_level();
xmce_get_battery_status();
xmce_get_battery_state();
+ xmce_get_charging_mode();
+ xmce_get_forced_charging_mode();
+ xmce_get_charging_enable_limit();
+ xmce_get_charging_disable_limit();
}
/* ------------------------------------------------------------------------- *
@@ -7989,6 +8111,7 @@
.name = "set-inactivity-shutdown-delay",
.with_arg = xmce_set_inactivity_shutdown_delay,
.values = "s",
+ .usage =
"set delay in seconds for automatic shutdown\n"
"\n"
"If the device is not in active use it will be\n"
@@ -8034,8 +8157,64 @@
.values = "percent",
.usage =
"Override battery level for debugging purposes\n"
+ "\n"
+ "values < 0 signify: unknown level\n"
|