tizen 2.3.1 release
[apps/home/starter.git] / src / clock-mgr.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 <ail.h>
18 #include <bundle.h>
19 #include <Elementary.h>
20 #include <Ecore_X.h>
21 #include <Ecore_Input.h>
22 #include <utilX.h>
23 #include <vconf.h>
24 #include <dd-display.h>
25 #if 0 // Disable temporarily for TIZEN 2.3 build
26 #include <message_port.h>
27 #endif
28
29 #include "starter_w.h"
30 #include "dbus-util_w.h"
31 #include "util.h"
32
33
34 #define APP_CONTROL_OPERATION_MAIN_KEY "__APP_SVC_OP_TYPE__"
35 #define APP_CONTROL_OPERATION_MAIN_VALUE "http://tizen.org/appcontrol/operation/main"
36 #define APP_CONTROL_OPERATION_DEFAULT_VALUE "http://tizen.org/appcontrol/operation/default"
37
38
39 #ifndef VCONFKEY_SHEALTH_VIEW_TYPE_STR
40 #define VCONFKEY_SHEALTH_VIEW_TYPE_STR "memory/shealth/view_type"
41 #endif
42
43 #ifndef VCONFKEY_HERE_TBT_STATUS_INT
44 #define VCONFKEY_HERE_TBT_STATUS_INT "memory/private/navigation/guidance"
45 #endif
46
47 #ifndef VCONFKEY_STARTER_RESERVED_APPS_STATUS
48 #define VCONFKEY_STARTER_RESERVED_APPS_STATUS "memory/starter/reserved_apps_status"             /*  2 digits for reserved apps & popup
49                                                                                                                                                                                  *      10 : popup
50                                                                                                                                                                                  *      01 : apps
51                                                                                                                                                                                  *                                                              */
52 #endif
53
54 #ifndef VCONFKEY_SETTING_SIMPLE_CLOCK_MODE
55 #define VCONFKEY_SETTING_SIMPLE_CLOCK_MODE      "db/setting/simpleclock_mode"
56 #endif
57
58
59
60 #define W_LOCKSCREEN_PKGNAME            "com.samsung.w-lockscreen"
61
62 #define W_ALPM_CLOCK_PKGNAME "com.samsung.alpm-clock-manager"
63 #define ALPM_CLOCK_OP "ALPM_CLOCK_OP"
64 #define ALPM_CLOCK_SHOW "alpm_clock_show"
65 #define ALPM_CLOCK_HIDE "alpm_clock_hide"
66
67 #define HOME_OPERATION_KEY "home_op"
68 #define POWERKEY_VALUE "powerkey"
69
70 #define PM_UNLOCK_TIMER_SEC 0.3
71
72 #define RESERVED_DISPLAY_MESSAGE_PORT_ID "Home.Reserved.Display"
73 #define RESERVED_DISPLAY_MESSAGE_KEY_STATE "state"
74 #define RESERVED_DISPLAY_MESSAGE_STATE_SHOW "show"
75 #define RESERVED_DISPLAY_MESSAGE_STATE_HIDE "hide"
76 #define RESERVED_DISPLAY_MESSAGE_STATE_POPUP_SHOW "popup_show"
77 #define RESERVED_DISPLAY_MESSAGE_STATE_POPUP_HIDE "popup_hide"
78
79 #define SHEALTH_SLEEP_PKGNAME           "com.samsung.shealth.sleep"
80
81 static int _check_reserved_popup_status(void *data)
82 {
83         int val = 0;
84         int tmp = 0;
85         struct appdata *ad = (struct appdata *)data;
86         if (ad == NULL) {
87                 _E("ad is NULL");
88                 return -1;
89         }
90
91         vconf_get_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, &val);
92
93         _W("Current reserved apps status : %x", val);
94
95         tmp = val;
96         tmp = tmp & 0x10;
97         if(tmp == 0x10){
98                 if(aul_app_is_running(ad->reserved_popup_app_id) == 1){
99                         return TRUE;
100                 }
101                 else{
102                         _E("%s is not running now.", ad->reserved_popup_app_id);
103                         ad->reserved_popup_app_id = NULL;
104                         val = val ^ 0x10;
105                         vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, val);
106                         _W("now reserved apps status %x", val);
107                         return FALSE;
108                 }
109         }
110         else{
111                 return FALSE;
112         }
113
114 }
115
116 static int _check_reserved_apps_status(void *data)
117 {
118         int val = 0;
119         struct appdata *ad = (struct appdata *)data;
120         if (ad == NULL) {
121                 _E("ad is NULL");
122                 return -1;
123         }
124
125         vconf_get_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, &val);
126
127         _W("Current reserved apps status : %x", val);
128
129         if(val > 0){
130                 val = TRUE;
131         }
132         else{
133                 val = FALSE;
134         }
135
136         return val;
137 }
138
139 static void reserved_apps_message_received_cb(int local_port_id, const char *remote_app_id, const char *remote_port, bool trusted_port, bundle* msg)
140 {
141         ret_if(remote_app_id == NULL);
142         ret_if(msg == NULL);
143         struct appdata *ad = starter_get_app_data();
144         Eina_List *l = NULL;
145         char *state = NULL;
146         char *data = NULL;
147         char *appid = NULL;
148         int count = 0;
149         int i = 0;
150         int val = 0;
151         int tmp = 0;
152
153         vconf_get_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, &val);
154         _W("current reserved apps status : %x", val);
155
156         state = bundle_get_val(msg, RESERVED_DISPLAY_MESSAGE_KEY_STATE);
157         _W("appid [%s], msg value[%s]", remote_app_id, state);
158         if (strncmp(state, RESERVED_DISPLAY_MESSAGE_STATE_SHOW, strlen(state)) == 0) {
159                 //reserved app is start
160                 EINA_LIST_FOREACH(ad->reserved_apps_list, l, data){
161                         if(strncmp(data, remote_app_id, strlen(data)) == 0){
162                                 _W("%s is already in the list", data);
163                                 ad->reserved_apps_list = eina_list_remove_list(ad->reserved_apps_list, l);
164                                 break;
165                         }
166                 }
167                 appid = strdup(remote_app_id);
168                 ad->reserved_apps_list = eina_list_append(ad->reserved_apps_list, appid);
169                 val = val | 0x01;
170                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, val);
171                 _W("now reserved apps status %x", val);
172         }
173         else if (strncmp(state, RESERVED_DISPLAY_MESSAGE_STATE_HIDE, strlen(state)) == 0){
174                 //reserved app is stop
175                 EINA_LIST_FOREACH(ad->reserved_apps_list, l, data){
176                         if(strncmp(data, remote_app_id, strlen(data)) == 0){
177                                 ad->reserved_apps_list = eina_list_remove_list(ad->reserved_apps_list, l);
178                                 break;
179                         }
180                 }
181                 count = eina_list_count(ad->reserved_apps_list);
182                 if(count == 0){
183                         _W("there is no reserved app.");
184                         tmp = val;
185                         val = tmp & 0x01;
186                         if(val == 0x01){
187                                 tmp = tmp ^ 0x01;
188                         }
189                         vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, tmp);
190                         _W("now reserved apps status %x", tmp);
191                 }
192         }
193         else if (strncmp(state, RESERVED_DISPLAY_MESSAGE_STATE_POPUP_SHOW, strlen(state)) == 0){
194                 //reserved popup is show
195                 ad->reserved_popup_app_id = strdup(remote_app_id);
196                 val = val | 0x0010;
197                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, val);
198                 _W("now reserved apps status %x", val);
199         }
200         else if (strncmp(state, RESERVED_DISPLAY_MESSAGE_STATE_POPUP_HIDE, strlen(state)) == 0){
201                 //reserved popup is hide
202                 if(ad->reserved_popup_app_id == NULL){
203                         _E("there is no reserved popup already");
204                 }
205                 else{
206                         if(strncmp(ad->reserved_popup_app_id, remote_app_id, strlen(ad->reserved_popup_app_id)) == 0){
207                                 ad->reserved_popup_app_id = NULL;
208                                 tmp = val;
209                                 val = tmp & 0x10;
210                                 if(val == 0x10){
211                                         tmp = tmp ^ 0x10;
212                                 }
213                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, tmp);
214                                 _W("now reserved apps status %x", tmp);
215                         }
216                 }
217         }
218         else{
219                 // no info
220         }
221         EINA_LIST_REVERSE_FOREACH(ad->reserved_apps_list, l, data){
222                 _W("%d. %s", i++, data);
223         }
224 }
225 #if 0
226 static void _shealth_view_type_changed_cb(keynode_t* node, void *data)
227 {
228         char *val = NULL;
229         struct appdata *ad = (struct appdata *)data;
230
231         _D("%s, %d", __func__, __LINE__);
232
233         if (ad == NULL) {
234                 _E("ad is NULL");
235                 return;
236         }
237
238         if (node) {
239                 val = vconf_keynode_get_str(node);
240         } else {
241                 val = vconf_get_str(VCONFKEY_SHEALTH_VIEW_TYPE_STR);
242         }
243
244         clock_mgr_set_reserved_apps_status(val, STARTER_RESERVED_APPS_SHEALTH, ad);
245 }
246
247 static void _here_navigation_status_changed_cb(keynode_t* node, void *data)
248 {
249         int val = NULL;
250         struct appdata *ad = (struct appdata *)data;
251
252         _D("%s, %d", __func__, __LINE__);
253
254         if (ad == NULL) {
255                 _E("ad is NULL");
256                 return;
257         }
258
259         if (node) {
260                 val = vconf_keynode_get_int(node);
261         } else {
262                 vconf_get_int(VCONFKEY_HERE_TBT_STATUS_INT, &val);
263         }
264
265         clock_mgr_set_reserved_apps_status(val, STARTER_RESERVED_APPS_HERE, ad);
266 }
267
268 void clock_mgr_set_reserved_apps_status(void *info, int type, void *data){
269         char *str_info = NULL;
270         int int_info = NULL;
271         int val = 0;
272         int tmp = 0;
273         struct appdata *ad = (struct appdata *)data;
274         _D("%s, %d", __func__, __LINE__);
275         if (ad == NULL) {
276                 _E("ad is NULL");
277                 return;
278         }
279
280         vconf_get_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, &val);
281         _W("current reserved apps status : %x", val);
282
283         switch(type){
284                 case STARTER_RESERVED_APPS_SHEALTH:{
285                         str_info = (char *)info;
286                         _W("Shealth status is changed (%s)", str_info);
287                         if (strncmp(str_info, "exercise", strlen(str_info)) == 0){
288                                 val = val | 0x1000;
289                                 if(val >= 0x1100){
290                                         val = val ^ 0x0100;
291                                 }
292                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, val);
293                                 _W("now reserved apps status %x", val);
294                         }
295                         else if (strncmp(str_info, "sleep", strlen(str_info)) == 0){
296                                 val = val | 0x0100;
297                                 if(val >= 0x1100){
298                                         val = val ^ 0x1000;
299                                 }
300                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, val);
301                                 _W("now reserved apps status %x", val);
302                         }
303                         else{
304                                 tmp = val;
305                                 val = tmp & 0x1000;
306                                 if(val == 0x1000){
307                                         tmp = tmp ^ 0x1000;
308                                 }
309                                 val = tmp & 0x0100;
310                                 if(val == 0x0100){
311                                         tmp = tmp ^ 0x0100;
312                                 }
313                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, tmp);
314                                 _W("now reserved apps status %x", tmp);
315                         }
316                         break;
317                 }
318                 case STARTER_RESERVED_APPS_NIKE:{
319                         int_info = (int)info;
320                         _W("Nike status is changed (%d)", int_info);
321                         if(int_info == 1){
322                                 val = val | 0x0010;
323                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, val);
324                                 _W("now reserved apps status %x", val);
325                         }
326                         else{
327                                 tmp = val;
328                                 val = tmp & 0x0010;
329                                 if(val == 0x0010){
330                                         tmp = tmp ^ 0x0010;
331                                 }
332                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, tmp);
333                                 _W("now reserved apps status %x", tmp);
334                         }
335                         break;
336                 }
337                 case STARTER_RESERVED_APPS_HERE:{
338                         int_info = (int)info;
339                         _W("Here status is changed (%d)", int_info);
340                         if(int_info == 1){
341                                 val = val | 0x0001;
342                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, val);
343                                 _W("now reserved apps status %x", val);
344                         }
345                         else{
346                                 tmp = val;
347                                 val = tmp & 0x0001;
348                                 if(val == 0x0001){
349                                         tmp = tmp ^ 0x0001;
350                                 }
351                                 vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, tmp);
352                                 _W("now reserved apps status %x", tmp);
353                         }
354                         break;
355                 }
356                 default:{
357                         _E("Unknown reserved app.");
358                         break;
359                 }
360         }
361         return 0;
362 }
363 #endif
364
365 static void _wake_up_setting_changed_cb(keynode_t* node, void *data)
366 {
367         int val = 0;
368         struct appdata *ad = (struct appdata *)data;
369
370         _D("%s, %d", __func__, __LINE__);
371
372         if (ad == NULL) {
373                 _E("ad is NULL");
374                 return;
375         }
376
377         if(vconf_get_int(VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING, &val) < 0) {
378                 _E("Failed to get VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING");
379                 val = 1;
380         }
381         ad->wake_up_setting = val;
382         _W("wake_up_setting is changed to [%d]", ad->wake_up_setting);
383 }
384
385 static void _ambient_mode_setting_changed_cb(keynode_t* node, void *data)
386 {
387         int ambient_mode = 0;
388         struct appdata *ad = (struct appdata *)data;
389         ret_if(!ad);
390
391         ambient_mode = vconf_keynode_get_bool(node);
392         _D("ambient mode : %d", ambient_mode);
393
394         if (ambient_mode) {
395                 _D("launch w-clock-viewer");
396                 ad->pid_clock_viewer = w_launch_app(W_CLOCK_VIEWER_PKGNAME, NULL);
397         } else {
398                 _D("kill w-clock-viewer(%d)", ad->pid_clock_viewer);
399                 if (ad->pid_clock_viewer > 0) {
400                         aul_kill_pid(ad->pid_clock_viewer);
401                         ad->pid_clock_viewer = 0;
402                 }
403         }
404
405         ad->ambient_mode = ambient_mode;
406         _W("ambient_mode_setting is changed to [%d]", ad->ambient_mode);
407 }
408
409
410 static Eina_Bool _w_lcdoff_idler_cb(void *data)
411 {
412         struct appdata *ad = (struct appdata *)data;
413
414         _D("%s, %d", __func__, __LINE__);
415
416         w_open_app(ad->home_pkgname);
417
418         return ECORE_CALLBACK_CANCEL;
419 }
420
421 static Eina_Bool _w_launch_pm_unlock_idler_cb(void *data)
422 {
423         struct appdata *ad = (struct appdata *)data;
424
425         _D("%s, %d", __func__, __LINE__);
426         display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
427
428         return ECORE_CALLBACK_CANCEL;
429 }
430
431 static Eina_Bool _pm_unlock_timer_cb(void *data){
432         _D("%s, %d", __func__, __LINE__);
433         ecore_idler_add(_w_launch_pm_unlock_idler_cb, data);
434         return ECORE_CALLBACK_CANCEL;
435 }
436
437
438 static void _notify_pm_lcdoff_cb(keynode_t * node, void *data)
439 {
440
441         int ret = -1;
442         int setup_wizard_state = -1;
443         bundle *b = NULL;
444         int lock_type = 0;
445         int tutorial_state = -1;
446         Eina_List *l = NULL;
447         char *info = NULL;
448         int count = 0;
449         int lcdoff_source = vconf_keynode_get_int(node);
450         struct appdata *ad = (struct appdata *)data;
451
452
453         if (ad == NULL) {
454                 _E("ad is NULL");
455                 return;
456         }
457
458         if (lcdoff_source < 0) {
459                 _E("Cannot get VCONFKEY, error (%d)", lcdoff_source);
460                 return;
461         }
462
463         _W("LCD OFF by lcd off source[%d], wake_up_setting[%d], ALPM_clock_state[%d]", lcdoff_source, ad->wake_up_setting, ad->ALPM_clock_state);
464
465 #if 0
466         if(csc_feature_get_bool(CSC_FEATURE_DEF_BOOL_HOME_LAUNCH_LOCK_WHEN_LCD_ON) == CSC_FEATURE_BOOL_TRUE){
467                 _E("CHC bin.");
468                 vconf_get_int(VCONFKEY_SETAPPL_PRIVACY_LOCK_TYPE_INT, &lock_type);
469                 if(lock_type == 1){
470                         int r = 0;
471                         //PM LOCK - don't go to sleep
472                         display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
473                         _E("CHC bin & lock type is %d", lock_type);
474                         r = w_launch_app(W_LOCKSCREEN_PKGNAME, NULL);
475
476                         ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
477                 }
478         }
479 #endif
480
481         if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &setup_wizard_state) < 0) {
482                 _E("Failed to get [%s]", VCONFKEY_SETUP_WIZARD_STATE);
483         } else {
484                 if (setup_wizard_state == VCONFKEY_SETUP_WIZARD_LOCK) {
485                         _E("don't react for lcd off, setup wizard state is [%d]", setup_wizard_state);
486                         return;
487                 }
488         }
489
490
491
492 #if 0
493         if (_check_reserved_apps_status(ad)) {
494                 _E("_check_running_heath = > don't react for lcd off except ALPM");
495                 if (ad->ambient_mode == 1)  {
496                         //Step1. Launch ALPM clock
497                         b = bundle_create();
498                         if(!b) {
499                                 _E("Failed to create bundle");
500                                 return;
501                         }
502                         //bundle_add(b, APP_CONTROL_OPERATION_MAIN_KEY, APP_CONTROL_OPERATION_MAIN_VALUE);
503                         bundle_add(b, ALPM_CLOCK_OP, ALPM_CLOCK_SHOW);
504
505                         //PM LOCK - don't go to sleep
506                         display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
507
508                         ad->pid_ALPM_clock = 0;
509                         ret = w_launch_app(W_ALPM_CLOCK_PKGNAME, b);
510                         if (ret >= 0) {
511                                 ad->pid_ALPM_clock =ret;
512                                 _SECURE_D("[%s] is launched, pid=[%d]", W_ALPM_CLOCK_PKGNAME, ad->pid_ALPM_clock );
513                         }
514                         if(b){
515                                 bundle_free(b);
516                         }
517                         //Step2. Do not raise Homescreen
518                         ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
519                 }
520                 return;
521         }
522
523
524         if (ad->wake_up_setting == SETTING_WAKE_UP_GESTURE_CLOCK) {
525                 //Step1. Launch ALPM clock
526                 b = bundle_create();
527                 if(!b) {
528                         _E("Failed to create bundle");
529                         return;
530                 }
531                 //bundle_add(b, APP_CONTROL_OPERATION_MAIN_KEY, APP_CONTROL_OPERATION_MAIN_VALUE);
532                 bundle_add(b, ALPM_CLOCK_OP, ALPM_CLOCK_SHOW);
533
534                 //PM LOCK - don't go to sleep
535                 display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
536
537                 ad->pid_ALPM_clock = 0;
538                 ret = w_launch_app(W_ALPM_CLOCK_PKGNAME, b);
539                 if (ret >= 0) {
540                         ad->pid_ALPM_clock =ret;
541                         _SECURE_D("[%s] is launched, pid=[%d]", W_ALPM_CLOCK_PKGNAME, ad->pid_ALPM_clock );
542                 }
543                 if(b) {
544                         bundle_free(b);
545                 }
546
547                 if(vconf_get_int("db/private/com.samsung.w-home/tutorial", &tutorial_state) < 0) {
548                         _E("Failed to get tutorial status");
549
550                 }
551                 if(!tutorial_state) {
552                         //Step2. Raise Homescreen
553                         w_open_app(ad->home_pkgname);
554                 }
555                 ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
556         } else if (ad->ambient_mode == 1)  {
557
558                 //Step1. Launch ALPM clock
559                 b = bundle_create();
560                 if(!b) {
561                         _E("Failed to create bundle");
562                         return;
563                 }
564                 //bundle_add(b, APP_CONTROL_OPERATION_MAIN_KEY, APP_CONTROL_OPERATION_MAIN_VALUE);
565                 bundle_add(b, ALPM_CLOCK_OP, ALPM_CLOCK_SHOW);
566
567                 //PM LOCK - don't go to sleep
568                 display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
569
570                 ad->pid_ALPM_clock = 0;
571                 ret = w_launch_app(W_ALPM_CLOCK_PKGNAME, b);
572                 if (ret >= 0) {
573                         ad->pid_ALPM_clock =ret;
574                         _SECURE_D("[%s] is launched, pid=[%d]", W_ALPM_CLOCK_PKGNAME, ad->pid_ALPM_clock );
575                 }
576                 if(b) {
577                         bundle_free(b);
578                 }
579                 //Step2. Do not raise Homescreen
580                 ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
581         }
582
583
584 #else
585         if(_check_reserved_popup_status(ad)){
586                 _W("reserved popup is on top. do nothing");
587                 if((ad->ambient_mode == 1) && (ad->ALPM_clock_state == 0)){
588                         starter_dbus_alpm_clock_signal_send(ad);
589                 }
590                 return;
591         }
592
593         if (_check_reserved_apps_status(ad)) {
594                 _W("reserved app is running now. raise it.");
595
596                 EINA_LIST_FOREACH(ad->reserved_apps_list, l, info){
597                         if(strncmp(info, SHEALTH_SLEEP_PKGNAME, strlen(info)) == 0){
598                                 _W("%s is in the list. check running state", info);
599                                 if(aul_app_is_running(info) == 1){
600                                         _W("%s is now running. raise it.", info);
601                                         //PM LOCK - don't go to sleep
602                                         display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
603                                         w_open_app(info);
604                                         ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
605                                         return;
606                                 }
607                                 else{
608                                         _W("%s is not running now", info);
609                                         ad->reserved_apps_list = eina_list_remove_list(ad->reserved_apps_list, l);
610                                         break;
611                                 }
612                         }
613                 }
614
615                 EINA_LIST_REVERSE_FOREACH(ad->reserved_apps_list, l, info){
616                         if(aul_app_is_running(info) == 1){
617                                 //PM LOCK - don't go to sleep
618                                 display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
619                                 w_open_app(info);
620                                 ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
621                                 break;
622                         }
623                         else{
624                                 _W("%s is not running now", info);
625                                 ad->reserved_apps_list = eina_list_remove_list(ad->reserved_apps_list, l);
626                                 continue;
627                         }
628                 }
629                 count = eina_list_count(ad->reserved_apps_list);
630                 if(count == 0){
631                         _W("there is no reserved app.");
632                         vconf_set_int(VCONFKEY_STARTER_RESERVED_APPS_STATUS, 0);
633                 }
634         }
635
636         if ((ad->ambient_mode == 1) && (ad->ALPM_clock_state == 0))  {
637 #if 0
638                 //Step1. Launch ALPM clock
639                 b = bundle_create();
640                 if(!b) {
641                         _E("Failed to create bundle");
642                         return;
643                 }
644                 //bundle_add(b, APP_CONTROL_OPERATION_MAIN_KEY, APP_CONTROL_OPERATION_MAIN_VALUE);
645                 bundle_add(b, ALPM_CLOCK_OP, ALPM_CLOCK_SHOW);
646
647                 //PM LOCK - don't go to sleep
648                 display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
649
650                 ad->pid_ALPM_clock = 0;
651                 ret = w_launch_app(W_ALPM_CLOCK_PKGNAME, b);
652                 if (ret >= 0) {
653                         ad->pid_ALPM_clock =ret;
654                         _SECURE_D("[%s] is launched, pid=[%d]", W_ALPM_CLOCK_PKGNAME, ad->pid_ALPM_clock );
655                 }
656                 if(b){
657                         bundle_free(b);
658                 }
659                 //Step2. Do not raise Homescreen
660                 ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
661 #endif
662                 starter_dbus_alpm_clock_signal_send(ad);
663         } else {
664                 int val = 0;
665                 if(vconf_get_bool(VCONFKEY_SETTING_SIMPLE_CLOCK_MODE, &val) < 0) {
666                         _E("Failed to get VCONFKEY_SETTING_SIMPLE_CLOCK_MODE");
667                 }
668
669
670                 // Not yet fix the setting concept.
671                 //if ((_check_reserved_apps_status(ad) == FALSE) && (val == TRUE) && (ad->wake_up_setting == SETTING_WAKE_UP_GESTURE_CLOCK)) {
672                 if ((_check_reserved_apps_status(ad) == FALSE) && (ad->wake_up_setting == SETTING_WAKE_UP_GESTURE_CLOCK) && (ad->ALPM_clock_state == 0)) {
673                         //_W("Not reserved apss status AND wake_up_setting is CLOCK AND simple clock setting is [%d] => show simple clock..!!", val);
674                         _W("Not reserved apss status AND wake_up_setting is CLOCK => show simple clock..!!");
675 #if 0
676                         //Step1. Launch ALPM clock
677                         b = bundle_create();
678                         if(!b) {
679                                 _E("Failed to create bundle");
680                                 return;
681                         }
682                         //bundle_add(b, APP_CONTROL_OPERATION_MAIN_KEY, APP_CONTROL_OPERATION_MAIN_VALUE);
683                         bundle_add(b, ALPM_CLOCK_OP, ALPM_CLOCK_SHOW);
684
685                         //PM LOCK - don't go to sleep
686                         display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
687
688                         ad->pid_ALPM_clock = 0;
689                         ret = w_launch_app(W_ALPM_CLOCK_PKGNAME, b);
690                         if (ret >= 0) {
691                                 ad->pid_ALPM_clock =ret;
692                                 _SECURE_D("[%s] is launched, pid=[%d]", W_ALPM_CLOCK_PKGNAME, ad->pid_ALPM_clock );
693                         }
694                         if(b){
695                                 bundle_free(b);
696                         }
697                         //Step2. Do not raise Homescreen
698                         ecore_timer_add(PM_UNLOCK_TIMER_SEC, _pm_unlock_timer_cb, ad);
699 #endif
700                         starter_dbus_alpm_clock_signal_send(ad);
701                 }
702         }
703 #endif
704 }
705
706
707 void init_clock_mgr(void *data)
708 {
709         int status = -1;
710         int ret = -1;
711         int val = -1;
712         int reserved_apps_msg_port_id = 0;
713         struct appdata *ad = (struct appdata *)data;
714
715         _W("init_clock_mgr.!!");
716 #if 0
717         //register message port for reserved apps
718         if ((reserved_apps_msg_port_id = message_port_register_local_port(RESERVED_DISPLAY_MESSAGE_PORT_ID, reserved_apps_message_received_cb)) <= 0) {
719                 _E("Failed to register reserved_apps message port cb");
720         }
721         _E("port_id:%d", reserved_apps_msg_port_id);
722         ad->reserved_apps_local_port_id = reserved_apps_msg_port_id;
723 #endif
724         if(init_dbus_ALPM_clock_state_signal(ad) < 0) {
725                 _E("Failed to init_dbus_ALPM_clock_state_signal");
726         }
727
728         //register wake up gesture setting changed.
729         if(vconf_get_int(VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING, &val) < 0) {
730                 _E("Failed to get VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING");
731                 val = 1;
732         }
733         ad->wake_up_setting = val;
734         _W("wake_up_setting : %d", ad->wake_up_setting);
735
736         if (vconf_notify_key_changed(VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING, _wake_up_setting_changed_cb, ad) < 0) {
737                 _E("Failed to add the callback for VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING changed");
738         }
739
740         //register ambient mode changed.
741         if(vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &val) < 0) {
742                 _E("Failed to get VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL");
743                 val = 0;
744         }
745         ad->ambient_mode = val;
746         _W("ambient_mode : %d", ad->ambient_mode);
747
748         if (vconf_notify_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, _ambient_mode_setting_changed_cb, ad) < 0) {
749                 _E("Failed to add the callback for VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL changed");
750         }
751
752         if (vconf_notify_key_changed(VCONFKEY_PM_LCDOFF_SOURCE, _notify_pm_lcdoff_cb, ad) != 0) {
753                 _E("Fail vconf_notify_key_changed : VCONFKEY_PM_LCDOFF_SOURCE");
754         }
755
756 #if 0
757         if (vconf_notify_key_changed(VCONFKEY_SHEALTH_VIEW_TYPE_STR, _shealth_view_type_changed_cb, ad) < 0) {
758                 _E("Failed to add the callback for VCONFKEY_SHEALTH_VIEW_TYPE_STR changed");
759         }
760
761         if (vconf_notify_key_changed(VCONFKEY_HERE_TBT_STATUS_INT, _here_navigation_status_changed_cb, ad) < 0) {
762                 _E("Failed to add the callback for VCONFKEY_HERE_TBT_STATUS_INT changed");
763         }
764 #endif
765 }
766
767
768
769 void fini_clock_mgr(void *data)
770 {
771         struct appdata *ad = (struct appdata *)data;
772
773         if(vconf_ignore_key_changed(VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING, _wake_up_setting_changed_cb) < 0) {
774                 _E("Failed to ignore the VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING");
775         }
776
777         if(vconf_ignore_key_changed(VCONFKEY_PM_LCDOFF_SOURCE, _notify_pm_lcdoff_cb) < 0) {
778                 _E("Failed to ignore the VCONFKEY_PM_LCDOFF_SOURCE");
779         }
780
781         if (vconf_ignore_key_changed(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, _ambient_mode_setting_changed_cb) < 0) {
782                 _E("Failed to ignore the VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL");
783         }
784
785 #if 0
786         if(vconf_ignore_key_changed(VCONFKEY_SHEALTH_VIEW_TYPE_STR, _shealth_view_type_changed_cb) < 0) {
787                 _E("Failed to ignore the VCONFKEY_SHEALTH_VIEW_TYPE_STR");
788         }
789
790         if(vconf_ignore_key_changed(VCONFKEY_HERE_TBT_STATUS_INT, _here_navigation_status_changed_cb) < 0) {
791                 _E("Failed to ignore the VCONFKEY_HERE_TBT_STATUS_INT");
792         }
793 #endif
794
795 #if 0 // Disable temporarily for TIZEN 2.3 build
796         if (ad->reserved_apps_local_port_id >= 0) {
797                 if (message_port_unregister_local_port(ad->reserved_apps_local_port_id) != MESSAGE_PORT_ERROR_NONE) {
798                         _E("Failed to unregister reserved apps message port cb");
799                 }
800         }
801 #endif
802
803 }
804
805
806
807 // End of a file