Skip to content

Commit

Permalink
Stop initial orientation reporting from triggering flip over gestures
Browse files Browse the repository at this point in the history
If device was face-up the last time orientation sensor was enabled,
sensord can report and mce assume that it is still face-up when the
sensor is powered up the next time. This can make it look like the
device were flipped over during sensor startup, which then silences
incoming call / snoozes alarm  (if device is face-down and proximity
sensor is not blocking display & sensor power up).

Make mce forget orientation sensor state altogether when the sensor
is stopped. And make sensor-gestures plugin wait a bit longer before
accepting face-up immediately after sensor power up.

[mce] Stop initial orientation reporting from triggering flip over gestures. Fixes NEMO#786
  • Loading branch information
spiiroin committed Feb 3, 2015
1 parent 67d966c commit 354553e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
27 changes: 26 additions & 1 deletion mce-sensorfw.c
Expand Up @@ -370,6 +370,9 @@ struct sfw_backend_t

/** Callback for restoring sensor value back to last-known */
sfw_reset_fn be_restore_cb;

/** Callback for setting sensor value when stopped */
sfw_reset_fn be_forget_cb;
};

/* ========================================================================= *
Expand Down Expand Up @@ -713,6 +716,7 @@ static void sfw_plugin_handle_sample (sfw_plugin_t *self, con
static void sfw_plugin_handle_value (sfw_plugin_t *self, unsigned value);
static void sfw_plugin_reset_value (sfw_plugin_t *self);
static void sfw_plugin_restore_value (sfw_plugin_t *self);
static void sfw_plugin_forget_value (sfw_plugin_t *self);

static void sfw_plugin_cancel_load (sfw_plugin_t *self);

Expand Down Expand Up @@ -817,7 +821,7 @@ static void sfw_service_set_orient (sfw_service_t *self, bo
#define SWF_NOTIFY_DEFAULT_ALS 400

/** Orientation state to use when sensor can't be enabled */
#define SWF_NOTIFY_DEFAULT_ORIENT MCE_ORIENTATION_FACE_UP
#define SWF_NOTIFY_DEFAULT_ORIENT MCE_ORIENTATION_UNDEFINED

/** Dummy sensor value to use when re-sending cached state data */
#define SWF_NOTIFY_DUMMY 0
Expand Down Expand Up @@ -1045,6 +1049,7 @@ static const sfw_backend_t sfw_backend_ps =

.be_reset_cb = sfw_backend_ps_reset_cb,
.be_restore_cb = sfw_backend_ps_restore_cb,
.be_forget_cb = 0,
};

/** Data and callbacks for ambient light sensor */
Expand All @@ -1062,6 +1067,7 @@ static const sfw_backend_t sfw_backend_als =

.be_reset_cb = sfw_backend_als_reset_cb,
.be_restore_cb = sfw_backend_als_restore_cb,
.be_forget_cb = 0,
};

/** Data and callbacks for orientation sensor */
Expand All @@ -1079,6 +1085,7 @@ static const sfw_backend_t sfw_backend_orient =

.be_reset_cb = sfw_backend_orient_reset_cb,
.be_restore_cb = sfw_backend_orient_restore_cb,
.be_forget_cb = sfw_backend_orient_reset_cb,
};

/* ========================================================================= *
Expand Down Expand Up @@ -1316,6 +1323,9 @@ sfw_reporting_trans(sfw_reporting_t *self, sfw_reporting_state_t state)
break;

case REPORTING_DISABLING:
// optional: switch to sensor stopped value
sfw_plugin_forget_value(self->rep_plugin);

dbus_send_ex(SENSORFW_SERVICE,
sfw_plugin_get_sensor_object(self->rep_plugin),
sfw_plugin_get_sensor_interface(self->rep_plugin),
Expand Down Expand Up @@ -2519,6 +2529,20 @@ sfw_plugin_restore_value(sfw_plugin_t *self)
self->plg_backend->be_restore_cb(self);
}

/** Set sensor state when stopped
*
* Used when sensor tracking is stopped
*/
static void
sfw_plugin_forget_value(sfw_plugin_t *self)
{
mce_log(LL_DEBUG, "plugin(%s): stopped",
sfw_plugin_get_sensor_name(self));

if( self->plg_backend->be_forget_cb )
self->plg_backend->be_forget_cb(self);
}

/** Get size of sensor specific change event
*/
static size_t
Expand Down Expand Up @@ -3239,6 +3263,7 @@ sfw_notify_orient(sfw_notify_t type, int input_value)

case NOTIFY_RESET:
tracking_active = false;
cached_value = default_value;
break;

case NOTIFY_RESTORE:
Expand Down
46 changes: 43 additions & 3 deletions modules/sensor-gestures.c
Expand Up @@ -123,7 +123,14 @@ static void sg_detect_flipover_gesture(void)
goto EXIT;
}

/* Check orientation state */
/* Check for undefined orientation state */
if( orientation_state_raw == MCE_ORIENTATION_UNDEFINED ||
orientation_state_eff == MCE_ORIENTATION_UNDEFINED ) {
primed = false;
goto EXIT;
}

/* Check effective orientation state */
if( orientation_state_eff == MCE_ORIENTATION_FACE_UP ) {
primed = true;
}
Expand Down Expand Up @@ -157,6 +164,10 @@ static void sg_call_state_cb(gconstpointer const data)
if( call_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "call: %s -> %s",
call_state_repr(prev),
call_state_repr(call_state));

sg_detect_flipover_gesture();
EXIT:

Expand All @@ -175,6 +186,10 @@ static void sg_alarm_ui_state_cb(gconstpointer data)
if( alarm_ui_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "alarm: %s -> %s",
alarm_state_repr(prev),
alarm_state_repr(alarm_ui_state));

sg_detect_flipover_gesture();

EXIT:
Expand All @@ -193,6 +208,10 @@ static void sg_display_state_cb(gconstpointer data)
if( display_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "display: %s -> %s",
display_state_repr(prev),
display_state_repr(display_state));

sg_detect_flipover_gesture();

EXIT:
Expand All @@ -209,6 +228,10 @@ static void sg_orientation_state_update(void)
if( orientation_state_eff == prev )
goto EXIT;

mce_log(LL_DEBUG, "orient.eff: %s -> %s",
orientation_state_repr(prev),
orientation_state_repr(orientation_state_eff));

sg_detect_flipover_gesture();

EXIT:
Expand All @@ -228,6 +251,8 @@ static gboolean sg_orientation_state_eff_cb(gpointer data)
if( !orientation_state_eff_id )
goto EXIT;

mce_log(LL_DEBUG, "orient.eff: timer triggered");

orientation_state_eff_id = 0;

sg_orientation_state_update();
Expand All @@ -245,6 +270,16 @@ static void sg_orientation_state_raw_cb(gconstpointer data)
orientation_state_t prev = orientation_state_raw;
orientation_state_raw = GPOINTER_TO_INT(data);

if( orientation_state_raw == prev )
goto EXIT;

mce_log(LL_DEBUG, "orient.raw: %s -> %s",
orientation_state_repr(prev),
orientation_state_repr(orientation_state_raw));

/* Unprime if orientation is unknown */
sg_detect_flipover_gesture();

/* When the orientation sensor is stopped and restarted,
* sensord reports initially the last state that was seen
* before the sensor was stopped.
Expand All @@ -258,22 +293,27 @@ static void sg_orientation_state_raw_cb(gconstpointer data)
if( orientation_state_eff_id ) {
g_source_remove(orientation_state_eff_id);
orientation_state_eff_id = 0;

mce_log(LL_DEBUG, "orient.eff: timer canceled");
}

if( prev == MCE_ORIENTATION_UNDEFINED &&
orientation_state_raw == MCE_ORIENTATION_FACE_UP ) {
/* Invalidate effective sensor value */
orientation_state_eff = MCE_ORIENTATION_UNDEFINED;

/* Schedule re-validation after 500 ms */
/* Schedule re-validation after 1000 ms */
orientation_state_eff_id =
g_timeout_add(500, sg_orientation_state_eff_cb, 0);
g_timeout_add(1000, sg_orientation_state_eff_cb, 0);

mce_log(LL_DEBUG, "orient.eff: timer started");
}
else {
/* Update effective sensor value immediately */
sg_orientation_state_update();
}

EXIT:
return;
}

Expand Down

0 comments on commit 354553e

Please sign in to comment.