Skip to content

Commit

Permalink
[fingerprint] Add settings for controlling fingerprint wakeups. JB#42135
Browse files Browse the repository at this point in the history
Settings for enabling/disabling fingerprint wakeups and finetuning
related delays.

Added mcetool options are:
      --set-fingerprint-wakeup-mode=<never|always|proximity>
      --set-fingerprint-wakeup-allow-delay=<ms>
      --set-fingerprint-wakeup-trigger-delay=<ms>
      --set-fingerprint-wakeup-throttle-delay=<ms>

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 18, 2018
1 parent 31a81d2 commit 925f51a
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .depend
Expand Up @@ -6,6 +6,7 @@ builtin-gconf.o:\
mce-dbus.h\
mce-io.h\
mce-log.h\
mce-setting.h\
mce.h\
modules/display.h\
modules/doubletap.h\
Expand All @@ -25,6 +26,7 @@ builtin-gconf.pic.o:\
mce-dbus.h\
mce-io.h\
mce-log.h\
mce-setting.h\
mce.h\
modules/display.h\
modules/doubletap.h\
Expand Down Expand Up @@ -734,6 +736,7 @@ modules/fingerprint.o:\
datapipe.h\
mce-dbus.h\
mce-log.h\
mce-setting.h\
mce.h\

modules/fingerprint.pic.o:\
Expand All @@ -742,6 +745,7 @@ modules/fingerprint.pic.o:\
datapipe.h\
mce-dbus.h\
mce-log.h\
mce-setting.h\
mce.h\

modules/inactivity.o:\
Expand Down Expand Up @@ -1304,9 +1308,11 @@ tools/fileusers.pic.o:\

tools/mcetool.o:\
tools/mcetool.c\
builtin-gconf.h\
datapipe.h\
event-input.h\
mce-command-line.h\
mce-setting.h\
mce.h\
modules/display.h\
modules/doubletap.h\
Expand All @@ -1322,9 +1328,11 @@ tools/mcetool.o:\

tools/mcetool.pic.o:\
tools/mcetool.c\
builtin-gconf.h\
datapipe.h\
event-input.h\
mce-command-line.h\
mce-setting.h\
mce.h\
modules/display.h\
modules/doubletap.h\
Expand Down
21 changes: 21 additions & 0 deletions builtin-gconf.c
Expand Up @@ -21,6 +21,7 @@
#include "mce-log.h"
#include "mce-io.h"
#include "mce-dbus.h"
#include "mce-setting.h"

#include "powerkey.h"
#include "tklock.h"
Expand Down Expand Up @@ -1586,6 +1587,26 @@ static const setting_t gconf_defaults[] =
.type = "i",
.def = G_STRINGIFY(MCE_DEFAULT_DOUBLETAP_MODE),
},
{
.key = MCE_SETTING_FPWAKEUP_MODE,
.type = "i",
.def = G_STRINGIFY(MCE_DEFAULT_FPWAKEUP_MODE),
},
{
.key = MCE_SETTING_FPWAKEUP_ALLOW_DELAY,
.type = "i",
.def = G_STRINGIFY(MCE_DEFAULT_FPWAKEUP_ALLOW_DELAY),
},
{
.key = MCE_SETTING_FPWAKEUP_TRIGGER_DELAY,
.type = "i",
.def = G_STRINGIFY(MCE_DEFAULT_FPWAKEUP_TRIGGER_DELAY),
},
{
.key = MCE_SETTING_FPWAKEUP_THROTTLE_DELAY,
.type = "i",
.def = G_STRINGIFY(MCE_DEFAULT_FPWAKEUP_THROTTLE_DELAY),
},
{
.key = MCE_SETTING_POWERKEY_MODE,
.type = "i",
Expand Down
40 changes: 40 additions & 0 deletions mce-setting.h
Expand Up @@ -25,6 +25,46 @@

# include "builtin-gconf.h"

/* ========================================================================= *
* Fingerprint Scanner Settings
* ========================================================================= */

/** Fingerprint wakeup enable modes */
typedef enum
{
/** Fingerprint wakeups disabled */
FPWAKEUP_ENABLE_NEVER = 0,

/** Fingerprint wakeups always enabled */
FPWAKEUP_ENABLE_ALWAYS = 1,

/** Fingerprint wakeups enabled when PS is not covered */
FPWAKEUP_ENABLE_NO_PROXIMITY = 2,
} fpwakeup_mode_t;

/** Prefix for fingerprint setting keys */
# define MCE_SETTING_FINGERPRINT_PATH "/system/osso/dsm/fingerprint"

/** When fingerprint wakeup is allowed */
# define MCE_SETTING_FPWAKEUP_MODE MCE_SETTING_FINGERPRINT_PATH "/mode"
# define MCE_DEFAULT_FPWAKEUP_MODE 2 // = FPWAKEUP_ENABLE_NO_PROXIMITY

/** Delay between policy change and activating fingerprint daemon [ms] */
# define MCE_SETTING_FPWAKEUP_ALLOW_DELAY MCE_SETTING_FINGERPRINT_PATH "/allow_delay"
# define MCE_DEFAULT_FPWAKEUP_ALLOW_DELAY 500

/** Delay between getting identified fingerprint and acting on it [ms] */
# define MCE_SETTING_FPWAKEUP_TRIGGER_DELAY MCE_SETTING_FINGERPRINT_PATH "/trigger_delay"
# define MCE_DEFAULT_FPWAKEUP_TRIGGER_DELAY 100

/** Delay between ipc attempts with fingerprint daemon [ms] */
# define MCE_SETTING_FPWAKEUP_THROTTLE_DELAY MCE_SETTING_FINGERPRINT_PATH "/throttle_delay"
# define MCE_DEFAULT_FPWAKEUP_THROTTLE_DELAY 250

/* ========================================================================= *
* Functions
* ========================================================================= */

gboolean mce_setting_has_key (const gchar *const key);
gboolean mce_setting_set_int (const gchar *const key, const gint value);
gboolean mce_setting_set_string (const gchar *const key, const gchar *const value);
Expand Down
159 changes: 154 additions & 5 deletions modules/fingerprint.c
Expand Up @@ -23,6 +23,7 @@
#include "../mce.h"
#include "../mce-log.h"
#include "../mce-dbus.h"
#include "../mce-setting.h"

#include <linux/input.h>

Expand Down Expand Up @@ -290,6 +291,14 @@ static void fingerprint_datapipe_keypress_event_cb (gconstpointer cons
static void fingerprint_datapipe_init (void);
static void fingerprint_datapipe_quit (void);

/* ------------------------------------------------------------------------- *
* FINGERPRINT_SETTING
* ------------------------------------------------------------------------- */

static void fingerprint_setting_cb (GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data);
static void fingerprint_setting_init(void);
static void fingerprint_setting_quit(void);

/* ------------------------------------------------------------------------- *
* FINGERPRINT_DBUS
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -372,6 +381,23 @@ static cover_state_t proximity_sensor_actual = COVER_UNDEF;
/** Cached power key pressed down state */
static bool powerkey_pressed = false;

/* ========================================================================= *
* FINGERPRINT_SETTINGS
* ========================================================================= */

/** Fingerprint wakeup enable mode */
static gint fingerprint_wakeup_mode = MCE_DEFAULT_FPWAKEUP_MODE;
static guint fingerprint_wakeup_mode_setting_id = 0;

static gint fingerprint_allow_delay = MCE_DEFAULT_FPWAKEUP_ALLOW_DELAY;
static guint fingerprint_allow_delay_setting_id = 0;

static gint fingerprint_trigger_delay = MCE_DEFAULT_FPWAKEUP_TRIGGER_DELAY;
static guint fingerprint_trigger_delay_setting_id = 0;

static gint fingerprint_throttle_delay = MCE_DEFAULT_FPWAKEUP_THROTTLE_DELAY;
static guint fingerprint_throttle_delay_setting_id = 0;

/* ========================================================================= *
* MANAGED_STATES
* ========================================================================= */
Expand Down Expand Up @@ -869,7 +895,8 @@ fpidentify_enter_cb(fpoperation_t *self)
* press happens in close proximity, */
if( fpwakeup_set_primed(true) )
mce_log(LL_DEBUG, "fp wakeup primed");
fpoperation_attach_timeout(self, 100, fpoperation_trigger_fpwakeup_cb);
fpoperation_attach_timeout(self, fingerprint_trigger_delay,
fpoperation_trigger_fpwakeup_cb);
break;
case FPOPSTATE_FAILURE:
break;
Expand All @@ -882,7 +909,8 @@ fpidentify_enter_cb(fpoperation_t *self)
case FPOPSTATE_ABORTED:
break;
case FPOPSTATE_THROTTLING:
fpoperation_attach_timeout(self, 250, fpoperation_throttling_ended_cb);
fpoperation_attach_timeout(self, fingerprint_throttle_delay,
fpoperation_throttling_ended_cb);
break;
default:
break;
Expand Down Expand Up @@ -1672,6 +1700,114 @@ fingerprint_datapipe_quit(void)
datapipe_bindings_quit(&fingerprint_datapipe_bindings);
}

/* ========================================================================= *
* FINGERPRINT_SETTINGS
* ========================================================================= */

/** Setting changed callback
*
* @param gcc Unused
* @param id Connection ID from gconf_client_notify_add()
* @param entry The modified GConf entry
* @param data Unused
*/
static void
fingerprint_setting_cb(GConfClient *const gcc, const guint id,
GConfEntry *const entry, gpointer const data)
{
(void)gcc;
(void)data;
(void)id;

const GConfValue *gcv = gconf_entry_get_value(entry);

if( !gcv ) {
mce_log(LL_DEBUG, "GConf Key `%s' has been unset",
gconf_entry_get_key(entry));
goto EXIT;
}

if( id == fingerprint_wakeup_mode_setting_id ) {
gint old = fingerprint_wakeup_mode;
fingerprint_wakeup_mode = gconf_value_get_int(gcv);
mce_log(LL_NOTICE, "fingerprint_wakeup_mode: %d -> %d",
old, fingerprint_wakeup_mode);
fpwakeup_schedule_rethink();
}
else if( id == fingerprint_trigger_delay_setting_id ) {
gint old = fingerprint_trigger_delay;
fingerprint_trigger_delay = gconf_value_get_int(gcv);
mce_log(LL_NOTICE, "fingerprint_trigger_delay: %d -> %d",
old, fingerprint_trigger_delay);
/* Takes effect on the next identify */
}
else if( id == fingerprint_throttle_delay_setting_id ) {
gint old = fingerprint_throttle_delay;
fingerprint_throttle_delay = gconf_value_get_int(gcv);
mce_log(LL_NOTICE, "fingerprint_throttle_delay: %d -> %d",
old, fingerprint_throttle_delay);
/* Takes effect after the next ipc attempt */
}
else if( id == fingerprint_allow_delay_setting_id ) {
gint old = fingerprint_allow_delay;
fingerprint_allow_delay = gconf_value_get_int(gcv);
mce_log(LL_NOTICE, "fingerprint_allow_delay: %d -> %d",
old, fingerprint_allow_delay);
/* Takes effect on the next policy change */
}
else {
mce_log(LL_WARN, "Spurious GConf value received; confused!");
}

EXIT:
return;
}

/** Get intial setting values and start tracking changes
*/
static void
fingerprint_setting_init(void)
{
mce_setting_track_int(MCE_SETTING_FPWAKEUP_MODE,
&fingerprint_wakeup_mode,
MCE_DEFAULT_FPWAKEUP_MODE,
fingerprint_setting_cb,
&fingerprint_wakeup_mode_setting_id);

mce_setting_track_int(MCE_SETTING_FPWAKEUP_ALLOW_DELAY,
&fingerprint_allow_delay,
MCE_DEFAULT_FPWAKEUP_ALLOW_DELAY,
fingerprint_setting_cb,
&fingerprint_allow_delay_setting_id);

mce_setting_track_int(MCE_SETTING_FPWAKEUP_TRIGGER_DELAY,
&fingerprint_trigger_delay,
MCE_DEFAULT_FPWAKEUP_TRIGGER_DELAY,
fingerprint_setting_cb,
&fingerprint_trigger_delay_setting_id);

mce_setting_track_int(MCE_SETTING_FPWAKEUP_THROTTLE_DELAY,
&fingerprint_throttle_delay,
MCE_DEFAULT_FPWAKEUP_THROTTLE_DELAY,
fingerprint_setting_cb,
&fingerprint_throttle_delay_setting_id);
}

/** Stop tracking setting changes
*/
static void
fingerprint_setting_quit(void)
{
mce_setting_notifier_remove(fingerprint_wakeup_mode_setting_id),
fingerprint_wakeup_mode_setting_id = 0;
mce_setting_notifier_remove(fingerprint_allow_delay_setting_id),
fingerprint_allow_delay_setting_id = 0;
mce_setting_notifier_remove(fingerprint_trigger_delay_setting_id),
fingerprint_trigger_delay_setting_id = 0;
mce_setting_notifier_remove(fingerprint_throttle_delay_setting_id),
fingerprint_throttle_delay_setting_id = 0;
}

/* ========================================================================= *
* FINGERPRINT_DBUS
* ========================================================================= */
Expand Down Expand Up @@ -2261,7 +2397,8 @@ static void
fpwakeup_schedule_allow(void)
{
if( !fpwakeup_allow_id ) {
fpwakeup_allow_id = g_timeout_add(500, fpwakeup_allow_cb, 0);
fpwakeup_allow_id = g_timeout_add(fingerprint_allow_delay,
fpwakeup_allow_cb, 0);
}
}

Expand All @@ -2284,9 +2421,19 @@ fpwakeup_evaluate_allowed(void)
if( !fingerprint_data_exists() )
goto EXIT;

/* Proximity sensor must not be covered */
if( proximity_sensor_actual != COVER_OPEN )
/* Check fpwakeup policy */
switch( fingerprint_wakeup_mode ) {
default:
case FPWAKEUP_ENABLE_NEVER:
goto EXIT;
case FPWAKEUP_ENABLE_ALWAYS:
break;
case FPWAKEUP_ENABLE_NO_PROXIMITY:
/* Proximity sensor must not be covered */
if( proximity_sensor_actual == COVER_CLOSED )
goto EXIT;
break;
}

/* Power key must not be pressed down */
if( powerkey_pressed )
Expand Down Expand Up @@ -2496,6 +2643,7 @@ g_module_check_init(GModule *module)
(void)module;

fingerprint_data_init();
fingerprint_setting_init();
fingerprint_datapipe_init();
fingerprint_dbus_init();

Expand All @@ -2512,6 +2660,7 @@ g_module_unload(GModule *module)
(void)module;

fingerprint_data_quit();
fingerprint_setting_quit();

fingerprint_dbus_quit();
fingerprint_datapipe_quit();
Expand Down

0 comments on commit 925f51a

Please sign in to comment.