display: change display state from standby to suspend automatically 33/60633/1
authorTaeyoung Kim <ty317.kim@samsung.com>
Mon, 29 Feb 2016 11:23:26 +0000 (20:23 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Mon, 29 Feb 2016 11:23:26 +0000 (20:23 +0900)
- 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 <ty317.kim@samsung.com>
src/core/device-notifier.h
src/display/core.c
src/display/poll.h
src/display/state-tv.c

index 85a4e9a..da2d6cc 100644 (file)
@@ -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,
index bff7de3..8b8c2f7 100644 (file)
@@ -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)
index e1a1200..567e394 100644 (file)
@@ -53,6 +53,7 @@ enum {
        INTERNAL_LOCK_TIME,
        INTERNAL_LOCK_USB,
        INTERNAL_LOCK_POWEROFF,
+       INTERNAL_LOCK_SUSPEND,
        INTERNAL_LOCK_COOL_DOWN,
        INTERNAL_LOCK_LOWBAT,
 };
index 4b759f6..263b32f 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <time.h>
+#include <Ecore.h>
 #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);
 }