2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
20 #include <sys/types.h>
26 #include <Ecore_Wl2.h>
29 #include <systemd/sd-daemon.h>
30 #include <ode/internal-encryption.h>
40 #include "process_mgr.h"
44 #include "dbus_util.h"
46 static void _set_starter_sequence(int val)
48 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, val);
53 static void _signal_handler(int signum, siginfo_t *info, void *unused)
55 _D("_signal_handler : Terminated...");
61 static int _power_off_cb(status_active_key_e key, void *data)
63 int val = status_active_get()->sysman_power_off_status;
65 if (val > VCONFKEY_SYSMAN_POWER_OFF_NONE) {
66 _D("_power_off_cb : Terminated...");
75 static void _language_changed_cb(keynode_t *node, void *data)
81 lang = vconf_keynode_get_str(node);
84 _D("language is changed : %s", lang);
86 elm_language_set(lang);
91 static int _set_i18n(const char *domain, const char *dir)
100 char *lang = vconf_get_str(VCONFKEY_LANGSET);
101 r = setlocale(LC_ALL, lang);
103 _E("setlocale() error");
109 r = bindtextdomain(domain, dir);
111 _E("bindtextdomain() error");
114 r = textdomain(domain);
116 _E("textdomain() error");
119 if (vconf_notify_key_changed(VCONFKEY_LANGSET, _language_changed_cb, NULL) < 0) {
120 _E("Failed to register changed cb : %s", VCONFKEY_LANGSET);
128 static int _check_dead_signal(int pid, void *data)
132 int indicator_pid = 0;
133 int quickpanel_pid = 0;
137 _D("Process %d is termianted", pid);
145 * starter try to re-launch these apps when the app is dead.
147 home_pid = home_mgr_get_home_pid();
148 volume_pid = home_mgr_get_volume_pid();
149 indicator_pid = home_mgr_get_indicator_pid();
150 quickpanel_pid = home_mgr_get_quickpanel_pid();
151 tray_pid = home_mgr_get_tray_pid();
152 lock_pid = lock_mgr_get_lock_pid();
154 if (pid == home_pid) {
155 _D("Homescreen is dead");
156 home_mgr_relaunch_homescreen();
157 } else if (pid == volume_pid) {
158 _D("volume is dead");
159 home_mgr_relaunch_volume();
160 } else if (pid == indicator_pid) {
161 _D("indicator is dead");
162 home_mgr_relaunch_indicator();
163 } else if (pid == quickpanel_pid) {
164 _D("quickpanel is dead");
165 home_mgr_relaunch_quickpanel();
166 } else if (pid == tray_pid) {
168 home_mgr_relaunch_tray();
169 } else if (pid == lock_pid) {
170 _D("lockscreen is dead");
173 _D("Unknown process, ignore it");
181 static void _launch_apps(void)
183 /* Tells the service manager that service startup is finished */
184 sd_notify(0, "READY=1");
187 * After user data partition mount,
188 * launch lockscreen, homescreen, etc.
194 * Set the starter sequence vconfkey.
195 * '1' menas that booting seqeunce is done.
197 _set_starter_sequence(1);
202 static void _init(void)
204 struct sigaction act;
205 char err_buf[128] = { 0, };
208 memset(&act, 0x00, sizeof(struct sigaction));
209 act.sa_sigaction = _signal_handler;
210 act.sa_flags = SA_SIGINFO;
212 ret = sigemptyset(&act.sa_mask);
214 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
215 _E("Failed to sigemptyset[%d / %s]", errno, err_buf);
218 ret = sigaddset(&act.sa_mask, SIGTERM);
220 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
221 _E("Failed to sigaddset[%d / %s]", errno, err_buf);
224 ret = sigaction(SIGTERM, &act, NULL);
226 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
227 _E("Failed to sigaction[%d / %s]", errno, err_buf);
231 _set_i18n(PACKAGE, LOCALEDIR);
234 status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
238 hw_key_create_window();
241 * Initialize starter sequence vconfkey.
243 _set_starter_sequence(0);
245 ret = starter_execute_ode_process(BEFORE_LOCKSCREEN);
247 _E("Failed to execute ode process");
250 aul_listen_app_dead_signal(_check_dead_signal, NULL);
255 static void _fini(void)
260 hw_key_destroy_window();
264 status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
267 if (vconf_ignore_key_changed(VCONFKEY_LANGSET, _language_changed_cb) < 0) {
268 _E("Failed to unregister changed cb : %s", VCONFKEY_LANGSET);
274 int main(int argc, char *argv[])
277 Ecore_Wl2_Display *display = NULL;
278 struct wl_display *displ = NULL;
280 _D("starter is launched..!!");
282 ret = elm_init(argc, argv);
284 _E("elm_init() failed : %d", ret);
288 ret = ecore_wl2_init();
290 _E("ecore_wl2_init() failed : %d", ret);
295 displ = ecore_wl2_display_get(NULL);
297 _W("There's no display");
298 display = ecore_wl2_display_connect(NULL);
300 _E("Failed to connect display");
313 ecore_wl2_display_disconnect(display);
314 ecore_wl2_shutdown();
324 static void _mount_complete_cb(void *user_data)
326 _D("Mount is successfully completed");
331 int starter_execute_ode_process(int booting_state)
333 _D("This call is before or after Lockscreen: %d", booting_state);
334 int ret = ODE_ERROR_NONE;
337 ret = ode_internal_encryption_get_state(&ode_state);
338 if (ret != ODE_ERROR_NONE) {
339 _E("Failed to get ODE state, ret: %d", ret);
343 if (booting_state == BEFORE_LOCKSCREEN) {
344 if (ode_state == ODE_STATE_ENCRYPTED) {
347 ret = ode_internal_encryption_set_mount_event_cb(_mount_complete_cb, NULL);
348 if (ret != ODE_ERROR_NONE) {
349 _E("Failed to set mount event cb");
354 } else if (booting_state == AFTER_LOCKSCREEN) {
355 if (ode_state == ODE_STATE_ENCRYPTED) {
356 _D("ODE state is: %d, and we should mount at this time", ode_state);
358 ret = ode_internal_encryption_mount();
359 if (ret != ODE_ERROR_NONE) {
360 _E("Failed to mount");
364 sd_notify(0, "READY=1");
367 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
369 _D("ODE state is: %d, Do nothing", ode_state);