4 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <eventsystem.h>
23 #include <libsyscommon/libgdbus.h>
24 #include <libsyscommon/libsystemd.h>
25 #include <libsyscommon/list.h>
26 #include <libsyscommon/file.h>
27 #include <libsyscommon/ini-parser.h>
28 #include <hal/device/hal-board.h>
31 #include "shared/device-notifier.h"
32 #include "shared/common.h"
33 #include "display/poll.h"
34 #include "display/display-ops.h"
35 #include "shared/plugin.h"
36 #include "power-doze.h"
37 #include "power-state-manager.h"
39 #define SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED "StartupFinished"
40 #define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED "UserSessionStartupFinished"
42 #define INIT_CONF_PATH "/etc/deviced/init.conf"
44 static struct trans_info initial_transition_info = {
50 static guint sig_id[2] = {0, 0};
52 void remove_delayed_init_done_handler(void *data)
54 gdbus_signal_unsubscribe(NULL, sig_id[0]);
55 gdbus_signal_unsubscribe(NULL, sig_id[1]);
58 static void delayed_init_done_received(GDBusConnection *conn,
66 static int system_done = 0;
67 static int user_done = 0;
69 if (strcmp(name, SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED) == 0) {
73 system_done = check_system_boot_finished();
74 if (system_done == 0) {
75 _E("System session is not ready yet.");
78 CRITICAL_LOG("System session is ready.");
79 device_notify_once(DEVICE_NOTIFIER_DELAYED_INIT, &system_done);
81 } else if (strcmp(name, SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED) == 0) {
85 _I("User session is ready.");
88 if (!system_done || !user_done)
91 remove_delayed_init_done_handler(NULL);
96 void add_delayed_init_done_handler(void *data)
98 /* System Session is loaded completely */
100 sig_id[0] = gdbus_signal_subscribe(NULL,
102 SYSTEMD_DBUS_IFACE_MANAGER,
103 SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED,
104 delayed_init_done_received,
108 _E("Failed to init dbus signal(%s).", SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED);
110 /* User Session is loaded completely */
111 sig_id[1] = gdbus_signal_subscribe(NULL,
113 SYSTEMD_DBUS_IFACE_MANAGER,
114 SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED,
115 delayed_init_done_received,
119 _E("Failed to init dbus signal(%s).", SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED);
122 static void parse_transition_info(const char *action)
124 char curr[16] = { 0, };
125 char next[16] = { 0, };
127 if (sscanf(action, "%15[^,],%15s", curr, next) == 2) {
128 initial_transition_info.curr = convert_action_string_to_psm_state(curr);
129 initial_transition_info.next = convert_action_string_to_psm_state(next);
133 static void parse_initial_transition_info(const struct parse_result *result)
136 struct section_property *prop;
138 SYS_G_LIST_FOREACH(result->props, elem, prop) {
139 if (MATCH(prop->key, "Enum"))
140 initial_transition_info.reason = atoi(prop->value);
141 else if (MATCH(prop->key, "Action"))
142 parse_transition_info(prop->value);
146 static int parse_matching_bootreason(const struct parse_result *result, void *data)
149 struct section_property *prop;
150 char *bootreason = (char *) data;
152 if (!MATCH(result->section, "EventAction"))
155 SYS_G_LIST_FOREACH(result->props, elem, prop) {
156 if (MATCH(prop->key, "BootReason") && MATCH(prop->value, bootreason))
157 parse_initial_transition_info(result);
163 /* the initial transition by bootreason is defined in init.conf */
164 void get_initial_transition_by_bootreason(void *data)
167 char bootreason[64] = "Unknown";
168 GList **head = (GList **) data;
173 retval = hal_device_board_get_boot_reason(bootreason, sizeof(bootreason));
175 libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason);
177 CRITICAL_LOG("BootReason=%s", bootreason);
179 *head = g_list_append(*head, &initial_transition_info);