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