input: acquire temporal lock on pressing key 65/266765/6
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 18 Nov 2021 09:07:03 +0000 (18:07 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Fri, 19 Nov 2021 01:04:10 +0000 (10:04 +0900)
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 <y0.cho@samsung.com>
plugins/iot-headless/input/input-handler.c
plugins/iot-headless/power/power-control.c
src/shared/device-notifier.h

index 69b619e..2c293d0 100644 (file)
 #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);
                }
        }
 
index 7e20ca5..5be4ad8 100644 (file)
 #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);
 }
 
index 7269d57..77c1b73 100644 (file)
@@ -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 */