Skip to content

Commit

Permalink
[tklock] Cancel display blanking on lockscreen interaction. Fixes JB#…
Browse files Browse the repository at this point in the history
…35376

Implicit display power ups due to notifications and such use shorter than
normal blanking timeouts. If mce sees sufficient user activity during the
exceptional situation, it cancels the display state restore. However since
the device unlocking was moved to happen within lockscreen context, mce
has no way to detect that there is significant user interaction with
the device and blanks the display while user is entering the lock code.

Listen to lockscreen notifications on D-Bus and cancel display state
restore when lockscreen signals transition to a state where user
interaction is expected to happen.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jun 2, 2017
1 parent 4b875af commit 1ee11dd
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
6 changes: 6 additions & 0 deletions datapipe.c
Expand Up @@ -145,6 +145,9 @@ datapipe_struct call_type_pipe;
/** The touchscreen/keypad lock state */
datapipe_struct tk_lock_pipe;

/** UI side is in a state where user interaction is expected */
datapipe_struct interaction_expected_pipe;

/** Charger state; read only */
datapipe_struct charger_state_pipe;

Expand Down Expand Up @@ -794,6 +797,8 @@ void mce_datapipe_init(void)
0, GINT_TO_POINTER(MCE_ORIENTATION_UNDEFINED));
setup_datapipe(&tk_lock_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(LOCK_UNDEF));
setup_datapipe(&interaction_expected_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(false));
setup_datapipe(&charger_state_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(CHARGER_STATE_UNDEF));
setup_datapipe(&battery_status_pipe, READ_ONLY, DONT_FREE_CACHE,
Expand Down Expand Up @@ -871,6 +876,7 @@ void mce_datapipe_quit(void)
free_datapipe(&camera_button_pipe);
free_datapipe(&battery_status_pipe);
free_datapipe(&charger_state_pipe);
free_datapipe(&interaction_expected_pipe);
free_datapipe(&tk_lock_pipe);
free_datapipe(&proximity_sensor_pipe);
free_datapipe(&ambient_light_sensor_pipe);
Expand Down
1 change: 1 addition & 0 deletions datapipe.h
Expand Up @@ -123,6 +123,7 @@ extern datapipe_struct call_state_pipe;
extern datapipe_struct ignore_incoming_call_pipe;
extern datapipe_struct call_type_pipe;
extern datapipe_struct tk_lock_pipe;
extern datapipe_struct interaction_expected_pipe;
extern datapipe_struct charger_state_pipe;
extern datapipe_struct battery_status_pipe;
extern datapipe_struct battery_level_pipe;
Expand Down
96 changes: 90 additions & 6 deletions tklock.c
Expand Up @@ -199,6 +199,7 @@ static void tklock_datapipe_keypress_cb(gconstpointer const data);
static void tklock_datapipe_exception_state_cb(gconstpointer data);
static void tklock_datapipe_audio_route_cb(gconstpointer data);
static void tklock_datapipe_tk_lock_cb(gconstpointer data);
static void tklock_datapipe_interaction_expected_cb(gconstpointer data);
static void tklock_datapipe_submode_cb(gconstpointer data);
static void tklock_datapipe_lockkey_cb(gconstpointer const data);
static void tklock_datapipe_heartbeat_cb(gconstpointer data);
Expand Down Expand Up @@ -297,7 +298,7 @@ static void tklock_uiexcept_begin(uiexctype_t type, int64_t linger);
static void tklock_uiexcept_end(uiexctype_t type, int64_t linger);
static void tklock_uiexcept_cancel(void);
static void tklock_uiexcept_finish(void);
static bool tklock_uiexcept_deny_state_restore(bool force);
static bool tklock_uiexcept_deny_state_restore(bool force, const char *cause);
static void tklock_uiexcept_rethink(void);

// low power mode ui state machine
Expand Down Expand Up @@ -380,6 +381,7 @@ static gboolean tklock_dbus_send_tklock_mode(DBusMessage *const method_call);

static gboolean tklock_dbus_mode_get_req_cb(DBusMessage *const msg);
static gboolean tklock_dbus_mode_change_req_cb(DBusMessage *const msg);
static gboolean tklock_dbus_interaction_expected_cb(DBusMessage *const msg);
static gboolean tklock_dbus_systemui_callback_cb(DBusMessage *const msg);

static gboolean tklock_dbus_device_lock_changed_cb(DBusMessage *const msg);
Expand Down Expand Up @@ -1429,6 +1431,43 @@ static void tklock_datapipe_tk_lock_cb(gconstpointer data)
tklock_ui_set(enable);
}

/** Interaction expected; assume false */
static bool interaction_expected = false;

/** Change notifications for interaction_expected_pipe
*/
static void tklock_datapipe_interaction_expected_cb(gconstpointer data)
{
bool prev = interaction_expected;
interaction_expected = GPOINTER_TO_INT(data);

if( prev == interaction_expected )
goto EXIT;

mce_log(LL_DEBUG, "interaction_expected: %d -> %d",
prev, interaction_expected);

/* All changes must be ignored when handling exceptional things
* like calls and alarms that are shown on top of lockscreen ui.
*/
if( exception_state & (UIEXC_CALL | UIEXC_ALARM) )
goto EXIT;

/* Edge triggered action: When interaction becomes expected
* while lockscreen is still active (e.g. display has been
* unblanked to show notification on the lockscreen and
* user has swiped from plain lockscreen view to device unlock
* code entry view) the display state restore should be disabled.
*/
if( display_state_next == MCE_DISPLAY_ON &&
tklock_ui_enabled && interaction_expected ) {
tklock_uiexcept_deny_state_restore(true, "interaction expected");
}

EXIT:
return;
}

static submode_t submode = MCE_INVALID_SUBMODE;

/** Change notifications for submode
Expand Down Expand Up @@ -1909,14 +1948,13 @@ static void tklock_datapipe_user_activity_cb(gconstpointer data)
switch( exception_state ) {
case UIEXC_LINGER:
/* touch events during linger -> do not restore display state */
if( tklock_uiexcept_deny_state_restore(true) )
mce_log(LL_DEBUG, "touch event during linger; do not restore display/tklock state");
tklock_uiexcept_deny_state_restore(true, "touch event during linger");
break;

case UIEXC_NOTIF:
/* touch events while device is not locked -> do not restore display state */
if( tklock_uiexcept_deny_state_restore(false) ) {
mce_log(LL_DEBUG, "touch event while unlocked; do not restore display/tklock state");
if( tklock_uiexcept_deny_state_restore(false,
"touch event during notification") ) {
break;
}
/* touchscreen activity makes notification exceptions to last longer */
Expand Down Expand Up @@ -1972,6 +2010,10 @@ static datapipe_handler_t tklock_datapipe_handlers[] =
.datapipe = &tk_lock_pipe,
.output_cb = tklock_datapipe_tk_lock_cb,
},
{
.datapipe = &interaction_expected_pipe,
.output_cb = tklock_datapipe_interaction_expected_cb,
},
{
.datapipe = &proximity_sensor_pipe,
.output_cb = tklock_datapipe_proximity_sensor_cb,
Expand Down Expand Up @@ -3278,7 +3320,7 @@ static void tklock_uiexcept_sync_to_datapipe(void)
* false for canceling only if neither tklock nor devicelock
* is active
*/
static bool tklock_uiexcept_deny_state_restore(bool force)
static bool tklock_uiexcept_deny_state_restore(bool force, const char *cause)
{
bool changed = false;

Expand All @@ -3290,6 +3332,8 @@ static bool tklock_uiexcept_deny_state_restore(bool force)
if( !force && (exdata.tklock || exdata.devicelock) )
goto EXIT;

mce_log(LL_DEVEL, "%s; state restore disabled", cause);

exdata.restore = false;
changed = true;

Expand Down Expand Up @@ -5845,6 +5889,39 @@ static gboolean tklock_dbus_mode_change_req_cb(DBusMessage *const msg)
return status;
}

/** D-Bus callback for handling interaction expected -state changed signals
*
* @param msg The D-Bus message
*
* @return TRUE
*/
static gboolean tklock_dbus_interaction_expected_cb(DBusMessage *const msg)
{
DBusError err = DBUS_ERROR_INIT;
dbus_bool_t arg = false;

if( !msg )
goto EXIT;

if( !dbus_message_get_args(msg, &err,
DBUS_TYPE_BOOLEAN, &arg,
DBUS_TYPE_INVALID) ) {
mce_log(LL_ERR, "Failed to parse interaction expected signal: %s: %s",
err.name, err.message);
goto EXIT;
}

mce_log(LL_DEBUG, "received interaction expected signal: state=%d", arg);
execute_datapipe(&interaction_expected_pipe,
GINT_TO_POINTER(arg),
USE_INDATA, CACHE_INDATA);

EXIT:
dbus_error_free(&err);

return TRUE;
}

/**
* D-Bus callback from SystemUI touchscreen/keypad lock
*
Expand Down Expand Up @@ -6010,6 +6087,13 @@ static mce_dbus_handler_t tklock_dbus_handlers[] =
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = tklock_dbus_device_lock_changed_cb,
},
{
.interface = "org.nemomobile.lipstick.screenlock",
.name = "interaction_expected",
.rules = "path='/screenlock'",
.type = DBUS_MESSAGE_TYPE_SIGNAL,
.callback = tklock_dbus_interaction_expected_cb,
},
/* signals - outbound (for Introspect purposes only) */
{
.interface = MCE_SIGNAL_IF,
Expand Down

0 comments on commit 1ee11dd

Please sign in to comment.