Skip to content

Commit

Permalink
[powerkey] Skip device lock requests while the service is not up. JB#…
Browse files Browse the repository at this point in the history
…38183

Filling journal with D-Bus method call failures can be confusing.

Skip device lock related requests when we know they have no chance of
succeeding and provide more context aware logging.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Apr 20, 2017
1 parent e45a775 commit 8faaa0b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions powerkey.c
Expand Up @@ -639,6 +639,9 @@ static alarm_ui_state_t alarm_ui_state = MCE_ALARM_UI_OFF_INT32;
/** Cached call state */
static call_state_t call_state = CALL_STATE_NONE;

/** devicelock dbus name is reserved; assume unknown */
static service_state_t devicelock_available = SERVICE_STATE_UNDEF;

/** Use powerkey for blanking during incoming calls */
static bool pwrkey_ignore_incoming_call = false;

Expand Down Expand Up @@ -861,12 +864,21 @@ pwrkey_action_devlock(void)
static const char method[] = "setState";
dbus_int32_t request = DEVICE_LOCK_LOCKED;

if( devicelock_available != SERVICE_STATE_RUNNING ) {
mce_log(LL_WARN, "devicelock service state is %s; skip %s request",
service_state_repr(devicelock_available),
device_lock_state_repr(request));
goto EXIT;
}

mce_log(LL_DEBUG, "Requesting devicelock=%s",
device_lock_state_repr(request));

dbus_send(service, object, interface, method, 0,
DBUS_TYPE_INT32, &request,
DBUS_TYPE_INVALID);
EXIT:
return;
}

static void
Expand Down Expand Up @@ -2969,6 +2981,26 @@ pwrkey_datapipe_alarm_ui_state_cb(gconstpointer data)
return;
}

/** Change notifications for devicelock_available
*/
static void pwrkey_datapipe_devicelock_available_cb(gconstpointer data)
{
service_state_t prev = devicelock_available;
devicelock_available = GPOINTER_TO_INT(data);

if( devicelock_available == prev )
goto EXIT;

mce_log(LL_DEBUG, "devicelock_available = %s -> %s",
service_state_repr(prev),
service_state_repr(devicelock_available));

/* no immediate action, but see pwrkey_action_devlock() */

EXIT:
return;
}

/** Array of datapipe handlers */
static datapipe_handler_t pwrkey_datapipe_handlers[] =
{
Expand Down Expand Up @@ -3010,6 +3042,10 @@ static datapipe_handler_t pwrkey_datapipe_handlers[] =
.datapipe = &call_state_pipe,
.output_cb = pwrkey_datapipe_call_state_cb,
},
{
.datapipe = &devicelock_available_pipe,
.output_cb = pwrkey_datapipe_devicelock_available_cb,
},
// sentinel
{
.datapipe = 0,
Expand Down

0 comments on commit 8faaa0b

Please sign in to comment.