From 34444b69296aa3d112e744473be5dab4c755fabd Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Mon, 29 Feb 2016 20:23:26 +0900 Subject: [PATCH] display: change display state from standby to suspend automatically - In TV profile, Standby mode will be changed to suspend mode if none of apps lock the S_LCDOFF. - display unlock event is added to update display state after unlocking display state. Change-Id: I9096396b5e9d90e0ffab712c327d6c2603747a2f Signed-off-by: Taeyoung Kim --- src/core/device-notifier.h | 1 + src/display/core.c | 6 ++++- src/display/poll.h | 1 + src/display/state-tv.c | 56 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 85a4e9a..da2d6cc 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -33,6 +33,7 @@ enum device_notifier_type { DEVICE_NOTIFIER_BATTERY_PRESENT, DEVICE_NOTIFIER_BATTERY_OVP, DEVICE_NOTIFIER_BATTERY_CHARGING, + DEVICE_NOTIFIER_DISPLAY_LOCK, DEVICE_NOTIFIER_POWER_RESUME, DEVICE_NOTIFIER_POWEROFF, DEVICE_NOTIFIER_POWEROFF_HAPTIC, diff --git a/src/display/core.c b/src/display/core.c index bff7de3..8b8c2f7 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -126,7 +126,7 @@ static int trans_table[S_END][EVENT_END] = { { S_LCDDIM, S_NORMAL }, /* S_NORMAL */ { S_LCDOFF, S_NORMAL }, /* S_LCDDIM */ { S_SLEEP, S_NORMAL }, /* S_LCDOFF */ - { S_STANDBY, S_STANDBY }, /* S_STANDBY */ + { S_SLEEP, S_STANDBY }, /* S_STANDBY */ { S_LCDOFF, S_NORMAL }, /* S_SLEEP */ { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; @@ -921,6 +921,8 @@ static void proc_condition_lock(PMMsg *data) _SD("[%s] locked by pid %d - process %s holdkeyblock %d\n", states[state].name, pid, pname, holdkey_block); set_lock_time(pname, state); + + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)true); } static void proc_condition_unlock(PMMsg *data) @@ -945,6 +947,8 @@ static void proc_condition_unlock(PMMsg *data) _SD("[%s] unlocked by pid %d - process %s\n", states[state].name, pid, pname); set_unlock_time(pname, state); + + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)false); } static int proc_condition(PMMsg *data) diff --git a/src/display/poll.h b/src/display/poll.h index e1a1200..567e394 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -53,6 +53,7 @@ enum { INTERNAL_LOCK_TIME, INTERNAL_LOCK_USB, INTERNAL_LOCK_POWEROFF, + INTERNAL_LOCK_SUSPEND, INTERNAL_LOCK_COOL_DOWN, INTERNAL_LOCK_LOWBAT, }; diff --git a/src/display/state-tv.c b/src/display/state-tv.c index 4b759f6..263b32f 100644 --- a/src/display/state-tv.c +++ b/src/display/state-tv.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "core/common.h" #include "core/log.h" #include "core/device-notifier.h" @@ -37,6 +38,8 @@ #define SIGNAL_POST_WAKEUP "PostWakeUp" #define SIGNAL_EARLY_WAKEUP "EarlyWakeUp" +static Ecore_Timer *standby_timer; + static int change_state(pid_t pid, int type, enum state_t st) { int ret; @@ -265,9 +268,9 @@ static int standby_check(int curr, int next) return -EPERM; /* do not change to next state if who lock the standby mode */ - check_processes(pm_cur_state); - if (check_lock_state(pm_cur_state)) { - _I("S_STANDBY Lock state"); + check_processes(S_LCDOFF); + if (check_lock_state(S_LCDOFF)) { + _I("S_LCDOFF Lock state"); return 1; } @@ -297,6 +300,26 @@ static int standby_post(void *data) return 0; } +static int poweroff_trans(int evt); + +static Eina_Bool standby_go_next_state(void *data) +{ + int ret; + + if (standby_timer) { + ecore_timer_del(standby_timer); + standby_timer = NULL; + } + + ret = pm_change_internal(INTERNAL_LOCK_SUSPEND, SUSPEND); + if (ret < 0) { + _E("Failed to change state to S_SUSPEND. Now Power off !!"); + poweroff_trans(0); + } + + return ECORE_CALLBACK_CANCEL; +} + static int standby_action(int timeout) { if (pm_cur_state != pm_old_state && @@ -305,6 +328,11 @@ static int standby_action(int timeout) backlight_ops.off(0); + standby_timer = ecore_timer_add(0, + standby_go_next_state, NULL); + if (!standby_timer) + _E("Failed to add timer to go to next state of S_STANDBY"); + return 0; } @@ -354,7 +382,7 @@ static int suspend_post(void *data) /* TODO: count InstandOn */ cond = S_LCDON; - ret = tv_proc_change_state(cond, getpid()); + ret = tv_proc_change_state(cond, INTERNAL_LOCK_SUSPEND); if (ret < 0) _E("Fail to change state to next_state(%s)", states[cond].name); @@ -453,6 +481,19 @@ static int poweroff_trans(int evt) return 0; } +static int display_lock_changed(void *data) +{ + bool state = (bool)data; + + if (pm_cur_state != S_STANDBY) + return 0; + + if (!state) + standby_go_next_state(NULL); + + return 0; +} + static void set_tv_operations(enum state_t st, char *name, int (*check) (int curr, int next), @@ -493,4 +534,11 @@ static void __CONSTRUCTOR__ state_tv_init(void) tv_states[i].action); change_proc_change_state(tv_proc_change_state); + + register_notifier(DEVICE_NOTIFIER_DISPLAY_LOCK, display_lock_changed); +} + +static void __DESTRUCTOR__ state_tv_deinit(void) +{ + unregister_notifier(DEVICE_NOTIFIER_DISPLAY_LOCK, display_lock_changed); } -- 2.7.4