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