Commit a80fd7ea authored by spiiroin's avatar spiiroin

[battery-udev] Make charger type available on D-Bus. JB#38667

Battery notifier in lipstick needs charger type information.

Add charger type evaluation to udev power supply device tracker and
broadcast changes internally within mce via a datapipe.

Reflect datapipe changes as D-Bus signals, and add D-Bus methods for
querying the current state.

For development builds enable charger type simulation and appropriate
mcetool options for controlling it.

The required D-Bus constants are available in mce-dev >= 1.27.0.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent def606b6
......@@ -1344,6 +1344,16 @@ tklock.pic.o:\
systemui/tklock-dbus-names.h\
tklock.h\
tools/dummy_compositor.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\
tools/dummy_compositor.pic.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\
tools/evdev_trace.o:\
tools/evdev_trace.c\
evdev.h\
......@@ -1356,16 +1366,6 @@ tools/evdev_trace.pic.o:\
mce-log.h\
tools/fileusers.h\
tools/dummy_compositor.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\
tools/dummy_compositor.pic.o:\
tools/dummy_compositor.c\
builtin-gconf.h\
mce-dbus.h\
tools/fileusers.o:\
tools/fileusers.c\
mce-log.h\
......
......@@ -5,6 +5,7 @@
* <p>
* Copyright © 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
......@@ -113,6 +114,7 @@ static const char *datapipe_hook_call_state_value (gconstpointer data);
static const char *datapipe_hook_call_type_value (gconstpointer data);
static const char *datapipe_hook_tklock_request_value (gconstpointer data);
static const char *datapipe_hook_charger_state_value (gconstpointer data);
static const char *datapipe_hook_charger_type_value (gconstpointer data);
static const char *datapipe_hook_battery_status_value (gconstpointer data);
static const char *datapipe_hook_camera_button_state_value(gconstpointer data);
static const char *datapipe_hook_audio_route_value (gconstpointer data);
......@@ -202,6 +204,13 @@ const char *service_state_repr(service_state_t state);
const char *usb_cable_state_repr (usb_cable_state_t state);
const char *usb_cable_state_to_dbus(usb_cable_state_t state);
/* ------------------------------------------------------------------------- *
* CHARGER_TYPE
* ------------------------------------------------------------------------- */
const char *charger_type_repr (charger_type_t type);
const char *charger_type_to_dbus(charger_type_t type);
/* ------------------------------------------------------------------------- *
* CHARGER_STATE
* ------------------------------------------------------------------------- */
......@@ -473,6 +482,14 @@ datapipe_hook_tklock_request_value(gconstpointer data)
}
#define datapipe_hook_tklock_request_change 0
static const char *
datapipe_hook_charger_type_value(gconstpointer data)
{
charger_type_t value = GPOINTER_TO_INT(data);
return charger_type_repr(value);
}
#define datapipe_hook_charger_type_change 0
static const char *
datapipe_hook_charger_state_value(gconstpointer data)
{
......@@ -698,6 +715,9 @@ datapipe_t tklock_request_pipe = DATAPIPE_INIT(tklock_request,
/** UI side is in a state where user interaction is expected */
datapipe_t interaction_expected_pipe = DATAPIPE_INIT(interaction_expected, boolean, false, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Charger type; read only */
datapipe_t charger_type_pipe = DATAPIPE_INIT(charger_type, charger_type, CHARGER_TYPE_NONE, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
/** Charger state; read only */
datapipe_t charger_state_pipe = DATAPIPE_INIT(charger_state, charger_state, CHARGER_STATE_UNDEF, 0, DATAPIPE_FILTERING_DENIED, DATAPIPE_CACHE_DEFAULT);
......@@ -1283,6 +1303,7 @@ void mce_datapipe_quit(void)
datapipe_free(&topmost_window_pid_pipe);
datapipe_free(&camera_button_state_pipe);
datapipe_free(&battery_status_pipe);
datapipe_free(&charger_type_pipe);
datapipe_free(&charger_state_pipe);
datapipe_free(&interaction_expected_pipe);
datapipe_free(&tklock_request_pipe);
......@@ -1614,6 +1635,51 @@ const char *usb_cable_state_to_dbus(usb_cable_state_t state)
return res;
}
/** Convert charger_type_t enum to human readable string
*
* @param type charger_type_t enumeration value
*
* @return human readable representation of type
*/
const char *
charger_type_repr(charger_type_t type)
{
const char *repr = "unknown";
switch( type ) {
case CHARGER_TYPE_NONE: repr = "none"; break;
case CHARGER_TYPE_USB: repr = "usb"; break;
case CHARGER_TYPE_DCP: repr = "dcp"; break;
case CHARGER_TYPE_HVDCP: repr = "hwdcp"; break;
case CHARGER_TYPE_CDP: repr = "cdp"; break;
case CHARGER_TYPE_WIRELESS: repr = "wireless"; break;
case CHARGER_TYPE_OTHER: repr = "other"; break;
default: break;
}
return repr;
}
/** Convert charger_type_t enum to dbus argument string
*
* @param type charger_type_t enumeration value
*
* @return representation of type for use over dbus
*/
const char *
charger_type_to_dbus(charger_type_t type)
{
const char *repr = MCE_CHARGER_TYPE_OTHER;
switch( type ) {
case CHARGER_TYPE_NONE: repr = MCE_CHARGER_TYPE_NONE; break;
case CHARGER_TYPE_USB: repr = MCE_CHARGER_TYPE_USB; break;
case CHARGER_TYPE_DCP: repr = MCE_CHARGER_TYPE_DCP; break;
case CHARGER_TYPE_HVDCP: repr = MCE_CHARGER_TYPE_HVDCP; break;
case CHARGER_TYPE_CDP: repr = MCE_CHARGER_TYPE_CDP; break;
case CHARGER_TYPE_WIRELESS: repr = MCE_CHARGER_TYPE_WIRELESS; break;
default: break;
}
return repr;
}
/** Convert charger_state_t enum to human readable string
*
* @param state charger_state_t enumeration value
......
......@@ -4,6 +4,7 @@
* <p>
* Copyright © 2007 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2014-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
......@@ -253,6 +254,7 @@ extern datapipe_t ignore_incoming_call_event_pipe;
extern datapipe_t call_type_pipe;
extern datapipe_t tklock_request_pipe;
extern datapipe_t interaction_expected_pipe;
extern datapipe_t charger_type_pipe;
extern datapipe_t charger_state_pipe;
extern datapipe_t battery_status_pipe;
extern datapipe_t battery_level_pipe;
......
......@@ -3,6 +3,7 @@
* Common state logic for Mode Control Entity
* <p>
* Copyright (C) 2017-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
......@@ -78,6 +79,8 @@ static void common_on_proximity_quit (void);
static void common_dbus_send_usb_cable_state (DBusMessage *const req);
static gboolean common_dbus_get_usb_cable_state_cb(DBusMessage *const req);
static void common_dbus_send_charger_type (DBusMessage *const req);
static gboolean common_dbus_get_charger_type_cb (DBusMessage *const req);
static void common_dbus_send_charger_state (DBusMessage *const req);
static gboolean common_dbus_get_charger_state_cb (DBusMessage *const req);
static void common_dbus_send_battery_status (DBusMessage *const req);
......@@ -93,6 +96,7 @@ static void common_dbus_quit (void);
* ------------------------------------------------------------------------- */
static void common_datapipe_usb_cable_state_cb (gconstpointer data);
static void common_datapipe_charger_type_cb (gconstpointer data);
static void common_datapipe_charger_state_cb (gconstpointer data);
static void common_datapipe_battery_status_cb (gconstpointer data);
static void common_datapipe_battery_level_cb (gconstpointer data);
......@@ -114,6 +118,9 @@ void mce_common_quit(void);
/** USB cable status; assume undefined */
static usb_cable_state_t usb_cable_state = USB_CABLE_UNDEF;
/** Charger type; assume none */
static charger_type_t charger_type = CHARGER_TYPE_NONE;
/** Charger state; assume undefined */
static charger_state_t charger_state = CHARGER_STATE_UNDEF;
......@@ -393,6 +400,69 @@ common_dbus_get_usb_cable_state_cb(DBusMessage *const req)
return TRUE;
}
/* ------------------------------------------------------------------------- *
* charger_type
* ------------------------------------------------------------------------- */
/** Send charger_type D-Bus signal / method call reply
*
* @param req method call message to reply, or NULL to send signal
*/
static void
common_dbus_send_charger_type(DBusMessage *const req)
{
static const char *last = 0;
DBusMessage *msg = NULL;
const char *value = charger_type_to_dbus(charger_type);
if( req ) {
msg = dbus_new_method_reply(req);
}
else if( last == value ) {
goto EXIT;
}
else {
last = value;
msg = dbus_new_signal(MCE_SIGNAL_PATH,
MCE_SIGNAL_IF,
MCE_CHARGER_TYPE_SIG);
}
if( !dbus_message_append_args(msg,
DBUS_TYPE_STRING, &value,
DBUS_TYPE_INVALID) )
goto EXIT;
mce_log(LL_DEBUG, "%s: %s = %s",
req ? "reply" : "broadcast",
"charger_type", value);
dbus_send_message(msg), msg = 0;
EXIT:
if( msg )
dbus_message_unref(msg);
}
/** Callback for handling charger_type D-Bus queries
*
* @param req method call message to reply
*/
static gboolean
common_dbus_get_charger_type_cb(DBusMessage *const req)
{
mce_log(LL_DEBUG, "charger_type query from: %s",
mce_dbus_get_message_sender_ident(req));
if( !dbus_message_get_no_reply(req) )
common_dbus_send_charger_type(req);
return TRUE;
}
/* ------------------------------------------------------------------------- *
* charger_state
* ------------------------------------------------------------------------- */
......@@ -562,7 +632,7 @@ common_dbus_send_battery_level(DBusMessage *const req)
mce_log(LL_DEBUG, "%s: %s = %d",
req ? "reply" : "broadcast",
"charger_state", value);
"battery_level", value);
dbus_send_message(msg), msg = 0;
......@@ -603,6 +673,13 @@ static mce_dbus_handler_t common_dbus_handlers[] =
.args =
" <arg name=\"usb_cable_state\" type=\"s\"/>\n"
},
{
.interface = MCE_SIGNAL_IF,
.name = MCE_CHARGER_TYPE_SIG,
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.args =
" <arg name=\"charger_type\" type=\"s\"/>\n"
},
{
.interface = MCE_SIGNAL_IF,
.name = MCE_CHARGER_STATE_SIG,
......@@ -633,6 +710,14 @@ static mce_dbus_handler_t common_dbus_handlers[] =
.args =
" <arg direction=\"out\" name=\"usb_cable_state\" type=\"s\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_CHARGER_TYPE_GET,
.type = DBUS_MESSAGE_TYPE_METHOD_CALL,
.callback = common_dbus_get_charger_type_cb,
.args =
" <arg direction=\"out\" name=\"charger_type\" type=\"s\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = MCE_CHARGER_STATE_GET,
......@@ -683,6 +768,7 @@ static gboolean common_dbus_initial_cb(gpointer aptr)
* some values to undefined state.
*/
common_dbus_send_usb_cable_state(0);
common_dbus_send_charger_type(0);
common_dbus_send_charger_state(0);
common_dbus_send_battery_status(0);
common_dbus_send_battery_level(0);
......@@ -754,6 +840,32 @@ EXIT:
return;
}
/* ------------------------------------------------------------------------- *
* charger_type
* ------------------------------------------------------------------------- */
/** Callback for handling charger_type_pipe state changes
*
* @param data charger_type (as void pointer)
*/
static void common_datapipe_charger_type_cb(gconstpointer data)
{
charger_type_t prev = charger_type;
charger_type = GPOINTER_TO_INT(data);
if( charger_type == prev )
goto EXIT;
mce_log(LL_DEBUG, "charger_type = %s -> %s",
charger_type_repr(prev),
charger_type_repr(charger_type));
common_dbus_send_charger_type(0);
EXIT:
return;
}
/* ------------------------------------------------------------------------- *
* charger_state
* ------------------------------------------------------------------------- */
......@@ -868,6 +980,10 @@ static datapipe_handler_t common_datapipe_handlers[] =
.datapipe = &usb_cable_state_pipe,
.output_cb = common_datapipe_usb_cable_state_cb,
},
{
.datapipe = &charger_type_pipe,
.output_cb = common_datapipe_charger_type_cb,
},
{
.datapipe = &charger_state_pipe,
.output_cb = common_datapipe_charger_state_cb,
......
......@@ -4,6 +4,7 @@
* <p>
* Copyright © 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2013-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
......@@ -49,6 +50,25 @@
*/
# define MCE_CHARGER_STATE_REQ "req_charger_state"
/** Override current charger type
*
* Available in devel flavor mce only, and only to privileged applications.
*
* @since mce 1.102.0
*
* @param string: current charger type, one of:
* - #MCE_CHARGER_TYPE_NONE
* - #MCE_CHARGER_TYPE_USB
* - #MCE_CHARGER_TYPE_DCP
* - #MCE_CHARGER_TYPE_HVDCP
* - #MCE_CHARGER_TYPE_CDP
* - #MCE_CHARGER_TYPE_WIRELESS
* - #MCE_CHARGER_TYPE_OTHER
*
* @return boolean true if accepted, false / error reply otherwise
*/
# define MCE_CHARGER_TYPE_REQ "req_charger_type"
/** Override current battery level
*
* Available in devel flavor mce only, and only to privileged applications.
......
......@@ -225,6 +225,9 @@
<allow send_destination="com.nokia.mce"
send_interface="com.nokia.mce.request"
send_member="get_charger_state"/>
<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"
......
......@@ -3,7 +3,8 @@
* Generic headers for Mode Control Entity
* <p>
* Copyright © 2004-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2017 Jolla Ltd.
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Irina Bezruk <ext-irina.bezruk@nokia.com>
......@@ -334,6 +335,41 @@ typedef enum {
const char *charger_state_repr(charger_state_t state);
const char *charger_state_to_dbus(charger_state_t state);
/** Known charger types
*
* Note that the ordering is:
*
* a) significant in the sense that in case there are several chargers
* connected and active at the same time, maximum numerical value is
* exposed as effective charger type on D-Bus
*
* b) internal to mce, so that values can and should be rearranged if
* there should be changes in what makes sense to ui side.
*/
typedef enum
{
CHARGER_TYPE_NONE,
/* Charger types that do not carry special meaning from
* sfos UI point of view.
*/
CHARGER_TYPE_OTHER,
CHARGER_TYPE_WIRELESS,
CHARGER_TYPE_CDP, // Charging Downstream Port
/* Wall chargers imply notification on disconnect
*/
CHARGER_TYPE_DCP, // Dedicated Charging Port
CHARGER_TYPE_HVDCP, // High Voltage DCP
/* PC connection implies usb mode management
*/
CHARGER_TYPE_USB, // Standard Downstream Port
} charger_type_t;
const char *charger_type_repr(charger_type_t type);
const char *charger_type_to_dbus(charger_type_t type);
/** Camera button state */
typedef enum {
CAMERA_BUTTON_UNDEF = -1, /**< Camera button state not set */
......
This diff is collapsed.
......@@ -20,7 +20,7 @@ BuildRequires: pkgconfig(dsme) >= 0.65.0
BuildRequires: pkgconfig(thermalmanager_dbus_if)
BuildRequires: pkgconfig(libiphb)
BuildRequires: pkgconfig(glib-2.0) >= 2.36.0
BuildRequires: pkgconfig(mce) >= 1.26.0
BuildRequires: pkgconfig(mce) >= 1.27.0
BuildRequires: pkgconfig(libngf0) >= 0.24
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: kernel-headers >= 2.6.32
......
......@@ -3,6 +3,7 @@
* <p>
* Copyright © 2005-2011 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2012-2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* <p>
* @author David Weinehall <david.weinehall@nokia.com>
* @author Santtu Lakkala <ext-santtu.1.lakkala@nokia.com>
......@@ -139,6 +140,7 @@ static bool xmce_get_color_profile_ids (const ch
static bool xmce_set_color_profile (const char *args);
static void xmce_get_color_profile (void);
#ifdef ENABLE_BATTERY_SIMULATION
static bool xmce_set_charger_type (const char *type);
static bool xmce_set_charger_state (const char *state);
static bool xmce_set_battery_level (int level);
#endif
......@@ -438,6 +440,7 @@ static bool mcetool_do_disable_led_pattern(const char *args);
static bool mcetool_do_activate_pattern (const char *args);
static bool mcetool_do_deactivate_pattern (const char *args);
#ifdef ENABLE_BATTERY_SIMULATION
static bool mcetool_do_set_charger_type(const char *arg);
static bool mcetool_do_set_charger_state (const char *arg);
static bool mcetool_do_set_battery_level (const char *arg);
#endif
......@@ -2583,6 +2586,33 @@ static void xmce_get_color_profile(void)
* ------------------------------------------------------------------------- */
#ifdef ENABLE_BATTERY_SIMULATION
static bool xmce_set_charger_type(const char *type)
{
dbus_bool_t ret = false;
DBusError err = DBUS_ERROR_INIT;
DBusMessage *rsp = 0;
gboolean ack = xmce_ipc(MCE_CHARGER_TYPE_REQ, &rsp,
DBUS_TYPE_STRING, &type,
DBUS_TYPE_INVALID);
if( !ack || !rsp )
goto EXIT;
if( !dbus_message_get_args(rsp, &err,
DBUS_TYPE_BOOLEAN, &ret,
DBUS_TYPE_INVALID) )
goto EXIT;
EXIT:
if( dbus_error_is_set(&err) ) {
errorf("set %s: %s: %s\n", type, err.name, err.message);
dbus_error_free(&err);
}
if( rsp ) dbus_message_unref(rsp);
return ack && ret;
}
static bool xmce_set_charger_state(const char *state)
{
dbus_bool_t ret = false;
......@@ -2638,6 +2668,31 @@ EXIT:
return ack && ret;
}
static bool mcetool_do_set_charger_type(const char *arg)
{
const char * const lut[] = {
MCE_CHARGER_TYPE_NONE,
MCE_CHARGER_TYPE_USB,
MCE_CHARGER_TYPE_DCP,
MCE_CHARGER_TYPE_HVDCP,
MCE_CHARGER_TYPE_CDP,
MCE_CHARGER_TYPE_WIRELESS,
MCE_CHARGER_TYPE_OTHER,
0
};
for( size_t i = 0; ; ++i ) {
if( !lut[i] ) {
errorf("%s: invalid charger type\n", arg);
return false;
}
if( !strcmp(lut[i], arg) )
break;
}
return xmce_set_charger_type(arg);
}
static bool mcetool_do_set_charger_state(const char *arg)
{
const char * const lut[] = {
......@@ -7863,6 +7918,20 @@ static const mce_opt_t options[] =
" disables the feature.\n"
},
#ifdef ENABLE_BATTERY_SIMULATION
{
.name = "set-charger-type",
.with_arg = mcetool_do_set_charger_type,
.values =
MCE_CHARGER_TYPE_NONE "|"
MCE_CHARGER_TYPE_USB "|"
MCE_CHARGER_TYPE_DCP "|"
MCE_CHARGER_TYPE_HVDCP "|"
MCE_CHARGER_TYPE_CDP "|"
MCE_CHARGER_TYPE_WIRELESS "|"
MCE_CHARGER_TYPE_OTHER,
.usage =
"Override charger type for debugging purposes\n"
},
{
.name = "set-charger-state",
.with_arg = mcetool_do_set_charger_state,
......
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