Tizen 2.4 SDK Rev6 Release
[framework/appfw/aul-1.git] / am_daemon / amd_status.c
1 /*
2  *  aul
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <glib.h>
25 #include <aul.h>
26 #include <string.h>
27 #include <Ecore.h>
28 #include <proc_stat.h>
29 #include <pkgmgr-info.h>
30 #ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
31 #include <Ecore_X.h>
32 #include <vconf/vconf.h>
33 #endif
34
35 #include "amd_config.h"
36 #include "amd_status.h"
37 #include "amd_appinfo.h"
38 #include "aul_util.h"
39 #include "simple_util.h"
40 #include "app_sock.h"
41 #include "menu_db_util.h"
42
43 GSList *app_status_info_list = NULL;
44 struct appinfomgr *_saf = NULL;
45
46 GHashTable *cooldown_tbl;
47
48 GHashTable *cooldown_black_tbl;
49
50 char *cooldown_list[] = {
51 };
52
53 char *cooldown_black_list[] = {
54 };
55
56 int cooldown_status = 0;
57
58 #define WHITE_LIST_COUNT 0
59 #define BLACK_LIST_COUNT 0
60
61 #ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
62 #define LCD_ON  "LCDOn"
63 #define LCD_OFF "LCDOff"
64 #define PROC_SIZE       256
65 #define WAKE_UP_GESTURE_CLOCK           1
66 #endif
67
68 int _status_add_app_info_list(char *appid, char *app_path, const char *caller, int pid, int pad_pid)
69 {
70         GSList *iter = NULL;
71         app_status_info_t *info_t = NULL;
72
73         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
74         {
75                 info_t = (app_status_info_t *)iter->data;
76                 if(pid == info_t->pid) {
77                         return 0;
78                 }
79         }
80
81         info_t = malloc(sizeof(app_status_info_t));
82         if (info_t == NULL) {
83                 _E("out of memory");
84                 return -1;
85         }
86
87         memset(info_t, 0, sizeof(app_status_info_t));
88
89         strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1);
90         strncpy(info_t->app_path, app_path, MAX_PACKAGE_APP_PATH_SIZE-1);
91         if(caller)
92                 strncpy(info_t->caller, caller, MAX_PACKAGE_STR_SIZE-1);
93         info_t->status = STATUS_LAUNCHING;
94         info_t->pid = pid;
95         info_t->pad_pid = pad_pid;
96         app_status_info_list = g_slist_append(app_status_info_list, info_t);
97
98         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
99         {
100                 info_t = (app_status_info_t *)iter->data;
101
102                 //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
103         }
104
105         return 0;
106 }
107
108 static Eina_Bool __app_terminate_timer_cb(void *data)
109 {
110         int pid = (int)data;
111         int ret = 0;
112
113         _D("pid(%d)", pid);
114
115         ret = kill(pid, SIGKILL);
116         if (ret == -1)
117                 _D("send SIGKILL: %s", strerror(errno));
118
119         return ECORE_CALLBACK_CANCEL;
120 }
121
122 int _status_update_app_info_list(int pid, int status)
123 {
124         GSList *iter = NULL;
125         app_status_info_t *info_t = NULL;
126
127         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
128         {
129                 info_t = (app_status_info_t *)iter->data;
130                 if(pid == info_t->pid) {
131                         info_t->status = status;
132                         if(status == STATUS_DYING) {
133                                 if(info_t->pad_pid != DEBUG_LAUNCHPAD_PID)
134                                         ecore_timer_add(2, __app_terminate_timer_cb, info_t->pid);
135                         }
136                         break;
137                 }
138         }
139
140         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
141         {
142                 info_t = (app_status_info_t *)iter->data;
143
144                 //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
145         }
146
147         return 0;
148 }
149
150 int _status_remove_app_info_list(int pid)
151 {
152         GSList *iter = NULL;
153         app_status_info_t *info_t = NULL;
154
155         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
156         {
157                 info_t = (app_status_info_t *)iter->data;
158                 if(pid == info_t->pid) {
159                         app_status_info_list = g_slist_remove(app_status_info_list, info_t);
160                         free(info_t);
161                         break;
162                 }
163         }
164
165         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
166         {
167                 info_t = (app_status_info_t *)iter->data;
168
169                 //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
170         }
171
172         return 0;
173 }
174
175 int _status_get_app_info_status(int pid)
176 {
177         GSList *iter = NULL;
178         app_status_info_t *info_t = NULL;
179
180         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
181         {
182                 info_t = (app_status_info_t *)iter->data;
183                 if(pid == info_t->pid) {
184                         return info_t->status;
185                 }
186         }
187
188         return -1;
189 }
190
191
192 int _status_app_is_running(char *appid)
193 {
194         GSList *iter = NULL;
195         app_status_info_t *info_t = NULL;
196
197         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
198         {
199                 info_t = (app_status_info_t *)iter->data;
200                 if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0 ) {
201                         return info_t->pid;
202                 }
203         }
204         return -1;
205 }
206
207 char* _status_app_get_appid_bypid(int pid)
208 {
209         GSList *iter = NULL;
210         app_status_info_t *info_t = NULL;
211
212         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
213         {
214                 info_t = (app_status_info_t *)iter->data;
215                 if( pid == info_t->pid ) {
216                         return info_t->appid;
217                 }
218         }
219         return NULL;
220 }
221
222 char* _status_get_caller_by_appid(const char *appid)
223 {
224         GSList *iter = NULL;
225         app_status_info_t *info_t = NULL;
226
227         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
228         {
229                 info_t = (app_status_info_t *)iter->data;
230                 if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE-1) == 0) {
231                         return info_t->caller;
232                 }
233         }
234
235         return NULL;
236 }
237
238 int _status_send_running_appinfo(int fd)
239 {
240         GSList *iter = NULL;
241         app_status_info_t *info_t = NULL;
242         app_pkt_t *pkt = NULL;
243         int len;
244         char tmp_pid[MAX_PID_STR_BUFSZ];
245
246         pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
247         if(!pkt) {
248                 _E("malloc fail");
249                 close(fd);
250                 return 0;
251         }
252
253         memset(pkt, 0, AUL_SOCK_MAXBUFF);
254
255         for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
256         {
257                 info_t = (app_status_info_t *)iter->data;
258                 snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", info_t->pid);
259                 strncat((char *)pkt->data, tmp_pid, MAX_PID_STR_BUFSZ);
260                 strncat((char *)pkt->data, ":", 1);
261                 strncat((char *)pkt->data, info_t->appid, MAX_PACKAGE_STR_SIZE);
262                 strncat((char *)pkt->data, ":", 1);
263                 strncat((char *)pkt->data, info_t->app_path, MAX_PACKAGE_APP_PATH_SIZE);
264                 strncat((char *)pkt->data, ";", 1);
265         }
266
267         pkt->cmd = APP_RUNNING_INFO_RESULT;
268         pkt->len = strlen((char *)pkt->data) + 1;
269
270         if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
271                 if (errno == EPIPE)
272                         _E("send failed due to EPIPE.\n");
273                 _E("send fail to client");
274         }
275
276         if(pkt)
277                 free(pkt);
278
279         close(fd);
280
281         return 0;
282 }
283
284 int _status_app_is_running_v2(char *appid)
285 {
286         char *apppath = NULL;
287         int ret = 0;
288         int i = 0;
289         const char *ae;
290         const struct appinfo *ai;
291
292         if(appid == NULL)
293                 return -1;
294
295         ai = appinfo_find(_saf, appid);
296
297         if (ai == NULL)
298                 return -1;
299
300         ae = appinfo_get_value(ai, AIT_EXEC);
301         if (ae == NULL)
302                 return -1;
303
304         apppath = strdup(ae);
305         if (apppath == NULL) {
306                 _E("out of memory");
307                 return -1;
308         }
309
310         /*truncate apppath if it includes default bundles */
311         while (apppath[i] != 0) {
312                 if (apppath[i] == ' ' || apppath[i] == '\t') {
313                         apppath[i]='\0';
314                         break;
315                 }
316                 i++;
317         }
318
319         ret = __proc_iter_cmdline(NULL, apppath);
320
321         free(apppath);
322
323         return ret;
324 }
325
326 static int __get_pkginfo(const char *dname, const char *cmdline, void *priv)
327 {
328         app_info_from_db *menu_info;
329         char *r_info;
330         char *pkgname = NULL;
331         char *app_path = NULL;
332
333         r_info = (char *)priv;
334
335         if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL)
336                 goto out;
337         else {
338                 pkgname = _get_pkgname(menu_info);
339                 if (pkgname == NULL)
340                         goto out;
341
342                 app_path = _get_app_path(menu_info);
343                 if (app_path == NULL)
344                         goto out;
345
346                 strncat(r_info, dname, 8);
347                 strncat(r_info, ":", 1);
348                 strncat(r_info, pkgname, MAX_PACKAGE_STR_SIZE);
349                 strncat(r_info, ":", 1);
350                 strncat(r_info, app_path, MAX_PACKAGE_APP_PATH_SIZE);
351                 strncat(r_info, ";", 1);
352         }
353
354  out:
355         if (menu_info != NULL)
356                 _free_app_info_from_db(menu_info);
357         return 0;
358 }
359
360 int _status_send_running_appinfo_v2(int fd)
361 {
362         app_pkt_t *pkt = NULL;
363         int len;
364
365         pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
366         if(!pkt) {
367                 _E("malloc fail");
368                 close(fd);
369                 return 0;
370         }
371
372         memset(pkt, 0, AUL_SOCK_MAXBUFF);
373
374         __proc_iter_cmdline(__get_pkginfo, pkt->data);
375
376         pkt->cmd = APP_RUNNING_INFO_RESULT;
377         pkt->len = strlen((char *)pkt->data) + 1;
378
379         if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
380                 if (errno == EPIPE)
381                         _E("send failed due to EPIPE.\n");
382                 _E("send fail to client");
383         }
384
385         if(pkt)
386                 free(pkt);
387
388         close(fd);
389
390         return 0;
391 }
392
393 int _status_get_pkgname_bypid(int pid, char *pkgname, int len)
394 {
395         char *cmdline;
396         app_info_from_db *menu_info;
397
398         cmdline = __proc_get_cmdline_bypid(pid);
399         if (cmdline == NULL)
400                 return -1;
401
402         if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
403                 free(cmdline);
404                 return -1;
405         } else {
406                 snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
407         }
408
409         free(cmdline);
410         _free_app_info_from_db(menu_info);
411
412         return 0;
413 }
414
415 int _status_get_appid_bypid(int fd, int pid)
416 {
417         app_pkt_t *pkt = NULL;
418         int len;
419         int pgid;
420
421         pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
422         if(!pkt) {
423                 _E("malloc fail");
424                 close(fd);
425                 return 0;
426         }
427
428         memset(pkt, 0, AUL_SOCK_MAXBUFF);
429
430         pkt->cmd = APP_GET_INFO_ERROR;
431
432         if (_status_get_pkgname_bypid(pid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) {
433                 SECURE_LOGD("appid for %d is %s", pid, pkt->data);
434                 pkt->cmd = APP_GET_INFO_OK;
435                 goto out;
436         }
437         /* support app launched by shell script*/
438         _D("second chance");
439         pgid = getpgid(pid);
440         if (pgid <= 1)
441                 goto out;
442
443         _D("second change pgid = %d, pid = %d", pgid, pid);
444         if (_status_get_pkgname_bypid(pgid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0)
445                 pkt->cmd = APP_GET_INFO_OK;
446
447  out:
448         pkt->len = strlen((char *)pkt->data) + 1;
449
450         if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
451                 if (errno == EPIPE)
452                         _E("send failed due to EPIPE.\n");
453                 _E("send fail to client");
454         }
455
456         if(pkt)
457                 free(pkt);
458
459         close(fd);
460
461         return 0;
462 }
463
464 static int __get_pkgid_bypid(int pid, char *pkgid, int len)
465 {
466         char *cmdline;
467         app_info_from_db *menu_info;
468
469         cmdline = __proc_get_cmdline_bypid(pid);
470         if (cmdline == NULL)
471                 return -1;
472
473         if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
474                 free(cmdline);
475                 return -1;
476         } else
477                 snprintf(pkgid, len, "%s", _get_pkgid(menu_info));
478
479         free(cmdline);
480         _free_app_info_from_db(menu_info);
481
482         return 0;
483 }
484
485 int _status_get_pkgid_bypid(int fd, int pid)
486 {
487         app_pkt_t *pkt = NULL;
488         int len;
489         int pgid;
490
491         pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
492         if(!pkt) {
493                 _E("malloc fail");
494                 close(fd);
495                 return 0;
496         }
497
498         memset(pkt, 0, AUL_SOCK_MAXBUFF);
499
500         pkt->cmd = APP_GET_INFO_ERROR;
501
502         if (__get_pkgid_bypid(pid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) {
503                 SECURE_LOGD("appid for %d is %s", pid, pkt->data);
504                 pkt->cmd = APP_GET_INFO_OK;
505                 goto out;
506         }
507         /* support app launched by shell script*/
508         _D("second chance");
509         pgid = getpgid(pid);
510         if (pgid <= 1)
511                 goto out;
512
513         _D("second change pgid = %d, pid = %d", pgid, pid);
514         if (__get_pkgid_bypid(pgid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0)
515                 pkt->cmd = APP_GET_INFO_OK;
516
517  out:
518         pkt->len = strlen((char *)pkt->data) + 1;
519
520         if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
521                 if (errno == EPIPE)
522                         _E("send failed due to EPIPE.\n");
523                 _E("send fail to client");
524         }
525
526         if(pkt)
527                 free(pkt);
528
529         close(fd);
530
531         return 0;
532 }
533
534 int _status_get_cmdline(int fd, int pid)
535 {
536         app_pkt_t *pkt = NULL;
537         int len;
538         int pgid;
539         char *cmdline;
540
541         pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
542         if(!pkt) {
543                 _E("malloc fail");
544                 close(fd);
545                 return 0;
546         }
547
548         memset(pkt, 0, AUL_SOCK_MAXBUFF);
549
550         pkt->cmd = APP_GET_INFO_ERROR;
551
552         cmdline = __proc_get_cmdline_bypid(pid);
553         if (cmdline == NULL)
554                 goto out;
555         _E("cmdline : %s", cmdline);
556
557         snprintf((char *)pkt->data, MAX_PACKAGE_STR_SIZE, cmdline);
558         _E("pkt->data : %s", pkt->data);
559         pkt->cmd = APP_GET_INFO_OK;
560
561  out:
562         pkt->len = strlen((char *)pkt->data) + 1;
563
564         if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
565                 if (errno == EPIPE)
566                         _E("send failed due to EPIPE.\n");
567                 _E("send fail to client");
568         }
569
570         free(cmdline);
571
572         if(pkt)
573                 free(pkt);
574
575         close(fd);
576
577         return 0;
578 }
579
580
581 static void __app_info_iter_limit_cb(void *user_data, const char *appid, const struct appinfo *ai)
582 {
583         if(!g_hash_table_lookup(cooldown_tbl, appid)) {
584                 appinfo_set_value(ai, AIT_STATUS, "blocking");
585         }
586 }
587
588 static void __app_info_iter_waring_cb(void *user_data, const char *appid, const struct appinfo *ai)
589 {
590         if(g_hash_table_lookup(cooldown_black_tbl, appid)) {
591                 appinfo_set_value(ai, AIT_STATUS, "blocking");
592         }
593 }
594
595 static void __app_info_iter_release_cb(void *user_data, const char *appid, const struct appinfo *ai)
596 {
597         const char *component = NULL;
598         int onboot = 0;
599         int restart = 0;
600
601         if(!g_hash_table_lookup(cooldown_tbl, appid)) {
602                 component = appinfo_get_value(ai, AIT_COMPTYPE);
603                 onboot = appinfo_get_boolean(ai, AIT_ONBOOT);
604                 restart = appinfo_get_boolean(ai, AIT_RESTART);
605                 if (onboot == 1 && restart == 1 && component && strncmp(component, "svcapp", 6) == 0)
606                 {
607                         if (_status_app_is_running(appid) < 0)
608                         {
609                                 _I("start service (cooldown release) - %s", appid);
610                                 _start_srv(ai, NULL);
611                         }
612                         else
613                         {
614                                 _E("service: %s is already running", appid);
615                         }
616                 }
617                 appinfo_set_value(ai, AIT_STATUS, "installed");
618         }
619 }
620
621
622
623 static int __cooldown_cb(const char* status, void *data)
624 {
625         GSList *iter = NULL;
626         app_status_info_t *info_t = NULL;
627         int ret;
628         int dummy;
629
630         _I("__cooldown_cb, status: %s", status);
631
632         if(strncmp(status, "LimitAction", 11) == 0) {
633                 appinfo_foreach(_saf, __app_info_iter_limit_cb, NULL);
634                 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
635                 {
636                         info_t = (app_status_info_t *)iter->data;
637                         if(!g_hash_table_lookup(cooldown_tbl, info_t->appid)) {
638                                 proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, info_t->pid, NULL);
639                                 ret = __app_send_raw_with_noreply(info_t->pid, APP_TERM_BY_PID_ASYNC, (unsigned char *)&dummy, sizeof(int) );
640                         }
641                 }
642                 cooldown_status = COOLDOWN_LIMIT;
643         } else if(strncmp(status, "WarningAction", 13) == 0) {
644                 appinfo_foreach(_saf, __app_info_iter_waring_cb, NULL);
645                 for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
646                 {
647                         info_t = (app_status_info_t *)iter->data;
648                         if(g_hash_table_lookup(cooldown_black_tbl, info_t->appid)) {
649                                 proc_group_change_status(PROC_CGROUP_SET_TERMINATE_REQUEST, info_t->pid, NULL);
650                                 ret = __app_send_raw_with_noreply(info_t->pid, APP_TERM_BY_PID_ASYNC, (unsigned char *)&dummy, sizeof(int) );
651                         }
652                 }
653                 cooldown_status = COOLDOWN_WARNING;
654         } else if (strncmp(status, "Release", 7) == 0){
655                 appinfo_foreach(_saf, __app_info_iter_release_cb, NULL);
656                 cooldown_status = COOLDOWN_RELEASE;
657         }
658
659         return 0;
660 }
661
662 int _status_get_cooldown_status(void)
663 {
664         return cooldown_status;
665 }
666
667 #ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
668 static int __lcd_status_cb(const char *lcd_status, void *data)
669 {
670         int gesture = -1;
671         Ecore_X_Window win;
672         int pid = 0;
673         bundle *kb = NULL;
674         char proc_file[PROC_SIZE] = {0, };
675         static int paused_pid = 0;
676
677         // Check the wake-up gesture is a clock or not.
678         // 0: Off, 1: Clock, 2: Last viewed screen
679         if (vconf_get_int(VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING, &gesture) < 0) {
680                 _E("Failed to get VCONFKEY_WMS_WAKEUP_BY_GESTURE_SETTING");
681                 return 0;
682         }
683
684         if (gesture == WAKE_UP_GESTURE_CLOCK) {
685                 SECURE_LOGD("Skip when wake-up gesture is a Clock.");
686                 return 0;
687         }
688
689         // Get the topmost app
690         win = ecore_x_window_focus_get();
691         if (ecore_x_netwm_pid_get(win, &pid) != 1) {
692                 _E("Can't get pid for focus x window (%x)", win);
693                 return 0;
694         }
695         SECURE_LOGD("The topmost app's pid is %d.", pid);
696
697         // Pause or Resume the app when the lcd becomes On/Off
698         if (lcd_status && (strncmp(lcd_status, LCD_OFF, strlen(LCD_OFF)) == 0)) {
699                 SECURE_LOGD("LCD status becomes Off. Pause the topmose app, %d", pid);
700                 paused_pid = pid;
701                 kb = bundle_create();
702                 app_send_cmd_with_noreply(pid, APP_PAUSE_LCD_OFF, kb);
703         }
704         else if (lcd_status && (strncmp(lcd_status, LCD_ON, strlen(LCD_ON)) == 0)) {
705                 if (paused_pid != pid) {
706                         SECURE_LOGE("The topmost app(%d) is different with the paused app(%d).", pid, paused_pid);
707                 }
708
709                 // Check whether the paused app is running or Not
710                 snprintf(proc_file, PROC_SIZE, "/proc/%d/cmdline", paused_pid);
711                 if (access(proc_file, F_OK) != 0) {
712                         SECURE_LOGE("paused app(%d) seems to be killed.", paused_pid);
713                         if (paused_pid != pid) {
714                                 paused_pid = pid;
715                         } else {
716                                 return 0;
717                         }
718                 }
719
720                 SECURE_LOGD("LCD status becomes On. Resume the paused app, %d", paused_pid);
721                 kb = bundle_create();
722                 app_send_cmd_with_noreply(paused_pid, APP_RESUME_LCD_ON, kb);
723         }
724         else {
725                 _E("Invalid input param for lcd_status.");
726         }
727
728         bundle_free(kb);
729         return 0;
730 }
731 #endif
732
733 static int __app_info_handler (const pkgmgrinfo_appinfo_h handle, void *data)
734 {
735         char *tmp_appid;
736         char *appid;
737
738         pkgmgrinfo_appinfo_get_appid(handle, &tmp_appid);
739
740         appid = strdup(tmp_appid);
741
742         g_hash_table_insert(cooldown_tbl, appid, appid);
743
744         SECURE_LOGD("white_list : %s", appid);
745
746         return 0;
747 }
748
749 static int __blacklist_app_info_handler (const pkgmgrinfo_appinfo_h handle, void *data)
750 {
751         char *tmp_appid;
752         char *appid;
753
754         pkgmgrinfo_appinfo_get_appid(handle, &tmp_appid);
755
756         appid = strdup(tmp_appid);
757
758         g_hash_table_insert(cooldown_black_tbl, appid, appid);
759
760         SECURE_LOGD("white_list : %s", appid);
761
762         return 0;
763 }
764
765 int _status_init(struct amdmgr* amd)
766 {
767         int i;
768         pkgmgrinfo_appinfo_h handle = NULL;
769
770         _saf = amd->af;
771
772         aul_listen_cooldown_signal(__cooldown_cb, NULL);
773
774         cooldown_tbl = g_hash_table_new(g_str_hash, g_str_equal);
775         for(i = 0; i < WHITE_LIST_COUNT; i++) {
776                 SECURE_LOGD("pkgid %s", cooldown_list[i]);
777                 if (pkgmgrinfo_pkginfo_get_pkginfo(cooldown_list[i], &handle) == PMINFO_R_OK){
778                         pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __app_info_handler, NULL);
779                         pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __app_info_handler, NULL);
780                         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
781                 }
782         }
783
784         cooldown_black_tbl = g_hash_table_new(g_str_hash, g_str_equal);
785         for(i = 0; i < BLACK_LIST_COUNT; i++) {
786                 SECURE_LOGD("pkgid %s", cooldown_black_list[i]);
787                 if (pkgmgrinfo_pkginfo_get_pkginfo(cooldown_black_list[i], &handle) == PMINFO_R_OK){
788                         pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, __blacklist_app_info_handler, NULL);
789                         pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __blacklist_app_info_handler, NULL);
790                         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
791                 }
792         }
793
794 #ifdef _APPFW_FEATURE_VISIBILITY_CHECK_BY_LCD_STATUS
795         // Register callback for LCD On/Off
796         aul_listen_lcd_status_signal(__lcd_status_cb, NULL);
797 #endif
798         return 0;
799 }
800