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>
28 #include <lazy_mount.h>
29 #include <systemd/sd-daemon.h>
39 #include "process_mgr.h"
43 #include "dbus_util.h"
45 #define APPID_SYS_LOCK "org.tizen.sys-lock"
48 static void _set_starter_sequence(int val)
50 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, val);
55 static void _signal_handler(int signum, siginfo_t *info, void *unused)
57 _D("_signal_handler : Terminated...");
63 static int _power_off_cb(status_active_key_e key, void *data)
65 int val = status_active_get()->sysman_power_off_status;
67 if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT
68 || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART)
70 _D("_power_off_cb : Terminated...");
79 static void _language_changed_cb(keynode_t *node, void *data)
85 lang = vconf_keynode_get_str(node);
88 _D("language is changed : %s", lang);
90 elm_language_set(lang);
95 static int _set_i18n(const char *domain, const char *dir)
104 char *lang = vconf_get_str(VCONFKEY_LANGSET);
105 r = setlocale(LC_ALL, lang);
107 _E("setlocale() error");
113 r = bindtextdomain(domain, dir);
115 _E("bindtextdomain() error");
118 r = textdomain(domain);
120 _E("textdomain() error");
123 if (vconf_notify_key_changed(VCONFKEY_LANGSET, _language_changed_cb, NULL) < 0) {
124 _E("Failed to register changed cb : %s", VCONFKEY_LANGSET);
132 static int _check_dead_signal(int pid, void *data)
136 int indicator_pid = 0;
137 int quickpanel_pid = 0;
140 _D("Process %d is termianted", pid);
148 * starter try to re-launch these apps when the app is dead.
150 home_pid = home_mgr_get_home_pid();
151 volume_pid = home_mgr_get_volume_pid();
152 indicator_pid = home_mgr_get_indicator_pid();
153 quickpanel_pid = home_mgr_get_quickpanel_pid();
154 lock_pid = lock_mgr_get_lock_pid();
156 if (pid == home_pid) {
157 _D("Homescreen is dead");
158 home_mgr_relaunch_homescreen();
159 } else if (pid == volume_pid) {
160 _D("volume is dead");
161 home_mgr_relaunch_volume();
162 } else if (pid == indicator_pid) {
163 _D("indicator is dead");
164 home_mgr_relaunch_indicator();
165 } else if (pid == quickpanel_pid) {
166 _D("quickpanel is dead");
167 home_mgr_relaunch_quickpanel();
168 } else if (pid == lock_pid) {
169 _D("lockscreen is dead");
172 _D("Unknown process, ignore it");
180 static void _mount_and_launch_apps(void)
185 * Do mount user data partition
187 ret = do_mount_user();
189 _E("Failed to do mount [/opt] area");
194 * Wait user data partition mount
196 ret = wait_mount_user();
198 _E("Failed to wait mount [/opt] area");
202 /* Tells the service manager that service startup is finished */
203 sd_notify(0, "READY=1");
206 * After user data partition mount,
207 * launch lockscreen, homescreen, etc.
213 * Set the starter sequence vconfkey.
214 * '1' menas that booting seqeunce is done.
216 _set_starter_sequence(1);
221 static void _sys_lock_status_changed_cb(void *data, DBusMessage *msg)
225 is_unlock = dbus_message_is_signal(msg, SYS_LOCK_INTERFACE_UNLOCK, SYS_LOCK_MEMBER_UNLOCK);
227 _D("sys-lock signal is received. unlock state(%d).", is_unlock);
230 _mount_and_launch_apps();
233 * Send DBus signal to terminate sys-lock
235 dbus_util_send_sys_lock_teminate_signal();
241 static void _init(struct appdata *ad)
243 struct sigaction act;
244 char err_buf[128] = { 0, };
245 int is_lazy_mount = 0;
248 memset(&act,0x00,sizeof(struct sigaction));
249 act.sa_sigaction = _signal_handler;
250 act.sa_flags = SA_SIGINFO;
252 ret = sigemptyset(&act.sa_mask);
254 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
255 _E("Failed to sigemptyset[%d / %s]", errno, err_buf);
258 ret = sigaddset(&act.sa_mask, SIGTERM);
260 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
261 _E("Failed to sigaddset[%d / %s]", errno, err_buf);
264 ret = sigaction(SIGTERM, &act, NULL);
266 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
267 _E("Failed to sigaction[%d / %s]", errno, err_buf);
271 _set_i18n(PACKAGE, LOCALEDIR);
274 status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
278 hw_key_create_window();
281 * Initialize starter sequence vconfkey.
283 _set_starter_sequence(0);
285 is_lazy_mount = get_need_ui_for_lazy_mount();
286 _D("Lazy mount : %d", is_lazy_mount);
291 process_mgr_must_launch(APPID_SYS_LOCK, NULL, NULL, NULL, NULL);
294 * Register sys-lock status changed cb
296 dbus_util_receive_sys_lock_status(_sys_lock_status_changed_cb, NULL);
298 _mount_and_launch_apps();
301 aul_listen_app_dead_signal(_check_dead_signal, NULL);
306 static void _fini(struct appdata *ad)
311 hw_key_destroy_window();
315 status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
318 if (vconf_ignore_key_changed(VCONFKEY_LANGSET, _language_changed_cb) < 0) {
319 _E("Failed to unregister changed cb : %s", VCONFKEY_LANGSET);
325 int main(int argc, char *argv[])
329 _D("starter is launched..!!");
331 elm_init(argc, argv);