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