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 <libgdbus/dbus-system.h>
26 #include "core/device-notifier.h"
27 #include "core/common.h"
28 #include "display/poll.h"
29 #include "shared/deviced-systemd.h"
31 #define SIGNAL_BOOTING_DONE "BootingDone"
33 #define SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED "StartupFinished"
34 #define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED "UserSessionStartupFinished"
35 #define SYSTEMD_DBUS_METHOD_SYSTEM_STATE "SystemState"
36 #define SYSTEMD_STATE_RUNNING "running"
37 #define SYSTEMD_STATE_DEGRADED "degraded"
39 int booting_finished(void)
44 GVariant *reply = NULL;
46 reply = deviced_systemd_get_manager_property(SYSTEMD_DBUS_METHOD_SYSTEM_STATE);
48 _E("Failed to get System State: no reply");
51 if (!dh_get_param_from_var(reply, "s", &state)) {
52 _E("Failed to get System State %s", g_variant_get_type_string(reply));
56 _I("System State: (%s)", state);
58 len = strlen(state) + 1;
59 if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) ||
60 !strncmp(state, SYSTEMD_STATE_DEGRADED, len))
67 g_variant_unref(reply);
73 static guint sig_id[2] = {0, 0};
75 void remove_booting_done_handler(void *data)
77 unsubscribe_dbus_signal(NULL, sig_id[0]);
78 unsubscribe_dbus_signal(NULL, sig_id[1]);
81 static void booting_done_received(GDBusConnection *conn,
90 static int system_done = 0;
91 static int user_done = 0;
93 if (strcmp(name, SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED) == 0) {
97 system_done = booting_finished();
98 if (system_done == 0) {
99 _E("System Session is not ready yet");
102 _I("System Session is Ready");
103 device_notify(DEVICE_NOTIFIER_BOOTING_DONE, &system_done);
105 } else if (strcmp(name, SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED) == 0) {
109 _I("User Session is Ready");
112 if (!system_done || !user_done)
115 remove_booting_done_handler(NULL);
117 _I("real booting done, unlock LCD_OFF");
118 pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN);
120 _I("signal booting done");
122 dbus_handle_broadcast_dbus_signal(DEVICED_PATH_CORE,
123 DEVICED_INTERFACE_CORE,
128 void add_booting_done_handler(void *data)
130 /* System Session is loaded completely */
132 sig_id[0] = subscribe_dbus_signal(NULL,
134 SYSTEMD_DBUS_IFACE_MANAGER,
135 SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED,
136 booting_done_received,
140 _E("fail to init dbus signal(%s)", SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED);
142 /* User Session is loaded completely */
143 sig_id[1] = subscribe_dbus_signal(NULL,
145 SYSTEMD_DBUS_IFACE_MANAGER,
146 SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED,
147 booting_done_received,
151 _E("fail to init dbus signal(%s)", SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED);