display: release display lock when apps go to background 65/59365/3
authorTaeyoung Kim <ty317.kim@samsung.com>
Mon, 15 Feb 2016 06:01:26 +0000 (15:01 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Thu, 18 Feb 2016 03:38:50 +0000 (12:38 +0900)
- When background apps lock display, power consumption is
  increased. Thus background app should release display lock.

- deviced gets app background information from resourced (dbus signal)
  When the information is delivered, deviced just checks
  the app status. And the display lock is released when
  display state is changed.

Change-Id: Ia3f5f1bbf311fc4784cd469e078ce4f476372420
Signed-off-by: Taeyoung Kim <ty317.kim@samsung.com>
src/core/device-notifier.h
src/display/core.c
src/proc/proc-handler.c

index 5b4f6bc..815e56b 100644 (file)
@@ -37,6 +37,7 @@ enum device_notifier_type {
        DEVICE_NOTIFIER_POWEROFF_HAPTIC,
        DEVICE_NOTIFIER_PMQOS_OOM,
        DEVICE_NOTIFIER_PROCESS_BACKGROUND,
+       DEVICE_NOTIFIER_PROCESS_FOREGROUND,
        DEVICE_NOTIFIER_MAX,
 };
 
index ef62157..a20f92f 100644 (file)
@@ -190,6 +190,7 @@ typedef struct _pm_lock_node {
        time_t time;
        bool holdkey_block;
        struct _pm_lock_node *next;
+       bool background;
 } PmLockNode;
 
 static PmLockNode *cond_head[S_END];
@@ -217,8 +218,13 @@ static void set_process_active(bool flag, pid_t pid)
 
 bool check_lock_state(int state)
 {
-       if (cond_head[state] != NULL)
-               return true;
+       PmLockNode *t = cond_head[state];
+
+       while (t) {
+               if (t->background == false)
+                       return true;
+               t = t->next;
+       }
 
        return false;
 }
@@ -360,16 +366,66 @@ static int refresh_app_cond()
 {
        trans_condition = 0;
 
-       if (cond_head[S_LCDDIM] != NULL)
+       if (check_lock_state(S_LCDDIM))
                trans_condition = trans_condition | MASK_DIM;
-       if (cond_head[S_LCDOFF] != NULL)
+       if (check_lock_state(S_LCDOFF))
                trans_condition = trans_condition | MASK_OFF;
-       if (cond_head[S_SLEEP] != NULL)
+       if (check_lock_state(S_SLEEP))
                trans_condition = trans_condition | MASK_SLP;
 
        return 0;
 }
 
+static void condition_background_remove(enum state_t s_index)
+{
+       PmLockNode *t;
+       PmLockNode *prev;
+
+       t = cond_head[s_index];
+       prev = NULL;
+
+       while (t != NULL) {
+               if (t->background == false) {
+                       prev = t;
+                       t = t->next;
+                       continue;
+               }
+
+               /* delete node */
+               if (prev != NULL)
+                       prev->next = t->next;
+               else
+                       cond_head[s_index] = cond_head[s_index]->next;
+
+               /* delete timer */
+               if (t->timeout_id)
+                       ecore_timer_del(t->timeout_id);
+
+               free(t);
+               if (prev != NULL)
+                       t = prev->next;
+               else
+                       t = cond_head[s_index];
+       }
+
+       refresh_app_cond();
+}
+
+static void makeup_trans_condition(void)
+{
+       enum state_t iter;
+       for (iter = S_START; iter < S_END; iter++) {
+               switch (iter) {
+               case S_LCDDIM:
+               case S_LCDOFF:
+               case S_SLEEP:
+                       condition_background_remove(iter);
+               default:
+                       break;
+               }
+       }
+}
+
 static PmLockNode *find_node(enum state_t s_index, pid_t pid)
 {
        PmLockNode *t = cond_head[s_index];
@@ -400,6 +456,7 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, Ecore_Timer *timeou
        n->time = now;
        n->holdkey_block = holdkey_block;
        n->next = cond_head[s_index];
+       n->background = false;
        cond_head[s_index] = n;
 
        refresh_app_cond();
@@ -1716,10 +1773,14 @@ go_lcd_off:
  */
 static int default_check(int next)
 {
-       int trans_cond = trans_condition & MASK_BIT;
+       int trans_cond;
        int lock_state = -1;
        int app_state = -1;
 
+       makeup_trans_condition();
+
+       trans_cond = trans_condition & MASK_BIT;
+
        vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state);
        if (lock_state==VCONFKEY_IDLE_LOCK && next != S_SLEEP) {
                vconf_get_int(VCONFKEY_CALL_STATE, &app_state);
@@ -2084,6 +2145,38 @@ static int booting_done(void *data)
        return 0;
 }
 
+static int process_background(void *data)
+{
+       pid_t pid;
+       PmLockNode *node;
+
+       pid = *(pid_t *)data;
+
+       node = find_node(S_LCDDIM, pid);
+       if (node) {
+               node->background = true;
+               _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid);
+       }
+
+       return 0;
+}
+
+static int process_foreground(void *data)
+{
+       pid_t pid;
+       PmLockNode *node;
+
+       pid = *(pid_t *)data;
+
+       node = find_node(S_LCDDIM, pid);
+       if (node) {
+               node->background = false;
+               _I("%d pid is foreground, then PM will be maintained locked LCD_NORMAL", pid);
+       }
+
+       return 0;
+}
+
 static int display_load_config(struct parse_result *result, void *user_data)
 {
        struct display_config *c = user_data;
@@ -2173,6 +2266,8 @@ static void display_init(void *data)
                    DISPLAY_CONF_FILE, ret);
 
        register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
+       register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background);
+       register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground);
 
        for (i = INIT_SETTING; i < INIT_END; i++) {
                switch (i) {
@@ -2262,8 +2357,9 @@ static void display_exit(void *data)
                        exit_sysfs();
                        break;
                case INIT_POLL:
-                       unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE,
-                           booting_done);
+                       unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
+                       unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background);
+                       unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground);
 
                        exit_input();
                        break;
index 59b2df3..6d3f43c 100644 (file)
@@ -175,6 +175,8 @@ static void proc_signal_handler(void *data, DBusMessage *msg)
 
        if (type == PROC_STATUS_BACKGROUND)
                device_notify(DEVICE_NOTIFIER_PROCESS_BACKGROUND, &pid);
+       if (type == PROC_STATUS_FOREGROUND)
+               device_notify(DEVICE_NOTIFIER_PROCESS_FOREGROUND, &pid);
 }
 
 static const struct edbus_method edbus_methods[] = {