Fix JIRA issue(TSAM-954) : System settings API returns SYSTEM_SETTINGS_LOCK_STATE_UNL...
[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 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         home_pid = home_mgr_get_home_pid();
211         volume_pid = home_mgr_get_volume_pid();
212         lock_pid = lock_mgr_get_lock_pid();
213
214         if (pid == home_pid) {
215                 _D("Homescreen is dead");
216                 home_mgr_relaunch_homescreen();
217         } else if (pid == volume_pid) {
218                 _D("volume is dead");
219                 home_mgr_relaunch_volume();
220         } else if (pid == lock_pid) {
221                 _D("lockscreen is dead");
222                 lock_mgr_unlock();
223         } else {
224                 _D("Unknown process, ignore it");
225         }
226
227         return 0;
228 }
229
230
231
232 static void _init(struct appdata *ad)
233 {
234         struct sigaction act;
235
236         memset(&act,0x00,sizeof(struct sigaction));
237         act.sa_sigaction = _signal_handler;
238         act.sa_flags = SA_SIGINFO;
239
240         int ret = sigemptyset(&act.sa_mask);
241         if (ret < 0) {
242                 _E("Failed to sigemptyset[%s]", strerror(errno));
243         }
244         ret = sigaddset(&act.sa_mask, SIGTERM);
245         if (ret < 0) {
246                 _E("Failed to sigaddset[%s]", strerror(errno));
247         }
248         ret = sigaction(SIGTERM, &act, NULL);
249         if (ret < 0) {
250                 _E("Failed to sigaction[%s]", strerror(errno));
251         }
252
253         _set_i18n(PACKAGE, LOCALEDIR);
254
255         status_register();
256         status_active_register_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb, NULL);
257         status_active_register_cb(STATUS_ACTIVE_KEY_BOOT_ANIMATION_FINISHED, _boot_animation_finished_cb, NULL);
258
259         /* Ordering : _hide_home -> process_mgr_must_launch(pwlock) -> _show_home */
260         _hide_home();
261 #if 0
262         process_mgr_must_launch(PWLOCK_LITE_PKG_NAME, NULL, NULL, _fail_to_launch_pwlock, _after_launch_pwlock);
263 #endif
264
265         hw_key_create_window();
266         home_mgr_init(NULL);
267
268         aul_listen_app_dead_signal(_check_dead_signal, NULL);
269 }
270
271
272
273 static void _fini(struct appdata *ad)
274 {
275         home_mgr_fini();
276         hw_key_destroy_window();
277         lock_mgr_daemon_end();
278
279         status_active_unregister_cb(STATUS_ACTIVE_KEY_SYSMAN_POWER_OFF_STATUS, _power_off_cb);
280         status_active_unregister_cb(STATUS_ACTIVE_KEY_BOOT_ANIMATION_FINISHED, _boot_animation_finished_cb);
281         status_unregister();
282
283         if (vconf_ignore_key_changed(VCONFKEY_LANGSET, _language_changed_cb) < 0) {
284                 _E("Failed to unregister changed cb : %s", VCONFKEY_LANGSET);
285         }
286 }
287
288
289
290 int main(int argc, char *argv[])
291 {
292         struct appdata ad;
293
294         _D("starter is launched..!!");
295
296         elm_init(argc, argv);
297         _init(&ad);
298
299         elm_run();
300
301         _fini(&ad);
302         elm_shutdown();
303
304         return 0;
305 }