apply Tizen 3.0 Message UX Guide
[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_DEFAULT_APP_ID);
1478
1479                         MSG_MGR_DEBUG("Active Notification button 2 - Msg Id = [%d]", noti_info->msg_id);
1480                         addServiceExtraData(noti_info->active_noti_svc_h[1], "type", "reply");
1481                         addServiceExtraData(noti_info->active_noti_svc_h[1], "msgId", noti_info->msg_id);
1482
1483                         char slot_id[5] = {0, };
1484                         snprintf(slot_id, sizeof(slot_id), "%d", noti_info->sim_idx - 1);
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                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3, noti_info->active_noti_svc_h[2]);
1507
1508                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "Call", NULL);
1509                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_2, "Reply", NULL);
1510                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_3, "View", NULL);
1511         } else {
1512                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, noti_info->active_noti_svc_h[2]);
1513
1514                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "View", NULL);
1515         }
1516
1517         setActiveProperty(noti_h, noti_info);
1518
1519         setTextDomain(noti_h);
1520
1521         setActiveText(noti_h, noti_info);
1522
1523         setActiveIcon(noti_h, noti_info);
1524
1525         noti_err = notification_post(noti_h);
1526         if (noti_err != NOTIFICATION_ERROR_NONE) {
1527                 MSG_MGR_DEBUG("Fail to notification_post");
1528         }
1529
1530         MSG_MGR_END();
1531 }
1532
1533
1534 void setNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info, bool bFeedback)
1535 {
1536         MSG_MGR_BEGIN();
1537
1538         int noti_err = NOTIFICATION_ERROR_NONE;
1539
1540         MSG_MGR_DEBUG("active num [%d]", noti_info->active_noti_button_num);
1541
1542         if (bFeedback && noti_info->active_noti_button_num > MSG_ACTIVE_NOTI_BUTTON_NUM_NONE &&
1543                 ((noti_info->type >= MSG_MGR_NOTI_TYPE_NORMAL && noti_info->type <= MSG_MGR_NOTI_TYPE_SIM) || noti_info->type == MSG_MGR_NOTI_TYPE_CLASS0)) {
1544                 notification_h active_noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
1545
1546                 setActiveNotification(active_noti_h, noti_info);
1547
1548                 notification_free(active_noti_h);
1549                 active_noti_h = NULL;
1550         }
1551
1552         setProperty(noti_h, noti_info);
1553
1554         setTextDomain(noti_h);
1555
1556         setText(noti_h, noti_info);
1557
1558         setIcon(noti_h, noti_info);
1559
1560         if (bFeedback) {
1561                 if (noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_1 || noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_2)
1562                         setSoundAndVibration(noti_h, noti_info->number, true);
1563                 else
1564                         setSoundAndVibration(noti_h, noti_info->number, false);
1565
1566         } else {
1567                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1568                 setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
1569         }
1570
1571         if (noti_info->id > 0) {
1572                 MSG_MGR_DEBUG("Notification update");
1573                 noti_err = notification_update(noti_h);
1574                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1575                         MSG_MGR_DEBUG("Fail to notification_update");
1576                 }
1577         } else {
1578                 MSG_MGR_DEBUG("Notification insert");
1579                 noti_err = notification_insert(noti_h, &noti_info->id);
1580                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1581                         MSG_MGR_DEBUG("Fail to notification_insert");
1582                 }
1583
1584                 updatePrivId(noti_info->type, noti_info->id, noti_info->sim_idx);
1585         }
1586
1587         if (noti_info->type == MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT && noti_info->msg_id > 0) {
1588                 int err = vconf_set_int(VCONFKEY_MESSAGE_READ_REPORT_SENT_MSG_ID, noti_info->msg_id);
1589                 if (err != 0)
1590                         MSG_MGR_ERR("vconf_set_int() failed [%d]", err);
1591         }
1592
1593         MSG_MGR_END();
1594 }
1595
1596
1597 void createActiveInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
1598 {
1599         MSG_MGR_BEGIN();
1600
1601         if (!msg_info) {
1602                 MSG_MGR_DEBUG("msg_info is NULL");
1603                 return;
1604         }
1605
1606         noti_info->msg_id = msg_info->msgId;
1607         noti_info->sim_idx = msg_info->sim_idx;
1608
1609         switch (noti_info->type) {
1610         case MSG_MGR_NOTI_TYPE_NORMAL: {
1611                 char *senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, PUSH_MESSAGE);
1612                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", senderStr);
1613                 if (senderStr) {
1614                         free(senderStr);
1615                         senderStr = NULL;
1616                 }
1617                 break;
1618         }
1619         case MSG_MGR_NOTI_TYPE_CLASS0: {
1620                 if (msg_info->displayName[0] == '\0')
1621                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->addressVal);
1622                 else
1623                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->displayName);
1624
1625                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", msg_info->msgText);
1626                 break;
1627         }
1628         default:
1629                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1630                 break;
1631         }
1632
1633         MSG_MGR_END();
1634 }
1635
1636
1637 void clearInfoData(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1638 {
1639         MSG_MGR_BEGIN();
1640
1641         if (noti_h) {
1642                 notification_free(noti_h);
1643                 noti_h = NULL;
1644         }
1645
1646         if (noti_info->svc_h) {
1647                 app_control_destroy(noti_info->svc_h);
1648                 noti_info->svc_h = NULL;
1649         }
1650
1651         for (int i = 0; i < MSG_ACTIVE_NOTI_BUTTON_NUM; i++) {
1652                 if (noti_info->active_noti_svc_h[i]) {
1653                         app_control_destroy(noti_info->active_noti_svc_h[i]);
1654                         noti_info->active_noti_svc_h[i] = NULL;
1655                 }
1656         }
1657
1658         MSG_MGR_END();
1659 }
1660
1661
1662 int getAppIcon(const char *app_id, char **icon_path)
1663 {
1664         MSG_MGR_BEGIN();
1665
1666         package_info_h pkg_info_h = NULL;
1667         int pkg_err = PACKAGE_MANAGER_ERROR_NONE;
1668         int ret = 0;
1669
1670         if (app_id == NULL) {
1671                 MSG_MGR_ERR("app id is NULL");
1672                 ret = -1;
1673                 goto END_OF_GET_APP_ICON;
1674         }
1675
1676         pkg_err = package_info_create(app_id, &pkg_info_h);
1677         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1678                 MSG_MGR_ERR("package_info_create failed (%d)", pkg_err);
1679                 ret = -1;
1680                 goto END_OF_GET_APP_ICON;
1681         }
1682
1683         pkg_err = package_info_get_icon(pkg_info_h, icon_path);
1684         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1685                 MSG_MGR_ERR("package_info_get_icon failed (%d)", pkg_err);
1686                 ret = -1;
1687         } else {
1688                 if (icon_path == NULL) {
1689                         MSG_MGR_WARN("icon path is NULL");
1690                         ret = -1;
1691                 }
1692         }
1693
1694 END_OF_GET_APP_ICON:
1695         if (pkg_info_h) {
1696                 pkg_err = package_info_destroy(pkg_info_h);
1697                 if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1698                         MSG_MGR_ERR("package_info_destroy failed (%d)", pkg_err);
1699                 }
1700
1701                 pkg_info_h = NULL;
1702         }
1703
1704         MSG_MGR_END();
1705
1706         return ret;
1707 }
1708
1709
1710 int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
1711 {
1712         MSG_MGR_BEGIN();
1713
1714         int noti_err = 0;
1715         msg_error_t msg_err = MSG_SUCCESS;
1716         char **db_res = NULL;
1717         int row_cnt = 0, col_cnt = 0;
1718
1719         switch (noti_info->type) {
1720         case MSG_MGR_NOTI_TYPE_NORMAL:
1721 #ifdef MSG_NOTI_INTEGRATION
1722         case MSG_MGR_NOTI_TYPE_CB:
1723         case MSG_MGR_NOTI_TYPE_SIM:
1724 #endif
1725         {
1726         int smsUnreadCnt = 0;
1727                 int mmsUnreadCnt = 0;
1728
1729                 char sqlQuery[MAX_QUERY_LEN     +1];
1730                 unsigned char mainType;
1731                 unsigned char subType;
1732                 int msgSize, attachmentCnt;
1733
1734                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1735 #ifdef MSG_NOTI_INTEGRATION
1736                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1737                                 "A.ADDRESS_VAL, "
1738                                 "B.SUB_TYPE "
1739                                 "FROM %s A, %s B "
1740                                 "WHERE A.CONV_ID=B.CONV_ID "
1741                                 "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1742                                 "AND B.STORAGE_ID = %d "
1743                                 "GROUP BY A.ADDRESS_VAL "
1744                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1745                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1746                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1747                                 MSG_STORAGE_PHONE);
1748 #else
1749                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1750                                 "A.ADDRESS_VAL, "
1751                                 "B.SUB_TYPE "
1752                                 "FROM %s A, %s B "
1753                                 "WHERE A.CONV_ID=B.CONV_ID "
1754                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1755                                 "AND B.STORAGE_ID = %d "
1756                                 "GROUP BY A.ADDRESS_VAL "
1757                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1758                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1759                                 MSG_INBOX_ID,
1760                                 MSG_STORAGE_PHONE);
1761 #endif
1762                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1763
1764                 row_cnt = 0, col_cnt = 0;
1765                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1766                 if (msg_err != MSG_SUCCESS) {
1767                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1768                         return -1;
1769                 }
1770
1771                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo;
1772                 int normalAddCnt = 0;
1773                 int index = col_cnt;
1774
1775                 for (int i = 1; i <= row_cnt; i++) {
1776                         memset(&tmpAddressInfo, 0x00, sizeof(MSG_MGR_ADDRESS_INFO_S));
1777
1778                         char *address = db_res[index++];
1779                         normalAddCnt++;
1780                         if (address) {
1781                                 snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", address);
1782                                 if (_is_valid_email(address)) {
1783                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
1784                                 } else {
1785                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
1786                                 }
1787                         }
1788                         subType = atoi(db_res[index++]);
1789
1790                         MSG_MGR_CONTACT_INFO_S tmpContact;
1791                         memset(&tmpContact, 0x00, sizeof(MSG_MGR_CONTACT_INFO_S));
1792
1793                         MsgMgrGetContactInfo(&tmpAddressInfo, &tmpContact);
1794
1795                         if (row_cnt == 1) {
1796                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1797                         }
1798
1799                         if (normalAddCnt > 1) {
1800                                 g_strlcat(noti_info->sender, ", ", sizeof(noti_info->sender)-strlen(noti_info->sender));
1801                         }
1802
1803                         if (tmpContact.firstName[0] != '\0') {
1804                                 g_strlcat(noti_info->sender, tmpContact.firstName, sizeof(noti_info->sender)-strlen(noti_info->sender));
1805                         } else if (tmpAddressInfo.addressVal[0] == '\0') {
1806                                 char *senderStr = NULL;
1807                                 senderStr = get_translate_text("message", MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
1808                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1809                                 if (senderStr) {
1810                                         free(senderStr);
1811                                         senderStr = NULL;
1812                                 }
1813
1814                                 if (i == 1) {
1815                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_UNKNOWN_SENDER;
1816                                 }
1817                         } else {
1818                                 char *senderStr = NULL;
1819                                 if (subType == MSG_CB_SMS) {
1820                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, CB_MESSAGE);
1821                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1822                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_CB_MESSAGE;
1823                                 } else if (subType == MSG_SYNCML_CP) {
1824                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, CP_MESSAGE);
1825                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1826                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_PUSH_MESSAGE;
1827                                 } else if (subType == MSG_WAP_SI_SMS || subType == MSG_WAP_SL_SMS) {
1828                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, PUSH_MESSAGE);
1829                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1830                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_PUSH_MESSAGE;
1831                                 } else {
1832                                         g_strlcat(noti_info->sender, tmpAddressInfo.addressVal, sizeof(noti_info->sender)-strlen(noti_info->sender));
1833                                         if (subType == MSG_NOTIFICATIONIND_MMS)
1834                                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_UNRETRIVED_MESSAGE;
1835                                 }
1836
1837                                 if (senderStr) {
1838                                         free(senderStr);
1839                                         senderStr = NULL;
1840                                 }
1841                         }
1842
1843                         if (i == 1) {
1844                                 noti_info->active_subtype = subType;
1845                                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->sender);
1846                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1847                         }
1848                 }
1849
1850                 noti_info->senderCount = normalAddCnt;
1851                 msg_db_free(msg_handle, db_res);
1852
1853                 MSG_MGR_SEC_DEBUG("sender info = [%s]", noti_info->sender);
1854
1855                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1856                 snprintf(sqlQuery, MAX_QUERY_LEN,
1857                                 "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS SMS_UNREAD_CNT, "
1858                                 "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS MMS_UNREAD_CNT "
1859                                 "FROM %s WHERE READ_STATUS = 0 AND (FOLDER_ID=%d OR FOLDER_ID=%d) AND STORAGE_ID = %d;",
1860                                 MSG_SMS_TYPE,
1861                                 MSG_MMS_TYPE,
1862                                 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
1863
1864                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1865
1866                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1867                 if (msg_err != MSG_SUCCESS) {
1868                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1869                         return -1;
1870                 }
1871
1872                 if (row_cnt > 0) {
1873                         smsUnreadCnt = atoi(db_res[col_cnt]);
1874                         mmsUnreadCnt = atoi(db_res[col_cnt+1]);
1875                 }
1876
1877                 msg_db_free(msg_handle, db_res);
1878
1879                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1880 #ifdef MSG_NOTI_INTEGRATION
1881                 snprintf(sqlQuery, sizeof(sqlQuery),
1882                                 "A.ADDRESS_VAL, "
1883                                 "B.DISPLAY_TIME, "
1884                                 "B.MSG_ID, "
1885                                 "(CASE WHEN B.DPM_RESTRICTED = 0 THEN B.SUBJECT ELSE \"restricted message\" END), "
1886                                 "(CASE WHEN B.DPM_RESTRICTED = 0 THEN B.MSG_TEXT ELSE \"restricted message\" END), "
1887                                 "B.MAIN_TYPE, "
1888                                 "B.CONV_ID, "
1889                                 "(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), "
1890                                 "B.ATTACHMENT_COUNT "
1891                                 "FROM %s B "
1892                                 "LEFT JOIN %s A ON A.CONV_ID=B.CONV_ID "
1893                                 "WHERE B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1894                                 "AND B.STORAGE_ID = %d "
1895                                 "ORDER BY B.DISPLAY_TIME DESC;",
1896                                 MSG_MMS_TYPE, MSG_NETWORK_RECEIVED, MMS_PLUGIN_MESSAGE_TABLE_NAME,
1897                                 MSGFW_MESSAGE_TABLE_NAME,
1898                                 MSGFW_ADDRESS_TABLE_NAME,
1899                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1900                                 MSG_STORAGE_PHONE);
1901 #else
1902                 snprintf(sqlQuery, sizeof(sqlQuery),
1903                                 "A.ADDRESS_VAL, "
1904                                 "B.DISPLAY_TIME, "
1905                                 "B.MSG_ID, "
1906                                 "B.SUBJECT, "
1907                                 "B.MSG_TEXT, "
1908                                 "B.MAIN_TYPE, "
1909                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT, "
1910                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS MMS_UNREAD_CNT "
1911                                 "FROM %s A, %s B "
1912                                 "WHERE A.CONV_ID=B.CONV_ID "
1913                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1914                                 "AND B.STORAGE_ID = %d "
1915                                 "ORDER BY B.DISPLAY_TIME DESC;",
1916                                 MSG_SMS_TYPE,
1917                                 MSG_MMS_TYPE,
1918                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1919                                 MSG_INBOX_ID,
1920                                 MSG_STORAGE_PHONE);
1921 #endif
1922                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1923
1924                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1925                 if (msg_err != MSG_SUCCESS) {
1926                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1927                         return -1;
1928                 }
1929
1930                 if (row_cnt > 0) {
1931                         msgSize = atoi(db_res[col_cnt+7]);
1932                         attachmentCnt = atoi(db_res[col_cnt+8]);
1933
1934                         noti_info->count = smsUnreadCnt + mmsUnreadCnt;
1935
1936                         if (noti_info->count > 0) {
1937                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", db_res[col_cnt]);
1938
1939                                 noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
1940
1941                                 noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
1942
1943                                 noti_info->conv_id = atoi(db_res[col_cnt+6]);
1944
1945                                 mainType = (unsigned char)atoi(db_res[col_cnt+5]);
1946
1947                                 if (mainType == MSG_MMS_TYPE) {
1948                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
1949                                         if (noti_info->text[0] == '\0') {
1950                                                 char *noti_text = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_NO_SUBJECT);
1951                                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", noti_text);
1952                                                 g_free(noti_text);
1953                                         }
1954
1955                                         char *prefix_subject = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_SUBJECT_COLON);
1956                                         if (prefix_subject) {
1957                                                 snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s%s", prefix_subject, noti_info->text);
1958                                                 g_free(prefix_subject);
1959                                         } else {
1960                                                 snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->text);
1961                                         }
1962
1963                                         if (msgSize > -1) {
1964                                                 int kb_msg_size = msgSize / 1024;
1965                                                 if (kb_msg_size == 0 && msgSize > 0)
1966                                                         kb_msg_size = 1;
1967                                                 else if (msgSize % 1024 >= 512)
1968                                                         kb_msg_size++;
1969
1970                                                 char *msg_size_string = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_STRING);
1971                                                 char *msg_size_unit_kb = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MESSAGE_SIZE_UNIT_KB);
1972
1973                                                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s : %d%s", msg_size_string, kb_msg_size, msg_size_unit_kb);
1974
1975                                                 g_free(msg_size_string);
1976                                                 g_free(msg_size_unit_kb);
1977                                         }
1978
1979                                         noti_info->active_media_cnt = attachmentCnt;
1980
1981                                 } else {
1982                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
1983                                 }
1984
1985                                 if (noti_info->active_text[0] == '\0')
1986                                         snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", db_res[col_cnt+4]);
1987
1988                                 MSG_MGR_DEBUG("unread message ID [%d].", noti_info->msg_id);
1989
1990                                 MSG_MGR_DEBUG("active sender [%s]", noti_info->active_sender);
1991                                 MSG_MGR_DEBUG("active subject [%s]", noti_info->active_subject);
1992                                 MSG_MGR_DEBUG("active text [%s]", noti_info->active_text);
1993
1994                                 if (!isForInstantMessage) {
1995                                         if (noti_info->id > 0 && noti_info->count == 1) {
1996                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
1997                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1998                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1999                                                 }
2000
2001                                                 noti_info->id = 0;
2002                                                 if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
2003                                                         MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
2004                                         }
2005
2006                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, smsUnreadCnt);
2007                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, mmsUnreadCnt);
2008                                         MsgMgrInsertBadge(noti_info->count);
2009                                         MsgMgrSoundSetRepeatAlarm();
2010                                 }
2011                         } else {
2012                                 MSG_MGR_DEBUG("No unread message.");
2013                                 MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
2014
2015                                 msg_db_free(msg_handle, db_res);
2016
2017                                 if (!isForInstantMessage) {
2018                                         /* No unread message. */
2019                                         if (noti_info->id > 0) {
2020                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2021                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2022                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2023                                                 }
2024                                         }
2025
2026                                         noti_info->id = 0;
2027
2028                                         if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
2029                                                 MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
2030
2031                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, 0);
2032                                         vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, 0);
2033                                         MsgMgrInsertBadge(0);
2034                                         MsgMgrSoundSetRepeatAlarm();
2035                                 }
2036
2037                                 return -1;
2038                         }
2039                 } else {
2040                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2041                         msg_db_free(msg_handle, db_res);
2042                         return -1;
2043                 }
2044
2045                 msg_db_free(msg_handle, db_res);
2046                 break;
2047         }
2048
2049 #ifndef MSG_NOTI_INTEGRATION
2050         case MSG_MGR_NOTI_TYPE_CB: {
2051                 char sqlQuery[MAX_QUERY_LEN+1];
2052                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2053
2054                 snprintf(sqlQuery, sizeof(sqlQuery),
2055                                 "A.ADDRESS_VAL, "
2056                                 "B.DISPLAY_TIME, "
2057                                 "B.MSG_ID, "
2058                                 "B.MSG_TEXT "
2059                                 "FROM %s A, %s B "
2060                                 "WHERE A.CONV_ID=B.CONV_ID "
2061                                 "AND B.READ_STATUS=0 "
2062                                 "AND B.FOLDER_ID=%d "
2063                                 "AND B.STORAGE_ID = %d "
2064                                 "ORDER BY B.DISPLAY_TIME DESC;",
2065                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
2066                                 MSG_CBMSGBOX_ID,
2067                                 MSG_STORAGE_PHONE);
2068
2069                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
2070                         return MSG_ERR_DB_PREPARE;
2071
2072                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
2073                         MSG_ADDRESS_INFO_S addrInfo;
2074                         memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
2075
2076                         if (dbhandler->columnText(0) != NULL)
2077                                 snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
2078
2079                         MSG_CONTACT_INFO_S tmpContact;
2080                         memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
2081
2082                         MsgGetContactInfo(&addrInfo, &tmpContact);
2083
2084                         if (tmpContact.firstName[0] != '\0') {
2085                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2086                         } else if (addrInfo.addressVal[0] == '\0') {
2087                                 char *senderStr = NULL;
2088                                 senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
2089                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2090                                 if (senderStr) {
2091                                         free(senderStr);
2092                                         senderStr = NULL;
2093                                 }
2094                         } else {
2095                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2096                         }
2097
2098                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2099
2100                         noti_info->time = (time_t)dbhandler->columnInt(1);
2101
2102                         noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
2103
2104                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
2105
2106                         MSG_MGR_DEBUG("unread CB message [%d].", noti_info->msg_id);
2107                 } else {
2108                         MSG_MGR_DEBUG("No unread CB message.");
2109                         MSG_MGR_DEBUG("notiCbId [%d]", noti_info->id);
2110
2111                         dbhandler->finalizeQuery();
2112
2113                         if (!isForInstantMessage) {
2114                                 /* No unread message. */
2115                                 if (noti_info->id > 0) {
2116                                         noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2117                                         if (noti_err != NOTIFICATION_ERROR_NONE) {
2118                                                 MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2119                                         }
2120                                 }
2121
2122                                 noti_info->id = 0;
2123
2124                                 if (MsgSettingSetInt(CB_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
2125                                         MSG_MGR_DEBUG("MsgSettingSetInt fail : CB_NOTI_PRIV_ID");
2126                         }
2127                         return MSG_ERR_DB_STEP;
2128                 }
2129
2130                 dbhandler->finalizeQuery();
2131
2132                 if (dbhandler->getTable(sqlQuery, &noti_info->count, NULL) != MSG_SUCCESS) {
2133                         MSG_MGR_DEBUG("getTable is failed");
2134                         dbhandler->freeTable();
2135                         return MSG_ERR_DB_GETTABLE;
2136                 }
2137
2138                 dbhandler->freeTable();
2139                 MSG_MGR_DEBUG("notiCbId [%d], unreadCbMsgCnt [%d]", noti_info->id, noti_info->count);
2140                 break;
2141         }
2142         case MSG_MGR_NOTI_TYPE_SIM: {
2143                 char sqlQuery[MAX_QUERY_LEN+1];
2144                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2145
2146                 snprintf(sqlQuery, sizeof(sqlQuery),
2147                                 "A.ADDRESS_VAL, "
2148                                 "B.DISPLAY_TIME, "
2149                                 "B.MSG_ID, "
2150                                 "B.MSG_TEXT, "
2151                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT "
2152                                 "FROM %s A, %s B "
2153                                 "WHERE A.CONV_ID=B.CONV_ID "
2154                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
2155                                 "AND B.STORAGE_ID = %d "
2156                                 "ORDER BY B.DISPLAY_TIME DESC;",
2157                                 MSG_SMS_TYPE,
2158                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
2159                                 MSG_INBOX_ID,
2160                                 MSG_STORAGE_SIM);
2161
2162                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2163
2164                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
2165                         return MSG_ERR_DB_PREPARE;
2166
2167                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
2168                         noti_info->count = dbhandler->columnInt(4);
2169
2170                         if (noti_info->count > 0) {
2171                                 MSG_ADDRESS_INFO_S addrInfo;
2172                                 memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
2173
2174                                 if (dbhandler->columnText(0) != NULL)
2175                                         snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
2176
2177                                 MSG_CONTACT_INFO_S tmpContact;
2178                                 memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
2179
2180                                 MsgGetContactInfo(&addrInfo, &tmpContact);
2181
2182                                 if (tmpContact.firstName[0] != '\0') {
2183                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2184                                 } else if (addrInfo.addressVal[0] == '\0') {
2185                                         char *senderStr = NULL;
2186                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
2187                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2188                                         if (senderStr) {
2189                                                 free(senderStr);
2190                                                 senderStr = NULL;
2191                                         }
2192                                 } else {
2193                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2194                                 }
2195
2196                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2197
2198                                 noti_info->time = (time_t)dbhandler->columnInt(1);
2199
2200                                 noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
2201
2202                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
2203
2204                                 MSG_MGR_DEBUG("unread SIM message [%d].", noti_info->msg_id);
2205                         } else {
2206                                 MSG_MGR_DEBUG("No unread SIM message.");
2207                                 MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
2208
2209                                 dbhandler->finalizeQuery();
2210
2211                                 if (!isForInstantMessage) {
2212                                         /* No unread message. */
2213                                         if (noti_info->id > 0) {
2214                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2215                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2216                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2217                                                 }
2218                                         }
2219
2220                                         noti_info->id = 0;
2221
2222                                         if (MsgSettingSetInt(SIM_MSG_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
2223                                                 MSG_MGR_DEBUG("MsgSettingSetInt fail : SIM_MSG_NOTI_PRIV_ID");
2224                                 }
2225
2226                                 return MSG_ERR_DB_STEP;
2227                         }
2228                 } else {
2229                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2230                         dbhandler->finalizeQuery();
2231                         return MSG_ERR_DB_STEP;
2232                 }
2233
2234                 dbhandler->finalizeQuery();
2235                 break;
2236         }
2237 #endif
2238         case MSG_MGR_NOTI_TYPE_FAILED: {
2239                 char sqlQuery[MAX_QUERY_LEN+1];
2240                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2241
2242                 snprintf(sqlQuery, sizeof(sqlQuery),
2243                                 "A.ADDRESS_VAL, "
2244                                 "B.DISPLAY_TIME, "
2245                                 "B.MSG_ID, "
2246                                 "B.MSG_TEXT, "
2247                                 "B.SUBJECT, "
2248                                 "B.MAIN_TYPE, "
2249                                 "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS SENT_FAILED_CNT "
2250                                 "FROM %s A, %s B "
2251                                 "WHERE A.CONV_ID=B.CONV_ID "
2252                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
2253                                 "AND B.STORAGE_ID = %d "
2254                                 "ORDER BY B.DISPLAY_TIME DESC;",
2255                                 MSG_NETWORK_SEND_FAIL,
2256                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
2257                                 MSG_OUTBOX_ID,
2258                                 MSG_STORAGE_PHONE);
2259
2260                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2261
2262                 row_cnt = 0, col_cnt = 0;
2263                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
2264                 if (msg_err != MSG_SUCCESS) {
2265                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
2266                         return -1;
2267                 }
2268
2269                 if (row_cnt > 0) {
2270                         noti_info->count = atoi(db_res[col_cnt+6]);
2271
2272                         if (noti_info->count > 0) {
2273                                 MSG_MGR_ADDRESS_INFO_S addrInfo = {0, };
2274
2275                                 snprintf(addrInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", db_res[col_cnt]);
2276
2277                                 MSG_MGR_CONTACT_INFO_S tmpContact = {0, };
2278
2279                                 MsgMgrGetContactInfo(&addrInfo, &tmpContact);
2280
2281                                 if (tmpContact.firstName[0] != '\0') {
2282                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2283                                 } else if (addrInfo.addressVal[0] == '\0') {
2284                                         char *senderStr = NULL;
2285                                         senderStr = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, MSG_UNKNOWN_SENDER);
2286                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2287                                         if (senderStr) {
2288                                                 free(senderStr);
2289                                                 senderStr = NULL;
2290                                         }
2291                                 } else {
2292                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2293                                 }
2294
2295                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2296
2297                                 noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
2298
2299                                 noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
2300
2301                                 unsigned char mainType = (unsigned char)atoi(db_res[col_cnt+5]);
2302
2303                                 if (mainType == MSG_TYPE_MMS)
2304                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
2305                                 else
2306                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
2307
2308                                 MSG_MGR_DEBUG("Sent failed message ID [%d].", noti_info->msg_id);
2309
2310                                 if (!isForInstantMessage) {
2311                                         if (noti_info->id > 0 && noti_info->count == 1) {
2312                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2313                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2314                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2315                                                 }
2316                                                 noti_info->id = 0;
2317                                                 if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2318                                                         MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2319                                         }
2320                                 }
2321                         } else {
2322                                 MSG_MGR_DEBUG("No sent failed message.");
2323                                 MSG_MGR_DEBUG("failedNotiId [%d]", noti_info->id);
2324
2325                                 msg_db_free(msg_handle, db_res);
2326
2327                                 if (!isForInstantMessage) {
2328                                         /* No unread message. */
2329                                         if (noti_info->id > 0) {
2330                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2331                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2332                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2333                                                 }
2334                                         }
2335
2336                                         noti_info->id = 0;
2337
2338                                         if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2339                                                 MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2340                                 }
2341
2342                                 return -1;
2343                         }
2344                 } else {
2345                         msg_db_free(msg_handle, db_res);
2346                         return -1;
2347                 }
2348
2349                 msg_db_free(msg_handle, db_res);
2350                 break;
2351         }
2352         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2353                 break;
2354         default:
2355                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2356                 return -1;
2357         }
2358
2359         MSG_MGR_END();
2360
2361         return 0;
2362 }
2363
2364
2365 notification_h getHandle(int *noti_id)
2366 {
2367         notification_h noti_h = NULL;
2368
2369         if (*noti_id > 0) {
2370                 MSG_MGR_DEBUG("Notification load");
2371                 noti_h = notification_load(NULL, *noti_id);
2372                 if (noti_h == NULL)
2373                         MSG_MGR_DEBUG("notification_load is failed.");
2374         }
2375
2376         if (noti_h == NULL) {
2377                 MSG_MGR_DEBUG("Notification create");
2378                 noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
2379                 if (noti_h == NULL) {
2380                         MSG_MGR_DEBUG("notification_create is failed.");
2381                         return NULL;
2382                 }
2383
2384                 *noti_id = 0;
2385         }
2386
2387         return noti_h;
2388 }
2389
2390
2391 int getPrivId(msg_mgr_notification_type_t noti_type, int sim_idx)
2392 {
2393         MSG_MGR_BEGIN();
2394
2395         int noti_id = 0;
2396
2397         switch (noti_type) {
2398 #ifdef MSG_NOTI_INTEGRATION
2399         case MSG_MGR_NOTI_TYPE_NORMAL:
2400         case MSG_MGR_NOTI_TYPE_SIM:
2401         case MSG_MGR_NOTI_TYPE_CB:
2402                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2403                 break;
2404 #else
2405         case MSG_MGR_NOTI_TYPE_NORMAL:
2406                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2407                 break;
2408         case MSG_MGR_NOTI_TYPE_SIM:
2409                 vconf_get_int(SIM_MSG_NOTI_PRIV_ID, &noti_id);
2410                 break;
2411         case MSG_MGR_NOTI_TYPE_CB:
2412                 vconf_get_int(CB_NOTI_PRIV_ID, &noti_id);
2413                 break;
2414 #endif
2415         case MSG_MGR_NOTI_TYPE_FAILED:
2416                 vconf_get_int(MSG_SENTFAIL_NOTI_ID, &noti_id);
2417                 break;
2418         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT:
2419                 vconf_get_int(VCONFKEY_MESSAGE_READ_REPORT_SENT_NOTI_ID, &noti_id);
2420                 break;
2421         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2422                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2423                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2424                 vconf_get_int(keyName, &noti_id);
2425                 break;
2426         }
2427         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2428                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2429                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2430                 vconf_get_int(keyName, &noti_id);
2431                 break;
2432         }
2433         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2434                 vconf_get_int(SIM_FULL_NOTI_PRIV_ID, &noti_id);
2435                 break;
2436         default:
2437                 MSG_MGR_DEBUG("No matching noti type [%d]", noti_type);
2438                 break;
2439         }
2440
2441         MSG_MGR_DEBUG("Get noti type = %d, id = %d, sim_idx:%d", noti_type, noti_id, sim_idx);
2442
2443         MSG_MGR_END();
2444
2445         return noti_id;
2446 }
2447
2448
2449 void updatePrivId(msg_mgr_notification_type_t noti_type, int noti_id, int sim_idx)
2450 {
2451         MSG_MGR_BEGIN();
2452
2453         int err = 0;
2454
2455         MSG_MGR_DEBUG("Update noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2456
2457         switch (noti_type) {
2458 #ifdef MSG_NOTI_INTEGRATION
2459         case MSG_MGR_NOTI_TYPE_NORMAL:
2460         case MSG_MGR_NOTI_TYPE_SIM:
2461         case MSG_MGR_NOTI_TYPE_CB:
2462                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2463                 break;
2464 #else
2465         case MSG_MGR_NOTI_TYPE_NORMAL:
2466                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2467                 break;
2468         case MSG_MGR_NOTI_TYPE_SIM:
2469                 err = vconf_set_int(SIM_MSG_NOTI_PRIV_ID, noti_id);
2470                 break;
2471         case MSG_MGR_NOTI_TYPE_CB:
2472                 err = vconf_set_int(CB_NOTI_PRIV_ID, noti_id);
2473                 break;
2474 #endif
2475         case MSG_MGR_NOTI_TYPE_FAILED:
2476                 err = vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_id);
2477                 break;
2478         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT:
2479                 err = vconf_set_int(VCONFKEY_MESSAGE_READ_REPORT_SENT_NOTI_ID, noti_id);
2480                 break;
2481         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2482                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2483                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2484                 err = vconf_set_int(keyName, noti_id);
2485                 break;
2486         }
2487         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2488                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2489                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2490                 err = vconf_set_int(keyName, noti_id);
2491                 break;
2492         }
2493         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2494                 err = vconf_set_int(SIM_FULL_NOTI_PRIV_ID, noti_id);
2495                 break;
2496         default:
2497                 MSG_MGR_DEBUG("No matching type [%d]", noti_type);
2498                 break;
2499         }
2500
2501         if (err != 0)
2502                 MSG_MGR_INFO("vconf_set_int fail : noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2503
2504         MSG_MGR_END();
2505 }
2506
2507
2508 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
2509 {
2510         MSG_MGR_BEGIN();
2511
2512         if (msg_info) {
2513                 noti_info->id = getPrivId(noti_info->type, msg_info->sim_idx);
2514                 noti_info->msg_id = msg_info->msgId;
2515         } else {
2516                 MSG_MGR_DEBUG("msg_info is NULL");
2517                 return;
2518         }
2519
2520         noti_info->sim_idx = msg_info->sim_idx;
2521
2522         createServiceHandle(&noti_info->svc_h);
2523         char keyName[MAX_VCONFKEY_NAME_LEN];
2524
2525         switch (noti_info->type) {
2526         case MSG_MGR_NOTI_TYPE_VOICE_1:
2527         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2528                 memset(keyName, 0x00, sizeof(keyName));
2529                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, msg_info->sim_idx);
2530                 vconf_get_int(keyName, &noti_info->count);
2531                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2532                 noti_info->time = msg_info->displayTime;
2533
2534                 memset(keyName, 0x00, sizeof(keyName));
2535                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msg_info->sim_idx);
2536                 char *voiceNumber = vconf_get_str(keyName);
2537                 memset(keyName, 0x00, sizeof(keyName));
2538                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msg_info->sim_idx);
2539                 char *voiceAlphaId = vconf_get_str(keyName);
2540                 char *dialNumber = NULL;
2541
2542                 MSG_MGR_SEC_DEBUG("Voice mail server - alpha id = [%s], default num = [%s]", voiceAlphaId, voiceNumber);
2543
2544                 if (voiceNumber && strlen(voiceNumber))
2545                         dialNumber = voiceNumber;
2546
2547                 if (voiceAlphaId && strlen(voiceAlphaId) > 0) {
2548                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", voiceAlphaId);
2549                 } else if (dialNumber && strlen(dialNumber) > 0) {
2550                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", dialNumber);
2551                 }
2552
2553                 if (dialNumber && strlen(dialNumber) > 0)
2554                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", dialNumber);
2555
2556                 if (noti_info->svc_h) {
2557                         setServiceOperation(noti_info->svc_h, APP_CONTROL_OPERATION_CALL);
2558                         setServiceUri(noti_info->svc_h, MSG_TEL_URI_VOICEMAIL);
2559
2560                         char slot_id[5] = {0, };
2561                         snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
2562                         addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
2563                 }
2564
2565                 if (voiceNumber)        g_free(voiceNumber);
2566                 if (voiceAlphaId) g_free(voiceAlphaId);
2567                 break;
2568         }
2569         case MSG_MGR_NOTI_TYPE_MWI:
2570         case MSG_MGR_NOTI_TYPE_CLASS0: {
2571                 noti_info->count = 1;
2572                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2573                 noti_info->time = msg_info->displayTime;
2574
2575                 if (msg_info->displayName[0] == '\0')
2576                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2577                 else
2578                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->displayName);
2579
2580                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2581
2582                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", msg_info->msgText);
2583
2584                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MWI) {
2585                         if (noti_info->svc_h) {
2586                                 setServiceOperation(noti_info->svc_h, APP_CONTROL_OPERATION_CALL);
2587                                 setServiceUri(noti_info->svc_h, MSG_TEL_URI_VOICEMAIL);
2588
2589                                 char slot_id[5] = {0, };
2590                                 snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
2591                                 addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
2592                         }
2593
2594                 } else {
2595                         setServiceAppId(noti_info->svc_h, "org.tizen.msg-ui-class0");
2596                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2597                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2598                 }
2599                 break;
2600         }
2601         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT: {
2602                 noti_info->count = 1;
2603                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2604                 noti_info->time = msg_info->displayTime;
2605                 noti_info->extra_data = msg_info->networkStatus;
2606
2607                 MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
2608                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0, };
2609                 if (msg_info->addressVal[0] != '\0') {
2610                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2611                         if (_is_valid_email(msg_info->addressVal)) {
2612                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2613                         } else {
2614                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2615                         }
2616                 }
2617
2618                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2619                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2620                 }
2621
2622                 if (contactInfo.firstName[0] == '\0')
2623                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2624                 else
2625                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2626
2627                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2628
2629                 if (noti_info->msg_id > 0) {
2630                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2631                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2632                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2633                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2634                 }
2635                 break;
2636         }
2637         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
2638         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
2639                 noti_info->count = 1;
2640                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2641                 noti_info->time = msg_info->displayTime;
2642
2643                 MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
2644                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0, };
2645                 if (msg_info->addressVal[0] != '\0') {
2646                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2647                         if (_is_valid_email(msg_info->addressVal)) {
2648                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2649                         } else {
2650                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2651                         }
2652                 }
2653
2654                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2655                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2656                 }
2657                 if (contactInfo.firstName[0] == '\0')
2658                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2659                 else
2660                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2661
2662                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2663
2664                 char sqlQuery[MAX_QUERY_LEN+1];
2665                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2666
2667                 int report_status_type;
2668                 int report_status_value;
2669
2670                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MMS_READ_REPORT) {
2671                         report_status_type = MSG_REPORT_TYPE_READ;
2672                 } else {
2673                         report_status_type = MSG_REPORT_TYPE_DELIVERY;
2674                 }
2675
2676                 snprintf(sqlQuery, sizeof(sqlQuery),
2677                                 "STATUS "
2678                                 "FROM %s "
2679                                 "WHERE MSG_ID=%d AND STATUS_TYPE=%d AND ADDRESS_VAL LIKE \"%%%s\";",
2680                                 MSGFW_REPORT_TABLE_NAME, msg_info->msgId, report_status_type, msg_mgr_normalize_number(msg_info->addressVal));
2681
2682                 MSG_MGR_DEBUG("sqlQuery = [%s]", sqlQuery);
2683
2684                 char **db_res = NULL;
2685                 int row_cnt = 0, col_cnt = 0;
2686
2687                 int msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
2688                 if (msg_err != MSG_SUCCESS || row_cnt <= 0) {
2689                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
2690                         return;
2691                 }
2692
2693                 report_status_value = atoi(db_res[col_cnt]);
2694
2695                 MSG_MGR_DEBUG("report status [type = %d, value = %d]", report_status_type, report_status_value);
2696
2697                 msg_err = msg_db_free(msg_handle, db_res);
2698                 if (msg_err != MSG_SUCCESS) {
2699                         MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
2700                         return;
2701                 }
2702
2703                 if (noti_info->msg_id > 0) {
2704                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2705                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2706                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2707                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2708                 }
2709
2710                 noti_info->extra_data = (unsigned char)report_status_value;
2711                 break;
2712         }
2713         default:
2714                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2715                 break;
2716         }
2717
2718         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2719         MSG_MGR_END();
2720 }
2721
2722
2723 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, msg_mgr_active_notification_type_t active_noti)
2724 {
2725         MSG_MGR_BEGIN();
2726
2727         createServiceHandle(&noti_info->svc_h);
2728
2729         switch (noti_info->type) {
2730         case MSG_MGR_NOTI_TYPE_NORMAL: {
2731                 if (noti_info->count > 1) {
2732                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2733                 } else {
2734                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2735                 }
2736
2737                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2738                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2739                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2740                 addServiceExtraData(noti_info->svc_h, "http://tizen.org/appcontrol/data/notification", "new_message");
2741
2742                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE) {
2743                         if (noti_info->active_noti_button_num == MSG_ACTIVE_NOTI_BUTTON_NUM_NONE)
2744                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NORMAL_MESSAGE;
2745
2746                         int activated_conv_id = -1;
2747                         vconf_get_int(VCONFKEY_MESSAGE_ACTIVATED_CONVERSATION_ID, &activated_conv_id);
2748
2749                         if (activated_conv_id == -1) {
2750                                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR;
2751                         } else if (activated_conv_id == 0) {
2752                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NONE;
2753                                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR|NOTIFICATION_DISPLAY_APP_TICKER;
2754                         } else if (activated_conv_id > 0){
2755                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NONE;
2756
2757                                 if (activated_conv_id != noti_info->conv_id)
2758                                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR|NOTIFICATION_DISPLAY_APP_TICKER;
2759                                 else
2760                                         MSG_MGR_WARN("No adding Notification : activated conv id [%d] / notification conv id [%d]", activated_conv_id, noti_info->conv_id);
2761                         }
2762                 } else {
2763                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR;
2764                 }
2765
2766                 break;
2767         }
2768         case MSG_MGR_NOTI_TYPE_CB: {
2769                 if (noti_info->count > 1) {
2770                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2771                 } else {
2772                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2773                 }
2774
2775                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2776                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2777                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2778
2779                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2780                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2781                 else
2782                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2783
2784                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_CB_MESSAGE;
2785                 break;
2786         }
2787         case MSG_MGR_NOTI_TYPE_SIM: {
2788                 if (noti_info->count > 1) {
2789                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2790                 } else {
2791                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2792                 }
2793
2794                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2795                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2796                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2797
2798                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2799                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2800                 else
2801                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2802
2803                 if (noti_info->active_noti_button_num == MSG_ACTIVE_NOTI_BUTTON_NUM_NONE)
2804                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NORMAL_MESSAGE;
2805                 break;
2806         }
2807         case MSG_MGR_NOTI_TYPE_FAILED: {
2808                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2809
2810                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2811                 addServiceExtraData(noti_info->svc_h, "type", "send_failed_msg");
2812                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2813
2814                 noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER^NOTIFICATION_DISPLAY_APP_LOCK;
2815                 break;
2816         }
2817         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
2818                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2819
2820                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2821                 addServiceExtraData(noti_info->svc_h, "sim_list_show", "sim_setting");
2822
2823                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2824                 break;
2825         }
2826         default:
2827                 break;
2828         }
2829
2830         if (active_noti != MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE)
2831                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NONE;
2832
2833         MSG_MGR_END();
2834 }
2835
2836
2837 void createServiceHandle(app_control_h *svc_h)
2838 {
2839         int svc_err = APP_CONTROL_ERROR_NONE;
2840
2841         svc_err = app_control_create(svc_h);
2842
2843         if (svc_err != APP_CONTROL_ERROR_NONE)
2844                 MSG_MGR_DEBUG("app_control_create() is failed, [%d]", svc_err);
2845 }
2846
2847
2848 void setServiceAppId(app_control_h svc_h, const char* app_id)
2849 {
2850         int svc_err = APP_CONTROL_ERROR_NONE;
2851
2852         svc_err = app_control_set_app_id(svc_h, app_id);
2853
2854         if (svc_err != APP_CONTROL_ERROR_NONE)
2855                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2856 }
2857
2858
2859 void setServiceUri(app_control_h svc_h, const char* uri)
2860 {
2861         int svc_err = APP_CONTROL_ERROR_NONE;
2862
2863         svc_err = app_control_set_uri(svc_h, uri);
2864
2865         if (svc_err != APP_CONTROL_ERROR_NONE)
2866                 MSG_MGR_DEBUG("app_control_set_uri() was failed, [%d]", svc_err);
2867 }
2868
2869
2870 void setServiceOperation(app_control_h svc_h, const char* operation)
2871 {
2872         int svc_err = APP_CONTROL_ERROR_NONE;
2873
2874         svc_err = app_control_set_operation(svc_h, operation);
2875
2876         if (svc_err != APP_CONTROL_ERROR_NONE)
2877                 MSG_MGR_DEBUG("app_control_set_operation() was failed, [%d]", svc_err);
2878 }
2879
2880
2881 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val)
2882 {
2883         int svc_err = APP_CONTROL_ERROR_NONE;
2884
2885         svc_err = app_control_add_extra_data(svc_h, bundle_key, bundle_val);
2886
2887         if (svc_err != APP_CONTROL_ERROR_NONE)
2888                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2889 }
2890
2891
2892 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val)
2893 {
2894         int svc_err = APP_CONTROL_ERROR_NONE;
2895
2896         char tempId[10];
2897         memset(&tempId, 0x00, sizeof(tempId));
2898         snprintf(tempId, sizeof(tempId), "%d", bundle_val);
2899
2900         svc_err = app_control_add_extra_data(svc_h, bundle_key, (const char *)tempId);
2901
2902         if (svc_err != APP_CONTROL_ERROR_NONE)
2903                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2904 }
2905
2906
2907 void setServicePackageName(app_control_h svc_h, const char* pkg_name)
2908 {
2909         int svc_err = APP_CONTROL_ERROR_NONE;
2910
2911         svc_err = app_control_set_app_id(svc_h, pkg_name);
2912
2913         if (svc_err != APP_CONTROL_ERROR_NONE)
2914                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2915 }
2916
2917
2918 void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data)
2919 {
2920         int svc_err = APP_CONTROL_ERROR_NONE;
2921
2922         svc_err = app_control_send_launch_request(svc_h, callback, user_data);
2923
2924         if (svc_err != APP_CONTROL_ERROR_NONE)
2925                 MSG_MGR_DEBUG("app_control_send_launch_request() is failed : %d", svc_err);
2926 }
2927
2928
2929 void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir)
2930 {
2931         int noti_err = NOTIFICATION_ERROR_NONE;
2932
2933         noti_err = notification_set_text_domain(noti_h, pkg_name, loc_dir);
2934         if (noti_err != NOTIFICATION_ERROR_NONE)
2935                 MSG_MGR_DEBUG("notification_set_text_domain() was failed. [%d]", noti_err);
2936 }
2937
2938
2939 void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key)
2940 {
2941         int noti_err = NOTIFICATION_ERROR_NONE;
2942
2943         noti_err = notification_set_text(noti_h, type, text, key, NOTIFICATION_VARIABLE_TYPE_NONE);
2944
2945         if (noti_err != NOTIFICATION_ERROR_NONE)
2946                 MSG_MGR_DEBUG("notification_set_text() was failed. [%d]", noti_err);
2947 }
2948
2949
2950 void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time)
2951 {
2952         int noti_err = NOTIFICATION_ERROR_NONE;
2953
2954         noti_err = notification_set_time_to_text(noti_h, type, time);
2955
2956         if (noti_err != NOTIFICATION_ERROR_NONE)
2957                 MSG_MGR_DEBUG("notification_set_time_to_text() was failed. [%d]", noti_err);
2958 }
2959
2960
2961 void setNotiTime(notification_h noti_h, time_t time)
2962 {
2963         int noti_err = NOTIFICATION_ERROR_NONE;
2964
2965         noti_err = notification_set_time(noti_h, time);
2966
2967         if (noti_err != NOTIFICATION_ERROR_NONE)
2968                 MSG_MGR_DEBUG("notification_set_time() was failed. [%d]", noti_err);
2969 }
2970
2971
2972
2973 void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path)
2974 {
2975         int noti_err = NOTIFICATION_ERROR_NONE;
2976
2977         noti_err = notification_set_image(noti_h, type, image_path);
2978
2979         if (noti_err != NOTIFICATION_ERROR_NONE)
2980                 MSG_MGR_DEBUG("notification_set_image() was failed. [%d]", noti_err);
2981 }
2982
2983
2984 void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path)
2985 {
2986         int noti_err = NOTIFICATION_ERROR_NONE;
2987
2988         noti_err = notification_set_sound(noti_h, type, path);
2989
2990         if (noti_err != NOTIFICATION_ERROR_NONE)
2991                 MSG_MGR_DEBUG("notification_set_sound() was failed. [%d]", noti_err);
2992 }
2993
2994
2995 void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path)
2996 {
2997         int noti_err = NOTIFICATION_ERROR_NONE;
2998
2999         noti_err = notification_set_vibration(noti_h, type, path);
3000
3001         if (noti_err != NOTIFICATION_ERROR_NONE)
3002                 MSG_MGR_DEBUG("notification_set_vibration() was failed. [%d]", noti_err);
3003 }
3004
3005
3006 void setNotiEventHandler(notification_h noti_h, notification_event_type_e type, app_control_h event_handler)
3007 {
3008         int noti_err = NOTIFICATION_ERROR_NONE;
3009
3010         noti_err = notification_set_event_handler(noti_h, type, event_handler);
3011
3012         if (noti_err != NOTIFICATION_ERROR_NONE)
3013                 MSG_MGR_DEBUG("notification_set_event_handler() was failed. [%d]", noti_err);
3014 }
3015
3016
3017 int MsgMgrInsertInstantMessage(msg_mgr_notification_type_t noti_type)
3018 {
3019         MSG_MGR_BEGIN();
3020
3021         char *notiMsg = NULL;
3022
3023         notification_h noti = notification_create(NOTIFICATION_TYPE_NOTI);
3024
3025         switch (noti_type) {
3026         case MSG_MGR_NOTI_TYPE_NORMAL:
3027         case MSG_MGR_NOTI_TYPE_SIM:
3028         case MSG_MGR_NOTI_TYPE_CB: {
3029                 MSG_MGR_NOTI_INFO_S noti_info;
3030                 memset(&noti_info, 0x00, sizeof(MSG_MGR_NOTI_INFO_S));
3031
3032                 noti_info.type = noti_type;
3033                 int err = getLatestMsgInfo(&noti_info, true);
3034
3035                 if (err == 0) {
3036                         MSG_MGR_DEBUG("Unread count [%d]", noti_info.count);
3037                         if (noti_info.count == 1) {
3038                                 MSG_MGR_SEC_DEBUG("noti_info.sender [%s]", noti_info.sender);
3039                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, noti_info.sender, NULL);
3040                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.text, NULL);
3041                         } else if (noti_info.count > 1) {
3042                                 gchar *cnt_string = g_strdup_printf("%i", noti_info.count);
3043
3044                                 notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, NEW_MESSAGES);
3045                                 gchar *outString = g_strconcat(cnt_string, " ", notiMsg, NULL);
3046                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, outString, NULL);
3047                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.sender, NULL);
3048                                 g_free(outString);
3049                                 g_free(cnt_string);
3050                         }
3051
3052                         setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
3053                 }
3054                 break;
3055         }
3056         case MSG_MGR_NOTI_TYPE_FAILED: {
3057                 notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, FAILED_TO_SEND_MESSAGE);
3058                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, notiMsg, NULL);
3059                 setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SMS_SENDING_FAILED_ICON_PATH);
3060                 break;
3061         }
3062         default:
3063                 MSG_MGR_DEBUG("No matching type for MsgNotiType%d]", noti_type);
3064                 goto _END_OF_INSTANT_NOTI;
3065                 break;
3066         }
3067
3068         if (notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER) != NOTIFICATION_ERROR_NONE)
3069                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
3070
3071         if (notification_set_pkgname(noti, MSG_DEFAULT_APP_ID) != NOTIFICATION_ERROR_NONE)
3072                 MSG_MGR_DEBUG("Fail to notification_set_pkgname");
3073
3074         if (notification_post(noti) != NOTIFICATION_ERROR_NONE)
3075                 MSG_MGR_DEBUG("Fail to notification_post");
3076
3077 _END_OF_INSTANT_NOTI:
3078
3079         if (notification_delete(noti) != NOTIFICATION_ERROR_NONE)
3080                 MSG_MGR_DEBUG("Fail to notification_delete");
3081         if (notiMsg) {
3082                 free(notiMsg);
3083                 notiMsg = NULL;
3084         }
3085
3086         if (noti) {
3087                 if (notification_free(noti) != NOTIFICATION_ERROR_NONE)
3088                         MSG_MGR_DEBUG("Fail to notification_free");
3089                 noti = NULL;
3090         }
3091
3092         MSG_MGR_END();
3093         return 0;
3094 }
3095
3096
3097 bool MsgMgrCheckNotificationSettingEnable()
3098 {
3099         bool msg_noti_enabled = false;
3100         notification_system_setting_h system_setting = NULL;
3101         notification_setting_h setting = NULL;
3102
3103         int err = NOTIFICATION_ERROR_NONE;
3104
3105         err = notification_setting_get_setting_by_package_name(MSG_DEFAULT_APP_ID, &setting);
3106
3107         if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
3108                 MSG_MGR_ERR("getting setting handle for [%s] is failed. err = %d", MSG_DEFAULT_APP_ID, err);
3109         } else {
3110                 msg_noti_enabled = true;
3111
3112                 bool allow_to_notify = false;
3113                 err = notification_setting_get_allow_to_notify(setting, &allow_to_notify);
3114
3115                 if (err != NOTIFICATION_ERROR_NONE) {
3116                         MSG_MGR_ERR("getting do not disturb setting is failed. err = %d", err);
3117                         goto EXIT;
3118                 }
3119
3120                 if (allow_to_notify) {
3121                         MSG_MGR_DEBUG("message notification is allowed");
3122
3123                         /* check do not disturb mode */
3124                         err = notification_system_setting_load_system_setting(&system_setting);
3125
3126                         if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
3127                                 MSG_MGR_ERR("getting system setting is failed. err = %d", err);
3128                                 goto EXIT;
3129                         }
3130
3131                         bool do_not_disturb_mode = false;
3132                         err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb_mode);
3133
3134                         if (err != NOTIFICATION_ERROR_NONE) {
3135                                 MSG_MGR_ERR("getting do not disturb setting is failed. err = %d", err);
3136                                 goto EXIT;
3137                         }
3138
3139                         if (do_not_disturb_mode) {
3140                                 bool is_msg_excepted = false;
3141                                 err = notification_setting_get_do_not_disturb_except(setting, &is_msg_excepted);
3142                                 if (err != NOTIFICATION_ERROR_NONE) {
3143                                         MSG_MGR_ERR("getting do not disturb except status for [%s] is failed. err = %d", MSG_DEFAULT_APP_ID, err);
3144                                         msg_noti_enabled = false;
3145                                 } else {
3146                                         MSG_MGR_INFO("do not disturb mode status for [%s] : %d", MSG_DEFAULT_APP_ID, is_msg_excepted);
3147                                         msg_noti_enabled = (is_msg_excepted) ? true : false;
3148                                 }
3149                         } else {
3150                                 MSG_MGR_DEBUG("do not disturb mode is off");
3151                         }
3152                 } else {
3153                         MSG_MGR_INFO("message notification is not allowed");
3154                         msg_noti_enabled = false;
3155                 }
3156         }
3157
3158 EXIT:
3159         if (system_setting)
3160                 notification_system_setting_free_system_setting(system_setting);
3161
3162         if (setting)
3163                 notification_setting_free_notification(setting);
3164
3165         return msg_noti_enabled;
3166 }
3167
3168
3169 int MsgMgrInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId)
3170 {
3171         MSG_MGR_DEBUG("pTickerMsg=[%s], pLocaleTickerMsg=[%s]", pTickerMsg, pLocaleTickerMsg);
3172         MSG_MGR_DEBUG("play feedback=[%d], msgId=[%d]", bPlayFeedback, msgId);
3173
3174         MsgMgrChangePmState();
3175
3176         char *notiMsg = NULL;
3177         msg_mgr_active_notification_type_t active_type = MSG_MGR_ACTIVE_NOTI_TYPE_NONE;
3178         int err = 0;
3179
3180         notiMsg = get_translate_text(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, pLocaleTickerMsg);
3181         MSG_MGR_DEBUG("notiMsg %s", notiMsg);
3182
3183         if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) != 0 &&
3184                 g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) != 0 &&
3185                 g_strcmp0(pLocaleTickerMsg, MESSAGE_RETRIEVED) != 0) {
3186                 if (g_strcmp0(pLocaleTickerMsg, notiMsg) == 0) {
3187                         notification_status_message_post(pTickerMsg);
3188                 } else {
3189                         notification_status_message_post(notiMsg);
3190                 }
3191         } else {
3192                 /* Show ticker popup for sending failed msg. */
3193                 active_type = MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT;
3194         }
3195
3196         if (notiMsg) {
3197                 free(notiMsg);
3198                 notiMsg = NULL;
3199         }
3200
3201         if (bPlayFeedback) {
3202                 if (msgId > 0 &&
3203                         (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) == 0 || g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) == 0)) {
3204                         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_FAILED, true, active_type);
3205                         if (err != 0) {
3206                                 MSG_MGR_DEBUG("MsgRefreshFailedNoti err=[%d]", err);
3207                         }
3208                 } else if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SIM_MESSAGE_FULL) == 0) {
3209                         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM_FULL, true, MSG_MGR_ACTIVE_NOTI_TYPE_NONE);
3210                         if (err != 0) {
3211                                 MSG_MGR_DEBUG("MsgRefreshSimFullNoti err=[%d]", err);
3212                         }
3213                 } else {
3214                         MsgMgrSoundPlayStart(NULL, MSG_MGR_SOUND_PLAY_DEFAULT);
3215                 }
3216         }
3217
3218         return err;
3219 }
3220
3221
3222 int MsgMgrInsertBadge(unsigned int unreadMsgCnt)
3223 {
3224         MSG_MGR_DEBUG("Start to set badge to [%d].", unreadMsgCnt);
3225
3226         int err = BADGE_ERROR_NONE;
3227         bool exist = false;
3228
3229         err = badge_is_existing(MSG_DEFAULT_APP_ID, &exist);
3230
3231         if (err != BADGE_ERROR_NONE) {
3232                 MSG_MGR_ERR("Fail to badge_is_existing : %d", err);
3233                 return -1;
3234         }
3235
3236         if (!exist) {
3237                 /* create badge */
3238                 err = badge_add(MSG_DEFAULT_APP_ID);
3239                 if (err != BADGE_ERROR_NONE) {
3240                         MSG_MGR_ERR("Fail to badge_add : %d", err);
3241                         return -1;
3242                 }
3243         }
3244
3245         err = badge_set_count(MSG_DEFAULT_APP_ID, unreadMsgCnt);
3246
3247         if (err != BADGE_ERROR_NONE) {
3248                 MSG_MGR_ERR("Fail to badge_set_count : %d", err);
3249                 return -1;
3250         }
3251
3252         return 0;
3253 }
3254
3255
3256 void MsgMgrNotiSoundRepeatAlarmCB(int alarmId)
3257 {
3258         MSG_MGR_BEGIN();
3259
3260         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3261
3262 #ifndef MSG_NOTI_INTEGRATION
3263         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3264         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_CB, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3265 #endif
3266
3267         MSG_MGR_END();
3268         return;
3269 }
3270
3271
3272 void MsgMgrSoundCreateRepeatAlarm(int RepeatTime)
3273 {
3274         MSG_MGR_BEGIN();
3275
3276         int tmpAlarmId = 0;
3277         time_t tmp_time;
3278         struct tm repeat_tm;
3279
3280         time(&tmp_time);
3281
3282         tmp_time += (RepeatTime*60);
3283         tzset();
3284         localtime_r(&tmp_time, &repeat_tm);
3285
3286         if (MsgMgrAlarmRegistration(&repeat_tm, MsgMgrNotiSoundRepeatAlarmCB, &tmpAlarmId) != 0) {
3287                 MSG_MGR_DEBUG("MsgAlarmRegistration fail.");
3288                 return;
3289         }
3290
3291         g_alarmId = tmpAlarmId;
3292         MSG_MGR_DEBUG("Set alarmId to [%d]", g_alarmId);
3293
3294         MSG_MGR_END();
3295
3296         return;
3297 }
3298
3299
3300 void MsgMgrSoundSetRepeatAlarm()
3301 {
3302         int nRepeatValue = 0;
3303         long nRepeatTime = 0;
3304
3305         if (vconf_get_int(MSG_ALERT_REP_TYPE, &nRepeatValue) != 0) {
3306                 MSG_MGR_INFO("vconf_get_int() is failed");
3307         }
3308
3309         switch (nRepeatValue) {
3310         case MSG_ALERT_TONE_ONCE:
3311                 nRepeatTime = 0;
3312                 break;
3313         case MSG_ALERT_TONE_2MINS:
3314                 nRepeatTime = 2;
3315                 break;
3316         case MSG_ALERT_TONE_5MINS:
3317                 nRepeatTime = 5;
3318                 break;
3319         case MSG_ALERT_TONE_10MINS:
3320                 nRepeatTime = 10;
3321                 break;
3322         default:
3323                 MSG_MGR_DEBUG("Invalid Repetition time");
3324                 break;
3325         }
3326
3327         MSG_MGR_DEBUG("nRepeatTime = %d", nRepeatTime);
3328
3329         if (nRepeatTime > 0) {
3330                 if (g_alarmId > 0) {
3331                         if (MsgMgrAlarmRemove(g_alarmId) != 0) {
3332                                 MSG_MGR_FATAL("MsgAlarmRemove fail.");
3333                         }
3334                         g_alarmId = 0;
3335                 }
3336                 MsgMgrSoundCreateRepeatAlarm(nRepeatTime);
3337         }
3338
3339         return;
3340 }
3341
3342
3343 char *get_translate_text(const char *pkg_name, const char *locale_dir, const char *text)
3344 {
3345         char *notiMsg = NULL;
3346         char *lang = NULL;
3347
3348         lang = vconf_get_str(VCONFKEY_LANGSET);
3349
3350         setlocale(LC_MESSAGES, lang);
3351
3352         bindtextdomain(pkg_name, locale_dir);
3353
3354         notiMsg = dgettext(pkg_name, text);
3355
3356         if (lang) {
3357                 free(lang);
3358                 lang = NULL;
3359         }
3360
3361         return g_strdup(notiMsg);
3362 }
3363