Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Block late suspend while bluetooth activity is seen on D-Bus
Add plugin for monitoring bluetooth activity on D-Bus.

Any D-Bus signals from bluez are taken as bluetooth activity and late
suspend is blocked until no more signals are seen for 5 seconds. This
should allow time for bluetooth related processing to happen without
the device falling to late suspend too early.

[mce] Block late suspend while bluetooth activity is seen on D-Bus. Fixes JB#18124
  • Loading branch information
spiiroin committed Apr 24, 2014
1 parent 09b13bb commit fc628ee
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .depend
Expand Up @@ -382,6 +382,18 @@ modules/battery-upower.pic.o:\
mce-log.h\
mce.h\

modules/bluetooth.o:\
modules/bluetooth.c\
libwakelock.h\
mce-dbus.h\
mce-log.h\

modules/bluetooth.pic.o:\
modules/bluetooth.c\
libwakelock.h\
mce-dbus.h\
mce-log.h\

modules/callstate.o:\
modules/callstate.c\
datapipe.h\
Expand Down
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -168,6 +168,7 @@ MODULES += $(MODULE_DIR)/camera.so
MODULES += $(MODULE_DIR)/alarm.so
MODULES += $(MODULE_DIR)/battery-bme.so
MODULES += $(MODULE_DIR)/battery-upower.so
MODULES += $(MODULE_DIR)/bluetooth.so
MODULES += $(MODULE_DIR)/display.so
MODULES += $(MODULE_DIR)/doubletap.so
MODULES += $(MODULE_DIR)/sensor-gestures.so
Expand Down
2 changes: 1 addition & 1 deletion inifiles/mce.ini
Expand Up @@ -16,7 +16,7 @@ ModulePath=/usr/lib/mce/modules
# 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-upower;inactivity;alarm;callstate;audiorouting;proximity;powersavemode;cpu-keepalive;doubletap;packagekit;sensor-gestures;
Modules=radiostates;filter-brightness-als;display;keypad;led;battery-upower;inactivity;alarm;callstate;audiorouting;proximity;powersavemode;cpu-keepalive;doubletap;packagekit;sensor-gestures;bluetooth;


[HomeKey]
Expand Down
1 change: 1 addition & 0 deletions mce.c
Expand Up @@ -290,6 +290,7 @@ static void mce_cleanup_wakelocks(void)
wakelock_unlock("mce_display_stm");
wakelock_unlock("mce_powerkey_stm");
wakelock_unlock("mce_proximity_stm");
wakelock_unlock("mce_bluez_wait");
}
#endif // ENABLE_WAKELOCKS

Expand Down
214 changes: 214 additions & 0 deletions modules/bluetooth.c
@@ -0,0 +1,214 @@
/**
* @file bluetooth.c
* Bluetooth module -- this implements bluez tracking for MCE
* <p>
* Copyright (C) 2014 Jolla Ltd
* <p>
* @author Simo Piiroinen <simo.piiroinen@jollamobile.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 "../mce-dbus.h"
#include "../mce-log.h"
#include "../libwakelock.h"

#include <stdlib.h>

#include <glib.h>
#include <gmodule.h>

/* ------------------------------------------------------------------------- *
* SUSPEND_BLOCK
* ------------------------------------------------------------------------- */

static gboolean bluetooth_suspend_block_timer_cb(gpointer aptr);
static void bluetooth_suspend_block_stop(void);
static void bluetooth_suspend_block_start(void);

/* ------------------------------------------------------------------------- *
* DBUS_HANDLERS
* ------------------------------------------------------------------------- */

static gboolean bluetooth_dbus_bluez_signal_cb(DBusMessage *const msg);

static void bluetooth_dbus_init(void);
static void bluetooth_dbus_quit(void);

/* ------------------------------------------------------------------------- *
* MODULE_LOAD_UNLOAD
* ------------------------------------------------------------------------- */

G_MODULE_EXPORT const gchar *g_module_check_init(GModule *module);
G_MODULE_EXPORT void g_module_unload(GModule *module);

/* ========================================================================= *
* SUSPEND_BLOCK
* ========================================================================= */

/** Timer id for cancelling suspend blocking */
static guint bluetooth_suspend_block_timer_id = 0;

/** Timer callback for cancelling suspend blocking
*
* @param aptr user data pointer (not used)
*
* @return FALSE to stop timer from repeating
*/
static gboolean bluetooth_suspend_block_timer_cb(gpointer aptr)
{
(void)aptr; // not used

if( bluetooth_suspend_block_timer_id ) {
bluetooth_suspend_block_timer_id = 0;
mce_log(LL_DEVEL, "bt suspend blocking ended");
wakelock_unlock("mce_bluez_wait");
}
return FALSE;
}

/** Cancel suspend blocking
*/
static void bluetooth_suspend_block_stop(void)
{
if( bluetooth_suspend_block_timer_id ) {
g_source_remove(bluetooth_suspend_block_timer_id),
bluetooth_suspend_block_timer_id = 0;
mce_log(LL_DEVEL, "bt suspend blocking cancelled");
wakelock_unlock("mce_bluez_wait");
}
}

/** Start/extend suspend blocking
*/
static void bluetooth_suspend_block_start(void)
{
if( bluetooth_suspend_block_timer_id ) {
g_source_remove(bluetooth_suspend_block_timer_id);
}
else {
wakelock_lock("mce_bluez_wait", -1);
mce_log(LL_DEVEL, "bt suspend blocking started");
}
bluetooth_suspend_block_timer_id =
g_timeout_add(5000, bluetooth_suspend_block_timer_cb, 0);
}

/* ========================================================================= *
* DBUS_HANDLERS
* ========================================================================= */

/** Handle signal originating from bluez
*
* MCE is not interested in the signal content per se, any incoming
* signals just mean there is bluetooth activity and mce should allow
* related ipc and processing to happen without the device getting
* suspened too soon.
*
* @param msg dbus signal message
*
* @return TRUE
*/
static gboolean
bluetooth_dbus_bluez_signal_cb(DBusMessage *const msg)
{
if( mce_log_p(LL_DEBUG) ) {
char *repr = mce_dbus_message_repr(msg);
mce_log(LL_DEBUG, "%s", repr ?: "bluez sig");
free(repr);
}

bluetooth_suspend_block_start();
return TRUE;
}

/** Array of dbus message handlers */
static mce_dbus_handler_t bluetooth_dbus_handlers[] =
{
/* signals */
{
.interface = "org.bluez.Manager",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = bluetooth_dbus_bluez_signal_cb,
},
{
.interface = "org.bluez.Adapter",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = bluetooth_dbus_bluez_signal_cb,
},
{
.interface = "org.bluez.Device",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = bluetooth_dbus_bluez_signal_cb,
},
{
.interface = "org.bluez.Input",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = bluetooth_dbus_bluez_signal_cb,
},
{
.interface = "org.bluez.SerialProxyManager",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = bluetooth_dbus_bluez_signal_cb,
},
/* sentinel */
{
.interface = 0
}
};

/** Add dbus handlers
*/
static void bluetooth_dbus_init(void)
{
mce_dbus_handler_register_array(bluetooth_dbus_handlers);
}

/** Remove dbus handlers
*/
static void bluetooth_dbus_quit(void)
{
mce_dbus_handler_unregister_array(bluetooth_dbus_handlers);
}

/* ========================================================================= *
* MODULE_LOAD_UNLOAD
* ========================================================================= */

/** Init function for the bluetooth module
*
* @param module (not used)
*
* @return NULL on success, a string with an error message on failure
*/
const gchar *g_module_check_init(GModule *module)
{
(void)module;

bluetooth_dbus_init();

return 0;
}

/** Exit function for the bluetooth module
*
* @param module (not used)
*/
void g_module_unload(GModule *module)
{
(void)module;

bluetooth_dbus_quit();

bluetooth_suspend_block_stop();
}

0 comments on commit fc628ee

Please sign in to comment.