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