tizen 2.4 release
[apps/home/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
40 #define PWLOCK_LITE_PKG_NAME "org.tizen.pwlock"
41
42 #define DATA_UNENCRYPTED "unencrypted"
43 #define DATA_MOUNTED "mounted"
44 #define SD_DATA_ENCRYPTED "encrypted"
45 #define SD_CRYPT_META_FILE ".MetaEcfsFile"
46 #define MMC_MOUNT_POINT "/opt/storage/sdcard"
47
48
49
50 static void _hide_home(void)
51 {
52         vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
53 }
54
55
56
57 static void _show_home(void)
58 {
59         int show_menu = 0;
60
61         if (status_active_get()->starter_sequence || !show_menu) {
62                 vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 1);
63         }
64 }
65
66
67
68 static Eina_Bool _finish_boot_animation(void *data)
69 {
70         if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) {
71                 _E("Failed to set boot animation finished set");
72         }
73         _show_home();
74
75         return ECORE_CALLBACK_CANCEL;
76 }
77
78
79
80 static int _fail_to_launch_pwlock(const char *appid, const char *key, const char *value, void *cfn, void *afn)
81 {
82         _finish_boot_animation(NULL);
83         return 0;
84 }
85
86
87
88 static void _after_launch_pwlock(int pid)
89 {
90         process_mgr_set_pwlock_priority(pid);
91         ecore_timer_add(0.5, _finish_boot_animation, NULL);
92 }
93
94
95
96 static void _signal_handler(int signum, siginfo_t *info, void *unused)
97 {
98     _D("_signal_handler : Terminated...");
99     elm_exit();
100 }
101
102
103
104 static int _power_off_cb(status_active_key_e key, void *data)
105 {
106         int val = status_active_get()->sysman_power_off_status;
107
108         if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT
109                 || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART)
110         {
111             _D("_power_off_cb : Terminated...");
112             elm_exit();
113         }
114
115         return 1;
116 }
117
118
119
120 static void _language_changed_cb(keynode_t *node, void *data)
121 {
122         char *lang = NULL;
123
124         ret_if(!node);
125
126         lang = vconf_keynode_get_str(node);
127         ret_if(!lang);
128
129         _D("language is changed : %s", lang);
130
131         elm_language_set(lang);
132
133         lock_pwd_util_view_init();
134 }
135
136
137
138 static int _set_i18n(const char *domain, const char *dir)
139 {
140         char *r = NULL;
141
142         if (domain == NULL) {
143                 errno = EINVAL;
144                 return -1;
145         }
146
147         char *lang = vconf_get_str(VCONFKEY_LANGSET);
148         r = setlocale(LC_ALL, lang);
149         if (!r) {
150                 _E("setlocale() error");
151         }
152         if (lang) {
153                 free(lang);
154         }
155
156         r = bindtextdomain(domain, dir);
157         if (!r) {
158                 _E("bindtextdomain() error");
159         }
160
161         r = textdomain(domain);
162         if (!r) {
163                 _E("textdomain() error");
164         }
165
166         if (vconf_notify_key_changed(VCONFKEY_LANGSET, _language_changed_cb, NULL) < 0) {
167                 _E("Failed to register changed cb : %s", VCONFKEY_LANGSET);
168         }
169
170         return 0;
171 }
172
173
174
175 static int _check_dead_signal(int pid, void *data)
176 {
177         int home_pid = 0;
178         int volume_pid = 0;
179         int lock_pid = 0;
180
181         _D("Process %d is termianted", pid);
182
183         if (pid < 0) {
184                 _E("pid : %d", pid);
185                 return 0;
186         }
187
188         home_pid = home_mgr_get_home_pid();
189         volume_pid = home_mgr_get_volume_pid();
190         lock_pid = lock_mgr_get_lock_pid();
191
192         if (pid == home_pid) {
193                 _D("Homescreen is dead");
194                 home_mgr_relaunch_homescreen();
195         } else if (pid == volume_pid) {
196                 _D("volume is dead");
197                 home_mgr_relaunch_volume();
198         } else if (pid == lock_pid) {
199                 _D("lockscreen is dead");
200                 lock_mgr_unlock();
201         } else {
202                 _D("Unknown process, ignore it");
203         }
204
205         return 0;
206 }
207
208
209
210 static void _init(struct appdata *ad)
211 {
212         struct sigaction act;
213
214         memset(&act,0x00,sizeof(struct sigaction));
215         act.sa_sigaction = _signal_handler;
216         act.sa_flags = SA_SIGINFO;
217
218         int ret = sigemptyset(&act.sa_mask);
219         if (ret < 0) {
220                 _E("Failed to sigemptyset[%s]", strerror(errno));
221         }
222         ret = sigaddset(&act.sa_mask, SIGTERM);
223         if (ret < 0) {
224                 _E("Failed to sigaddset[%s]", strerror(errno));
225         }
226         ret = sigaction(SIGTERM, &act, NULL);
227         if (ret < 0) {
228                 _E("Failed to sigaction[%s]", strerror(errno));
229         }
230
231         _set_i18n(PACKAGE, LOCALEDIR);
232
233         status_register();
234         status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
235
236         /* Ordering : _hide_home -> process_mgr_must_launch(pwlock) -> _show_home */
237         _hide_home();
238         process_mgr_must_launch(PWLOCK_LITE_PKG_NAME, NULL, NULL, _fail_to_launch_pwlock, _after_launch_pwlock);
239
240         lock_mgr_daemon_start();
241         hw_key_create_window();
242         home_mgr_init(NULL);
243
244         aul_listen_app_dead_signal(_check_dead_signal, NULL);
245 }
246
247
248
249 static void _fini(struct appdata *ad)
250 {
251         home_mgr_fini();
252         hw_key_destroy_window();
253         lock_mgr_daemon_end();
254
255         status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
256         status_unregister();
257
258         if (vconf_ignore_key_changed(VCONFKEY_LANGSET, _language_changed_cb) < 0) {
259                 _E("Failed to unregister changed cb : %s", VCONFKEY_LANGSET);
260         }
261 }
262
263
264
265 int main(int argc, char *argv[])
266 {
267         struct appdata ad;
268
269         _D("starter is launched..!!");
270
271         elm_init(argc, argv);
272         _init(&ad);
273
274         elm_run();
275
276         _fini(&ad);
277         elm_shutdown();
278
279         return 0;
280 }