Fixed build warnings
[apps/native/starter.git] / src / mobile / starter.c
1 /*
2  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <Elementary.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <string.h>
25
26 #include <aul.h>
27 #include <vconf.h>
28 #include <signal.h>
29
30 #include "starter.h"
31 #include "lock_mgr.h"
32 #include "lock_pwd_util.h"
33 #include "lock_pwd_control_panel.h"
34 #include "home_mgr.h"
35 #include "hw_key.h"
36 #include "process_mgr.h"
37 #include "util.h"
38 #include "status.h"
39 #include "hw_key.h"
40
41 #define PWLOCK_LITE_PKG_NAME "org.tizen.pwlock-lite"
42
43 #define DATA_UNENCRYPTED "unencrypted"
44 #define DATA_MOUNTED "mounted"
45 #define SD_DATA_ENCRYPTED "encrypted"
46 #define SD_CRYPT_META_FILE ".MetaEcfsFile"
47 #define MMC_MOUNT_POINT "/opt/storage/sdcard"
48
49
50
51 static void _hide_home(void)
52 {
53         int seq = status_active_get()->starter_sequence;
54         ret_if(seq == 1);
55
56         vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
57 }
58
59
60
61 static void _show_home(void)
62 {
63         int show_menu = 0;
64
65         if (status_active_get()->starter_sequence || !show_menu) {
66                 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
67         }
68 }
69
70
71
72 #if 0
73 static Eina_Bool _finish_boot_animation(void *data)
74 {
75         if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) {
76                 _E("Failed to set boot animation finished set");
77         }
78         _show_home();
79
80         return ECORE_CALLBACK_CANCEL;
81 }
82
83
84
85 static int _fail_to_launch_pwlock(const char *appid, const char *key, const char *value, void *cfn, void *afn)
86 {
87         _finish_boot_animation(NULL);
88         return 0;
89 }
90
91
92
93 static void _after_launch_pwlock(int pid)
94 {
95         process_mgr_set_pwlock_priority(pid);
96         ecore_timer_add(0.5, _finish_boot_animation, NULL);
97 }
98 #endif
99
100
101
102 static void _signal_handler(int signum, siginfo_t *info, void *unused)
103 {
104     _D("_signal_handler : Terminated...");
105     elm_exit();
106 }
107
108
109
110 static int _power_off_cb(status_active_key_e key, void *data)
111 {
112         int val = status_active_get()->sysman_power_off_status;
113
114         if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT
115                 || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART)
116         {
117             _D("_power_off_cb : Terminated...");
118             elm_exit();
119         }
120
121         return 1;
122 }
123
124
125
126 static int _boot_animation_finished_cb(status_active_key_e key, void *data)
127 {
128         int val = status_active_get()->boot_animation_finished;
129         _D("boot animation finished : %d", val);
130
131         if (val == 1) {
132                 lock_mgr_daemon_start();
133                 _show_home();
134         }
135
136         return 1;
137 }
138
139
140
141 static void _language_changed_cb(keynode_t *node, void *data)
142 {
143         char *lang = NULL;
144
145         ret_if(!node);
146
147         lang = vconf_keynode_get_str(node);
148         ret_if(!lang);
149
150         _D("language is changed : %s", lang);
151
152         elm_language_set(lang);
153
154         lock_pwd_util_view_init();
155         lock_pwd_control_panel_emg_btn_text_update();
156 }
157
158
159
160 static int _set_i18n(const char *domain, const char *dir)
161 {
162         char *r = NULL;
163
164         if (domain == NULL) {
165                 errno = EINVAL;
166                 return -1;
167         }
168
169         char *lang = vconf_get_str(VCONFKEY_LANGSET);
170         r = setlocale(LC_ALL, lang);
171         if (!r) {
172                 _E("setlocale() error");
173         }
174         if (lang) {
175                 free(lang);
176         }
177
178         r = bindtextdomain(domain, dir);
179         if (!r) {
180                 _E("bindtextdomain() error");
181         }
182
183         r = textdomain(domain);
184         if (!r) {
185                 _E("textdomain() error");
186         }
187
188         if (vconf_notify_key_changed(VCONFKEY_LANGSET, _language_changed_cb, NULL) < 0) {
189                 _E("Failed to register changed cb : %s", VCONFKEY_LANGSET);
190         }
191
192         return 0;
193 }
194
195
196
197 static int _check_dead_signal(int pid, void *data)
198 {
199         int home_pid = 0;
200         int volume_pid = 0;
201         int indicator_pid = 0;
202         int quickpanel_pid = 0;
203         int lock_pid = 0;
204
205         _D("Process %d is termianted", pid);
206
207         if (pid < 0) {
208                 _E("pid : %d", pid);
209                 return 0;
210         }
211
212         home_pid = home_mgr_get_home_pid();
213         volume_pid = home_mgr_get_volume_pid();
214         indicator_pid = home_mgr_get_indicator_pid();
215         quickpanel_pid = home_mgr_get_quickpanel_pid();
216         lock_pid = lock_mgr_get_lock_pid();
217
218         if (pid == home_pid) {
219                 _D("Homescreen is dead");
220                 home_mgr_relaunch_homescreen();
221         } else if (pid == volume_pid) {
222                 _D("volume is dead");
223                 home_mgr_relaunch_volume();
224         } else if (pid == indicator_pid) {
225                 _D("indicator is dead");
226                 home_mgr_relaunch_indicator();
227         } else if (pid == quickpanel_pid) {
228                 _D("quickpanel is dead");
229                 home_mgr_relaunch_quickpanel();
230         } else if (pid == lock_pid) {
231                 _D("lockscreen is dead");
232                 lock_mgr_unlock();
233         } else {
234                 _D("Unknown process, ignore it");
235         }
236
237         return 0;
238 }
239
240
241
242 static void _init(struct appdata *ad)
243 {
244         struct sigaction act;
245         char err_buf[128] = {0,};
246
247         memset(&act,0x00,sizeof(struct sigaction));
248         act.sa_sigaction = _signal_handler;
249         act.sa_flags = SA_SIGINFO;
250
251         int ret = sigemptyset(&act.sa_mask);
252         if (ret < 0) {
253                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
254                         _E("Failed to sigemptyset[%d / %s]", errno, err_buf);
255                 }
256         }
257         ret = sigaddset(&act.sa_mask, SIGTERM);
258         if (ret < 0) {
259                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
260                         _E("Failed to sigaddset[%d / %s]", errno, err_buf);
261                 }
262         }
263         ret = sigaction(SIGTERM, &act, NULL);
264         if (ret < 0) {
265                 if (strerror_r(errno, err_buf, sizeof(err_buf)) == 0) {
266                         _E("Failed to sigaction[%d / %s]", errno, err_buf);
267                 }
268         }
269
270         _set_i18n(PACKAGE, LOCALEDIR);
271
272         status_register();
273         status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
274         status_active_register_cb(STATUS_ACTIVE_KEY_BOOT_ANIMATION_FINISHED, _boot_animation_finished_cb, NULL);
275
276         /* Ordering : _hide_home -> process_mgr_must_launch(pwlock) -> _show_home */
277         _hide_home();
278 #if 0
279         process_mgr_must_launch(PWLOCK_LITE_PKG_NAME, NULL, NULL, _fail_to_launch_pwlock, _after_launch_pwlock);
280 #endif
281
282         hw_key_create_window();
283         home_mgr_init(NULL);
284
285         aul_listen_app_dead_signal(_check_dead_signal, NULL);
286 }
287
288
289
290 static void _fini(struct appdata *ad)
291 {
292         home_mgr_fini();
293         hw_key_destroy_window();
294         lock_mgr_daemon_end();
295
296         status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
297         status_active_unregister_cb(STATUS_ACTIVE_KEY_BOOT_ANIMATION_FINISHED, _boot_animation_finished_cb);
298         status_unregister();
299
300         if (vconf_ignore_key_changed(VCONFKEY_LANGSET, _language_changed_cb) < 0) {
301                 _E("Failed to unregister changed cb : %s", VCONFKEY_LANGSET);
302         }
303 }
304
305
306
307 int main(int argc, char *argv[])
308 {
309         struct appdata ad;
310
311         _D("starter is launched..!!");
312
313         elm_init(argc, argv);
314         _init(&ad);
315
316         elm_run();
317
318         _fini(&ad);
319         elm_shutdown();
320
321         return 0;
322 }