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