power: change state only when it is explicitly specified 43/276543/5 accepted/tizen/unified/20220626.224815 submit/tizen/20220624.005127
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 20 Jun 2022 07:57:46 +0000 (16:57 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 21 Jun 2022 02:26:27 +0000 (11:26 +0900)
It might not to change state if there is no defined ActionChangeState.

Change-Id: I16f6bd7992722787d2a95cc38c6764db81b67238
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
conf/init.conf
src/power/power-boot.c
src/power/power-boot.h
src/power/power.c

index 22c910d..3b19f18 100644 (file)
@@ -9,3 +9,9 @@ ActionChangeState=start,normal
 Enum=3001
 BootReason=charger
 ActionChangeState=start,sleep
+
+[EventAction]
+#INITIAL_STATE_BY_SILENT_REBOOT
+#Do no action. Stay in POWER_STATE_START on booting.
+Enum=3002
+BootReason=reboot
index 9926b68..ff6ba8a 100644 (file)
@@ -43,8 +43,8 @@
 
 static struct trans_info init_ti = {
        .reason = -1,
-       .curr = POWER_STATE_START,
-       .next = POWER_STATE_NORMAL,
+       .curr = 0,
+       .next = 0,
 };
 
 static guint sig_id[2] = {0, 0};
@@ -160,15 +160,20 @@ static int parse_matching_bootreason(const struct parse_result *result, void *da
        return 0;
 }
 
-void do_initial_transition_by_bootreason(void)
+void initial_transition_by_bootreason(void)
 {
        int retval;
        char bootreason[64] = "Unknown";
 
        retval = hal_device_board_get_boot_reason(bootreason, sizeof(bootreason));
-       if (retval == 0)
-               libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason);
+       if (retval != 0) {
+               _I("Failed to get BootReason, %d. Default change state to normal.", retval);
+               power_request_change_state_strict(POWER_STATE_START, POWER_STATE_NORMAL, 1, NULL);
+               return;
+       }
 
        CRITICAL_LOG("BootReason=%s", bootreason);
+       libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason);
+
        power_request_change_state_strict(init_ti.curr, init_ti.next, init_ti.reason, NULL);
 }
index c0fcda6..cdabd28 100644 (file)
@@ -21,7 +21,7 @@
 
 void add_delayed_init_done_handler(void *data);
 void remove_delayed_init_done_handler(void *data);
-void do_initial_transition_by_bootreason(void);
+void initial_transition_by_bootreason(void);
 
 extern int silent_boot;
 
index 793a4a0..43cd084 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#include <inttypes.h>
 #include <linux/input.h>
 #include <libsyscommon/libgdbus.h>
 #include <libsyscommon/list.h>
@@ -245,6 +246,12 @@ static int power_transition_state(void *data)
        if (!ti)
                return 0;
 
+       // check invalid next state
+       if (__builtin_popcountll(ti->next & POWER_STATE_ALL) != 1) {
+               _E("Invalid next state, curr=%"PRIx64", next=%"PRIx64", reason=%d", ti->curr, ti->next, ti->reason);
+               return 0;
+       }
+
        // defer state transition until delayed_init_done unless it is transition to poweroff.
        // poweroff shall be handled immediately regardless of the delayed_init_done.
        if (!delayed_init_done && !is_poweroff_state(ti->next)) {
@@ -303,9 +310,9 @@ void power_state_init(void *data)
        /* Take the first transition.
         *
         * It is determined by bootreason to which state to transition, POWER_STATE_NORMAL or POWER_STATE_SLEEP.
-        * Normally, it will be transitioned to the POWER_STATE_NORMAL unless there is configuration for
-        * the initial state in init.conf. */
-       do_initial_transition_by_bootreason();
+        * Or it may stay in POWER_STATE_START if there is no defined action for the matching bootreason.
+        */
+       initial_transition_by_bootreason();
 }
 
 static const struct device_ops power_state_device_ops = {