display: state-transition: Remove default_check() 12/293812/6
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 5 Jun 2023 10:24:02 +0000 (19:24 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Wed, 7 Jun 2023 09:07:05 +0000 (18:07 +0900)
default_check() was used for checking state transition condition.
If there is any pmlock of the state checked which is not background status,
it is impossible to move next state.
default_check() follows same policy from all plugins.
To move from current display state to next display state, this function is necessary.

Thus, this function is added below display-state-transition.
int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state);

Change-Id: I06adb467ac81a04596f22a7b0fe9b06c3b72d248
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
plugins/iot-headed/display/core.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/display/display-plugin.c
src/display/display-plugin.h
src/display/display-state-transition.c
src/display/display-state-transition.h

index d2c1440..8634eb6 100644 (file)
@@ -113,18 +113,17 @@ static bool touch_blocked = false;
 /* default transition, action fuctions */
 static int default_trans(int evt);
 static int default_action(int timeout);
-static int default_check(int curr, int next);
 
 static int default_proc_change_state(unsigned int cond, pid_t pid);
 static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state;
 
 static struct state states[S_END] = {
        { S_START,    "S_START",    NULL,          NULL,           NULL,          NULL            },
-       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, default_check, NULL            },
-       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, default_check, NULL            },
-       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, default_check, NULL            },
+       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, NULL,          NULL            },
        { S_STANDBY,  "S_STANDBY",  NULL,          NULL,           NULL,          NULL            },
-       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, default_check, NULL            },
+       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, NULL,          NULL            },
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
@@ -798,11 +797,13 @@ static int default_trans(int evt)
 {
        struct state *st = &states[get_pm_cur_state()];
        enum state_t next_state;
+       int ret = 0;
 
        display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
 
        /* check conditions */
-       if (st->check && !st->check(get_pm_cur_state(), next_state)) {
+       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
+       if (ret < 0) {
                /* There is a condition. */
                _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name,
                       states[next_state].name);
@@ -1019,45 +1020,6 @@ go_lcd_off:
        return 0;
 }
 
-/*
- * default check function
- *   return
- *    0 : can't transit, others : transitable
- */
-static int default_check(int curr, int next)
-{
-       int trans_cond;
-
-       makeup_trans_condition();
-
-       trans_cond = get_trans_condition() & MASK_BIT;
-
-       if (next == S_NORMAL) /* S_NORMAL is exceptional */
-               return 1;
-
-       switch (curr) {
-       case S_NORMAL:
-               trans_cond = trans_cond & MASK_NORMAL;
-               break;
-       case S_LCDDIM:
-               trans_cond = trans_cond & MASK_DIM;
-               break;
-       case S_LCDOFF:
-               trans_cond = trans_cond & MASK_OFF;
-               break;
-       default:
-               trans_cond = 0;
-               break;
-       }
-
-       if (trans_cond != 0) {
-               print_node(curr);
-               return 0;
-       }
-
-       return 1;               /* transitable */
-}
-
 static void default_saving_mode(int onoff)
 {
        if (onoff)
index a5bda11..e29de08 100644 (file)
@@ -80,7 +80,6 @@
  */
 
 #define LOCK_SCREEN_CONTROL_TIMEOUT    5000
-#define ALWAYS_ON_TIMEOUT              360000000
 
 #define GESTURE_STR            "gesture"
 #define POWER_KEY_STR          "powerkey"
@@ -116,18 +115,17 @@ static bool touch_blocked = false;
 /* default transition, action fuctions */
 static int default_trans(int evt);
 static int default_action(int timeout);
-static int default_check(int curr, int next);
 
 static int default_proc_change_state(unsigned int cond, pid_t pid);
 static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state;
 
 static struct state states[S_END] = {
        { S_START,    "S_START",    NULL,          NULL,           NULL,          NULL            },
-       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, default_check, NULL            },
-       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, default_check, NULL            },
-       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, default_check, NULL            },
+       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, NULL,          NULL            },
        { S_STANDBY,  "S_STANDBY",  NULL,          NULL,           NULL,          NULL            },
-       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, default_check, NULL            },
+       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, NULL,          NULL            },
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
@@ -809,11 +807,13 @@ static int default_trans(int evt)
 {
        struct state *st = &states[get_pm_cur_state()];
        enum state_t next_state;
+       int ret = 0;
 
        display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
 
        /* check conditions */
-       if (st->check && !st->check(get_pm_cur_state(), next_state)) {
+       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
+       if (ret < 0) {
                /* There is a condition. */
                _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name,
                       states[next_state].name);
@@ -1030,45 +1030,6 @@ go_lcd_off:
        return 0;
 }
 
-/*
- * default check function
- *   return
- *    0 : can't transit, others : transitable
- */
-static int default_check(int curr, int next)
-{
-       int trans_cond;
-
-       makeup_trans_condition();
-
-       trans_cond = get_trans_condition() & MASK_BIT;
-
-       if (next == S_NORMAL) /* S_NORMAL is exceptional */
-               return 1;
-
-       switch (curr) {
-       case S_NORMAL:
-               trans_cond = trans_cond & MASK_NORMAL;
-               break;
-       case S_LCDDIM:
-               trans_cond = trans_cond & MASK_DIM;
-               break;
-       case S_LCDOFF:
-               trans_cond = trans_cond & MASK_OFF;
-               break;
-       default:
-               trans_cond = 0;
-               break;
-       }
-
-       if (trans_cond != 0) {
-               print_node(curr);
-               return 0;
-       }
-
-       return 1;               /* transitable */
-}
-
 static void default_saving_mode(int onoff)
 {
        if (onoff)
index 6794768..32a23c2 100644 (file)
@@ -113,18 +113,17 @@ static bool touch_blocked = false;
 /* default transition, action fuctions */
 static int default_trans(int evt);
 static int default_action(int timeout);
-static int default_check(int curr, int next);
 
 static int default_proc_change_state(unsigned int cond, pid_t pid);
 static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state;
 
 static struct state states[S_END] = {
        { S_START,    "S_START",    NULL,          NULL,           NULL,          NULL            },
-       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, default_check, NULL            },
-       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, default_check, NULL            },
-       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, default_check, NULL            },
+       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, NULL,          NULL            },
        { S_STANDBY,  "S_STANDBY",  NULL,          NULL,           NULL,          NULL            },
-       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, default_check, NULL            },
+       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, NULL,          NULL            },
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
@@ -798,11 +797,13 @@ static int default_trans(int evt)
 {
        struct state *st = &states[get_pm_cur_state()];
        enum state_t next_state;
+       int ret = 0;
 
        display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
 
        /* check conditions */
-       if (st->check && !st->check(get_pm_cur_state(), next_state)) {
+       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
+       if (ret < 0) {
                /* There is a condition. */
                _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name,
                       states[next_state].name);
@@ -1019,45 +1020,6 @@ go_lcd_off:
        return 0;
 }
 
-/*
- * default check function
- *   return
- *    0 : can't transit, others : transitable
- */
-static int default_check(int curr, int next)
-{
-       int trans_cond;
-
-       makeup_trans_condition();
-
-       trans_cond = get_trans_condition() & MASK_BIT;
-
-       if (next == S_NORMAL) /* S_NORMAL is exceptional */
-               return 1;
-
-       switch (curr) {
-       case S_NORMAL:
-               trans_cond = trans_cond & MASK_NORMAL;
-               break;
-       case S_LCDDIM:
-               trans_cond = trans_cond & MASK_DIM;
-               break;
-       case S_LCDOFF:
-               trans_cond = trans_cond & MASK_OFF;
-               break;
-       default:
-               trans_cond = 0;
-               break;
-       }
-
-       if (trans_cond != 0) {
-               print_node(curr);
-               return 0;
-       }
-
-       return 1;               /* transitable */
-}
-
 static void default_saving_mode(int onoff)
 {
        if (onoff)
index 600c6f2..e3bd04d 100644 (file)
@@ -126,18 +126,17 @@ static bool touch_blocked = false;
 /* default transition, action fuctions */
 static int default_trans(int evt);
 static int default_action(int timeout);
-static int default_check(int curr, int next);
 
 static int default_proc_change_state(unsigned int cond, pid_t pid);
 static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state;
 
 static struct state states[S_END] = {
        { S_START,    "S_START",    NULL,          NULL,           NULL,          NULL            },
-       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, default_check, NULL            },
-       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, default_check, NULL            },
-       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, default_check, NULL            },
+       { S_NORMAL,   "S_NORMAL",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDDIM,   "S_LCDDIM",   default_trans, default_action, NULL,          NULL            },
+       { S_LCDOFF,   "S_LCDOFF",   default_trans, default_action, NULL,          NULL            },
        { S_STANDBY,  "S_STANDBY",  NULL,          NULL,           NULL,          NULL            },
-       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, default_check, NULL            },
+       { S_SLEEP,    "S_SLEEP",    default_trans, default_action, NULL,          NULL            },
        { S_POWEROFF, "S_POWEROFF", NULL,          NULL,           NULL,          NULL            },
 };
 
@@ -1138,7 +1137,8 @@ static int default_trans(int evt)
        display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
 
        /* check conditions */
-       if (st->check && !st->check(get_pm_cur_state(), next_state)) {
+       ret = display_state_transition_check_state_transition_condition(get_pm_cur_state(), next_state);
+       if (ret < 0) {
                /* There is a condition. */
                _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name,
                       states[next_state].name);
@@ -1375,45 +1375,6 @@ go_lcd_off:
        return 0;
 }
 
-/*
- * default check function
- *   return
- *    0 : can't transit, others : transitable
- */
-static int default_check(int curr, int next)
-{
-       int trans_cond;
-
-       makeup_trans_condition();
-
-       trans_cond = get_trans_condition() & MASK_BIT;
-
-       if (next == S_NORMAL) /* S_NORMAL is exceptional */
-               return 1;
-
-       switch (curr) {
-       case S_NORMAL:
-               trans_cond = trans_cond & MASK_NORMAL;
-               break;
-       case S_LCDDIM:
-               trans_cond = trans_cond & MASK_DIM;
-               break;
-       case S_LCDOFF:
-               trans_cond = trans_cond & MASK_OFF;
-               break;
-       default:
-               trans_cond = 0;
-               break;
-       }
-
-       if (trans_cond != 0) {
-               print_node(curr);
-               return 0;
-       }
-
-       return 1;               /* transitable */
-}
-
 static void default_saving_mode(int onoff)
 {
        if (onoff) {
index 9985701..2e7ffac 100644 (file)
@@ -166,14 +166,6 @@ int display_plugin_state_do_default_action(enum state_t state, int timeout)
        return -EOPNOTSUPP;
 }
 
-int display_plugin_state_do_default_check(enum state_t state, int curr, int next)
-{
-       if (g_display_plugin.display_states[state] && g_display_plugin.display_states[state]->check)
-               return g_display_plugin.display_states[state]->check(curr, next);
-
-       return -EOPNOTSUPP;
-}
-
 int display_plugin_state_get_name(enum state_t state, const char **state_name)
 {
        if (!state_name)
index fe88489..09d8aa3 100644 (file)
@@ -97,7 +97,6 @@ int display_plugin_backlight_transit_brightness(int start, int end, int step);
 int display_plugin_state_do_default_trans(enum state_t state, int evt);
 bool display_plugin_state_is_there_default_trans(enum state_t state);
 int display_plugin_state_do_default_action(enum state_t state, int timeout);
-int display_plugin_state_do_default_check(enum state_t state, int curr, int next);
 int display_plugin_state_get_name(enum state_t state, const char **state_name);
 int display_plugin_state_set_timeout(enum state_t state, int state_timeout);
 int display_plugin_state_get_timeout(enum state_t state, int *state_timeout);
index 5676860..002f838 100644 (file)
@@ -224,4 +224,56 @@ void display_state_transition_update_display_state_timeout_by_priority(void)
        display_plugin_state_get_timeout(S_LCDDIM, &dim_state_timeout);
        _I("Normal: NORMAL timeout is set by %d ms", normal_state_timeout);
        _I("Normal: DIM timeout is set by %d ms", dim_state_timeout);
+}
+
+static bool is_display_state_valid_for_transition(enum state_t state)
+{
+       switch(state) {
+       case S_NORMAL:
+       case S_LCDDIM:
+       case S_LCDOFF:
+       case S_SLEEP:
+               return true;
+       default:
+               return false;
+       }
+
+       return false;
+}
+
+int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state)
+{
+       int trans_cond;
+
+       if (!is_display_state_valid_for_transition(cur_state))
+               return -EPERM;
+
+       makeup_trans_condition();
+
+       trans_cond = get_trans_condition() & MASK_BIT;
+
+       if (next_state == S_NORMAL) /* S_NORMAL is exceptional */
+               return 0;
+
+       switch (cur_state) {
+       case S_NORMAL:
+               trans_cond = trans_cond & MASK_NORMAL;
+               break;
+       case S_LCDDIM:
+               trans_cond = trans_cond & MASK_DIM;
+               break;
+       case S_LCDOFF:
+               trans_cond = trans_cond & MASK_OFF;
+               break;
+       default:
+               trans_cond = 0;
+               break;
+       }
+
+       if (trans_cond != 0) {
+               print_node(cur_state);
+               return -EPERM;
+       }
+
+       return 0;               /* transitable */
 }
\ No newline at end of file
index 51762a1..caed462 100644 (file)
@@ -37,5 +37,6 @@ int display_state_transition_get_custom_timeout(enum state_t state, unsigned int
 int display_state_transition_set_lock_screen_timeout(int timeout);
 int display_state_transition_get_lock_screen_timeout(int *timeout);
 void display_state_transition_update_display_state_timeout_by_priority(void);
+int display_state_transition_check_state_transition_condition(enum state_t cur_state, enum state_t next_state);
 
 #endif /* __DISPLAY_STATE_TRANSITION_H__ */
\ No newline at end of file