#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;
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");
}
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);
}
}
#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 {
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;
/* 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);
}
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 */