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