tizen 2.3.1 release
[apps/home/starter.git] / src / starter_w.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 <poll.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <glib.h>
29
30 #include <vconf.h>
31 #include <signal.h>
32
33 #include <dd-deviced.h>
34
35 #include "starter_w.h"
36 #include "starter-util.h"
37 #include "x11.h"
38 #include "lockd-debug.h"
39 #include "hw_key_w.h"
40 #include "util.h"
41
42 int errno;
43
44 #ifndef PACKAGE_NAME
45 #define PACKAGE_NAME "com.samsung.starter"
46 #endif
47
48 #define DEFAULT_THEME                           "tizen"
49
50 #define W_LOCKSCREEN_PKGNAME            "com.samsung.w-lockscreen"
51 #define REMOTE_LOCK_PKGNAME                     "com.samsung.wfmw-remote-lock"
52
53 #ifdef FEATURE_TIZENW2
54 #define SETUP_WIZARD_PKGNAME            "com.samsung.b2-setup-wizard"
55 #else
56 #define SETUP_WIZARD_PKGNAME            "com.samsung.b2-setup-wizard"
57 #endif
58 #define PWLOCK_PKGNAME                          "com.samsung.b2-pwlock"
59
60 #define NOTIFICATION_APP_PKGNAME        "com.samsung.idle-noti-drawer"
61
62 #define FACTORY_TDF_NOTIFIER_PATH                       "/csa/factory/cblkftdf"
63
64 #define VCONFKEY_BT_CONNECTED           "memory/private/sap/conn_type"
65
66 #define VCONFKEY_REMOTE_LOCK_ISLOCKED           "db/private/com.samsung.wfmw/is_locked"
67
68 static struct appdata *g_app_data = NULL;
69
70 void *starter_get_app_data(void){
71         return g_app_data;
72 }
73
74
75 static void _signal_handler(int signum, siginfo_t *info, void *unused)
76 {
77     _DBG("_signal_handler : Terminated...");
78     elm_exit();
79 }
80
81 int w_open_app(char *pkgname)
82 {
83         int r = AUL_R_OK;
84
85         _SECURE_D("w_open_app:[%s]", pkgname);
86
87         r = aul_open_app(pkgname);
88
89         if (r < 0) {
90                 _ERR("open app failed [%s] ret=[%d]", pkgname, r);
91         }
92
93         return r;
94 }
95
96 int w_launch_app(char *pkgname, bundle *b)
97 {
98         int r = AUL_R_OK;
99
100         _SECURE_D("w_launch_app:[%s]", pkgname);
101
102         r = aul_launch_app(pkgname, b);
103
104         if (r < 0) {
105                 _ERR("launch failed [%s] ret=[%d]", pkgname, r);
106         }
107
108         return r;
109 }
110
111 #define RETRY_CNT 5
112 static Eina_Bool _w_retry_idler_cb(void *data)
113 {
114         struct appdata *ad = (struct appdata *)data;
115
116         _DBG("%s, %d", __func__, __LINE__);
117
118         ad->retry_cnt++;
119         ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
120
121         if (ad->launcher_pid > 0) {
122                 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
123                         _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
124                 } else {
125                         _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
126                 }
127         }
128         else{
129                 if(ad->retry_cnt >= RETRY_CNT){
130                         ad->retry_cnt = 0;
131                         return ECORE_CALLBACK_CANCEL;
132                 }
133                 else{
134                         return ECORE_CALLBACK_RENEW;
135                 }
136         }
137         ad->retry_cnt = 0;
138         return ECORE_CALLBACK_CANCEL;
139 }
140
141 static Eina_Bool _w_retry_idler_first_launch_cb(void *data)
142 {
143         struct appdata *ad = (struct appdata *)data;
144         bundle *b;
145         b = bundle_create();
146         if (!b) {
147                 _E("Cannot create bundle");
148                 return ECORE_CALLBACK_CANCEL;
149         }
150
151         _DBG("%s, %d", __func__, __LINE__);
152
153         bundle_add(b, "home_op", "first_boot");
154
155         ad->retry_cnt++;
156         ad->launcher_pid = w_launch_app(ad->home_pkgname, b);
157
158         if (ad->launcher_pid > 0) {
159                 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
160                         _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
161                 } else {
162                         _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
163                 }
164         }
165         else{
166                 if(ad->retry_cnt >= RETRY_CNT){
167                         ad->retry_cnt = 0;
168                         bundle_free(b);
169                         return ECORE_CALLBACK_CANCEL;
170                 }
171                 else{
172                         bundle_free(b);
173                         return ECORE_CALLBACK_RENEW;
174                 }
175         }
176         ad->retry_cnt = 0;
177         bundle_free(b);
178         return ECORE_CALLBACK_CANCEL;
179 }
180
181 static int _w_app_dead_cb(int pid, void *data)
182 {
183         _DBG("app dead cb call! (pid : %d)", pid);
184
185         struct appdata *ad = (struct appdata *)data;
186
187         if (pid == ad->launcher_pid) {
188                 _ERR("w-launcher-app (pid:%d) is destroyed.", pid);
189                 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
190                 if (ad->launcher_pid > 0) {
191                         if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
192                                 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
193                         } else {
194                                 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
195                         }
196                 }
197                 else{
198                         _ERR("Launch Home failed.");
199                         ecore_idler_add(_w_retry_idler_cb, ad);
200                 }
201         } else if (pid == ad->pid_clock_viewer) {
202                 _ERR("w-clock-viewer (pid:%d) is destroyed.", pid);
203                 int ambient_mode = 0;
204                 if (vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &ambient_mode) < 0) {
205                         _E("Failed to get vconfkey : %s", VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL);
206                         ambient_mode = 0;
207                 }
208
209                 if (ambient_mode) {
210                         ad->pid_clock_viewer = w_launch_app(W_CLOCK_VIEWER_PKGNAME, NULL);
211                 }
212         }
213
214         return 0;
215 }
216
217 static int _w_check_first_boot(void)
218 {
219         int is_first = 0;
220         int ret = 0;
221
222 #if 1 // NOT YET define vconfkey from setting  "VCONFKEY_SETUP_WIZARD_FIRST_BOOT"
223         ret = vconf_get_bool(VCONFKEY_SETUP_WIZARD_FIRST_BOOT, &is_first);
224         if (ret < 0){
225                 _ERR("can't get vconfkey value of [%s], ret=[%d]", VCONFKEY_SETUP_WIZARD_FIRST_BOOT, ret);
226                 is_first = 0;
227         } else if (is_first == 1) {
228                 _ERR("[%s] value is [%d], first booting..!!", VCONFKEY_SETUP_WIZARD_FIRST_BOOT, is_first);
229         }
230 #endif
231
232         return is_first;
233 }
234
235 static Eina_Bool _w_starter_idler_cb(void *data)
236 {
237         struct appdata *ad = (struct appdata *)data;
238
239         _DBG("%s, %d", __func__, __LINE__);
240
241         ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
242
243         if (ad->launcher_pid > 0) {
244                 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
245                         _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
246                 } else {
247                         _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
248                 }
249         }
250         else{
251                 _ERR("Launch Home failed.");
252                 ecore_idler_add(_w_retry_idler_cb, ad);
253         }
254
255         return ECORE_CALLBACK_CANCEL;
256 }
257
258
259 static Eina_Bool _w_starter_lockscreen_idler_cb(void *data)
260 {
261         struct appdata *ad = (struct appdata *)data;
262
263         _DBG("%s, %d", __func__, __LINE__);
264
265         w_launch_app(W_LOCKSCREEN_PKGNAME, NULL);
266
267         if (ad->first_boot == FALSE)
268                 ecore_idler_add(_w_starter_idler_cb, ad);
269
270         return ECORE_CALLBACK_CANCEL;
271 }
272
273
274 #define TEMP_VCONFKEY_LOCK_TYPE "db/setting/lock_type"
275 static void _w_BT_changed_cb(keynode_t* node, void *data)
276 {
277         int bt_state = -1;
278         int lock_type = -1;
279         int test_mode = -1;
280         struct appdata *ad = (struct appdata *)data;
281
282         _DBG("%s, %d", __func__, __LINE__);
283
284         if (node) {
285                 bt_state = vconf_keynode_get_int(node);
286         } else {
287                 if (vconf_get_int(VCONFKEY_BT_CONNECTED, &bt_state) < 0) {
288                         _ERR("Failed to get %s", VCONFKEY_BT_CONNECTED);
289                         return;
290                 }
291         }
292         _DBG("WMS key value:[%d], previous state:[%d]", bt_state, ad->bt_connected);
293
294         vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
295         vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
296
297         if ((lock_type != 1) || (test_mode == VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE)) {
298                 ad->bt_connected = bt_state;
299                 return;
300         }
301
302         if (bt_state == FALSE) {
303                 if (ad->bt_connected == TRUE) {
304                         _ERR("BT connect state is changed from [%d] to [%d]", ad->bt_connected, bt_state);
305                         w_launch_app(W_LOCKSCREEN_PKGNAME, NULL);
306                 }
307         }
308         ad->bt_connected = bt_state;
309
310         return;
311 }
312
313 static void _w_power_off_cb(keynode_t* node, void *data)
314 {
315         int val = VCONFKEY_SYSMAN_POWER_OFF_NONE;
316
317         vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val);
318
319         if (val > VCONFKEY_SYSMAN_POWER_OFF_POPUP) {
320                 _ERR("power off status : %d", val);
321                 if (vconf_ignore_key_changed(VCONFKEY_BT_CONNECTED, _w_BT_changed_cb) < 0)
322                         _ERR("Failed to ignore the callback for [%s]", VCONFKEY_BT_CONNECTED);
323                 exit(0);
324         }
325 }
326
327 static void _w_lang_changed_cb(keynode_t* node, void *data)
328 {
329         char *locale = NULL;
330         _DBG("%s, %d", __func__, __LINE__);
331
332         locale = vconf_get_str(VCONFKEY_LANGSET);
333
334         if (locale != NULL) {
335                 elm_language_set(locale);
336         }
337 }
338
339
340 static void _launch_home_cb(keynode_t* node, void *data)
341 {
342         int seq;
343         struct appdata *ad = (struct appdata *)data;
344         bundle *b = NULL;
345
346         if (node) {
347                 seq = vconf_keynode_get_int(node);
348         } else {
349                 if (vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &seq) < 0) {
350                         _E("Failed to get sequence info");
351                         return;
352                 }
353         }
354
355         b = bundle_create();
356         if (!b) {
357                 _E("Cannot create bundle");
358                 return;
359         }
360         bundle_add(b, "home_op", "first_boot");
361
362         _DBG("_launch_home_cb, seq=%d", seq);
363         if (seq == 1) {
364                 ad->launcher_pid = w_launch_app(ad->home_pkgname, b);
365                 if (ad->launcher_pid > 0) {
366                         if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
367                                 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
368                         } else {
369                                 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
370                         }
371                 } else{
372                         _ERR("Launch Home failed.");
373                         ecore_idler_add(_w_retry_idler_first_launch_cb, ad);
374                 }
375         }
376
377         create_key_window(ad->home_pkgname, ad);
378         bundle_free(b);
379 }
380
381 static void _ambient_mode_event_add(void *data)
382 {
383         _DBG("%s", __func__);
384
385         int ambient_mode = 0;
386         struct appdata *ad = (struct appdata *)data;
387         ret_if(!ad);
388
389         if (vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &ambient_mode) < 0) {
390                 _E("Failed to get vconfkey : %s", VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL);
391                 ambient_mode = 0;
392         }
393
394         if (ambient_mode) {
395                 ad->pid_clock_viewer = w_launch_app(W_CLOCK_VIEWER_PKGNAME, NULL);
396         }
397 }
398
399 static void _init(struct appdata *ad)
400 {
401         int r;
402         struct sigaction act;
403         char *file = NULL;
404         int first = -1;
405         int lock_type = -1;
406         int bt_state = -1;
407         int test_mode = -1;
408         int remote_lock = 0;
409
410         memset(&act,0x00,sizeof(struct sigaction));
411         act.sa_sigaction = _signal_handler;
412         act.sa_flags = SA_SIGINFO;
413
414         int ret = sigemptyset(&act.sa_mask);
415         if (ret < 0) {
416                 _ERR("Failed to sigemptyset[%s]", strerror(errno));
417         }
418         ret = sigaddset(&act.sa_mask, SIGTERM);
419         if (ret < 0) {
420                 _ERR("Failed to sigaddset[%s]", strerror(errno));
421         }
422         ret = sigaction(SIGTERM, &act, NULL);
423         if (ret < 0) {
424                 _ERR("Failed to sigaction[%s]", strerror(errno));
425         }
426
427         memset(ad, 0, sizeof(struct appdata));
428         g_app_data = &*ad;
429
430         ad->retry_cnt = 0;
431         ad->nike_running_status = 0;
432         ad->lcd_status = 0;
433
434         gettimeofday(&ad->tv_start, NULL);
435         aul_launch_init(NULL,NULL);
436
437         aul_listen_app_dead_signal(_w_app_dead_cb, ad);
438
439         if (vconf_notify_key_changed(VCONFKEY_LANGSET, _w_lang_changed_cb, NULL) < 0)
440                 _ERR("Failed to add the callback for [%s]", VCONFKEY_LANGSET);
441
442         ad->home_pkgname = vconf_get_str("file/private/homescreen/pkgname");
443         if (!ad->home_pkgname) {
444                 ad->home_pkgname = W_HOME_PKGNAME;
445         }
446         _ERR("Home pkg name is [%s]", ad->home_pkgname);
447
448 #ifdef TARGET
449         if (bincfg_is_factory_binary() == BIN_TYPE_FACTORY) {
450                 gchar *contents;
451                 gsize length;
452                 GError *error = NULL;
453                 gboolean result = FALSE;
454
455                 _ERR("Factory binary..!!");
456
457                 if (g_file_get_contents(FACTORY_TDF_NOTIFIER_PATH, &contents, &length, &error)) {
458                         gchar *found = NULL;
459                         _ERR("Read %d bytes from filesystem", length);
460                         if ((found = g_strstr_len(contents, strlen(contents), "ON"))) {
461                                 // Launch TDF Notifier
462                                 char *argv[3];
463                                 argv[0] = "/usr/bin/testmode";
464                                 argv[1] = "*#833#";
465                                 argv[2] = NULL;
466
467                                 execv("/usr/bin/testmode", argv);
468
469                                 g_free(contents);
470                                 return;
471                         }
472                         g_free(contents);
473                 } else {
474                         _ERR("read failed [%d]: [%s]", error->code, error->message);
475                         g_error_free(error);
476                         error = NULL;
477                 }
478                 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
479                 if(ad->launcher_pid < 0){
480                         _ERR("Launch Home failed.");
481                         ecore_idler_add(_w_retry_idler_cb, ad);
482                 }
483                 create_key_window_factory_mode(ad->home_pkgname, ad);
484         } else {
485 #endif
486                 if (vconf_notify_key_changed(VCONFKEY_BT_CONNECTED, _w_BT_changed_cb, ad) < 0) {
487                         _ERR("Failed to add the callback for %s changed", VCONFKEY_BT_CONNECTED);
488                 }
489                 if (vconf_get_int(VCONFKEY_BT_CONNECTED, &bt_state) < 0) {
490                         _ERR("Failed to get [%s]", VCONFKEY_BT_CONNECTED);
491                 } else {
492                         ad->bt_connected = bt_state;
493                         _DBG("ad->bt_connected : [%d]", ad->bt_connected);
494                 }
495
496 #ifdef TELEPHONY_DISABLE //B2
497                 if (_w_check_first_boot() == TRUE) {
498                         w_launch_app(SETUP_WIZARD_PKGNAME, NULL);
499                         ecore_idler_add(_w_starter_idler_cb, ad);
500                 } else {
501                         _DBG("Not first booting, launch [%s]..!!", ad->home_pkgname);
502
503                         vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
504                         vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
505
506                         if ((bt_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE))  {
507                                 _ERR("BT disconneted and privacy lock is set");
508                                 w_launch_app(W_LOCKSCREEN_PKGNAME, NULL);
509                                 ecore_idler_add(_w_starter_idler_cb, ad);
510                         } else {
511                                 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
512                                 if (ad->launcher_pid > 0) {
513                                         if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
514                                                 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
515                                         } else {
516                                                 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
517                                         }
518                                 }
519                         }
520                 }
521 #else //B2-3G //TELEPHONY_DISABLE 
522
523 #if 0 // To do not display home before setupwizard
524
525                 w_launch_app(PWLOCK_PKGNAME, NULL);
526                 vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
527                 vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
528
529                 if ((wms_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE))  {
530                         _ERR("BT disconneted and privacy lock is set");
531                         ecore_idler_add(_w_starter_lockscreen_idler_cb, ad);
532                 } else {
533                         ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
534                         if (ad->launcher_pid > 0) {
535                                 if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
536                                         _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
537                                 } else {
538                                         _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
539                                 }
540                         }
541                 }
542
543 #else //B3
544
545                 vconf_get_int(VCONFKEY_TESTMODE_SCREEN_LOCK, &test_mode);
546                 vconf_get_int(TEMP_VCONFKEY_LOCK_TYPE, &lock_type);
547
548                 if (_w_check_first_boot() == TRUE) {
549
550                         //First boot : launch pwlock > set seq > home
551                         ad->first_boot = TRUE;
552
553                         vconf_set_int(VCONFKEY_STARTER_SEQUENCE, 0);
554
555                         if (vconf_notify_key_changed(VCONFKEY_STARTER_SEQUENCE, _launch_home_cb, ad) < 0)
556                                 _ERR("Failed to add the callback for show event");
557 #ifdef MODEM_ALWAYS_OFF
558                         w_launch_app(SETUP_WIZARD_PKGNAME, NULL);
559 #else
560                         w_launch_app(PWLOCK_PKGNAME, NULL);
561 #endif
562                         if ((bt_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE))  {
563                                 _ERR("BT disconneted and privacy lock is set");
564                                 ecore_idler_add(_w_starter_lockscreen_idler_cb, ad);
565                         }
566                 }else {
567
568                         // Not first boot : launch home > pwlock
569                         ad->first_boot = FALSE;
570
571                         if ((bt_state == FALSE) && (lock_type == 1) && (test_mode != VCONFKEY_TESTMODE_SCREEN_LOCK_DISABLE))  {
572                                 _ERR("BT disconneted and privacy lock is set");
573                                 ecore_idler_add(_w_starter_lockscreen_idler_cb, ad);
574                         } else {
575                                 ad->launcher_pid = w_launch_app(ad->home_pkgname, NULL);
576                                 if (ad->launcher_pid > 0) {
577                                         if (-1 == deviced_conf_set_mempolicy_bypid(ad->launcher_pid, OOM_IGNORE)) {
578                                                 _ERR("Cannot set the memory policy for Homescreen(%d)", ad->launcher_pid);
579                                         } else {
580                                                 _ERR("Set the memory policy for Homescreen(%d)", ad->launcher_pid);
581                                         }
582                                 }
583                                 else{
584                                         _ERR("Launch Home failed.");
585                                         ecore_idler_add(_w_retry_idler_cb, ad);
586                                 }
587                         }
588                         create_key_window(ad->home_pkgname, ad);
589 #ifndef MODEM_ALWAYS_OFF
590                         w_launch_app(PWLOCK_PKGNAME, NULL);
591 #endif
592                 }
593 #endif
594
595 #endif //TELEPHONY_DISABLE
596 #ifdef TARGET
597         }
598 #endif
599
600         /* add ambient mode event */
601         _ambient_mode_event_add(ad);
602
603         /* Check remote-lock state */
604         if(vconf_get_bool(VCONFKEY_REMOTE_LOCK_ISLOCKED, &remote_lock) < 0){
605                 _E("failed to get %s", VCONFKEY_REMOTE_LOCK_ISLOCKED);
606         }
607
608         if(remote_lock == true){
609                 w_launch_app(REMOTE_LOCK_PKGNAME, NULL);
610         }
611
612 //      create_key_window(ad->home_pkgname, ad);
613         init_hourly_alert(ad);
614         get_dbus_cool_down_mode(ad);
615         init_dbus_COOL_DOWN_MODE_signal(ad);
616         starter_dbus_connection_get();
617         init_dbus_lcd_on_off_signal(ad);
618         init_clock_mgr(ad);
619
620         // THIS ROUTINE IS FOR SAT.
621         vconf_set_int(VCONFKEY_IDLE_SCREEN_LAUNCHED, VCONFKEY_IDLE_SCREEN_LAUNCHED_TRUE);
622
623         if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, _w_power_off_cb, NULL) < 0)
624                 _ERR("Failed to add the callback for [%s]", VCONFKEY_SYSMAN_POWER_OFF_STATUS);
625
626         return;
627 }
628
629 static void _fini(struct appdata *ad)
630 {
631         struct timeval tv, res;
632
633         if (ad == NULL) {
634                 fprintf(stderr, "Invalid argument: appdata is NULL\n");
635                 return;
636         }
637
638         destroy_key_window();
639         fini_hourly_alert(ad);
640         fini_clock_mgr();
641
642         gettimeofday(&tv, NULL);
643         timersub(&tv, &ad->tv_start, &res);
644         _DBG("Total time: %d.%06d sec\n", (int)res.tv_sec, (int)res.tv_usec);
645 }
646
647 int main(int argc, char *argv[])
648 {
649         struct appdata ad;
650
651 //      WRITE_FILE_LOG("%s", "Main function is started in starter");
652         _DBG("starter is launched..!!");
653 #if 0
654         set_window_scale();     /* not in loop */
655 #endif
656
657         elm_init(argc, argv);
658
659         _init(&ad);
660
661         elm_run();
662
663         _fini(&ad);
664
665         elm_shutdown();
666
667         return 0;
668 }