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