From: Youngjae Cho Date: Thu, 18 Nov 2021 09:07:03 +0000 (+0900) Subject: input: acquire temporal lock on pressing key X-Git-Tag: accepted/tizen/unified/20211213.133447~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f05f3dbf3e696670679efd0fbde24bca23cb9e7;p=platform%2Fcore%2Fsystem%2Fdeviced.git input: acquire temporal lock on pressing key To process shortkey/longkey during autosleep is enabled, it must be prevented to re-enter sleep right after the device is woken up by key press. Therefore, hold wakelock temporarily during key pressed. Change-Id: I9d4f282fcae0beeec9edb97e463f4b0eef2bfacb Signed-off-by: Youngjae Cho --- diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index 69b619e..2c293d0 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -31,8 +31,10 @@ #define LONGPRESS_INTERVAL 10000 /* milisecond */ #define SHORTPRESS_INTERVAL 3000 /* milisecond */ +/* milisecond */ static int longpress_interval = LONGPRESS_INTERVAL; static int shortpress_interval = SHORTPRESS_INTERVAL; + static guint shortpress_timer_id; static guint longpress_timer_id; @@ -54,6 +56,8 @@ static gboolean longpressed_cb(void *data) return G_SOURCE_REMOVE; if (power_device->execute) { + /* disable autosleep */ + device_notify(DEVICE_NOTIFIER_REQUEST_DISABLE_AUTOSLEEP, NULL); _D("powerkey long pressed"); power_device->execute("poweroff"); } @@ -122,11 +126,13 @@ static int input_handler_execute(void *data) if (keycode == KEY_POWER) { if (keyvalue == KEYVALUE_PRESS) { + device_notify(DEVICE_NOTIFIER_KEY_PRESS, (void *)(intptr_t) KEY_POWER); start_shortpress_timer(); start_longpress_timer(); } else if (keyvalue == KEYVALUE_RELEASE) { stop_shortpress_timer(); stop_longpress_timer(); + device_notify(DEVICE_NOTIFIER_KEY_RELEASE, (void *)(intptr_t) KEY_POWER); } } diff --git a/plugins/iot-headless/power/power-control.c b/plugins/iot-headless/power/power-control.c index 7e20ca5..5be4ad8 100644 --- a/plugins/iot-headless/power/power-control.c +++ b/plugins/iot-headless/power/power-control.c @@ -34,6 +34,12 @@ #define PROCESS_CHECK_TIMEOUT 600000 /* milisecond, 10 minute */ #endif +#define KEYPRESS_LOCK_TIMEOUT 4000 /* milisecond */ + +/* temporal wakelock of powerkey input */ +#define KEY_PRESSED_TEMPORAL_LOCK "templock" +#define TEMPORAL_LOCK_WAKE_MARGIN 1000 /* milisecond */ + static GList *lock_list; struct lock_node { @@ -44,6 +50,54 @@ struct lock_node { char locktime[64]; }; +static guint keypress_temporal_timer_id; + +static gboolean temporal_lock_expired_cb(void *data) +{ + sys_set_str("/sys/power/wake_unlock", KEY_PRESSED_TEMPORAL_LOCK); + keypress_temporal_timer_id = 0; + + return G_SOURCE_REMOVE; +} + +static int acquire_temporal_lock(void *data) +{ + int keycode = (int)(intptr_t) data; + + if (keycode != KEY_POWER) + return 0; + + if (keypress_temporal_timer_id) { + g_source_remove(keypress_temporal_timer_id); + keypress_temporal_timer_id = 0; + } + + sys_set_str("/sys/power/wake_lock", KEY_PRESSED_TEMPORAL_LOCK); + keypress_temporal_timer_id = g_timeout_add(KEYPRESS_LOCK_TIMEOUT + TEMPORAL_LOCK_WAKE_MARGIN, + temporal_lock_expired_cb, NULL); + + return 0; +} + +static int release_temporal_lock(void * data) +{ + int keycode = (int)(intptr_t) data; + + if (keycode != KEY_POWER) + return 0; + + if (keypress_temporal_timer_id) { + g_source_remove(keypress_temporal_timer_id); + keypress_temporal_timer_id = 0; + } + + /* shorten timeout */ + keypress_temporal_timer_id = g_timeout_add(TEMPORAL_LOCK_WAKE_MARGIN, + temporal_lock_expired_cb, NULL); + + return 0; +} + static void print_lock_node(void) { GList *elem; @@ -287,6 +341,8 @@ static void power_control_init(void *data) /* initial sleep state: disabled */ device_notify(DEVICE_NOTIFIER_REQUEST_DISABLE_AUTOSLEEP, NULL); + register_notifier(DEVICE_NOTIFIER_KEY_PRESS, acquire_temporal_lock); + register_notifier(DEVICE_NOTIFIER_KEY_RELEASE, release_temporal_lock); register_notifier(DEVICE_NOTIFIER_KEY_SHORTPRESS, powerkey_short_pressed_cb); } diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index 7269d57..77c1b73 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -60,6 +60,8 @@ enum device_notifier_type { DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, DEVICE_NOTIFIER_ULTRAPOWERSAVING, DEVICE_NOTIFIER_EXTCON_COUNT, + DEVICE_NOTIFIER_KEY_PRESS, + DEVICE_NOTIFIER_KEY_RELEASE, DEVICE_NOTIFIER_KEY_SHORTPRESS, /* hold down a key for a short duration */ DEVICE_NOTIFIER_KEY_LONGPRESS, /* hold down a key for a long duration */