resolve TSAM-5913: set message app's package name for notification apis
[platform/core/messaging/msg-service.git] / manager / src / msg-manager-notification.cpp
1 /*
2  * Copyright (c) 2016 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 /*==================================================================================================
18                                          INCLUDE FILES
19 ==================================================================================================*/
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <glib.h>
24
25 #include <libintl.h>
26 #include <locale.h>
27 #include <stdarg.h>
28
29 #include <app_control.h>
30 #include <badge_internal.h>
31 #include <notification_list.h>
32 #include <notification_text_domain.h>
33 #include <notification_internal.h>
34 #include <notification_status.h>
35 #include <notification_setting.h>
36 #include <notification_setting_internal.h>
37 #include <package_manager.h>
38 #include <vconf.h>
39
40 #include <msg.h>
41 #include <msg_storage.h>
42
43 #include <msg-manager-util.h>
44 #include <msg-manager-contact.h>
45 #include <msg-manager-debug.h>
46 #include <msg-manager-notification.h>
47 #include <msg-manager-sound.h>
48
49
50 #define EMAIL_AT '@'
51
52 /*==================================================================================================
53                                      VARIABLES
54 ==================================================================================================*/
55
56 static GList *msg_report_notification_list = NULL;
57 static bool is_init = false;
58 extern msg_handle_t msg_handle;
59 int g_alarmId = 0;
60
61
62 /*==================================================================================================
63                                          STRUCTURES
64 ==================================================================================================*/
65 typedef struct _report_notification_s
66 {
67         int priv_id;
68         char addressVal[MAX_ADDRESS_VAL_LEN+1];
69 } report_notification_s;
70
71
72 typedef struct _msg_mgr_noti_info_s
73 {
74         msg_mgr_notification_type_t             type;
75         int                     id;
76         int                     layout;
77         int                     count;
78         int                     senderCount;
79         time_t          time;
80         char            sender[MSG_NOTI_TEXT_LEN_S+1];
81         char            text[MSG_NOTI_TEXT_LEN+1];
82         char            number[MSG_NOTI_TEXT_LEN_S+1];
83         char            imagePath[MAX_IMAGE_PATH_LEN+1];                /**< Indicates the image path of contact. */
84         int                     applist;
85         app_control_h           svc_h;
86         app_control_h           active_noti_svc_h[MSG_ACTIVE_NOTI_BUTTON_NUM];
87         msg_message_id_t                msg_id;
88         unsigned char           extra_data;
89         int             sim_idx;
90         int                     active_noti_button_num;
91         int             active_media_cnt;
92         int             active_media_size;
93         unsigned char   active_subtype;         /**< to distinguish cb, push message */
94         char            active_sender[MSG_NOTI_TEXT_LEN_S+1];
95         char            active_subject[MSG_NOTI_TEXT_LEN_S+1];
96         char            active_text[MSG_NOTI_TEXT_LEN+1];
97 } MSG_MGR_NOTI_INFO_S;
98
99
100 typedef struct _del_noti_info_s
101 {
102         msg_mgr_notification_type_t                     type;
103         int             sim_idx;
104 } DEL_NOTI_INFO_S;
105
106
107 /*==================================================================================================
108                                                                                 FUNCTION DEFINE
109 ===================================================================================================*/
110
111 void MsgMgrInitReportNotiList();
112 void MsgRefreshNotiCb(void *data);
113 void MsgMgrDeleteNotiCb(void *data);
114
115 void MsgMgrDeleteNotification(msg_mgr_notification_type_t noti_type, int simIndex);
116
117 notification_h getHandle(int *noti_id);
118
119 int getPrivId(msg_mgr_notification_type_t noti_type, int sim_idx);
120 void updatePrivId(msg_mgr_notification_type_t noti_type, int noti_id, int sim_idx);
121
122 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info); /* For addNoti() */
123 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, msg_mgr_active_notification_type_t active_noti);
124 void createActiveInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info);
125 void clearInfoData(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
126
127 int getAppIcon(const char *app_id, char **icon_path);
128 int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage);
129
130 void setProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
131 void setTextDomain(notification_h noti_h);
132 void setText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
133 void setIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
134 void setSoundAndVibration(notification_h noti_h, char *addressVal, bool bVoiceMail);
135 void setActiveNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
136 void setActiveProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
137 void setActiveText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
138 void setActiveIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info);
139
140 void setNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info, bool bFeedback);
141
142 bool isExistAddressInReportTable(const char *addr);
143
144 /* Wrapper */
145 void createServiceHandle(app_control_h *svc_h);
146 void setServiceAppId(app_control_h svc_h, const char* app_id);
147 void setServiceUri(app_control_h svc_h, const char* uri);
148 void setServiceOperation(app_control_h svc_h, const char* operation);
149 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val);
150 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val);
151 void setServicePackageName(app_control_h svc_h, const char* pkg_name);
152 void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data);
153
154 void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir);
155 void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key);
156 void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time);
157 void setNotiTime(notification_h noti_h, time_t time);
158 void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path);
159 void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path);
160 void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path);
161 void setNotiEventHandler(notification_h noti_h, notification_event_type_e type, app_control_h event_handler);
162
163 /* Alarm */
164 void MsgMgrNotiSoundRepeatAlarmCB(int alarmId);
165 void MsgMgrSoundCreateRepeatAlarm(int RepeatTime);
166 void MsgMgrSoundSetRepeatAlarm();
167
168 char *get_translate_text(const char *pkg_name, const char *locale_dir, const char *text);
169
170 /*==================================================================================================
171                                                                         FUNCTION IMPLEMENTATION
172 ==================================================================================================*/
173 bool _is_valid_email(char *pAddress)
174 {
175         if (!pAddress || pAddress[0] == 0)
176                 return false;
177         if (!strchr (pAddress, EMAIL_AT))
178                 return false;
179         return true;
180 }
181
182
183 bool isExistAddressInReportTable(const char *addr)
184 {
185         char sqlQuery[MAX_QUERY_LEN+1];
186         int rowCnt = 0, colCnt = 0;
187         char **db_res = NULL;
188         int msg_err = 0;
189
190         char *normal_addr = msg_mgr_normalize_number((char *)addr);
191
192         memset(sqlQuery, 0x00, sizeof(sqlQuery));
193         snprintf(sqlQuery, sizeof(sqlQuery), "* FROM %s WHERE ADDRESS_VAL LIKE '%%%%%s'", MSGFW_SMS_REPORT_TABLE_NAME, normal_addr);
194
195         msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &rowCnt, &colCnt);
196         if (msg_err != MSG_SUCCESS) {
197                 MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
198                 return false;
199         }
200
201         msg_err = msg_db_free(msg_handle, db_res);
202         if (msg_err != MSG_SUCCESS) {
203                 MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
204                 return false;
205         }
206
207         if (rowCnt > 0)
208                 return true;
209
210         memset(sqlQuery, 0x00, sizeof(sqlQuery));
211         snprintf(sqlQuery, sizeof(sqlQuery), "* FROM %s WHERE ADDRESS_VAL LIKE '%%%%%s'", MSGFW_REPORT_TABLE_NAME, normal_addr);
212
213         msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &rowCnt, &colCnt);
214         if (msg_err != MSG_SUCCESS) {
215                 MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
216                 return false;
217         }
218
219         msg_err = msg_db_free(msg_handle, db_res);
220         if (msg_err != MSG_SUCCESS) {
221                 MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
222                 return false;
223         }
224
225         if (rowCnt > 0)
226                 return true;
227
228         return false;
229 }
230
231
232 void MsgMgrInitReportNotiList()
233 {
234         MSG_MGR_BEGIN();
235
236         if (msg_report_notification_list) {
237                 MSG_MGR_DEBUG("Report Noti List is already inited");
238                 return;
239         }
240
241         msg_report_notification_list = NULL;
242
243         notification_h noti = NULL;
244         notification_list_h noti_list = NULL;
245         notification_list_h head_noti_list = NULL;
246         int noti_err = NOTIFICATION_ERROR_NONE;
247         app_control_h app_control = NULL;
248
249         noti_err = notification_get_list(NOTIFICATION_TYPE_NONE, -1, &noti_list);
250         if (noti_err != NOTIFICATION_ERROR_NONE) {
251                 MSG_MGR_DEBUG("notification_get_list() is failed!!");
252                 return;
253         }
254
255         head_noti_list = noti_list;
256
257         while (noti_list != NULL) {
258                 noti = notification_list_get_data(noti_list);
259
260                 char tempAddr[MAX_ADDRESS_VAL_LEN+1];
261                 memset(tempAddr, 0x00, sizeof(tempAddr));
262
263                 noti_err = notification_get_launch_option(noti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, &app_control);
264                 if (noti_err != NOTIFICATION_ERROR_NONE) {
265                         MSG_MGR_DEBUG("notification_get_excute_option() failed!!");
266                         break;
267                 }
268
269                 char *addr = NULL;
270
271                 int ret = app_control_get_extra_data(app_control, "address", &addr);
272                 if (ret == APP_CONTROL_ERROR_NONE && addr != NULL) {
273                         if (isExistAddressInReportTable(addr)) {
274                                 report_notification_s *info = new report_notification_s;
275                                 memset(info, 0x00, sizeof(report_notification_s));
276
277                                 notification_get_id(noti, NULL, &(info->priv_id));
278                                 snprintf(info->addressVal, sizeof(info->addressVal), "%s", addr);
279
280                                 msg_report_notification_list = g_list_append(msg_report_notification_list, (void *)info);
281                                 MSG_MGR_SEC_DEBUG("appended list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
282                         }
283
284                         g_free(addr);
285                         addr = NULL;
286                 }
287
288                 noti_list = notification_list_get_next(noti_list);
289         }
290
291         if (head_noti_list)
292                 notification_free_list(head_noti_list);
293
294         MSG_MGR_END();
295 }
296
297
298 void MsgMgrInitNoti()
299 {
300         if (is_init)
301                 return;
302
303         bool bNotiSvcReady = false;
304
305         bNotiSvcReady = notification_is_service_ready();
306
307         if (bNotiSvcReady == true) {
308                 MSG_MGR_DEBUG("Notification server is available");
309 #ifndef MSG_NOTI_INTEGRATION
310                 MsgDeleteNotification(MSG_MGR_NOTI_TYPE_SIM, -1);
311 #endif
312                 MsgMgrRefreshAllNotification(false, true, MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT);            /* On Booting */
313                 MsgMgrInitReportNotiList();
314         } else {
315                 MSG_MGR_DEBUG("Notification server is not available. Init is defered");
316 #ifndef MSG_NOTI_INTEGRATION
317                 MSG_MGR_NOTI_INFO_S *delNotiInfo = (MSG_MGR_NOTI_INFO_S *)calloc(1, sizeof(MSG_MGR_NOTI_INFO_S));
318                 if (delNotiInfo) {
319                         delNotiInfo->type = MSG_MGR_NOTI_TYPE_SIM;
320                         delNotiInfo->sim_idx = -1;
321                 }
322                 notification_add_deferred_task(MsgDeleteNotiCb, (void *)delNotiInfo);
323 #endif
324                 notification_add_deferred_task(MsgRefreshNotiCb, (void *)NULL);
325         }
326
327         is_init = true;
328 }
329
330
331 void MsgRefreshNotiCb(void *data)
332 {
333         MsgMgrRefreshAllNotification(false, true, MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT);
334         MsgMgrInitReportNotiList();
335
336         if (data) {
337                 free(data);
338                 data = NULL;
339         }
340
341         return;
342 }
343
344
345 void MsgMgrDeleteNotiCb(void *data)
346 {
347         if (data) {
348                 DEL_NOTI_INFO_S *delNotiInfo = (DEL_NOTI_INFO_S *)data;
349
350                 MsgMgrDeleteNotification(delNotiInfo->type, delNotiInfo->sim_idx);
351
352                 free(data);
353                 data = NULL;
354         }
355
356         return;
357 }
358
359
360 int MsgMgrInsertOnlyActiveNotification(msg_mgr_notification_type_t noti_type, MSG_MGR_MESSAGE_INFO_S *msg_info)
361 {
362         MSG_MGR_BEGIN();
363
364         notification_h noti_h = NULL;
365
366         MSG_MGR_NOTI_INFO_S noti_info = {0, };
367
368         noti_info.type = noti_type;
369         noti_info.active_noti_button_num = 1;
370
371         createActiveInfoData(&noti_info, msg_info);
372
373         noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
374
375         setActiveNotification(noti_h, &noti_info);
376
377         clearInfoData(noti_h, &noti_info);
378
379         MSG_MGR_END();
380         return 0;
381 }
382
383
384 int MsgMgrRefreshNotification(msg_mgr_notification_type_t noti_type, bool bFeedback, msg_mgr_active_notification_type_t active_type)
385 {
386         int err = 0;
387         notification_h noti_h = NULL;
388         int bNotification = 1;
389 /*      bool bReplyPopup = false; */
390
391         MSG_MGR_NOTI_INFO_S noti_info = {0, };
392         noti_info.type = noti_type;
393         noti_info.id = getPrivId(noti_info.type, -1);
394
395         err = getLatestMsgInfo(&noti_info, false);
396
397         if (err != 0) {
398                 MSG_MGR_DEBUG("getLatestMsgInfo() err = [%d]", err);
399                 goto __END_OF_REFRESH_NOTI;
400         }
401
402         if (active_type == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT) {
403                 err = MsgMgrInsertInstantMessage(noti_type);
404
405                 if (err != 0) {
406                         MSG_MGR_DEBUG(" MsgMgrInsertInstantMessage() err = [%d]", err);
407                         goto __END_OF_REFRESH_NOTI;
408                 }
409         }
410
411         if (vconf_get_bool(MSG_SETTING_NOTIFICATION, &bNotification) != 0) {
412                 MSG_MGR_DEBUG("vconf_get_bool is failed.");
413         }
414
415         if (bNotification == 0) {
416                 MSG_MGR_DEBUG("Msg Alert notification is off.");
417                 goto __END_OF_REFRESH_NOTI;
418         }
419
420         createInfoData(&noti_info, active_type);
421
422         noti_h = getHandle(&noti_info.id);
423
424         if (noti_h == NULL) {
425                 MSG_MGR_DEBUG("Notification handle is NULL");
426                 err = MSG_ERR_NULL_POINTER;
427                 goto __END_OF_REFRESH_NOTI;
428         }
429
430         setNotification(noti_h, &noti_info, bFeedback);
431
432 __END_OF_REFRESH_NOTI :
433         clearInfoData(noti_h, &noti_info);
434
435         return err;
436 }
437
438
439 int MsgMgrAddReportNotification(msg_mgr_notification_type_t noti_type, MSG_MGR_MESSAGE_INFO_S *msg_info)
440 {
441         int ret = 0;
442
443         notification_h noti_h = NULL;
444
445         report_notification_s *info = new report_notification_s;
446         memset(info, 0x00, sizeof(report_notification_s));
447
448         MSG_MGR_NOTI_INFO_S noti_info = {0, };
449         noti_info.type = noti_type;
450
451         createInfoData(&noti_info, msg_info);
452
453         noti_h = getHandle(&noti_info.id);
454
455         if (noti_h == NULL) {
456                 MSG_MGR_DEBUG("Notification handle is NULL");
457                 ret = -1;
458                 goto __END_OF_ADD_REPORT_NOTI;
459         }
460
461         setNotification(noti_h, &noti_info, true);
462
463         info->priv_id = noti_info.id;
464         snprintf(info->addressVal, sizeof(info->addressVal), "%s", msg_info->addressVal);
465         msg_report_notification_list = g_list_append(msg_report_notification_list, (void *)info);
466         MSG_MGR_SEC_DEBUG("appended list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
467
468 __END_OF_ADD_REPORT_NOTI :
469         clearInfoData(noti_h, &noti_info);
470
471         return ret;
472 }
473
474
475 int MsgMgrDeleteReportNotification(const char *addr)
476 {
477         MSG_MGR_BEGIN();
478
479         notification_h noti_h = NULL;
480         int bNotification = 1;
481
482         if (vconf_get_bool(MSG_SETTING_NOTIFICATION, &bNotification) != 0) {
483                 MSG_MGR_DEBUG("vconf_get_bool is failed.");
484         }
485
486         if (bNotification == 0) {
487                 MSG_MGR_DEBUG("Msg Alert notification is off.");
488                 return 0;
489         }
490
491         char* normalAddr = NULL;
492         unsigned int list_length = g_list_length(msg_report_notification_list);
493         bool isDelete = false;
494
495         MSG_MGR_DEBUG("list length [%d]", list_length);
496
497         if (list_length > 0) {
498                 GList *iter = g_list_first(msg_report_notification_list);
499
500                 while (iter != NULL) {
501                         isDelete = false;
502                         report_notification_s *info = (report_notification_s*)(iter->data);
503                         if (info == NULL) {
504                                 MSG_MGR_DEBUG("info is NULL!");
505                                 return -1;
506                         }
507
508                         MSG_MGR_SEC_DEBUG("list data = [priv_id = %d address = %s]", info->priv_id, info->addressVal);
509
510                         noti_h = notification_load(NULL, info->priv_id);
511                         if (noti_h == NULL) {
512                                 MSG_MGR_DEBUG("notification with priv_id [%d] is NULL", info->priv_id);
513                                 isDelete = true;
514                         } else {
515                                 normalAddr = msg_mgr_normalize_number(info->addressVal);
516
517                                 if (normalAddr) {
518                                         MSG_MGR_SEC_DEBUG("normalized number = %s", normalAddr);
519
520                                         if (g_str_has_suffix(addr, normalAddr)) {
521                                                 if (notification_delete(noti_h) == NOTIFICATION_ERROR_NONE) {
522                                                         MSG_MGR_SEC_DEBUG("delete report notification address [%s]", info->addressVal);
523                                                         isDelete = true;
524                                                 } else {
525                                                         MSG_MGR_DEBUG("delete notification failed");
526                                                 }
527                                         }
528                                 }
529
530                                 notification_free(noti_h);
531                                 noti_h = NULL;
532                         }
533
534                         iter = g_list_next(iter);
535
536                         if (isDelete) {
537                                 msg_report_notification_list = g_list_remove(msg_report_notification_list, (void *)info);
538                                 if (info) {
539                                         delete info;
540                                         info = NULL;
541                                 }
542                         }
543                 }
544         }
545
546         MSG_MGR_END();
547
548         return 0;
549 }
550
551 int MsgMgrAddNotification(msg_mgr_notification_type_t noti_type, MSG_MGR_MESSAGE_INFO_S *msg_info)
552 {
553         int ret = 0;
554
555         notification_h noti_h = NULL;
556
557         MSG_MGR_NOTI_INFO_S noti_info = {0, };
558
559         noti_info.type = noti_type;
560
561         createInfoData(&noti_info, msg_info);
562
563         /* check mwi or voicemail count is 0 then skip add notification */
564         if (noti_info.count == 0) {
565                 MSG_MGR_DEBUG("Notification count is 0");
566                 ret = -1;
567                 goto __END_OF_ADD_NOTI;
568         }
569
570         noti_h = getHandle(&noti_info.id);
571
572         if (noti_h == NULL) {
573                 MSG_MGR_DEBUG("Notification handle is NULL");
574                 ret = -1;
575                 goto __END_OF_ADD_NOTI;
576         }
577
578         setNotification(noti_h, &noti_info, true);
579
580 __END_OF_ADD_NOTI :
581         clearInfoData(noti_h, &noti_info);
582
583         return ret;
584 }
585
586
587 void MsgMgrDeleteNotification(msg_mgr_notification_type_t noti_type, int simIndex)
588 {
589         int noti_err = NOTIFICATION_ERROR_NONE;
590
591         if (noti_type == MSG_MGR_NOTI_TYPE_ALL) {
592                 noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
593         } else if (noti_type == MSG_MGR_NOTI_TYPE_VOICE_1 || noti_type == MSG_MGR_NOTI_TYPE_VOICE_2 || noti_type == MSG_MGR_NOTI_TYPE_SIM) {
594                 int notiId = 0;
595
596                 notiId = getPrivId(noti_type, simIndex);
597                 MSG_MGR_DEBUG("deleted notification ID = [%d] Type = [%d]", notiId, noti_type);
598
599                 if (notiId > 0)
600                         noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, notiId);
601
602         } else {
603                 MSG_MGR_DEBUG("No matching type [%d]", noti_type);
604         }
605
606         if (noti_err != NOTIFICATION_ERROR_NONE) {
607                 MSG_MGR_DEBUG("Fail to notification_delete_all noti_err [%d]", noti_err);
608         }
609
610         updatePrivId(noti_type, 0, simIndex);
611 }
612
613
614 int MsgMgrDeleteNoti(msg_mgr_notification_type_t noti_type, int simIndex)
615 {
616         bool bNotiSvcReady = false;
617
618         DEL_NOTI_INFO_S *delNotiInfo = (DEL_NOTI_INFO_S *)calloc(1, sizeof(DEL_NOTI_INFO_S));
619
620         if (delNotiInfo) {
621                 delNotiInfo->type = noti_type;
622                 delNotiInfo->sim_idx = simIndex;
623         }
624
625         bNotiSvcReady = notification_is_service_ready();
626
627         if (bNotiSvcReady == true) {
628                 MSG_MGR_DEBUG("Notification server is available");
629                 MsgMgrDeleteNotiCb((void *)delNotiInfo);
630         } else {
631                 MSG_MGR_DEBUG("Notification server is not available. Delete is defered");
632                 notification_add_deferred_task(MsgMgrDeleteNotiCb, (void *)delNotiInfo);
633         }
634         return 0;
635 }
636
637
638 void MsgMgrRefreshAllNotification(bool bWithSimNoti, bool bFeedback, msg_mgr_active_notification_type_t active_type)
639 {
640         MSG_MGR_BEGIN();
641
642         int err = 0;
643
644 #ifndef MSG_NOTI_INTEGRATION
645         MsgDeleteNotification(MSG_MGR_NOTI_TYPE_SIM);
646 #endif
647
648 #ifdef MSG_NOTI_INTEGRATION
649         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, bFeedback, active_type);
650         if (err != 0)
651                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_NORMAL, err);
652 #else
653         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, bFeedback, active_type);
654         if (err != 0)
655                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_NORMAL, err);
656
657         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_CB, bFeedback, active_type);
658         if (err != 0)
659                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_CB, err);
660
661         if (bWithSimNoti) {
662                 err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM, bFeedback, active_type);
663                 if (err != 0)
664                         MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_SIM, err);
665         }
666 #endif
667
668         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_FAILED, bFeedback, active_type);
669         if (err != 0)
670                 MSG_MGR_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_MGR_NOTI_TYPE_FAILED, err);
671
672         MSG_MGR_END();
673 }
674
675
676 void setProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
677 {
678         MSG_MGR_BEGIN();
679
680         int noti_err = NOTIFICATION_ERROR_NONE;
681
682         /* set layout */
683         noti_err = notification_set_layout(noti_h, (notification_ly_type_e)noti_info->layout);
684         if (noti_err != NOTIFICATION_ERROR_NONE) {
685                 MSG_MGR_DEBUG("Fail to notification_set_layout : %d", noti_err);
686         }
687
688         /* set led */
689         noti_err = notification_set_led(noti_h, NOTIFICATION_LED_OP_ON, 0x00);
690         if (noti_err != NOTIFICATION_ERROR_NONE) {
691                 MSG_MGR_DEBUG("Fail to notification_set_led.");
692         }
693
694         /* set execute option and property */
695         switch (noti_info->type) {
696         case MSG_MGR_NOTI_TYPE_NORMAL: {
697                 if (noti_info->count > 1) {
698                         notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
699                 } else {
700                         if (noti_info->svc_h) { /* overwrite bundle key "type" */
701                                 /* addServiceExtraData(noti_info->svc_h, "type", "reply"); */
702                                 addServiceExtraData(noti_info->svc_h, "show_list", "list_show");
703                         }
704                         notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
705                 }
706
707                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
708                 break;
709         }
710         case MSG_MGR_NOTI_TYPE_CB:
711         case MSG_MGR_NOTI_TYPE_SIM: {
712                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
713                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE|NOTIFICATION_PROP_VOLATILE_DISPLAY);
714                 break;
715         }
716         case MSG_MGR_NOTI_TYPE_FAILED: {
717                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
718                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
719                 break;
720         }
721         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
722                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
723                 break;
724         }
725         case MSG_MGR_NOTI_TYPE_VOICE_1:
726         case MSG_MGR_NOTI_TYPE_VOICE_2:
727         case MSG_MGR_NOTI_TYPE_MWI:
728         case MSG_MGR_NOTI_TYPE_CLASS0:
729         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT:
730         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
731         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
732                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
733                 break;
734         }
735         default:
736                 MSG_MGR_DEBUG("No matching type for notification_set_launch_option() [%d]", noti_info->type);
737                 break;
738         }
739
740         /* set applist */
741         noti_err = notification_set_display_applist(noti_h, noti_info->applist);
742         if (noti_err != NOTIFICATION_ERROR_NONE) {
743                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
744         }
745
746         /* set pkg name */
747         noti_err = notification_set_pkgname(noti_h, MSG_DEFAULT_APP_ID);
748         if (noti_err != NOTIFICATION_ERROR_NONE) {
749                 MSG_MGR_DEBUG("Fail to notification_set_pkgname");
750         }
751
752         MSG_MGR_END();
753 }
754
755
756 void setTextDomain(notification_h noti_h)
757 {
758         MSG_MGR_BEGIN();
759
760         setNotiTextDomain(noti_h, MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR);
761         MSG_MGR_END();
762 }
763
764
765 void setText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
766 {
767         MSG_MGR_BEGIN();
768
769         char unreadMsgCntStr[10] = {0};
770         int bPreview = 1;
771
772         if (vconf_get_bool(MSG_SETTING_PREVIEW, &bPreview) != 0) {
773                 MSG_MGR_DEBUG("vconf_get_bool is failed.");
774         }
775
776         /* set title and content */
777         switch (noti_info->type) {
778 #ifdef MSG_NOTI_INTEGRATION
779         case MSG_MGR_NOTI_TYPE_NORMAL:
780         case MSG_MGR_NOTI_TYPE_CB:
781         case MSG_MGR_NOTI_TYPE_SIM: {
782                 if (noti_info->count > 1) {
783                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
784                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
785                         setNotiTime(noti_h, noti_info->time);
786
787                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
788                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
789
790                 } else {
791                         if (bPreview) {
792                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
793                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
794                         } else {
795                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
796                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
797                         }
798                         setNotiTime(noti_h, noti_info->time);
799                 }
800                 break;
801         }
802 #else
803         case MSG_MGR_NOTI_TYPE_NORMAL: {
804                 if (noti_info->count > 1) {
805                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
806                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
807                         setNotiTime(noti_h, noti_info->time);
808
809                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
810                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
811                 } else {
812                         if (bPreview) {
813                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
814                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
815                         } else {
816                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
817                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
818                         }
819                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
820                         setNotiTime(noti_h, noti_info->time);
821                 }
822                 break;
823         }
824         case MSG_MGR_NOTI_TYPE_CB: {
825                 if (noti_info->count > 1) {
826                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
827                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
828                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
829                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
830                         setNotiTime(noti_h, noti_info->time);
831
832                 } else {
833                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
834                         setNotiTime(noti_h, noti_info->time);
835
836                         if (bPreview) {
837                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
838                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
839                         } else {
840                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
841                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
842                         }
843                 }
844                 break;
845         }
846         case MSG_MGR_NOTI_TYPE_SIM: {
847                 if (noti_info->count > 1) {
848                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
849                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
850                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
851
852                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
853                         setNotiTime(noti_h, noti_info->time);
854                 } else {
855                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
856                         setNotiTime(noti_h, noti_info->time);
857
858                         if (bPreview) {
859                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
860                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
861                         } else {
862                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
863                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
864                         }
865                 }
866                 break;
867         }
868 #endif
869         case MSG_MGR_NOTI_TYPE_FAILED: {
870                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MSG_MESSAGE);
871                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Failed to send message.", FAILED_TO_SEND_MESSAGE);
872                 if (noti_info->count > 1) {
873                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
874                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
875                 }
876                 setNotiTime(noti_h, noti_info->time);
877                 break;
878         }
879         case MSG_MGR_NOTI_TYPE_VOICE_1:
880         case MSG_MGR_NOTI_TYPE_VOICE_2: {
881                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Voicemail", VOICE_MAIL);
882                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
883                 setNotiTime(noti_h, noti_info->time);
884
885                 if (noti_info->count == 1) {
886                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
887                 } else if (noti_info->count > 1) {
888                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
889                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
890                 } else {
891                         MSG_MGR_DEBUG("Invalid notification count, [cnt = %d]", noti_info->count);
892                 }
893                 break;
894         }
895         case MSG_MGR_NOTI_TYPE_MWI: {
896                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "MWI Message", NULL);
897                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
898                 setNotiTime(noti_h, noti_info->time);
899                 break;
900         }
901         case MSG_MGR_NOTI_TYPE_CLASS0: {
902                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL);
903                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
904                 setNotiTime(noti_h, noti_info->time);
905                 break;
906         }
907         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT: {
908                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery report", DELIVERY_MESSAGE);
909                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
910
911                 if (noti_info->extra_data == MSG_NETWORK_DELIVER_SUCCESS) {
912                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", DELIVERED_MESSAGE);
913                 } else if (noti_info->extra_data == MSG_NETWORK_DELIVER_EXPIRED) {
914                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", EXPIRED_MESSAGE);
915                 } else {
916                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deferred", DEFERRED_MESSAGE);
917                 }
918
919                 setNotiTime(noti_h, noti_info->time);
920                 break;
921         }
922         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT: {
923                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Read Report", READ_REPORT_MESSAGE);
924                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
925
926                 if (noti_info->extra_data == MSG_READ_REPORT_IS_DELETED) {
927                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deleted", READ_REPORT_DELETE);
928                 /* CID 45672: noti_info->extra_data in unsigned char but MSG_READ_REPORT_NONE is -1. So the expression is always false */
929 #if 0
930                 } else if (noti_info->extra_data == MSG_READ_REPORT_NONE) {
931                         /* notification free */
932 #endif
933                 } else {
934                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message read", READ_REPORT_READ);
935                 }
936
937                 setNotiTime(noti_h, noti_info->time);
938                 break;
939         }
940         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
941                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Report", DELIVERY_MESSAGE);
942                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
943
944                 if (noti_info->extra_data == MSG_DELIVERY_REPORT_EXPIRED)
945                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", EXPIRED_MESSAGE);
946                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_REJECTED)
947                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message rejected", REJECTED_MESSAGE);
948                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_DEFERRED)
949                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message deferred", DEFERRED_MESSAGE);
950                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_UNRECOGNISED)
951                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message unrecognised", UNRECOGNISED_MESSAGE);
952                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_INDETERMINATE)
953                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message indeterminate", INDETEMINATE_MESSAGE);
954                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_FORWARDED)
955                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message forwarded", NULL);
956                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_UNREACHABLE)
957                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message unreachable", UNREACHABLE_MESSAGE);
958                 else if (noti_info->extra_data == MSG_DELIVERY_REPORT_ERROR)
959                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message error", NULL);
960                 else
961                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", DELIVERED_MESSAGE);
962
963                 setNotiTime(noti_h, noti_info->time);
964                 break;
965         }
966         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
967                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card full", SMS_SIM_CARD_FULL);
968                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Not enough memory. Delete some items.", SMS_MESSAGE_MEMORY_FULL);
969                 break;
970         }
971         default:
972                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
973                 break;
974         }
975
976         MSG_MGR_END();
977 }
978
979 void setIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
980 {
981         MSG_MGR_BEGIN();
982
983         switch (noti_info->type) {
984 #ifdef MSG_NOTI_INTEGRATION
985         case MSG_MGR_NOTI_TYPE_NORMAL:
986         case MSG_MGR_NOTI_TYPE_CB:
987         case MSG_MGR_NOTI_TYPE_SIM: {
988                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
989                 if (noti_info->count > 1 && noti_info->senderCount > 1) {
990                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
991                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
992                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, "");
993                 } else {
994                         if (noti_info->active_subtype == MSG_CB_SMS) {
995                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_CB_ICON_PATH);
996                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
997                         } else if (noti_info->active_subtype == MSG_WAP_SI_SMS || noti_info->active_subtype == MSG_WAP_SL_SMS) {
998                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_ACTIVE_PUSH_ICON_PATH);
999                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_ACTIVE_PUSH_ICON_PATH);
1000                         } else if (noti_info->active_subtype == MSG_SYNCML_CP) {
1001                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_OTA_ICON_PATH);
1002                         } else {
1003                                 if (noti_info->imagePath[0] != '\0') {
1004                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, noti_info->imagePath);
1005                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, noti_info->imagePath);
1006                                 } else {
1007                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NO_CONTACT_PROFILE_ICON_PATH);
1008                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NO_CONTACT_PROFILE_ICON_PATH);
1009                                 }
1010
1011                                 char *msg_icon_path = NULL;
1012                                 if (getAppIcon(MSG_DEFAULT_APP_ID, &msg_icon_path) == 0) {
1013                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, msg_icon_path);
1014                                         g_free(msg_icon_path);
1015                                 } else {
1016                                         MSG_MGR_ERR("fail to get message-app icon");
1017                                 }
1018                         }
1019                 }
1020                 break;
1021         }
1022 #else
1023         case MSG_MGR_NOTI_TYPE_NORMAL: {
1024                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1025                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
1026
1027                 if (noti_info->count > 1) {
1028                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1029                 } else {
1030                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_REPLY_ICON_PATH);
1031                 }
1032                 break;
1033         }
1034         case MSG_MGR_NOTI_TYPE_CB: {
1035                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1036                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_CB_ICON_PATH);
1037                 break;
1038         }
1039         case MSG_MGR_NOTI_TYPE_SIM: {
1040                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SIM_ICON_PATH);
1041                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_SIM_ICON_PATH);
1042                 break;
1043         }
1044 #endif
1045         case MSG_MGR_NOTI_TYPE_FAILED: {
1046                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SMS_SENDING_FAILED_ICON_PATH);
1047                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_FAILED_STATUS_ICON);
1048                 break;
1049         }
1050         case MSG_MGR_NOTI_TYPE_VOICE_1:
1051         case MSG_MGR_NOTI_TYPE_VOICE_2:
1052         case MSG_MGR_NOTI_TYPE_MWI: {
1053                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_VOICE_MSG_STATUS_ICON);
1054                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_VOICE_ICON_PATH);
1055                 break;
1056         }
1057         case MSG_MGR_NOTI_TYPE_CLASS0:
1058                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1059                 break;
1060         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT:
1061                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1062                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1063                 break;
1064         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
1065                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1066                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1067                 break;
1068         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT:
1069                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1070                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1071                 break;
1072         case MSG_MGR_NOTI_TYPE_SIM_FULL:
1073                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1074                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1075                 break;
1076         default:
1077                 MSG_MGR_DEBUG("No matching type for MsgNotiSetImage [%d]", noti_info->type);
1078                 break;
1079         }
1080
1081         MSG_MGR_END();
1082 }
1083
1084 void setActiveProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1085 {
1086         MSG_MGR_BEGIN();
1087
1088         int noti_err = NOTIFICATION_ERROR_NONE;
1089
1090         /* set layout */
1091         noti_err = notification_set_layout(noti_h, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
1092         if (noti_err != NOTIFICATION_ERROR_NONE) {
1093                 MSG_MGR_DEBUG("Fail to notification_set_layout : %d", noti_err);
1094         }
1095
1096         /* set led */
1097         noti_err = notification_set_led(noti_h, NOTIFICATION_LED_OP_ON, 0x00);
1098         if (noti_err != NOTIFICATION_ERROR_NONE) {
1099                 MSG_MGR_DEBUG("Fail to notification_set_led.");
1100         }
1101
1102         /* set execute option and property */
1103         switch (noti_info->type) {
1104         case MSG_MGR_NOTI_TYPE_NORMAL:
1105                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->active_noti_svc_h[2]);
1106                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
1107                 break;
1108         case MSG_MGR_NOTI_TYPE_CLASS0:
1109                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->active_noti_svc_h[2]);
1110                 break;
1111         default:
1112                 MSG_MGR_DEBUG("No matching type for notification_set_launch_option() [%d]", noti_info->type);
1113                 break;
1114         }
1115
1116         /* set applist */
1117         noti_err = notification_set_display_applist(noti_h, NOTIFICATION_DISPLAY_APP_ACTIVE);
1118         if (noti_err != NOTIFICATION_ERROR_NONE) {
1119                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
1120         }
1121
1122         /* set pkg name */
1123         noti_err = notification_set_pkgname(noti_h, MSG_DEFAULT_APP_ID);
1124         if (noti_err != NOTIFICATION_ERROR_NONE) {
1125                 MSG_MGR_DEBUG("Fail to notification_set_pkgname");
1126         }
1127
1128         MSG_MGR_END();
1129 }
1130
1131
1132 void setActiveText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1133 {
1134         MSG_MGR_BEGIN();
1135
1136         switch (noti_info->type) {
1137         case MSG_MGR_NOTI_TYPE_NORMAL:
1138         case MSG_MGR_NOTI_TYPE_SIM:
1139         case MSG_MGR_NOTI_TYPE_CB: {
1140                 if (noti_info->active_subject[0] == '\0') {
1141                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->active_sender, NULL);
1142                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_text, NULL);
1143                 } else {
1144                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->active_sender, NULL);
1145                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, noti_info->active_subject, NULL);
1146                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_text, NULL);
1147                 }
1148                 break;
1149         }
1150         case MSG_MGR_NOTI_TYPE_CLASS0: {
1151                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL);
1152                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_sender, NULL);
1153                 break;
1154         }
1155         default:
1156                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1157                 break;
1158         }
1159
1160         MSG_MGR_END();
1161 }
1162
1163
1164 void setActiveIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1165 {
1166         MSG_MGR_BEGIN();
1167
1168         switch (noti_info->type) {
1169         case MSG_MGR_NOTI_TYPE_NORMAL:
1170         case MSG_MGR_NOTI_TYPE_SIM: {
1171                 switch (noti_info->active_subtype) {
1172                 case MSG_CB_SMS:
1173                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1174                         break;
1175                 case MSG_WAP_SI_SMS:
1176                 case MSG_WAP_SL_SMS:
1177                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_ACTIVE_PUSH_ICON_PATH);
1178                         break;
1179                 case MSG_SYNCML_CP:
1180                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_OTA_ICON_PATH);
1181                         break;
1182                 default:
1183                         if (noti_info->imagePath[0] != '\0')
1184                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, noti_info->imagePath);
1185                         else
1186                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NO_CONTACT_PROFILE_ICON_PATH);
1187
1188                         char *msg_icon_path = NULL;
1189                         if (getAppIcon(MSG_DEFAULT_APP_ID, &msg_icon_path) == 0) {
1190                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, msg_icon_path);
1191                                 g_free(msg_icon_path);
1192                         } else {
1193                                 MSG_MGR_ERR("fail to get message-app icon");
1194                         }
1195
1196                         break;
1197                 }
1198
1199                 break;
1200         }
1201         case MSG_MGR_NOTI_TYPE_CB: {
1202                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1203                 break;
1204         }
1205         case MSG_MGR_NOTI_TYPE_CLASS0:
1206                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1207                 break;
1208         default:
1209                 MSG_MGR_DEBUG("No matching type for MsgNotiSetImage [%d]", noti_info->type);
1210                 break;
1211         }
1212
1213         MSG_MGR_END();
1214 }
1215
1216
1217 void setSoundAndVibration(notification_h noti_h, char *addressVal, bool bVoiceMail)
1218 {
1219         MSG_MGR_BEGIN();
1220
1221         MSG_MGR_ADDRESS_INFO_S addrInfo = {0, };
1222         MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
1223
1224         if (addressVal != NULL) {
1225                 snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", addressVal);
1226                 /* Get Contact Info */
1227                 if (MsgMgrGetContactInfo(&addrInfo, &contactInfo) != 0) {
1228                         MSG_MGR_DEBUG("MsgMgrGetContactInfo() fail.");
1229                 }
1230         } else {
1231                 MSG_MGR_DEBUG("addressVal is NULL.");
1232         }
1233
1234         char *msg_tone_file_path = NULL;
1235
1236         MsgMgrGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
1237
1238         MSG_MGR_SEC_DEBUG("Sound File [%s]", msg_tone_file_path);
1239
1240         bool bPlaySound = false;
1241         bool bPlayVibration = false;
1242         bool bOnCall = false;
1243
1244         MsgMgrGetPlayStatus(bVoiceMail, &bPlaySound, &bPlayVibration, &bOnCall);
1245
1246         if (bPlaySound) {
1247                 if (msg_tone_file_path) {
1248                         setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_USER_DATA, msg_tone_file_path);
1249                 } else {
1250                         int tmpVal = 0;
1251                         if (vconf_get_int(MSG_SETTING_RINGTONE_TYPE, &tmpVal) != 0) {
1252                                 MSG_MGR_INFO("MsgSettingGetInt() is failed");
1253                         }
1254                         int ringtoneType = tmpVal;
1255                         if (ringtoneType == MSG_RINGTONE_TYPE_SILENT)
1256                                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1257                         else
1258                                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
1259                 }
1260         } else {
1261                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1262         }
1263
1264         if (bPlayVibration) {
1265                 if (contactInfo.vibrationPath[0] == '\0')
1266                         setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
1267                 else
1268                         setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_USER_DATA, contactInfo.vibrationPath);
1269         } else {
1270                 setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
1271         }
1272
1273         if (msg_tone_file_path)
1274                 delete [] msg_tone_file_path;
1275
1276         MSG_MGR_END();
1277 }
1278
1279
1280 void setActiveNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1281 {
1282         MSG_MGR_BEGIN();
1283
1284         int noti_err = NOTIFICATION_ERROR_NONE;
1285
1286         if (noti_info->active_noti_button_num > 1) {
1287                 createServiceHandle(&noti_info->active_noti_svc_h[0]);
1288                 if (noti_info->active_noti_svc_h[0]) {
1289                         setServicePackageName(noti_info->active_noti_svc_h[0], MSG_CALL_APP_ID);
1290                         setServiceOperation(noti_info->active_noti_svc_h[0], APP_CONTROL_OPERATION_CALL);
1291
1292                         MSG_MGR_DEBUG("Active Notification button 1 - Msg Id = [%d]", noti_info->msg_id);
1293
1294                         char tel_num[MSG_NOTI_TEXT_LEN_S] = {0, };
1295                         snprintf(tel_num, sizeof(tel_num), "tel:%s", noti_info->number);
1296                         MSG_MGR_SEC_DEBUG("Active sender number [%s]", noti_info->number);
1297                         setServiceUri(noti_info->active_noti_svc_h[0], tel_num);
1298                 }
1299
1300                 createServiceHandle(&noti_info->active_noti_svc_h[1]);
1301                 if (noti_info->active_noti_svc_h[1]) {
1302                         setServicePackageName(noti_info->active_noti_svc_h[1], MSG_DEFAULT_APP_ID);
1303
1304                         MSG_MGR_DEBUG("Active Notification button 2 - Msg Id = [%d]", noti_info->msg_id);
1305                         addServiceExtraData(noti_info->active_noti_svc_h[1], "type", "reply");
1306                         addServiceExtraData(noti_info->active_noti_svc_h[1], "msgId", noti_info->msg_id);
1307
1308                         char slot_id[5] = {0, };
1309                         snprintf(slot_id, sizeof(slot_id), "%d", noti_info->sim_idx - 1);
1310                         addServiceExtraData(noti_info->active_noti_svc_h[1], "slot_id", slot_id);
1311                 }
1312         }
1313
1314         createServiceHandle(&noti_info->active_noti_svc_h[2]);
1315         if (noti_info->active_noti_svc_h[2]) {
1316                 setServicePackageName(noti_info->active_noti_svc_h[2], MSG_DEFAULT_APP_ID);
1317
1318                 MSG_MGR_DEBUG("Active Notification button 3 - msgId = [%d]", noti_info->msg_id);
1319                 addServiceExtraData(noti_info->active_noti_svc_h[2], "type", "new_msg");
1320                 addServiceExtraData(noti_info->active_noti_svc_h[2], "msgId", noti_info->msg_id);
1321                 addServiceExtraData(noti_info->active_noti_svc_h[2], "CALLER", "active_noti");
1322
1323                 char slot_id[5] = {0, };
1324                 snprintf(slot_id, sizeof(slot_id), "%d", noti_info->sim_idx - 1);
1325                 addServiceExtraData(noti_info->active_noti_svc_h[2], "slot_id", slot_id);
1326         }
1327
1328         if (noti_info->active_noti_button_num > 1) {
1329                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, noti_info->active_noti_svc_h[0]);
1330                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2, noti_info->active_noti_svc_h[1]);
1331                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3, noti_info->active_noti_svc_h[2]);
1332
1333                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "Call", NULL);
1334                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_2, "Reply", NULL);
1335                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_3, "View", NULL);
1336         } else {
1337                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, noti_info->active_noti_svc_h[2]);
1338
1339                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "View", NULL);
1340         }
1341
1342         setActiveProperty(noti_h, noti_info);
1343
1344         setTextDomain(noti_h);
1345
1346         setActiveText(noti_h, noti_info);
1347
1348         setActiveIcon(noti_h, noti_info);
1349
1350         noti_err = notification_post(noti_h);
1351         if (noti_err != NOTIFICATION_ERROR_NONE) {
1352                 MSG_MGR_DEBUG("Fail to notification_post");
1353         }
1354
1355         MSG_MGR_END();
1356 }
1357
1358
1359 void setNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info, bool bFeedback)
1360 {
1361         MSG_MGR_BEGIN();
1362
1363         int noti_err = NOTIFICATION_ERROR_NONE;
1364
1365         MSG_MGR_DEBUG("active num [%d]", noti_info->active_noti_button_num);
1366
1367         if (bFeedback && noti_info->active_noti_button_num > 0 &&
1368                 ((noti_info->type >= MSG_MGR_NOTI_TYPE_NORMAL && noti_info->type <= MSG_MGR_NOTI_TYPE_SIM) || noti_info->type == MSG_MGR_NOTI_TYPE_CLASS0)) {
1369                 notification_h active_noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
1370
1371                 setActiveNotification(active_noti_h, noti_info);
1372
1373                 notification_free(active_noti_h);
1374                 active_noti_h = NULL;
1375         }
1376
1377         setProperty(noti_h, noti_info);
1378
1379         setTextDomain(noti_h);
1380
1381         setText(noti_h, noti_info);
1382
1383         setIcon(noti_h, noti_info);
1384
1385         if (bFeedback) {
1386                 if (noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_1 || noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_2)
1387                         setSoundAndVibration(noti_h, noti_info->number, true);
1388                 else
1389                         setSoundAndVibration(noti_h, noti_info->number, false);
1390
1391         } else {
1392                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1393                 setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
1394         }
1395
1396         if (noti_info->id > 0) {
1397                 MSG_MGR_DEBUG("Notification update");
1398                 noti_err = notification_update(noti_h);
1399                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1400                         MSG_MGR_DEBUG("Fail to notification_update");
1401                 }
1402         } else {
1403                 MSG_MGR_DEBUG("Notification insert");
1404                 noti_err = notification_insert(noti_h, &noti_info->id);
1405                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1406                         MSG_MGR_DEBUG("Fail to notification_insert");
1407                 }
1408
1409                 updatePrivId(noti_info->type, noti_info->id, noti_info->sim_idx);
1410         }
1411
1412         MSG_MGR_END();
1413 }
1414
1415
1416 void createActiveInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
1417 {
1418         MSG_MGR_BEGIN();
1419
1420         if (!msg_info) {
1421                 MSG_MGR_DEBUG("msg_info is NULL");
1422                 return;
1423         }
1424
1425         noti_info->msg_id = msg_info->msgId;
1426         noti_info->sim_idx = msg_info->sim_idx;
1427
1428         switch (noti_info->type) {
1429         case MSG_MGR_NOTI_TYPE_NORMAL: {
1430                 char *senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, PUSH_MESSAGE);
1431                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", senderStr);
1432                 if (senderStr) {
1433                         free(senderStr);
1434                         senderStr = NULL;
1435                 }
1436                 break;
1437         }
1438         case MSG_MGR_NOTI_TYPE_CLASS0: {
1439                 if (msg_info->displayName[0] == '\0')
1440                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->addressVal);
1441                 else
1442                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->displayName);
1443
1444                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", msg_info->msgText);
1445                 break;
1446         }
1447         default:
1448                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1449                 break;
1450         }
1451
1452         MSG_MGR_END();
1453 }
1454
1455
1456 void clearInfoData(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1457 {
1458         MSG_MGR_BEGIN();
1459
1460         if (noti_h) {
1461                 notification_free(noti_h);
1462                 noti_h = NULL;
1463         }
1464
1465         if (noti_info->svc_h) {
1466                 app_control_destroy(noti_info->svc_h);
1467                 noti_info->svc_h = NULL;
1468         }
1469
1470         for (int i = 0; i < MSG_ACTIVE_NOTI_BUTTON_NUM; i++) {
1471                 if (noti_info->active_noti_svc_h[i]) {
1472                         app_control_destroy(noti_info->active_noti_svc_h[i]);
1473                         noti_info->active_noti_svc_h[i] = NULL;
1474                 }
1475         }
1476
1477         MSG_MGR_END();
1478 }
1479
1480
1481 int getAppIcon(const char *app_id, char **icon_path)
1482 {
1483         MSG_MGR_BEGIN();
1484
1485         package_info_h pkg_info_h = NULL;
1486         int pkg_err = PACKAGE_MANAGER_ERROR_NONE;
1487         int ret = 0;
1488
1489         if (app_id == NULL) {
1490                 MSG_MGR_ERR("app id is NULL");
1491                 ret = -1;
1492                 goto END_OF_GET_APP_ICON;
1493         }
1494
1495         pkg_err = package_info_create(app_id, &pkg_info_h);
1496         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1497                 MSG_MGR_ERR("package_info_create failed (%d)", pkg_err);
1498                 ret = -1;
1499                 goto END_OF_GET_APP_ICON;
1500         }
1501
1502         pkg_err = package_info_get_icon(pkg_info_h, icon_path);
1503         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1504                 MSG_MGR_ERR("package_info_get_icon failed (%d)", pkg_err);
1505                 ret = -1;
1506         } else {
1507                 if (icon_path == NULL) {
1508                         MSG_MGR_WARN("icon path is NULL");
1509                         ret = -1;
1510                 }
1511         }
1512
1513 END_OF_GET_APP_ICON:
1514         if (pkg_info_h) {
1515                 pkg_err = package_info_destroy(pkg_info_h);
1516                 if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1517                         MSG_MGR_ERR("package_info_destroy failed (%d)", pkg_err);
1518                 }
1519
1520                 pkg_info_h = NULL;
1521         }
1522
1523         MSG_MGR_END();
1524
1525         return ret;
1526 }
1527
1528
1529 int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
1530 {
1531         MSG_MGR_BEGIN();
1532
1533         int noti_err = 0;
1534         msg_error_t msg_err = MSG_SUCCESS;
1535         char **db_res = NULL;
1536         int row_cnt = 0, col_cnt = 0;
1537
1538         switch (noti_info->type) {
1539         case MSG_MGR_NOTI_TYPE_NORMAL:
1540 #ifdef MSG_NOTI_INTEGRATION
1541         case MSG_MGR_NOTI_TYPE_CB:
1542         case MSG_MGR_NOTI_TYPE_SIM:
1543 #endif
1544         {
1545         int smsUnreadCnt = 0;
1546                 int mmsUnreadCnt = 0;
1547
1548                 char sqlQuery[MAX_QUERY_LEN     +1];
1549                 unsigned char mainType;
1550                 unsigned char subType;
1551                 int msgSize;
1552
1553                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1554 #ifdef MSG_NOTI_INTEGRATION
1555                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1556                                 "A.ADDRESS_VAL, "
1557                                 "B.SUB_TYPE "
1558                                 "FROM %s A, %s B "
1559                                 "WHERE A.CONV_ID=B.CONV_ID "
1560                                 "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1561                                 "AND B.STORAGE_ID = %d "
1562                                 "GROUP BY A.ADDRESS_VAL "
1563                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1564                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1565                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1566                                 MSG_STORAGE_PHONE);
1567 #else
1568                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1569                                 "A.ADDRESS_VAL, "
1570                                 "B.SUB_TYPE "
1571                                 "FROM %s A, %s B "
1572                                 "WHERE A.CONV_ID=B.CONV_ID "
1573                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1574                                 "AND B.STORAGE_ID = %d "
1575                                 "GROUP BY A.ADDRESS_VAL "
1576                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1577                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1578                                 MSG_INBOX_ID,
1579                                 MSG_STORAGE_PHONE);
1580 #endif
1581                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1582
1583                 row_cnt = 0, col_cnt = 0;
1584                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1585                 if (msg_err != MSG_SUCCESS) {
1586                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1587                         return -1;
1588                 }
1589
1590                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo;
1591                 int normalAddCnt = 0;
1592                 int index = col_cnt;
1593
1594                 for (int i = 1; i <= row_cnt; i++) {
1595                         memset(&tmpAddressInfo, 0x00, sizeof(MSG_MGR_ADDRESS_INFO_S));
1596
1597                         char *address = db_res[index++];
1598                         normalAddCnt++;
1599                         if (address) {
1600                                 snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", address);
1601                                 if (_is_valid_email(address)) {
1602                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
1603                                 } else {
1604                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
1605                                 }
1606                         }
1607                         subType = atoi(db_res[index++]);
1608
1609                         MSG_MGR_CONTACT_INFO_S tmpContact;
1610                         memset(&tmpContact, 0x00, sizeof(MSG_MGR_CONTACT_INFO_S));
1611
1612                         MsgMgrGetContactInfo(&tmpAddressInfo, &tmpContact);
1613
1614                         if (row_cnt == 1) {
1615                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1616                         }
1617
1618                         if (normalAddCnt > 1) {
1619                                 g_strlcat(noti_info->sender, ", ", sizeof(noti_info->sender)-strlen(noti_info->sender));
1620                         }
1621
1622                         if (tmpContact.firstName[0] != '\0') {
1623                                 g_strlcat(noti_info->sender, tmpContact.firstName, sizeof(noti_info->sender)-strlen(noti_info->sender));
1624                         } else if (tmpAddressInfo.addressVal[0] == '\0') {
1625                                 char *senderStr = NULL;
1626                                 senderStr = get_translate_text("message", MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
1627                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1628                                 if (senderStr) {
1629                                         free(senderStr);
1630                                         senderStr = NULL;
1631                                 }
1632
1633                                 if (i == 1) {
1634                                         noti_info->active_noti_button_num = 1;
1635                                 }
1636                         } else {
1637                                 char *senderStr = NULL;
1638                                 if (subType == MSG_CB_SMS) {
1639                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, CB_MESSAGE);
1640                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1641                                         noti_info->active_noti_button_num = 1;
1642                                 } else if (subType == MSG_SYNCML_CP) {
1643                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, CP_MESSAGE);
1644                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1645                                         noti_info->active_noti_button_num = 1;
1646                                 } else if (subType == MSG_WAP_SI_SMS || subType == MSG_WAP_SL_SMS) {
1647                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, PUSH_MESSAGE);
1648                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1649                                         noti_info->active_noti_button_num = 1;
1650                                 } else {
1651                                         g_strlcat(noti_info->sender, tmpAddressInfo.addressVal, sizeof(noti_info->sender)-strlen(noti_info->sender));
1652                                 }
1653
1654                                 if (senderStr) {
1655                                         free(senderStr);
1656                                         senderStr = NULL;
1657                                 }
1658                         }
1659
1660                         if (i == 1) {
1661                                 noti_info->active_subtype = subType;
1662                                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->sender);
1663                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1664                         }
1665                 }
1666
1667                 noti_info->senderCount = normalAddCnt;
1668                 msg_db_free(msg_handle, db_res);
1669
1670                 MSG_MGR_SEC_DEBUG("sender info = [%s]", noti_info->sender);
1671
1672                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1673
1674 #ifdef MSG_NOTI_INTEGRATION
1675                 snprintf(sqlQuery, sizeof(sqlQuery),
1676                                 "A.ADDRESS_VAL, "
1677                                 "B.DISPLAY_TIME, "
1678                                 "B.MSG_ID, "
1679                                 "B.SUBJECT, "
1680                                 "B.MSG_TEXT, "
1681                                 "B.MAIN_TYPE, "
1682                                 "(COUNT(DISTINCT(CASE WHEN B.MAIN_TYPE = %d THEN B.MSG_ID END))) AS SMS_UNREAD_CNT, "
1683                                 "(COUNT(DISTINCT(CASE WHEN B.MAIN_TYPE = %d THEN B.MSG_ID END))) AS MMS_UNREAD_CNT, "
1684                                 "(CASE WHEN B.MAIN_TYPE = %d AND B.NETWORK_STATUS = %d THEN (SELECT C.MSG_SIZE FROM %s C WHERE B.MSG_ID = C.MSG_ID) ELSE -1 END) "
1685                                 "FROM %s A, %s B "
1686                                 "WHERE A.CONV_ID=B.CONV_ID "
1687                                 "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1688                                 "AND B.STORAGE_ID = %d "
1689                                 "ORDER BY B.DISPLAY_TIME DESC;",
1690                                 MSG_SMS_TYPE,
1691                                 MSG_MMS_TYPE,
1692                                 MSG_MMS_TYPE, MSG_NETWORK_RECEIVED, MMS_PLUGIN_MESSAGE_TABLE_NAME,
1693                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1694                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1695                                 MSG_STORAGE_PHONE);
1696 #else
1697                 snprintf(sqlQuery, sizeof(sqlQuery),
1698                                 "A.ADDRESS_VAL, "
1699                                 "B.DISPLAY_TIME, "
1700                                 "B.MSG_ID, "
1701                                 "B.SUBJECT, "
1702                                 "B.MSG_TEXT, "
1703                                 "B.MAIN_TYPE, "
1704                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT, "
1705                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS MMS_UNREAD_CNT "
1706                                 "FROM %s A, %s B "
1707                                 "WHERE A.CONV_ID=B.CONV_ID "
1708                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1709                                 "AND B.STORAGE_ID = %d "
1710                                 "ORDER BY B.DISPLAY_TIME DESC;",
1711                                 MSG_SMS_TYPE,
1712                                 MSG_MMS_TYPE,
1713                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1714                                 MSG_INBOX_ID,
1715                                 MSG_STORAGE_PHONE);
1716 #endif
1717                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1718
1719                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1720                 if (msg_err != MSG_SUCCESS) {
1721                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1722                         return -1;
1723                 }
1724
1725                 if (row_cnt > 0) {
1726                         smsUnreadCnt = atoi(db_res[col_cnt+6]);
1727                         mmsUnreadCnt = atoi(db_res[col_cnt+7]);
1728                         msgSize = atoi(db_res[col_cnt+8]);
1729
1730                         noti_info->count = smsUnreadCnt + mmsUnreadCnt;
1731
1732                         if (noti_info->count > 0) {
1733                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", db_res[col_cnt]);
1734
1735                                 noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
1736
1737                                 noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
1738
1739                                 mainType = (unsigned char)atoi(db_res[col_cnt+5]);
1740
1741                                 if (mainType == MSG_MMS_TYPE) {
1742                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
1743                                         if (noti_info->text[0] == '\0') {
1744                                                 char *noti_text = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_NO_SUBJECT);
1745                                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", noti_text);
1746                                                 g_free(noti_text);
1747                                         }
1748
1749                                         char *prefix_subject = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_SUBJECT_COLON);
1750                                         if (prefix_subject) {
1751                                                 snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s%s", prefix_subject, noti_info->text);
1752                                                 g_free(prefix_subject);
1753                                         } else {
1754                                                 snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->text);
1755                                         }
1756
1757                                         if (msgSize > -1) {
1758                                                 int kb_msg_size = msgSize / 1024;
1759                                                 if (kb_msg_size == 0 && msgSize > 0)
1760                                                         kb_msg_size = 1;
1761                                                 else if (msgSize % 1024 >= 512)
1762                                                         kb_msg_size++;
1763
1764                                                 char *msg_size_string = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_STRING);
1765                                                 char *msg_size_unit_kb = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_UNIT_KB);
1766
1767                                                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s : %d%s", msg_size_string, kb_msg_size, msg_size_unit_kb);
1768
1769                                                 g_free(msg_size_string);
1770                                                 g_free(msg_size_unit_kb);
1771                                         }
1772
1773                                 } else {
1774                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
1775                                 }
1776
1777                                 if (noti_info->active_text[0] == '\0')
1778                                         snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", db_res[col_cnt+4]);
1779
1780                                 MSG_MGR_DEBUG("unread message ID [%d].", noti_info->msg_id);
1781
1782                                 MSG_MGR_DEBUG("active sender [%s]", noti_info->active_sender);
1783                                 MSG_MGR_DEBUG("active subject [%s]", noti_info->active_subject);
1784                                 MSG_MGR_DEBUG("active text [%s]", noti_info->active_text);
1785
1786                                 if (!isForInstantMessage) {
1787                                         if (noti_info->id > 0 && noti_info->count == 1) {
1788                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
1789                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1790                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1791                                                 }
1792
1793                                                 noti_info->id = 0;
1794                                                 if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
1795                                                         MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
1796                                         }
1797
1798                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, smsUnreadCnt);
1799                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, mmsUnreadCnt);
1800                                         MsgMgrInsertBadge(noti_info->count);
1801                                         MsgMgrSoundSetRepeatAlarm();
1802                                 }
1803                         } else {
1804                                 MSG_MGR_DEBUG("No unread message.");
1805                                 MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
1806
1807                                 msg_db_free(msg_handle, db_res);
1808
1809                                 if (!isForInstantMessage) {
1810                                         /* No unread message. */
1811                                         if (noti_info->id > 0) {
1812                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
1813                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1814                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1815                                                 }
1816                                         }
1817
1818                                         noti_info->id = 0;
1819
1820                                         if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
1821                                                 MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
1822
1823                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, 0);
1824                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, 0);
1825                                         MsgMgrInsertBadge(0);
1826                                         MsgMgrSoundSetRepeatAlarm();
1827                                 }
1828
1829                                 return -1;
1830                         }
1831                 } else {
1832                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1833                         msg_db_free(msg_handle, db_res);
1834                         return -1;
1835                 }
1836
1837                 msg_db_free(msg_handle, db_res);
1838                 break;
1839         }
1840
1841 #ifndef MSG_NOTI_INTEGRATION
1842         case MSG_MGR_NOTI_TYPE_CB: {
1843                 char sqlQuery[MAX_QUERY_LEN+1];
1844                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1845
1846                 snprintf(sqlQuery, sizeof(sqlQuery),
1847                                 "A.ADDRESS_VAL, "
1848                                 "B.DISPLAY_TIME, "
1849                                 "B.MSG_ID, "
1850                                 "B.MSG_TEXT "
1851                                 "FROM %s A, %s B "
1852                                 "WHERE A.CONV_ID=B.CONV_ID "
1853                                 "AND B.READ_STATUS=0 "
1854                                 "AND B.FOLDER_ID=%d "
1855                                 "AND B.STORAGE_ID = %d "
1856                                 "ORDER BY B.DISPLAY_TIME DESC;",
1857                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1858                                 MSG_CBMSGBOX_ID,
1859                                 MSG_STORAGE_PHONE);
1860
1861                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
1862                         return MSG_ERR_DB_PREPARE;
1863
1864                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
1865                         MSG_ADDRESS_INFO_S addrInfo;
1866                         memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1867
1868                         if (dbhandler->columnText(0) != NULL)
1869                                 snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
1870
1871                         MSG_CONTACT_INFO_S tmpContact;
1872                         memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
1873
1874                         MsgGetContactInfo(&addrInfo, &tmpContact);
1875
1876                         if (tmpContact.firstName[0] != '\0') {
1877                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
1878                         } else if (addrInfo.addressVal[0] == '\0') {
1879                                 char *senderStr = NULL;
1880                                 senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
1881                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1882                                 if (senderStr) {
1883                                         free(senderStr);
1884                                         senderStr = NULL;
1885                                 }
1886                         } else {
1887                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
1888                         }
1889
1890                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
1891
1892                         noti_info->time = (time_t)dbhandler->columnInt(1);
1893
1894                         noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
1895
1896                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
1897
1898                         MSG_MGR_DEBUG("unread CB message [%d].", noti_info->msg_id);
1899                 } else {
1900                         MSG_MGR_DEBUG("No unread CB message.");
1901                         MSG_MGR_DEBUG("notiCbId [%d]", noti_info->id);
1902
1903                         dbhandler->finalizeQuery();
1904
1905                         if (!isForInstantMessage) {
1906                                 /* No unread message. */
1907                                 if (noti_info->id > 0) {
1908                                         noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
1909                                         if (noti_err != NOTIFICATION_ERROR_NONE) {
1910                                                 MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1911                                         }
1912                                 }
1913
1914                                 noti_info->id = 0;
1915
1916                                 if (MsgSettingSetInt(CB_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
1917                                         MSG_MGR_DEBUG("MsgSettingSetInt fail : CB_NOTI_PRIV_ID");
1918                         }
1919                         return MSG_ERR_DB_STEP;
1920                 }
1921
1922                 dbhandler->finalizeQuery();
1923
1924                 if (dbhandler->getTable(sqlQuery, &noti_info->count, NULL) != MSG_SUCCESS) {
1925                         MSG_MGR_DEBUG("getTable is failed");
1926                         dbhandler->freeTable();
1927                         return MSG_ERR_DB_GETTABLE;
1928                 }
1929
1930                 dbhandler->freeTable();
1931                 MSG_MGR_DEBUG("notiCbId [%d], unreadCbMsgCnt [%d]", noti_info->id, noti_info->count);
1932                 break;
1933         }
1934         case MSG_MGR_NOTI_TYPE_SIM: {
1935                 char sqlQuery[MAX_QUERY_LEN+1];
1936                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1937
1938                 snprintf(sqlQuery, sizeof(sqlQuery),
1939                                 "A.ADDRESS_VAL, "
1940                                 "B.DISPLAY_TIME, "
1941                                 "B.MSG_ID, "
1942                                 "B.MSG_TEXT, "
1943                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT "
1944                                 "FROM %s A, %s B "
1945                                 "WHERE A.CONV_ID=B.CONV_ID "
1946                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1947                                 "AND B.STORAGE_ID = %d "
1948                                 "ORDER BY B.DISPLAY_TIME DESC;",
1949                                 MSG_SMS_TYPE,
1950                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1951                                 MSG_INBOX_ID,
1952                                 MSG_STORAGE_SIM);
1953
1954                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1955
1956                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
1957                         return MSG_ERR_DB_PREPARE;
1958
1959                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
1960                         noti_info->count = dbhandler->columnInt(4);
1961
1962                         if (noti_info->count > 0) {
1963                                 MSG_ADDRESS_INFO_S addrInfo;
1964                                 memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1965
1966                                 if (dbhandler->columnText(0) != NULL)
1967                                         snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
1968
1969                                 MSG_CONTACT_INFO_S tmpContact;
1970                                 memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
1971
1972                                 MsgGetContactInfo(&addrInfo, &tmpContact);
1973
1974                                 if (tmpContact.firstName[0] != '\0') {
1975                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
1976                                 } else if (addrInfo.addressVal[0] == '\0') {
1977                                         char *senderStr = NULL;
1978                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
1979                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1980                                         if (senderStr) {
1981                                                 free(senderStr);
1982                                                 senderStr = NULL;
1983                                         }
1984                                 } else {
1985                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
1986                                 }
1987
1988                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
1989
1990                                 noti_info->time = (time_t)dbhandler->columnInt(1);
1991
1992                                 noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
1993
1994                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
1995
1996                                 MSG_MGR_DEBUG("unread SIM message [%d].", noti_info->msg_id);
1997                         } else {
1998                                 MSG_MGR_DEBUG("No unread SIM message.");
1999                                 MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
2000
2001                                 dbhandler->finalizeQuery();
2002
2003                                 if (!isForInstantMessage) {
2004                                         /* No unread message. */
2005                                         if (noti_info->id > 0) {
2006                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2007                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2008                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2009                                                 }
2010                                         }
2011
2012                                         noti_info->id = 0;
2013
2014                                         if (MsgSettingSetInt(SIM_MSG_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
2015                                                 MSG_MGR_DEBUG("MsgSettingSetInt fail : SIM_MSG_NOTI_PRIV_ID");
2016                                 }
2017
2018                                 return MSG_ERR_DB_STEP;
2019                         }
2020                 } else {
2021                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2022                         dbhandler->finalizeQuery();
2023                         return MSG_ERR_DB_STEP;
2024                 }
2025
2026                 dbhandler->finalizeQuery();
2027                 break;
2028         }
2029 #endif
2030         case MSG_MGR_NOTI_TYPE_FAILED: {
2031                 char sqlQuery[MAX_QUERY_LEN+1];
2032                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2033
2034                 snprintf(sqlQuery, sizeof(sqlQuery),
2035                                 "A.ADDRESS_VAL, "
2036                                 "B.DISPLAY_TIME, "
2037                                 "B.MSG_ID, "
2038                                 "B.MSG_TEXT, "
2039                                 "B.SUBJECT, "
2040                                 "B.MAIN_TYPE, "
2041                                 "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS SENT_FAILED_CNT "
2042                                 "FROM %s A, %s B "
2043                                 "WHERE A.CONV_ID=B.CONV_ID "
2044                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
2045                                 "AND B.STORAGE_ID = %d "
2046                                 "ORDER BY B.DISPLAY_TIME DESC;",
2047                                 MSG_NETWORK_SEND_FAIL,
2048                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
2049                                 MSG_OUTBOX_ID,
2050                                 MSG_STORAGE_PHONE);
2051
2052                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2053
2054                 row_cnt = 0, col_cnt = 0;
2055                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
2056                 if (msg_err != MSG_SUCCESS) {
2057                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
2058                         return -1;
2059                 }
2060
2061                 if (row_cnt > 0) {
2062                         noti_info->count = atoi(db_res[col_cnt+6]);
2063
2064                         if (noti_info->count > 0) {
2065                                 MSG_MGR_ADDRESS_INFO_S addrInfo = {0, };
2066
2067                                 snprintf(addrInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", db_res[col_cnt]);
2068
2069                                 MSG_MGR_CONTACT_INFO_S tmpContact = {0, };
2070
2071                                 MsgMgrGetContactInfo(&addrInfo, &tmpContact);
2072
2073                                 if (tmpContact.firstName[0] != '\0') {
2074                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2075                                 } else if (addrInfo.addressVal[0] == '\0') {
2076                                         char *senderStr = NULL;
2077                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
2078                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2079                                         if (senderStr) {
2080                                                 free(senderStr);
2081                                                 senderStr = NULL;
2082                                         }
2083                                 } else {
2084                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2085                                 }
2086
2087                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2088
2089                                 noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
2090
2091                                 noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
2092
2093                                 unsigned char mainType = (unsigned char)atoi(db_res[col_cnt+5]);
2094
2095                                 if (mainType == MSG_TYPE_MMS)
2096                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
2097                                 else
2098                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
2099
2100                                 MSG_MGR_DEBUG("Sent failed message ID [%d].", noti_info->msg_id);
2101
2102                                 if (!isForInstantMessage) {
2103                                         if (noti_info->id > 0 && noti_info->count == 1) {
2104                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2105                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2106                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2107                                                 }
2108                                                 noti_info->id = 0;
2109                                                 if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2110                                                         MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2111                                         }
2112                                 }
2113                         } else {
2114                                 MSG_MGR_DEBUG("No sent failed message.");
2115                                 MSG_MGR_DEBUG("failedNotiId [%d]", noti_info->id);
2116
2117                                 msg_db_free(msg_handle, db_res);
2118
2119                                 if (!isForInstantMessage) {
2120                                         /* No unread message. */
2121                                         if (noti_info->id > 0) {
2122                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2123                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2124                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2125                                                 }
2126                                         }
2127
2128                                         noti_info->id = 0;
2129
2130                                         if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2131                                                 MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2132                                 }
2133
2134                                 return -1;
2135                         }
2136                 } else {
2137                         msg_db_free(msg_handle, db_res);
2138                         return -1;
2139                 }
2140
2141                 msg_db_free(msg_handle, db_res);
2142                 break;
2143         }
2144         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2145                 break;
2146         default:
2147                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2148                 return -1;
2149         }
2150
2151         MSG_MGR_END();
2152
2153         return 0;
2154 }
2155
2156
2157 notification_h getHandle(int *noti_id)
2158 {
2159         notification_h noti_h = NULL;
2160
2161         if (*noti_id > 0) {
2162                 MSG_MGR_DEBUG("Notification load");
2163                 noti_h = notification_load(NULL, *noti_id);
2164                 if (noti_h == NULL)
2165                         MSG_MGR_DEBUG("notification_load is failed.");
2166         }
2167
2168         if (noti_h == NULL) {
2169                 MSG_MGR_DEBUG("Notification create");
2170                 noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
2171                 if (noti_h == NULL) {
2172                         MSG_MGR_DEBUG("notification_create is failed.");
2173                         return NULL;
2174                 }
2175
2176                 *noti_id = 0;
2177         }
2178
2179         return noti_h;
2180 }
2181
2182
2183 int getPrivId(msg_mgr_notification_type_t noti_type, int sim_idx)
2184 {
2185         MSG_MGR_BEGIN();
2186
2187         int noti_id = 0;
2188
2189         switch (noti_type) {
2190 #ifdef MSG_NOTI_INTEGRATION
2191         case MSG_MGR_NOTI_TYPE_NORMAL:
2192         case MSG_MGR_NOTI_TYPE_SIM:
2193         case MSG_MGR_NOTI_TYPE_CB:
2194                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2195                 break;
2196 #else
2197         case MSG_MGR_NOTI_TYPE_NORMAL:
2198                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2199                 break;
2200         case MSG_MGR_NOTI_TYPE_SIM:
2201                 vconf_get_int(SIM_MSG_NOTI_PRIV_ID, &noti_id);
2202                 break;
2203         case MSG_MGR_NOTI_TYPE_CB:
2204                 vconf_get_int(CB_NOTI_PRIV_ID, &noti_id);
2205                 break;
2206 #endif
2207         case MSG_MGR_NOTI_TYPE_FAILED:
2208                 vconf_get_int(MSG_SENTFAIL_NOTI_ID, &noti_id);
2209                 break;
2210         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2211                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2212                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2213                 vconf_get_int(keyName, &noti_id);
2214                 break;
2215         }
2216         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2217                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2218                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2219                 vconf_get_int(keyName, &noti_id);
2220                 break;
2221         }
2222         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2223                 vconf_get_int(SIM_FULL_NOTI_PRIV_ID, &noti_id);
2224                 break;
2225         default:
2226                 MSG_MGR_DEBUG("No matching noti type [%d]", noti_type);
2227                 break;
2228         }
2229
2230         MSG_MGR_DEBUG("Get noti type = %d, id = %d, sim_idx:%d", noti_type, noti_id, sim_idx);
2231
2232         MSG_MGR_END();
2233
2234         return noti_id;
2235 }
2236
2237
2238 void updatePrivId(msg_mgr_notification_type_t noti_type, int noti_id, int sim_idx)
2239 {
2240         MSG_MGR_BEGIN();
2241
2242         int err = 0;
2243
2244         MSG_MGR_DEBUG("Update noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2245
2246         switch (noti_type) {
2247 #ifdef MSG_NOTI_INTEGRATION
2248         case MSG_MGR_NOTI_TYPE_NORMAL:
2249         case MSG_MGR_NOTI_TYPE_SIM:
2250         case MSG_MGR_NOTI_TYPE_CB:
2251                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2252                 break;
2253 #else
2254         case MSG_MGR_NOTI_TYPE_NORMAL:
2255                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2256                 break;
2257         case MSG_MGR_NOTI_TYPE_SIM:
2258                 err = vconf_set_int(SIM_MSG_NOTI_PRIV_ID, noti_id);
2259                 break;
2260         case MSG_MGR_NOTI_TYPE_CB:
2261                 err = vconf_set_int(CB_NOTI_PRIV_ID, noti_id);
2262                 break;
2263 #endif
2264         case MSG_MGR_NOTI_TYPE_FAILED:
2265                 err = vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_id);
2266                 break;
2267         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2268                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2269                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2270                 err = vconf_set_int(keyName, noti_id);
2271                 break;
2272         }
2273         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2274                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2275                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2276                 err = vconf_set_int(keyName, noti_id);
2277                 break;
2278         }
2279         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2280                 err = vconf_set_int(SIM_FULL_NOTI_PRIV_ID, noti_id);
2281                 break;
2282         default:
2283                 MSG_MGR_DEBUG("No matching type [%d]", noti_type);
2284                 break;
2285         }
2286
2287         if (err != 0)
2288                 MSG_MGR_INFO("vconf_set_int fail : noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2289
2290         MSG_MGR_END();
2291 }
2292
2293
2294 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
2295 {
2296         MSG_MGR_BEGIN();
2297
2298         if (msg_info) {
2299                 noti_info->id = getPrivId(noti_info->type, msg_info->sim_idx);
2300                 noti_info->msg_id = msg_info->msgId;
2301         } else {
2302                 MSG_MGR_DEBUG("msg_info is NULL");
2303                 return;
2304         }
2305
2306         noti_info->sim_idx = msg_info->sim_idx;
2307
2308         createServiceHandle(&noti_info->svc_h);
2309         char keyName[MAX_VCONFKEY_NAME_LEN];
2310
2311         switch (noti_info->type) {
2312         case MSG_MGR_NOTI_TYPE_VOICE_1:
2313         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2314                 memset(keyName, 0x00, sizeof(keyName));
2315                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, msg_info->sim_idx);
2316                 vconf_get_int(keyName, &noti_info->count);
2317                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2318                 noti_info->time = msg_info->displayTime;
2319
2320                 memset(keyName, 0x00, sizeof(keyName));
2321                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msg_info->sim_idx);
2322                 char *voiceNumber = vconf_get_str(keyName);
2323                 memset(keyName, 0x00, sizeof(keyName));
2324                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msg_info->sim_idx);
2325                 char *voiceAlphaId = vconf_get_str(keyName);
2326                 char *dialNumber = NULL;
2327
2328                 MSG_MGR_SEC_DEBUG("Voice mail server - alpha id = [%s], default num = [%s]", voiceAlphaId, voiceNumber);
2329
2330                 if (voiceNumber && strlen(voiceNumber))
2331                         dialNumber = voiceNumber;
2332
2333                 if (voiceAlphaId && strlen(voiceAlphaId) > 0) {
2334                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", voiceAlphaId);
2335                 } else if (dialNumber && strlen(dialNumber) > 0) {
2336                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", dialNumber);
2337                 }
2338
2339                 if (dialNumber && strlen(dialNumber) > 0)
2340                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", dialNumber);
2341
2342                 if (noti_info->svc_h) {
2343                         setServiceOperation(noti_info->svc_h, APP_CONTROL_OPERATION_CALL);
2344                         setServiceUri(noti_info->svc_h, MSG_TEL_URI_VOICEMAIL);
2345
2346                         char slot_id[5] = {0, };
2347                         snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
2348                         addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
2349                 }
2350
2351                 if (voiceNumber)        g_free(voiceNumber);
2352                 if (voiceAlphaId) g_free(voiceAlphaId);
2353                 break;
2354         }
2355         case MSG_MGR_NOTI_TYPE_MWI:
2356         case MSG_MGR_NOTI_TYPE_CLASS0: {
2357                 noti_info->count = 1;
2358                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2359                 noti_info->time = msg_info->displayTime;
2360
2361                 if (msg_info->displayName[0] == '\0')
2362                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2363                 else
2364                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->displayName);
2365
2366                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2367
2368                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", msg_info->msgText);
2369
2370                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MWI) {
2371                         if (noti_info->svc_h) {
2372                                 setServiceOperation(noti_info->svc_h, APP_CONTROL_OPERATION_CALL);
2373                                 setServiceUri(noti_info->svc_h, MSG_TEL_URI_VOICEMAIL);
2374
2375                                 char slot_id[5] = {0, };
2376                                 snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
2377                                 addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
2378                         }
2379
2380                 } else {
2381                         setServiceAppId(noti_info->svc_h, "org.tizen.msg-ui-class0");
2382                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2383                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2384                 }
2385                 break;
2386         }
2387         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT: {
2388                 noti_info->count = 1;
2389                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2390                 noti_info->time = msg_info->displayTime;
2391                 noti_info->extra_data = msg_info->networkStatus;
2392
2393                 MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
2394                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0, };
2395                 if (msg_info->addressVal[0] != '\0') {
2396                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2397                         if (_is_valid_email(msg_info->addressVal)) {
2398                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2399                         } else {
2400                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2401                         }
2402                 }
2403
2404                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2405                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2406                 }
2407
2408                 if (contactInfo.firstName[0] == '\0')
2409                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2410                 else
2411                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2412
2413                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2414
2415                 if (noti_info->msg_id > 0) {
2416                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2417                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2418                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2419                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2420                 }
2421                 break;
2422         }
2423         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
2424         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
2425                 noti_info->count = 1;
2426                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2427                 noti_info->time = msg_info->displayTime;
2428
2429                 MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
2430                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0, };
2431                 if (msg_info->addressVal[0] != '\0') {
2432                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2433                         if (_is_valid_email(msg_info->addressVal)) {
2434                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2435                         } else {
2436                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2437                         }
2438                 }
2439
2440                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2441                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2442                 }
2443                 if (contactInfo.firstName[0] == '\0')
2444                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2445                 else
2446                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2447
2448                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2449
2450                 char sqlQuery[MAX_QUERY_LEN+1];
2451                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2452
2453                 int report_status_type;
2454                 int report_status_value;
2455
2456                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MMS_READ_REPORT) {
2457                         report_status_type = MSG_REPORT_TYPE_READ;
2458                 } else {
2459                         report_status_type = MSG_REPORT_TYPE_DELIVERY;
2460                 }
2461
2462                 snprintf(sqlQuery, sizeof(sqlQuery),
2463                                 "STATUS "
2464                                 "FROM %s "
2465                                 "WHERE MSG_ID=%d AND STATUS_TYPE=%d AND ADDRESS_VAL LIKE '%%%s';",
2466                                 MSGFW_REPORT_TABLE_NAME, msg_info->msgId, report_status_type, msg_mgr_normalize_number(msg_info->addressVal));
2467
2468                 MSG_MGR_DEBUG("sqlQuery = [%s]", sqlQuery);
2469
2470                 char **db_res = NULL;
2471                 int row_cnt = 0, col_cnt = 0;
2472
2473                 int msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
2474                 if (msg_err != MSG_SUCCESS || row_cnt <= 0) {
2475                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
2476                         return;
2477                 }
2478
2479                 report_status_value = atoi(db_res[col_cnt]);
2480
2481                 MSG_MGR_DEBUG("report status [type = %d, value = %d]", report_status_type, report_status_value);
2482
2483                 msg_err = msg_db_free(msg_handle, db_res);
2484                 if (msg_err != MSG_SUCCESS) {
2485                         MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
2486                         return;
2487                 }
2488
2489                 if (noti_info->msg_id > 0) {
2490                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2491                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2492                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2493                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2494                 }
2495
2496                 noti_info->extra_data = (unsigned char)report_status_value;
2497                 break;
2498         }
2499         default:
2500                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2501                 break;
2502         }
2503
2504         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2505         MSG_MGR_END();
2506 }
2507
2508
2509 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, msg_mgr_active_notification_type_t active_noti)
2510 {
2511         MSG_MGR_BEGIN();
2512
2513         createServiceHandle(&noti_info->svc_h);
2514
2515         switch (noti_info->type) {
2516         case MSG_MGR_NOTI_TYPE_NORMAL: {
2517                 if (noti_info->count > 1) {
2518                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2519                 } else {
2520                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2521                 }
2522
2523                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2524                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2525                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2526                 addServiceExtraData(noti_info->svc_h, "http://tizen.org/appcontrol/data/notification", "new_message");
2527
2528                 noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER;
2529
2530                 if (noti_info->active_noti_button_num == 0)
2531                         noti_info->active_noti_button_num = 3;
2532                 break;
2533         }
2534         case MSG_MGR_NOTI_TYPE_CB: {
2535                 if (noti_info->count > 1) {
2536                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2537                 } else {
2538                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2539                 }
2540
2541                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2542                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2543                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2544
2545                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2546                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2547                 else
2548                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2549
2550                 noti_info->active_noti_button_num = 1;
2551                 break;
2552         }
2553         case MSG_MGR_NOTI_TYPE_SIM: {
2554                 if (noti_info->count > 1) {
2555                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2556                 } else {
2557                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2558                 }
2559
2560                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2561                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2562                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2563
2564                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2565                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2566                 else
2567                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2568
2569                 if (noti_info->active_noti_button_num == 0)
2570                         noti_info->active_noti_button_num = 3;
2571                 break;
2572         }
2573         case MSG_MGR_NOTI_TYPE_FAILED: {
2574                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2575
2576                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2577                 addServiceExtraData(noti_info->svc_h, "type", "send_failed_msg");
2578                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2579
2580                 noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER^NOTIFICATION_DISPLAY_APP_LOCK;
2581                 break;
2582         }
2583         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
2584                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2585
2586                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2587                 addServiceExtraData(noti_info->svc_h, "sim_list_show", "sim_setting");
2588
2589                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2590                 break;
2591         }
2592         default:
2593                 break;
2594         }
2595
2596         if (active_noti != MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE)
2597                 noti_info->active_noti_button_num = 0;
2598
2599         MSG_MGR_END();
2600 }
2601
2602
2603 void createServiceHandle(app_control_h *svc_h)
2604 {
2605         int svc_err = APP_CONTROL_ERROR_NONE;
2606
2607         svc_err = app_control_create(svc_h);
2608
2609         if (svc_err != APP_CONTROL_ERROR_NONE)
2610                 MSG_MGR_DEBUG("app_control_create() is failed, [%d]", svc_err);
2611 }
2612
2613
2614 void setServiceAppId(app_control_h svc_h, const char* app_id)
2615 {
2616         int svc_err = APP_CONTROL_ERROR_NONE;
2617
2618         svc_err = app_control_set_app_id(svc_h, app_id);
2619
2620         if (svc_err != APP_CONTROL_ERROR_NONE)
2621                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2622 }
2623
2624
2625 void setServiceUri(app_control_h svc_h, const char* uri)
2626 {
2627         int svc_err = APP_CONTROL_ERROR_NONE;
2628
2629         svc_err = app_control_set_uri(svc_h, uri);
2630
2631         if (svc_err != APP_CONTROL_ERROR_NONE)
2632                 MSG_MGR_DEBUG("app_control_set_uri() was failed, [%d]", svc_err);
2633 }
2634
2635
2636 void setServiceOperation(app_control_h svc_h, const char* operation)
2637 {
2638         int svc_err = APP_CONTROL_ERROR_NONE;
2639
2640         svc_err = app_control_set_operation(svc_h, operation);
2641
2642         if (svc_err != APP_CONTROL_ERROR_NONE)
2643                 MSG_MGR_DEBUG("app_control_set_operation() was failed, [%d]", svc_err);
2644 }
2645
2646
2647 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val)
2648 {
2649         int svc_err = APP_CONTROL_ERROR_NONE;
2650
2651         svc_err = app_control_add_extra_data(svc_h, bundle_key, bundle_val);
2652
2653         if (svc_err != APP_CONTROL_ERROR_NONE)
2654                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2655 }
2656
2657
2658 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val)
2659 {
2660         int svc_err = APP_CONTROL_ERROR_NONE;
2661
2662         char tempId[10];
2663         memset(&tempId, 0x00, sizeof(tempId));
2664         snprintf(tempId, sizeof(tempId), "%d", bundle_val);
2665
2666         svc_err = app_control_add_extra_data(svc_h, bundle_key, (const char *)tempId);
2667
2668         if (svc_err != APP_CONTROL_ERROR_NONE)
2669                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2670 }
2671
2672
2673 void setServicePackageName(app_control_h svc_h, const char* pkg_name)
2674 {
2675         int svc_err = APP_CONTROL_ERROR_NONE;
2676
2677         svc_err = app_control_set_app_id(svc_h, pkg_name);
2678
2679         if (svc_err != APP_CONTROL_ERROR_NONE)
2680                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2681 }
2682
2683
2684 void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data)
2685 {
2686         int svc_err = APP_CONTROL_ERROR_NONE;
2687
2688         svc_err = app_control_send_launch_request(svc_h, callback, user_data);
2689
2690         if (svc_err != APP_CONTROL_ERROR_NONE)
2691                 MSG_MGR_DEBUG("app_control_send_launch_request() is failed : %d", svc_err);
2692 }
2693
2694
2695 void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir)
2696 {
2697         int noti_err = NOTIFICATION_ERROR_NONE;
2698
2699         noti_err = notification_set_text_domain(noti_h, pkg_name, loc_dir);
2700         if (noti_err != NOTIFICATION_ERROR_NONE)
2701                 MSG_MGR_DEBUG("notification_set_text_domain() was failed. [%d]", noti_err);
2702 }
2703
2704
2705 void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key)
2706 {
2707         int noti_err = NOTIFICATION_ERROR_NONE;
2708
2709         noti_err = notification_set_text(noti_h, type, text, key, NOTIFICATION_VARIABLE_TYPE_NONE);
2710
2711         if (noti_err != NOTIFICATION_ERROR_NONE)
2712                 MSG_MGR_DEBUG("notification_set_text() was failed. [%d]", noti_err);
2713 }
2714
2715
2716 void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time)
2717 {
2718         int noti_err = NOTIFICATION_ERROR_NONE;
2719
2720         noti_err = notification_set_time_to_text(noti_h, type, time);
2721
2722         if (noti_err != NOTIFICATION_ERROR_NONE)
2723                 MSG_MGR_DEBUG("notification_set_time_to_text() was failed. [%d]", noti_err);
2724 }
2725
2726
2727 void setNotiTime(notification_h noti_h, time_t time)
2728 {
2729         int noti_err = NOTIFICATION_ERROR_NONE;
2730
2731         noti_err = notification_set_time(noti_h, time);
2732
2733         if (noti_err != NOTIFICATION_ERROR_NONE)
2734                 MSG_MGR_DEBUG("notification_set_time() was failed. [%d]", noti_err);
2735 }
2736
2737
2738
2739 void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path)
2740 {
2741         int noti_err = NOTIFICATION_ERROR_NONE;
2742
2743         noti_err = notification_set_image(noti_h, type, image_path);
2744
2745         if (noti_err != NOTIFICATION_ERROR_NONE)
2746                 MSG_MGR_DEBUG("notification_set_image() was failed. [%d]", noti_err);
2747 }
2748
2749
2750 void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path)
2751 {
2752         int noti_err = NOTIFICATION_ERROR_NONE;
2753
2754         noti_err = notification_set_sound(noti_h, type, path);
2755
2756         if (noti_err != NOTIFICATION_ERROR_NONE)
2757                 MSG_MGR_DEBUG("notification_set_sound() was failed. [%d]", noti_err);
2758 }
2759
2760
2761 void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path)
2762 {
2763         int noti_err = NOTIFICATION_ERROR_NONE;
2764
2765         noti_err = notification_set_vibration(noti_h, type, path);
2766
2767         if (noti_err != NOTIFICATION_ERROR_NONE)
2768                 MSG_MGR_DEBUG("notification_set_vibration() was failed. [%d]", noti_err);
2769 }
2770
2771
2772 void setNotiEventHandler(notification_h noti_h, notification_event_type_e type, app_control_h event_handler)
2773 {
2774         int noti_err = NOTIFICATION_ERROR_NONE;
2775
2776         noti_err = notification_set_event_handler(noti_h, type, event_handler);
2777
2778         if (noti_err != NOTIFICATION_ERROR_NONE)
2779                 MSG_MGR_DEBUG("notification_set_event_handler() was failed. [%d]", noti_err);
2780 }
2781
2782
2783 int MsgMgrInsertInstantMessage(msg_mgr_notification_type_t noti_type)
2784 {
2785         MSG_MGR_BEGIN();
2786
2787         char *notiMsg = NULL;
2788
2789         notification_h noti = notification_create(NOTIFICATION_TYPE_NOTI);
2790
2791         switch (noti_type) {
2792         case MSG_MGR_NOTI_TYPE_NORMAL:
2793         case MSG_MGR_NOTI_TYPE_SIM:
2794         case MSG_MGR_NOTI_TYPE_CB: {
2795                 MSG_MGR_NOTI_INFO_S noti_info;
2796                 memset(&noti_info, 0x00, sizeof(MSG_MGR_NOTI_INFO_S));
2797
2798                 noti_info.type = noti_type;
2799                 int err = getLatestMsgInfo(&noti_info, true);
2800
2801                 if (err == 0) {
2802                         MSG_MGR_DEBUG("Unread count [%d]", noti_info.count);
2803                         if (noti_info.count == 1) {
2804                                 MSG_MGR_SEC_DEBUG("noti_info.sender [%s]", noti_info.sender);
2805                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, noti_info.sender, NULL);
2806                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.text, NULL);
2807                         } else if (noti_info.count > 1) {
2808                                 gchar *cnt_string = g_strdup_printf("%i", noti_info.count);
2809
2810                                 notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, NEW_MESSAGES);
2811                                 gchar *outString = g_strconcat(cnt_string, " ", notiMsg, NULL);
2812                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, outString, NULL);
2813                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.sender, NULL);
2814                                 g_free(outString);
2815                                 g_free(cnt_string);
2816                         }
2817
2818                         setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
2819                 }
2820                 break;
2821         }
2822         case MSG_MGR_NOTI_TYPE_FAILED: {
2823                 notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, FAILED_TO_SEND_MESSAGE);
2824                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, notiMsg, NULL);
2825                 setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SMS_SENDING_FAILED_ICON_PATH);
2826                 break;
2827         }
2828         default:
2829                 MSG_MGR_DEBUG("No matching type for MsgNotiType%d]", noti_type);
2830                 goto _END_OF_INSTANT_NOTI;
2831                 break;
2832         }
2833
2834         if (notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER) != NOTIFICATION_ERROR_NONE)
2835                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
2836
2837         if (notification_set_pkgname(noti, MSG_DEFAULT_APP_ID) != NOTIFICATION_ERROR_NONE)
2838                 MSG_MGR_DEBUG("Fail to notification_set_pkgname");
2839
2840         if (notification_post(noti) != NOTIFICATION_ERROR_NONE)
2841                 MSG_MGR_DEBUG("Fail to notification_post");
2842
2843 _END_OF_INSTANT_NOTI:
2844
2845         if (notification_delete(noti) != NOTIFICATION_ERROR_NONE)
2846                 MSG_MGR_DEBUG("Fail to notification_delete");
2847         if (notiMsg) {
2848                 free(notiMsg);
2849                 notiMsg = NULL;
2850         }
2851
2852         if (noti) {
2853                 if (notification_free(noti) != NOTIFICATION_ERROR_NONE)
2854                         MSG_MGR_DEBUG("Fail to notification_free");
2855                 noti = NULL;
2856         }
2857
2858         MSG_MGR_END();
2859         return 0;
2860 }
2861
2862
2863 bool MsgMgrCheckNotificationSettingEnable()
2864 {
2865         bool msg_noti_enabled = false;
2866         notification_system_setting_h system_setting = NULL;
2867         notification_setting_h setting = NULL;
2868
2869         int err = NOTIFICATION_ERROR_NONE;
2870
2871         err = notification_setting_get_setting_by_package_name(MSG_DEFAULT_APP_ID, &setting);
2872
2873         if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
2874                 MSG_MGR_ERR("getting setting handle for [%s] is failed. err = %d", MSG_DEFAULT_APP_ID, err);
2875         } else {
2876                 msg_noti_enabled = true;
2877
2878                 bool allow_to_notify = false;
2879                 err = notification_setting_get_allow_to_notify(setting, &allow_to_notify);
2880
2881                 if (err != NOTIFICATION_ERROR_NONE) {
2882                         MSG_MGR_ERR("getting do not disturb setting is failed. err = %d", err);
2883                         goto EXIT;
2884                 }
2885
2886                 if (allow_to_notify) {
2887                         MSG_MGR_DEBUG("message notification is allowed");
2888
2889                         /* check do not disturb mode */
2890                         err = notification_system_setting_load_system_setting(&system_setting);
2891
2892                         if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
2893                                 MSG_MGR_ERR("getting system setting is failed. err = %d", err);
2894                                 goto EXIT;
2895                         }
2896
2897                         bool do_not_disturb_mode = false;
2898                         err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb_mode);
2899
2900                         if (err != NOTIFICATION_ERROR_NONE) {
2901                                 MSG_MGR_ERR("getting do not disturb setting is failed. err = %d", err);
2902                                 goto EXIT;
2903                         }
2904
2905                         if (do_not_disturb_mode) {
2906                                 bool is_msg_excepted = false;
2907                                 err = notification_setting_get_do_not_disturb_except(setting, &is_msg_excepted);
2908                                 if (err != NOTIFICATION_ERROR_NONE) {
2909                                         MSG_MGR_ERR("getting do not disturb except status for [%s] is failed. err = %d", MSG_DEFAULT_APP_ID, err);
2910                                         msg_noti_enabled = false;
2911                                 } else {
2912                                         MSG_MGR_INFO("do not disturb mode status for [%s] : %d", MSG_DEFAULT_APP_ID, is_msg_excepted);
2913                                         msg_noti_enabled = (is_msg_excepted) ? true : false;
2914                                 }
2915                         } else {
2916                                 MSG_MGR_DEBUG("do not disturb mode is off");
2917                         }
2918                 } else {
2919                         MSG_MGR_INFO("message notification is not allowed");
2920                         msg_noti_enabled = false;
2921                 }
2922         }
2923
2924 EXIT:
2925         if (system_setting)
2926                 notification_system_setting_free_system_setting(system_setting);
2927
2928         if (setting)
2929                 notification_setting_free_notification(setting);
2930
2931         return msg_noti_enabled;
2932 }
2933
2934
2935 int MsgMgrInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId)
2936 {
2937         MSG_MGR_DEBUG("pTickerMsg=[%s], pLocaleTickerMsg=[%s]", pTickerMsg, pLocaleTickerMsg);
2938         MSG_MGR_DEBUG("play feedback=[%d], msgId=[%d]", bPlayFeedback, msgId);
2939
2940         MsgMgrChangePmState();
2941
2942         char *notiMsg = NULL;
2943         msg_mgr_active_notification_type_t active_type = MSG_MGR_ACTIVE_NOTI_TYPE_NONE;
2944         int err = 0;
2945
2946         notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, pLocaleTickerMsg);
2947         MSG_MGR_DEBUG("notiMsg %s", notiMsg);
2948
2949         if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) != 0 &&
2950                 g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) != 0 &&
2951                 g_strcmp0(pLocaleTickerMsg, MESSAGE_RETRIEVED) != 0) {
2952                 if (g_strcmp0(pLocaleTickerMsg, notiMsg) == 0) {
2953                         notification_status_message_post(pTickerMsg);
2954                 } else {
2955                         notification_status_message_post(notiMsg);
2956                 }
2957         } else {
2958                 /* Show ticker popup for sending failed msg. */
2959                 active_type = MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT;
2960         }
2961
2962         if (notiMsg) {
2963                 free(notiMsg);
2964                 notiMsg = NULL;
2965         }
2966
2967         if (bPlayFeedback) {
2968                 if (msgId > 0 &&
2969                         (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) == 0 || g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) == 0)) {
2970                         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_FAILED, true, active_type);
2971                         if (err != 0) {
2972                                 MSG_MGR_DEBUG("MsgRefreshFailedNoti err=[%d]", err);
2973                         }
2974                 } else if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SIM_MESSAGE_FULL) == 0) {
2975                         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM_FULL, true, MSG_MGR_ACTIVE_NOTI_TYPE_NONE);
2976                         if (err != 0) {
2977                                 MSG_MGR_DEBUG("MsgRefreshSimFullNoti err=[%d]", err);
2978                         }
2979                 } else {
2980                         MsgMgrSoundPlayStart(NULL, MSG_MGR_SOUND_PLAY_DEFAULT);
2981                 }
2982         }
2983
2984         return err;
2985 }
2986
2987
2988 int MsgMgrInsertBadge(unsigned int unreadMsgCnt)
2989 {
2990         MSG_MGR_DEBUG("Start to set badge to [%d].", unreadMsgCnt);
2991
2992         int err = BADGE_ERROR_NONE;
2993         bool exist = false;
2994
2995         err = badge_is_existing(MSG_DEFAULT_APP_ID, &exist);
2996
2997         if (err != BADGE_ERROR_NONE) {
2998                 MSG_MGR_ERR("Fail to badge_is_existing : %d", err);
2999                 return -1;
3000         }
3001
3002         if (!exist) {
3003                 /* create badge */
3004                 err = badge_add(MSG_DEFAULT_APP_ID);
3005                 if (err != BADGE_ERROR_NONE) {
3006                         MSG_MGR_ERR("Fail to badge_add : %d", err);
3007                         return -1;
3008                 }
3009         }
3010
3011         err = badge_set_count(MSG_DEFAULT_APP_ID, unreadMsgCnt);
3012
3013         if (err != BADGE_ERROR_NONE) {
3014                 MSG_MGR_ERR("Fail to badge_set_count : %d", err);
3015                 return -1;
3016         }
3017
3018         return 0;
3019 }
3020
3021
3022 void MsgMgrNotiSoundRepeatAlarmCB(int alarmId)
3023 {
3024         MSG_MGR_BEGIN();
3025
3026         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3027
3028 #ifndef MSG_NOTI_INTEGRATION
3029         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3030         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_CB, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3031 #endif
3032
3033         MSG_MGR_END();
3034         return;
3035 }
3036
3037
3038 void MsgMgrSoundCreateRepeatAlarm(int RepeatTime)
3039 {
3040         MSG_MGR_BEGIN();
3041
3042         int tmpAlarmId = 0;
3043         time_t tmp_time;
3044         struct tm repeat_tm;
3045
3046         time(&tmp_time);
3047
3048         tmp_time += (RepeatTime*60);
3049         tzset();
3050         localtime_r(&tmp_time, &repeat_tm);
3051
3052         if (MsgMgrAlarmRegistration(&repeat_tm, MsgMgrNotiSoundRepeatAlarmCB, &tmpAlarmId) != 0) {
3053                 MSG_MGR_DEBUG("MsgAlarmRegistration fail.");
3054                 return;
3055         }
3056
3057         g_alarmId = tmpAlarmId;
3058         MSG_MGR_DEBUG("Set alarmId to [%d]", g_alarmId);
3059
3060         MSG_MGR_END();
3061
3062         return;
3063 }
3064
3065
3066 void MsgMgrSoundSetRepeatAlarm()
3067 {
3068         int nRepeatValue = 0;
3069         long nRepeatTime = 0;
3070
3071         if (vconf_get_int(MSG_ALERT_REP_TYPE, &nRepeatValue) != 0) {
3072                 MSG_MGR_INFO("vconf_get_int() is failed");
3073         }
3074
3075         switch (nRepeatValue) {
3076         case MSG_ALERT_TONE_ONCE:
3077                 nRepeatTime = 0;
3078                 break;
3079         case MSG_ALERT_TONE_2MINS:
3080                 nRepeatTime = 2;
3081                 break;
3082         case MSG_ALERT_TONE_5MINS:
3083                 nRepeatTime = 5;
3084                 break;
3085         case MSG_ALERT_TONE_10MINS:
3086                 nRepeatTime = 10;
3087                 break;
3088         default:
3089                 MSG_MGR_DEBUG("Invalid Repetition time");
3090                 break;
3091         }
3092
3093         MSG_MGR_DEBUG("nRepeatTime = %d", nRepeatTime);
3094
3095         if (nRepeatTime > 0) {
3096                 if (g_alarmId > 0) {
3097                         if (MsgMgrAlarmRemove(g_alarmId) != 0) {
3098                                 MSG_MGR_FATAL("MsgAlarmRemove fail.");
3099                         }
3100                         g_alarmId = 0;
3101                 }
3102                 MsgMgrSoundCreateRepeatAlarm(nRepeatTime);
3103         }
3104
3105         return;
3106 }
3107
3108
3109 char *get_translate_text(const char *pkg_name, const char *locale_dir, const char *text)
3110 {
3111         char *notiMsg = NULL;
3112         char *lang = NULL;
3113
3114         lang = vconf_get_str(VCONFKEY_LANGSET);
3115
3116         setlocale(LC_MESSAGES, lang);
3117
3118         bindtextdomain(pkg_name, locale_dir);
3119
3120         notiMsg = dgettext(pkg_name, text);
3121
3122         if (lang) {
3123                 free(lang);
3124                 lang = NULL;
3125         }
3126
3127         return g_strdup(notiMsg);
3128 }
3129