Skip to content

Commit

Permalink
Block user interaction when shutdown/reboot starts
Browse files Browse the repository at this point in the history
It is possible to trigger ui actions via touchscreen and volume keys
after shutdown/reboot has already started.

Take shutdown state into account in input policy and block touch
screen and volume keys during shutdown/reboot.

Tune rules for touch-is-blocked debug led pattern so that it will get
triggered also if blocking starts at display on state.

[mce] Block user interaction when shutdown/reboot starts. Fixes JB#26533
  • Loading branch information
spiiroin committed May 13, 2015
1 parent 3d65140 commit b763de1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 16 deletions.
6 changes: 6 additions & 0 deletions datapipe.c
Expand Up @@ -178,6 +178,9 @@ datapipe_struct packagekit_locked_pipe;
/** Update mode active status; read only */
datapipe_struct update_mode_pipe;

/** Shutting down; read only */
datapipe_struct shutting_down_pipe;

/** Device Lock state; read only */
datapipe_struct device_lock_state_pipe;

Expand Down Expand Up @@ -891,6 +894,8 @@ void mce_datapipe_init(void)
0, GINT_TO_POINTER(FALSE));
setup_datapipe(&update_mode_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(FALSE));
setup_datapipe(&shutting_down_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(FALSE));
setup_datapipe(&device_lock_state_pipe, READ_ONLY, DONT_FREE_CACHE,
0, GINT_TO_POINTER(DEVICE_LOCK_UNDEFINED));
setup_datapipe(&touch_grab_wanted_pipe, READ_WRITE, DONT_FREE_CACHE,
Expand Down Expand Up @@ -959,6 +964,7 @@ void mce_datapipe_quit(void)
free_datapipe(&dsme_available_pipe);
free_datapipe(&packagekit_locked_pipe);
free_datapipe(&update_mode_pipe);
free_datapipe(&shutting_down_pipe);
free_datapipe(&device_lock_state_pipe);
free_datapipe(&touch_grab_active_pipe);
free_datapipe(&touch_grab_wanted_pipe);
Expand Down
1 change: 1 addition & 0 deletions datapipe.h
Expand Up @@ -138,6 +138,7 @@ extern datapipe_struct usbmoded_available_pipe;
extern datapipe_struct dsme_available_pipe;
extern datapipe_struct packagekit_locked_pipe;
extern datapipe_struct update_mode_pipe;
extern datapipe_struct shutting_down_pipe;
extern datapipe_struct device_lock_state_pipe;
extern datapipe_struct touch_grab_wanted_pipe;
extern datapipe_struct touch_grab_active_pipe;
Expand Down
50 changes: 36 additions & 14 deletions event-input.c
Expand Up @@ -2887,6 +2887,29 @@ evin_ts_grab_set_led(bool enabled)
return;
}

/** Evaluate need for grab active led notification
*
* This should be called when display state or
* touch screen grab state changes.
*/
static void
evin_ts_grab_rethink_led(void)
{
bool enable = false;

switch( datapipe_get_gint(display_state_pipe) )
{
case MCE_DISPLAY_ON:
case MCE_DISPLAY_DIM:
enable = datapipe_get_gint(touch_grab_active_pipe);
break;
default:
break;
}

evin_ts_grab_set_led(enable);
}

/** Grab/ungrab all monitored touch input devices
*/
static void
Expand All @@ -2908,9 +2931,7 @@ evin_ts_grab_set_active(gboolean grab)
GINT_TO_POINTER(grab),
USE_INDATA, CACHE_INDATA);

/* disable led pattern if grab ended */
if( !grab )
evin_ts_grab_set_led(false);
evin_ts_grab_rethink_led();

EXIT:
return;
Expand Down Expand Up @@ -3108,17 +3129,19 @@ evin_ts_grab_wanted_cb(gconstpointer data)
static void
evin_ts_grab_display_state_cb(gconstpointer data)
{
static display_state_t prev = MCE_DISPLAY_UNDEF;
static display_state_t display_state = MCE_DISPLAY_UNDEF;

display_state_t prev = display_state;
display_state = GPOINTER_TO_INT(data);

display_state_t display_state = GPOINTER_TO_INT(data);
if( display_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "display_state=%s", display_state_repr(display_state));

switch( display_state ) {
case MCE_DISPLAY_POWER_DOWN:
/* Deactivate debug led pattern once we start to
* power off display and touch panel. */
evin_ts_grab_set_led(false);
/* NOP */
break;

case MCE_DISPLAY_OFF:
Expand Down Expand Up @@ -3154,11 +3177,6 @@ evin_ts_grab_display_state_cb(gconstpointer data)
* release ends. */
evin_input_grab_set_touching(&evin_ts_grab_state, false);
}
/* Activate (delayed) debug led pattern if we reach
* display on with input grabbed */
if( datapipe_get_gint(touch_grab_active_pipe) ) {
evin_ts_grab_set_led(true);
}
break;

default:
Expand All @@ -3168,7 +3186,11 @@ evin_ts_grab_display_state_cb(gconstpointer data)
break;
}

prev = display_state;
evin_ts_grab_rethink_led();

EXIT:
return;

}

/** Initialize touch screen grabbing state machine
Expand Down
4 changes: 4 additions & 0 deletions modules/display.c
Expand Up @@ -754,6 +754,10 @@ static void mdy_shutdown_set_state(bool in_progress)
mce_log(LL_DEVEL, "Shutdown canceled");
}

execute_datapipe(&shutting_down_pipe,
GINT_TO_POINTER(mdy_shutdown_started_flag),
USE_INDATA, CACHE_INDATA);

/* Framebuffer must be kept open during shutdown */
mdy_fbdev_rethink();

Expand Down
37 changes: 35 additions & 2 deletions tklock.c
Expand Up @@ -144,6 +144,7 @@ static void tklock_datapipe_device_lock_state_cb(gconstpointer data);
static void tklock_datapipe_device_resumed_cb(gconstpointer data);
static void tklock_datapipe_lipstick_available_cb(gconstpointer data);
static void tklock_datapipe_update_mode_cb(gconstpointer data);
static void tklock_datapipe_shutting_down_cb(gconstpointer data);
static void tklock_datapipe_display_state_cb(gconstpointer data);
static void tklock_datapipe_proximity_update(void);
static gboolean tklock_datapipe_proximity_uncover_cb(gpointer data);
Expand Down Expand Up @@ -697,6 +698,27 @@ static void tklock_datapipe_update_mode_cb(gconstpointer data)
return;
}

/** Device is shutting down; assume false */
static bool shutting_down = false;

/** Change notifications for shutting_down
*/
static void tklock_datapipe_shutting_down_cb(gconstpointer data)
{
bool prev = shutting_down;
shutting_down = GPOINTER_TO_INT(data);

if( shutting_down == prev )
goto EXIT;

mce_log(LL_DEBUG, "shutting_down = %d -> %d", prev, shutting_down);

tklock_evctrl_rethink();

EXIT:
return;
}

/** Display state; undefined initially, can't assume anything */
static display_state_t display_state = MCE_DISPLAY_UNDEF;

Expand Down Expand Up @@ -1868,6 +1890,10 @@ static datapipe_handler_t tklock_datapipe_handlers[] =
.datapipe = &update_mode_pipe,
.output_cb = tklock_datapipe_update_mode_cb,
},
{
.datapipe = &shutting_down_pipe,
.output_cb = tklock_datapipe_shutting_down_cb,
},
{
.datapipe = &device_lock_state_pipe,
.output_cb = tklock_datapipe_device_lock_state_cb,
Expand Down Expand Up @@ -3492,6 +3518,13 @@ static void tklock_evctrl_rethink(void)
}
#endif

/* No interaction during shutdown */
if( shutting_down ) {
enable_kp = false;
enable_ts = false;
enable_dt = false;
}

/* - - - - - - - - - - - - - - - - - - - *
* set updated state
* - - - - - - - - - - - - - - - - - - - */
Expand Down Expand Up @@ -3528,8 +3561,8 @@ static void tklock_evctrl_rethink(void)

case MCE_DISPLAY_ON:
case MCE_DISPLAY_DIM:
// release grab
grab_ts = false;
// grab/ungrab based on policy
grab_ts = !enable_ts;
break;
}

Expand Down

0 comments on commit b763de1

Please sign in to comment.