fix error related showing unknown sender
[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_STORAGE_FULL: {
811                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
812                 break;
813         }
814         case MSG_MGR_NOTI_TYPE_VOICE_1:
815         case MSG_MGR_NOTI_TYPE_VOICE_2:
816         case MSG_MGR_NOTI_TYPE_MWI:
817         case MSG_MGR_NOTI_TYPE_CLASS0:
818         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT:
819         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
820         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
821                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->svc_h);
822                 break;
823         }
824         default:
825                 MSG_MGR_DEBUG("No matching type for notification_set_launch_option() [%d]", noti_info->type);
826                 break;
827         }
828
829         /* set applist */
830         noti_err = notification_set_display_applist(noti_h, noti_info->applist);
831         if (noti_err != NOTIFICATION_ERROR_NONE) {
832                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
833         }
834
835         /* set pkg name */
836         noti_err = notification_set_pkgname(noti_h, MSG_DEFAULT_APP_ID);
837         if (noti_err != NOTIFICATION_ERROR_NONE) {
838                 MSG_MGR_DEBUG("Fail to notification_set_pkgname");
839         }
840
841         MSG_MGR_END();
842 }
843
844
845 void setTextDomain(notification_h noti_h)
846 {
847         MSG_MGR_BEGIN();
848
849         setNotiTextDomain(noti_h, MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR);
850         MSG_MGR_END();
851 }
852
853
854 void setText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
855 {
856         MSG_MGR_BEGIN();
857
858         char unreadMsgCntStr[10] = {0};
859         int bPreview = 1;
860
861         if (vconf_get_bool(MSG_SETTING_PREVIEW, &bPreview) != 0) {
862                 MSG_MGR_DEBUG("vconf_get_bool is failed.");
863         }
864
865         /* set title and content */
866         switch (noti_info->type) {
867 #ifdef MSG_NOTI_INTEGRATION
868         case MSG_MGR_NOTI_TYPE_NORMAL:
869         case MSG_MGR_NOTI_TYPE_CB:
870         case MSG_MGR_NOTI_TYPE_SIM: {
871                 if (noti_info->count > 1) {
872                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
873                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
874                         setNotiTime(noti_h, noti_info->time);
875
876                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
877                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
878
879                 } else {
880                         if (bPreview) {
881                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
882                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
883                         } else {
884                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
885                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
886                         }
887                         setNotiTime(noti_h, noti_info->time);
888                 }
889                 break;
890         }
891 #else
892         case MSG_MGR_NOTI_TYPE_NORMAL: {
893                 if (noti_info->count > 1) {
894                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Messages", NEW_MESSAGES);
895                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
896                         setNotiTime(noti_h, noti_info->time);
897
898                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
899                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
900                 } else {
901                         if (bPreview) {
902                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
903                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
904                         } else {
905                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "New Message", NEW_MESSAGE);
906                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
907                         }
908                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
909                         setNotiTime(noti_h, noti_info->time);
910                 }
911                 break;
912         }
913         case MSG_MGR_NOTI_TYPE_CB: {
914                 if (noti_info->count > 1) {
915                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
916                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
917                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
918                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
919                         setNotiTime(noti_h, noti_info->time);
920
921                 } else {
922                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
923                         setNotiTime(noti_h, noti_info->time);
924
925                         if (bPreview) {
926                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
927                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
928                         } else {
929                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", CB_MESSAGE);
930                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
931                         }
932                 }
933                 break;
934         }
935         case MSG_MGR_NOTI_TYPE_SIM: {
936                 if (noti_info->count > 1) {
937                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
938                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
939                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
940
941                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
942                         setNotiTime(noti_h, noti_info->time);
943                 } else {
944                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
945                         setNotiTime(noti_h, noti_info->time);
946
947                         if (bPreview) {
948                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->sender, NULL);
949                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->text, NULL);
950                         } else {
951                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card Message", SIM_CARD_MESSAGE);
952                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
953                         }
954                 }
955                 break;
956         }
957 #endif
958         case MSG_MGR_NOTI_TYPE_FAILED: {
959                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MSG_MESSAGE);
960                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Failed to send message.", FAILED_TO_SEND_MESSAGE);
961                 if (noti_info->count > 1) {
962                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
963                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
964                 }
965                 setNotiTime(noti_h, noti_info->time);
966                 break;
967         }
968         case MSG_MGR_NOTI_TYPE_VOICE_1:
969         case MSG_MGR_NOTI_TYPE_VOICE_2: {
970                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Voicemail", VOICE_MAIL);
971                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
972                 setNotiTime(noti_h, noti_info->time);
973
974                 if (noti_info->count == 1) {
975                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, "1", NULL);
976                 } else if (noti_info->count > 1) {
977                         snprintf(unreadMsgCntStr, sizeof(unreadMsgCntStr), "%d", noti_info->count);
978                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL);
979                 } else {
980                         MSG_MGR_DEBUG("Invalid notification count, [cnt = %d]", noti_info->count);
981                 }
982                 break;
983         }
984         case MSG_MGR_NOTI_TYPE_MWI: {
985                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "MWI Message", NULL);
986                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
987                 setNotiTime(noti_h, noti_info->time);
988                 break;
989         }
990         case MSG_MGR_NOTI_TYPE_CLASS0: {
991                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL);
992                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
993                 setNotiTime(noti_h, noti_info->time);
994                 break;
995         }
996         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT: {
997                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery report", DELIVERY_MESSAGE);
998                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
999
1000                 if (noti_info->extra_data == MSG_NETWORK_DELIVER_SUCCESS) {
1001                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", MESSAGE_DELIVERED);
1002                 } else if (noti_info->extra_data == MSG_NETWORK_DELIVER_EXPIRED) {
1003                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", MESSAGE_EXPIRED);
1004                 } else {
1005                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delayed", MESSAGE_DELAYED);
1006                 }
1007
1008                 setNotiTime(noti_h, noti_info->time);
1009                 break;
1010         }
1011         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT: {
1012                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Read Report", READ_REPORT_MESSAGE);
1013
1014                 char readStatusString[50] = {0,};
1015                 if (noti_info->extra_data == MSG_READ_REPORT_IS_DELETED) {
1016                         snprintf(readStatusString, sizeof(readStatusString), "Message deleted by %s", noti_info->sender);
1017                         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);
1018                 } else {
1019                         char readStatusString[50] = {0,};
1020                         snprintf(readStatusString, sizeof(readStatusString), "Message read by %s", noti_info->sender);
1021                         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);
1022                 }
1023
1024                 setNotiTime(noti_h, noti_info->time);
1025                 break;
1026         }
1027         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
1028                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Report", DELIVERY_MESSAGE);
1029                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->sender, NULL);
1030
1031                 if (noti_info->extra_data == MSG_DELIVERY_REPORT_EXPIRED) {
1032                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message expired", MESSAGE_EXPIRED);
1033                 } else if (noti_info->extra_data == MSG_DELIVERY_REPORT_REJECTED) {
1034                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message rejected", MESSAGE_REJECTED);
1035                 } else if (noti_info->extra_data == MSG_DELIVERY_REPORT_DEFERRED) {
1036                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delayed", MESSAGE_DELAYED);
1037                 } else if (noti_info->extra_data == MSG_DELIVERY_REPORT_UNRECOGNISED || noti_info->extra_data == MSG_DELIVERY_REPORT_INDETERMINATE
1038                                 || noti_info->extra_data == MSG_DELIVERY_REPORT_FORWARDED || noti_info->extra_data == MSG_DELIVERY_REPORT_UNREACHABLE
1039                                 || noti_info->extra_data == MSG_DELIVERY_REPORT_ERROR) {
1040                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Recipient not available", RECIPIENT_NOT_AVAILABLE);
1041                 } else {
1042                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, "Message delivered", MESSAGE_DELIVERED);
1043                 }
1044
1045                 setNotiTime(noti_h, noti_info->time);
1046                 break;
1047         }
1048         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT: {
1049                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Messages", MSG_MESSAGE);
1050
1051                 if ((int)noti_info->extra_data == MSG_NETWORK_SEND_FAIL) {
1052                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Failed to send Read report", FAILED_TO_SEND_MMS_READ_REPORT);
1053                 } else {
1054                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Read report sent", MMS_READ_REPORT_SENT);
1055                 }
1056
1057                 setNotiTime(noti_h, noti_info->time);
1058                 break;
1059         }
1060         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
1061                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "SIM card full", SMS_SIM_CARD_FULL);
1062                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Not enough memory. Delete some items.", SMS_MESSAGE_MEMORY_FULL);
1063                 break;
1064         }
1065         case MSG_MGR_NOTI_TYPE_STORAGE_FULL: {
1066                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "Not enough space", NULL);
1067                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "Couldn't receive new messages", NULL);
1068                 setNotiTime(noti_h, time(NULL));
1069                 break;
1070         }
1071         default:
1072                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1073                 break;
1074         }
1075
1076         MSG_MGR_END();
1077 }
1078
1079 void setIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1080 {
1081         MSG_MGR_BEGIN();
1082
1083         switch (noti_info->type) {
1084 #ifdef MSG_NOTI_INTEGRATION
1085         case MSG_MGR_NOTI_TYPE_NORMAL:
1086         case MSG_MGR_NOTI_TYPE_CB:
1087         case MSG_MGR_NOTI_TYPE_SIM: {
1088                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1089                 if (noti_info->count > 1 && noti_info->senderCount > 1) {
1090                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
1091                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1092                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, "");
1093                 } else {
1094                         if (noti_info->active_subtype == MSG_CB_SMS) {
1095                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_CB_ICON_PATH);
1096                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1097                         } else if (noti_info->active_subtype == MSG_WAP_SI_SMS || noti_info->active_subtype == MSG_WAP_SL_SMS) {
1098                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_ACTIVE_PUSH_ICON_PATH);
1099                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_ACTIVE_PUSH_ICON_PATH);
1100                         } else if (noti_info->active_subtype == MSG_SYNCML_CP) {
1101                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_OTA_ICON_PATH);
1102                         } else {
1103                                 if (noti_info->imagePath[0] != '\0') {
1104                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, noti_info->imagePath);
1105                                         /* for user profile image, use NOTIFICATION_IMAGE_TYPE_THUMBNAIL to show icon as circle */
1106                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, noti_info->imagePath);
1107                                 } else {
1108                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NO_CONTACT_PROFILE_ICON_PATH);
1109                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NO_CONTACT_PROFILE_ICON_PATH);
1110                                         /* TSAM-9359 : priority of image selection on quickpanel, thumbnail is higher. So set NOTIFICATION_IMAGE_TYPE_THUMBNAIL with null */
1111                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, NULL);
1112                                 }
1113
1114                                 char *msg_icon_path = NULL;
1115                                 if (getAppIcon(MSG_DEFAULT_APP_ID, &msg_icon_path) == 0) {
1116                                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, msg_icon_path);
1117                                         g_free(msg_icon_path);
1118                                 } else {
1119                                         MSG_MGR_ERR("fail to get message-app icon");
1120                                 }
1121                         }
1122                 }
1123                 break;
1124         }
1125 #else
1126         case MSG_MGR_NOTI_TYPE_NORMAL: {
1127                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_NORMAL_STATUS_ICON);
1128                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, MSG_NORMAL_ICON_PATH);
1129
1130                 if (noti_info->count > 1) {
1131                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1132                 } else {
1133                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_REPLY_ICON_PATH);
1134                 }
1135                 break;
1136         }
1137         case MSG_MGR_NOTI_TYPE_CB: {
1138                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1139                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_CB_ICON_PATH);
1140                 break;
1141         }
1142         case MSG_MGR_NOTI_TYPE_SIM: {
1143                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SIM_ICON_PATH);
1144                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_SIM_ICON_PATH);
1145                 break;
1146         }
1147 #endif
1148         case MSG_MGR_NOTI_TYPE_FAILED: {
1149                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SMS_SENDING_FAILED_ICON_PATH);
1150                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_FAILED_STATUS_ICON);
1151                 break;
1152         }
1153         case MSG_MGR_NOTI_TYPE_VOICE_1:
1154         case MSG_MGR_NOTI_TYPE_VOICE_2:
1155         case MSG_MGR_NOTI_TYPE_MWI: {
1156                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_VOICE_MSG_STATUS_ICON);
1157                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_VOICE_ICON_PATH);
1158                 break;
1159         }
1160         case MSG_MGR_NOTI_TYPE_CLASS0:
1161                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1162                 break;
1163         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT:
1164                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_DELIVER_REPORT_STATUS_ICON);
1165                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_DELIVERY_ICON_PATH);
1166                 break;
1167         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
1168                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_READ_REPORT_STATUS_ICON);
1169                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_READ_ICON_PATH);
1170                 break;
1171         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT:
1172                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_READ_REPORT_STATUS_ICON);
1173                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_READ_ICON_PATH);
1174                 break;
1175         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT:
1176                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_DELIVER_REPORT_STATUS_ICON);
1177                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_DELIVERY_ICON_PATH);
1178                 break;
1179         case MSG_MGR_NOTI_TYPE_SIM_FULL:
1180                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1181                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_SIM_FULL_STATUS_ICON);
1182                 break;
1183         case MSG_MGR_NOTI_TYPE_STORAGE_FULL: {
1184                 char *msg_icon_path = NULL;
1185                 if (getAppIcon(MSG_DEFAULT_APP_ID, &msg_icon_path) == 0) {
1186                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, msg_icon_path);
1187                         g_free(msg_icon_path);
1188                 } else {
1189                         MSG_MGR_ERR("fail to get message-app icon");
1190                 }
1191                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, MSG_STORAGE_FULL_STATUS_ICON);
1192                 break;
1193         }
1194         default:
1195                 MSG_MGR_DEBUG("No matching type for MsgNotiSetImage [%d]", noti_info->type);
1196                 break;
1197         }
1198
1199         MSG_MGR_END();
1200 }
1201
1202 void setActiveProperty(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1203 {
1204         MSG_MGR_BEGIN();
1205
1206         int noti_err = NOTIFICATION_ERROR_NONE;
1207
1208         /* set layout */
1209         noti_err = notification_set_layout(noti_h, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
1210         if (noti_err != NOTIFICATION_ERROR_NONE) {
1211                 MSG_MGR_DEBUG("Fail to notification_set_layout : %d", noti_err);
1212         }
1213
1214         /* set led */
1215         noti_err = notification_set_led(noti_h, NOTIFICATION_LED_OP_ON, 0x00);
1216         if (noti_err != NOTIFICATION_ERROR_NONE) {
1217                 MSG_MGR_DEBUG("Fail to notification_set_led.");
1218         }
1219
1220         /* set execute option and property */
1221         switch (noti_info->type) {
1222         case MSG_MGR_NOTI_TYPE_NORMAL:
1223                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->active_noti_svc_h[2]);
1224                 notification_set_property(noti_h, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
1225                 break;
1226         case MSG_MGR_NOTI_TYPE_CLASS0:
1227                 notification_set_launch_option(noti_h, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, noti_info->active_noti_svc_h[2]);
1228                 break;
1229         default:
1230                 MSG_MGR_DEBUG("No matching type for notification_set_launch_option() [%d]", noti_info->type);
1231                 break;
1232         }
1233
1234         /* set applist */
1235         noti_err = notification_set_display_applist(noti_h, NOTIFICATION_DISPLAY_APP_ACTIVE);
1236         if (noti_err != NOTIFICATION_ERROR_NONE) {
1237                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
1238         }
1239
1240         /* set pkg name */
1241         noti_err = notification_set_pkgname(noti_h, MSG_DEFAULT_APP_ID);
1242         if (noti_err != NOTIFICATION_ERROR_NONE) {
1243                 MSG_MGR_DEBUG("Fail to notification_set_pkgname");
1244         }
1245
1246         MSG_MGR_END();
1247 }
1248
1249
1250 void setActiveText(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1251 {
1252         MSG_MGR_BEGIN();
1253
1254         switch (noti_info->type) {
1255         case MSG_MGR_NOTI_TYPE_NORMAL:
1256         case MSG_MGR_NOTI_TYPE_SIM:
1257         case MSG_MGR_NOTI_TYPE_CB: {
1258                 if (noti_info->active_subject[0] == '\0') {
1259                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->active_sender, NULL);
1260                         if (noti_info->active_text[0] != '\0') {
1261                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_text, NULL);
1262                         } else {
1263                                 if (noti_info->active_media_cnt > 1) {
1264                                         char attach_string[20] = {0,};
1265                                         snprintf(attach_string, sizeof(attach_string), "%d attachments", noti_info->active_media_cnt);
1266                                         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);
1267                                 } else if (noti_info->active_media_cnt == 1) {
1268                                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "1 attachment", MSG_SINGLE_ATTACHMENT);
1269                                 }
1270                         }
1271                 } else {
1272                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, noti_info->active_sender, NULL);
1273                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_INFO_1, noti_info->active_subject, NULL);
1274                         if (noti_info->active_text[0] != '\0') {
1275                                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_text, NULL);
1276                         } else {
1277                                 if (noti_info->active_media_cnt > 1) {
1278                                         char attach_string[20] = {0,};
1279                                         snprintf(attach_string, sizeof(attach_string), "%d attachments", noti_info->active_media_cnt);
1280                                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, attach_string, NULL);
1281                                 } else if (noti_info->active_media_cnt == 1) {
1282                                         setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, "1 attachment", NULL);
1283                                 }
1284                         }
1285                 }
1286                 break;
1287         }
1288         case MSG_MGR_NOTI_TYPE_CLASS0: {
1289                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_TITLE, "CLASS 0 Message", NULL);
1290                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info->active_sender, NULL);
1291                 break;
1292         }
1293         default:
1294                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1295                 break;
1296         }
1297
1298         MSG_MGR_END();
1299 }
1300
1301
1302 void setActiveIcon(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1303 {
1304         MSG_MGR_BEGIN();
1305
1306         switch (noti_info->type) {
1307         case MSG_MGR_NOTI_TYPE_NORMAL:
1308         case MSG_MGR_NOTI_TYPE_SIM: {
1309                 switch (noti_info->active_subtype) {
1310                 case MSG_CB_SMS:
1311                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1312                         break;
1313                 case MSG_WAP_SI_SMS:
1314                 case MSG_WAP_SL_SMS:
1315                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_ACTIVE_PUSH_ICON_PATH);
1316                         break;
1317                 case MSG_SYNCML_CP:
1318                         setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_OTA_ICON_PATH);
1319                         break;
1320                 default:
1321                         if (noti_info->imagePath[0] != '\0')
1322                                 /* for user profile image, use NOTIFICATION_IMAGE_TYPE_THUMBNAIL to show icon as circle */
1323                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_THUMBNAIL, noti_info->imagePath);
1324                         else
1325                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NO_CONTACT_PROFILE_ICON_PATH);
1326
1327                         char *msg_icon_path = NULL;
1328                         if (getAppIcon(MSG_DEFAULT_APP_ID, &msg_icon_path) == 0) {
1329                                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON_SUB, msg_icon_path);
1330                                 g_free(msg_icon_path);
1331                         } else {
1332                                 MSG_MGR_ERR("fail to get message-app icon");
1333                         }
1334
1335                         break;
1336                 }
1337
1338                 break;
1339         }
1340         case MSG_MGR_NOTI_TYPE_CB: {
1341                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_CB_ICON_PATH);
1342                 break;
1343         }
1344         case MSG_MGR_NOTI_TYPE_CLASS0:
1345                 setNotiImage(noti_h, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
1346                 break;
1347         default:
1348                 MSG_MGR_DEBUG("No matching type for MsgNotiSetImage [%d]", noti_info->type);
1349                 break;
1350         }
1351
1352         MSG_MGR_END();
1353 }
1354
1355
1356 int MsgMgrInsertDeliveryReportInstantNotification(msg_mgr_notification_type_t noti_type, int result)
1357 {
1358         MSG_MGR_BEGIN();
1359
1360         notification_h noti = notification_create(NOTIFICATION_TYPE_NOTI);
1361         notification_set_pkgname(noti, MSG_DEFAULT_APP_ID);
1362
1363         setTextDomain(noti);
1364         setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery report", DELIVERY_MESSAGE);
1365         setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_DELIVER_REPORT_STATUS_ICON);
1366
1367         if (noti_type == MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT) {
1368                 if (result == MSG_NETWORK_DELIVER_SUCCESS) {
1369                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message delivered.", MESSAGE_DELIVERED_POPUP);
1370                 } else if (result == MSG_NETWORK_DELIVER_EXPIRED) {
1371                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Couldn't deliver message. Message expired.", UNABLE_TO_DELIVER_MESSAGE_MESSAGE_EXPIRED);
1372                 } else if (result == MSG_NETWORK_DELIVER_PENDING) {
1373                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message delayed.", MESSAGE_DELAYED_POPUP);
1374                 } else {
1375                         MSG_MGR_ERR("unexpected result! [%d]", result);
1376                         goto _END_OF_INSTANT_DELIVERY_REPORT_NOTI;
1377                 }
1378         } else if (noti_type == MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT) {
1379                 if (result == MSG_DELIVERY_REPORT_EXPIRED)
1380                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Couldn't deliver message. Message expired.", UNABLE_TO_DELIVER_MESSAGE_MESSAGE_EXPIRED);
1381                 else if (result== MSG_DELIVERY_REPORT_REJECTED)
1382                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Couldn't deliver message. Message rejected by recipient.", UNABLE_TO_DELIVER_MESSAGE_MESSAGE_REJECTED);
1383                 else if (result == MSG_DELIVERY_REPORT_DEFERRED)
1384                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message delayed.", MESSAGE_DELAYED_POPUP);
1385                 else if (result == MSG_DELIVERY_REPORT_UNRECOGNISED || result == MSG_DELIVERY_REPORT_INDETERMINATE ||
1386                                 result == MSG_DELIVERY_REPORT_FORWARDED || result == MSG_DELIVERY_REPORT_UNREACHABLE ||
1387                                 result == MSG_DELIVERY_REPORT_ERROR)
1388                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Couldn't deliver message. Recipient not available.", UNABLE_TO_DELIVER_MESSAGE_RECIPIENT_NOT_AVAILABLE);
1389                 else
1390                         setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message delivered.", MESSAGE_DELIVERED_POPUP);
1391         }
1392
1393         if (notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER) != NOTIFICATION_ERROR_NONE)
1394                 MSG_MGR_ERR("Fail to notification_set_display_applist");
1395
1396         if (notification_post(noti) != NOTIFICATION_ERROR_NONE)
1397                 MSG_MGR_ERR("Fail to notification_post");
1398
1399 _END_OF_INSTANT_DELIVERY_REPORT_NOTI:
1400
1401         if (notification_delete(noti) != NOTIFICATION_ERROR_NONE)
1402                 MSG_MGR_ERR("Fail to notification_delete");
1403
1404         if (noti) {
1405                 if (notification_free(noti) != NOTIFICATION_ERROR_NONE)
1406                         MSG_MGR_ERR("Fail to notification_free");
1407                 noti = NULL;
1408         }
1409
1410         MSG_MGR_END();
1411         return 0;
1412 }
1413
1414
1415 void setSoundAndVibration(notification_h noti_h, char *addressVal, bool bVoiceMail)
1416 {
1417         MSG_MGR_BEGIN();
1418
1419         MSG_MGR_ADDRESS_INFO_S addrInfo = {0, };
1420         MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
1421
1422         if (addressVal != NULL) {
1423                 snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", addressVal);
1424                 /* Get Contact Info */
1425                 if (MsgMgrGetContactInfo(&addrInfo, &contactInfo) != 0) {
1426                         MSG_MGR_DEBUG("MsgMgrGetContactInfo() fail.");
1427                 }
1428         } else {
1429                 MSG_MGR_DEBUG("addressVal is NULL.");
1430         }
1431
1432         char *msg_tone_file_path = NULL;
1433
1434         MsgMgrGetRingtonePath(contactInfo.alerttonePath, &msg_tone_file_path);
1435
1436         MSG_MGR_SEC_DEBUG("Sound File [%s]", msg_tone_file_path);
1437
1438         bool bPlaySound = false;
1439         bool bPlayVibration = false;
1440         bool bOnCall = false;
1441
1442         MsgMgrGetPlayStatus(bVoiceMail, &bPlaySound, &bPlayVibration, &bOnCall);
1443
1444         if (bPlaySound) {
1445                 if (msg_tone_file_path) {
1446                         setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_USER_DATA, msg_tone_file_path);
1447                 } else {
1448                         int tmpVal = 0;
1449                         if (vconf_get_int(MSG_SETTING_RINGTONE_TYPE, &tmpVal) != 0) {
1450                                 MSG_MGR_INFO("vconf_get_int() is failed");
1451                         }
1452                         int ringtoneType = tmpVal;
1453                         if (ringtoneType == MSG_RINGTONE_TYPE_SILENT)
1454                                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1455                         else
1456                                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_DEFAULT, NULL);
1457                 }
1458         } else {
1459                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1460         }
1461
1462         if (bPlayVibration) {
1463                 if (contactInfo.vibrationPath[0] == '\0')
1464                         setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_DEFAULT, NULL);
1465                 else
1466                         setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_USER_DATA, contactInfo.vibrationPath);
1467         } else {
1468                 setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
1469         }
1470
1471         if (msg_tone_file_path)
1472                 delete [] msg_tone_file_path;
1473
1474         MSG_MGR_END();
1475 }
1476
1477
1478 void setActiveNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1479 {
1480         MSG_MGR_BEGIN();
1481
1482         int noti_err = NOTIFICATION_ERROR_NONE;
1483
1484         if (noti_info->active_noti_button_num > 1) {
1485                 createServiceHandle(&noti_info->active_noti_svc_h[0]);
1486                 if (noti_info->active_noti_svc_h[0]) {
1487                         setServicePackageName(noti_info->active_noti_svc_h[0], MSG_CALL_APP_ID);
1488                         setServiceOperation(noti_info->active_noti_svc_h[0], APP_CONTROL_OPERATION_CALL);
1489
1490                         MSG_MGR_DEBUG("Active Notification button 1 - Msg Id = [%d]", noti_info->msg_id);
1491
1492                         char tel_num[MSG_NOTI_TEXT_LEN_S] = {0, };
1493                         snprintf(tel_num, sizeof(tel_num), "tel:%s", noti_info->number);
1494                         MSG_MGR_SEC_DEBUG("Active sender number [%s]", noti_info->number);
1495                         setServiceUri(noti_info->active_noti_svc_h[0], tel_num);
1496                 }
1497
1498                 createServiceHandle(&noti_info->active_noti_svc_h[1]);
1499                 if (noti_info->active_noti_svc_h[1]) {
1500                         setServicePackageName(noti_info->active_noti_svc_h[1], MSG_MGR_APP_ID);
1501
1502                         MSG_MGR_DEBUG("Active Notification button 2 - Msg Id = [%d] number = [%s] slot_id = [%d]", noti_info->msg_id, noti_info->number, noti_info->sim_idx);
1503                         addServiceExtraData(noti_info->active_noti_svc_h[1], "cmd", "reply_msg");
1504                         addServiceExtraData(noti_info->active_noti_svc_h[1], "msg_id", noti_info->msg_id);
1505                         addServiceExtraData(noti_info->active_noti_svc_h[1], "addr", noti_info->number);
1506
1507                         char slot_id[5] = {0, };
1508                         snprintf(slot_id, sizeof(slot_id), "%d", noti_info->sim_idx);
1509                         addServiceExtraData(noti_info->active_noti_svc_h[1], "slot_id", slot_id);
1510                 }
1511         }
1512
1513         createServiceHandle(&noti_info->active_noti_svc_h[2]);
1514         if (noti_info->active_noti_svc_h[2]) {
1515                 setServicePackageName(noti_info->active_noti_svc_h[2], MSG_DEFAULT_APP_ID);
1516
1517                 MSG_MGR_DEBUG("Active Notification button 3 - msgId = [%d]", noti_info->msg_id);
1518                 addServiceExtraData(noti_info->active_noti_svc_h[2], "type", "new_msg");
1519                 addServiceExtraData(noti_info->active_noti_svc_h[2], "msgId", noti_info->msg_id);
1520                 addServiceExtraData(noti_info->active_noti_svc_h[2], "CALLER", "active_noti");
1521
1522                 char slot_id[5] = {0, };
1523                 snprintf(slot_id, sizeof(slot_id), "%d", noti_info->sim_idx - 1);
1524                 addServiceExtraData(noti_info->active_noti_svc_h[2], "slot_id", slot_id);
1525         }
1526
1527         if (noti_info->active_noti_button_num > 1) {
1528                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, noti_info->active_noti_svc_h[0]);
1529                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2, noti_info->active_noti_svc_h[1]);
1530                 notification_set_text_input(noti_h, 100);
1531                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_TEXT_INPUT_BUTTON, noti_info->active_noti_svc_h[1]);
1532                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_3, noti_info->active_noti_svc_h[2]);
1533
1534                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "Call", MSG_STRING_CALL);
1535                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_2, "Reply", MSG_STRING_REPLY);
1536                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_3, "View", MSG_STRING_VIEW);
1537         } else {
1538                 setNotiEventHandler(noti_h, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, noti_info->active_noti_svc_h[2]);
1539
1540                 setNotiText(noti_h, NOTIFICATION_TEXT_TYPE_BUTTON_1, "View", MSG_STRING_VIEW);
1541         }
1542
1543         setActiveProperty(noti_h, noti_info);
1544
1545         setTextDomain(noti_h);
1546
1547         setActiveText(noti_h, noti_info);
1548
1549         setActiveIcon(noti_h, noti_info);
1550
1551         noti_err = notification_post(noti_h);
1552         if (noti_err != NOTIFICATION_ERROR_NONE) {
1553                 MSG_MGR_DEBUG("Fail to notification_post");
1554         }
1555
1556         MSG_MGR_END();
1557 }
1558
1559
1560 void setNotification(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info, bool bFeedback)
1561 {
1562         MSG_MGR_BEGIN();
1563
1564         int noti_err = NOTIFICATION_ERROR_NONE;
1565
1566         MSG_MGR_DEBUG("active num [%d]", noti_info->active_noti_button_num);
1567
1568         if (bFeedback && noti_info->active_noti_button_num > MSG_ACTIVE_NOTI_BUTTON_NUM_NONE &&
1569                 ((noti_info->type >= MSG_MGR_NOTI_TYPE_NORMAL && noti_info->type <= MSG_MGR_NOTI_TYPE_SIM) || noti_info->type == MSG_MGR_NOTI_TYPE_CLASS0)) {
1570                 notification_h active_noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
1571
1572                 setActiveNotification(active_noti_h, noti_info);
1573
1574                 notification_free(active_noti_h);
1575                 active_noti_h = NULL;
1576         }
1577
1578         setProperty(noti_h, noti_info);
1579
1580         setTextDomain(noti_h);
1581
1582         setText(noti_h, noti_info);
1583
1584         setIcon(noti_h, noti_info);
1585
1586         if (bFeedback) {
1587                 if (noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_1 || noti_info->type == MSG_MGR_NOTI_TYPE_VOICE_2)
1588                         setSoundAndVibration(noti_h, noti_info->number, true);
1589                 else
1590                         setSoundAndVibration(noti_h, noti_info->number, false);
1591
1592         } else {
1593                 setNotiSound(noti_h, NOTIFICATION_SOUND_TYPE_NONE, NULL);
1594                 setNotiVibration(noti_h, NOTIFICATION_VIBRATION_TYPE_NONE, NULL);
1595         }
1596
1597         if (noti_info->id > 0) {
1598                 MSG_MGR_DEBUG("Notification update");
1599                 noti_err = notification_update(noti_h);
1600                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1601                         MSG_MGR_DEBUG("Fail to notification_update");
1602                 }
1603         } else {
1604                 MSG_MGR_DEBUG("Notification insert");
1605                 noti_err = notification_insert(noti_h, &noti_info->id);
1606                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1607                         MSG_MGR_DEBUG("Fail to notification_insert");
1608                 }
1609
1610                 updatePrivId(noti_info->type, noti_info->id, noti_info->sim_idx);
1611         }
1612
1613         if (noti_info->type == MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT && noti_info->msg_id > 0) {
1614                 int err = vconf_set_int(VCONFKEY_MESSAGE_READ_REPORT_SENT_MSG_ID, noti_info->msg_id);
1615                 if (err != 0)
1616                         MSG_MGR_ERR("vconf_set_int() failed [%d]", err);
1617         }
1618
1619         MSG_MGR_END();
1620 }
1621
1622
1623 void createActiveInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
1624 {
1625         MSG_MGR_BEGIN();
1626
1627         if (!msg_info) {
1628                 MSG_MGR_DEBUG("msg_info is NULL");
1629                 return;
1630         }
1631
1632         noti_info->msg_id = msg_info->msgId;
1633         noti_info->sim_idx = msg_info->sim_idx;
1634
1635         switch (noti_info->type) {
1636         case MSG_MGR_NOTI_TYPE_NORMAL: {
1637                 char *senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, PUSH_MESSAGE);
1638                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", senderStr);
1639                 if (senderStr) {
1640                         free(senderStr);
1641                         senderStr = NULL;
1642                 }
1643                 break;
1644         }
1645         case MSG_MGR_NOTI_TYPE_CLASS0: {
1646                 if (msg_info->displayName[0] == '\0')
1647                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->addressVal);
1648                 else
1649                         snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", msg_info->displayName);
1650
1651                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", msg_info->msgText);
1652                 break;
1653         }
1654         default:
1655                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
1656                 break;
1657         }
1658
1659         MSG_MGR_END();
1660 }
1661
1662
1663 void clearInfoData(notification_h noti_h, MSG_MGR_NOTI_INFO_S *noti_info)
1664 {
1665         MSG_MGR_BEGIN();
1666
1667         if (noti_h) {
1668                 notification_free(noti_h);
1669                 noti_h = NULL;
1670         }
1671
1672         if (noti_info->svc_h) {
1673                 app_control_destroy(noti_info->svc_h);
1674                 noti_info->svc_h = NULL;
1675         }
1676
1677         for (int i = 0; i < MSG_ACTIVE_NOTI_BUTTON_NUM; i++) {
1678                 if (noti_info->active_noti_svc_h[i]) {
1679                         app_control_destroy(noti_info->active_noti_svc_h[i]);
1680                         noti_info->active_noti_svc_h[i] = NULL;
1681                 }
1682         }
1683
1684         MSG_MGR_END();
1685 }
1686
1687
1688 int getAppIcon(const char *app_id, char **icon_path)
1689 {
1690         MSG_MGR_BEGIN();
1691
1692         package_info_h pkg_info_h = NULL;
1693         int pkg_err = PACKAGE_MANAGER_ERROR_NONE;
1694         int ret = 0;
1695
1696         if (app_id == NULL) {
1697                 MSG_MGR_ERR("app id is NULL");
1698                 ret = -1;
1699                 goto END_OF_GET_APP_ICON;
1700         }
1701
1702         pkg_err = package_info_create(app_id, &pkg_info_h);
1703         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1704                 MSG_MGR_ERR("package_info_create failed (%d)", pkg_err);
1705                 ret = -1;
1706                 goto END_OF_GET_APP_ICON;
1707         }
1708
1709         pkg_err = package_info_get_icon(pkg_info_h, icon_path);
1710         if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1711                 MSG_MGR_ERR("package_info_get_icon failed (%d)", pkg_err);
1712                 ret = -1;
1713         } else {
1714                 if (icon_path == NULL) {
1715                         MSG_MGR_WARN("icon path is NULL");
1716                         ret = -1;
1717                 }
1718         }
1719
1720 END_OF_GET_APP_ICON:
1721         if (pkg_info_h) {
1722                 pkg_err = package_info_destroy(pkg_info_h);
1723                 if (pkg_err != PACKAGE_MANAGER_ERROR_NONE) {
1724                         MSG_MGR_ERR("package_info_destroy failed (%d)", pkg_err);
1725                 }
1726
1727                 pkg_info_h = NULL;
1728         }
1729
1730         MSG_MGR_END();
1731
1732         return ret;
1733 }
1734
1735
1736 int getLatestMsgInfo(MSG_MGR_NOTI_INFO_S *noti_info, bool isForInstantMessage)
1737 {
1738         MSG_MGR_BEGIN();
1739
1740         int noti_err = 0;
1741         msg_error_t msg_err = MSG_SUCCESS;
1742         char **db_res = NULL;
1743         int row_cnt = 0, col_cnt = 0;
1744
1745         switch (noti_info->type) {
1746         case MSG_MGR_NOTI_TYPE_NORMAL:
1747 #ifdef MSG_NOTI_INTEGRATION
1748         case MSG_MGR_NOTI_TYPE_CB:
1749         case MSG_MGR_NOTI_TYPE_SIM:
1750 #endif
1751         {
1752         int smsUnreadCnt = 0;
1753                 int mmsUnreadCnt = 0;
1754
1755                 char sqlQuery[MAX_QUERY_LEN     +1];
1756                 unsigned char mainType;
1757                 unsigned char subType;
1758                 int msgSize, attachmentCnt;
1759
1760                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1761 #ifdef MSG_NOTI_INTEGRATION
1762                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1763                                 "A.ADDRESS_VAL, "
1764                                 "B.SUB_TYPE "
1765                                 "FROM %s A, %s B "
1766                                 "WHERE A.CONV_ID=B.CONV_ID "
1767                                 "AND B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1768                                 "AND B.STORAGE_ID = %d "
1769                                 "GROUP BY A.ADDRESS_VAL "
1770                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1771                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1772                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1773                                 MSG_STORAGE_PHONE);
1774 #else
1775                 snprintf(sqlQuery, sizeof(sqlQuery), "DISTINCT "
1776                                 "A.ADDRESS_VAL, "
1777                                 "B.SUB_TYPE "
1778                                 "FROM %s A, %s B "
1779                                 "WHERE A.CONV_ID=B.CONV_ID "
1780                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1781                                 "AND B.STORAGE_ID = %d "
1782                                 "GROUP BY A.ADDRESS_VAL "
1783                                 "ORDER BY B.DISPLAY_TIME DESC LIMIT 5;",
1784                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1785                                 MSG_INBOX_ID,
1786                                 MSG_STORAGE_PHONE);
1787 #endif
1788                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1789
1790                 row_cnt = 0, col_cnt = 0;
1791                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1792                 if (msg_err != MSG_SUCCESS) {
1793                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1794                         return -1;
1795                 }
1796
1797                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo;
1798                 int normalAddCnt = 0;
1799                 int index = col_cnt;
1800
1801                 for (int i = 1; i <= row_cnt; i++) {
1802                         memset(&tmpAddressInfo, 0x00, sizeof(MSG_MGR_ADDRESS_INFO_S));
1803
1804                         char *address = db_res[index++];
1805                         normalAddCnt++;
1806                         if (address) {
1807                                 snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", address);
1808                                 if (_is_valid_email(address)) {
1809                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
1810                                 } else {
1811                                         tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
1812                                 }
1813                         }
1814                         subType = atoi(db_res[index++]);
1815
1816                         MSG_MGR_CONTACT_INFO_S tmpContact;
1817                         memset(&tmpContact, 0x00, sizeof(MSG_MGR_CONTACT_INFO_S));
1818
1819                         MsgMgrGetContactInfo(&tmpAddressInfo, &tmpContact);
1820
1821                         if (row_cnt == 1) {
1822                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1823                         }
1824
1825                         if (normalAddCnt > 1) {
1826                                 g_strlcat(noti_info->sender, ", ", sizeof(noti_info->sender)-strlen(noti_info->sender));
1827                         }
1828
1829                         if (tmpContact.firstName[0] != '\0') {
1830                                 g_strlcat(noti_info->sender, tmpContact.firstName, sizeof(noti_info->sender)-strlen(noti_info->sender));
1831                         } else if (tmpAddressInfo.addressVal[0] == '\0') {
1832                                 char *senderStr = NULL;
1833                                 senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MSG_UNKNOWN_SENDER);
1834                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1835                                 if (senderStr) {
1836                                         free(senderStr);
1837                                         senderStr = NULL;
1838                                 }
1839
1840                                 if (i == 1) {
1841                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_UNKNOWN_SENDER;
1842                                 }
1843                         } else {
1844                                 char *senderStr = NULL;
1845                                 if (subType == MSG_CB_SMS) {
1846                                         senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, CB_MESSAGE);
1847                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1848                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_CB_MESSAGE;
1849                                 } else if (subType == MSG_SYNCML_CP) {
1850                                         senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, CP_MESSAGE);
1851                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1852                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_PUSH_MESSAGE;
1853                                 } else if (subType == MSG_WAP_SI_SMS || subType == MSG_WAP_SL_SMS) {
1854                                         senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, PUSH_MESSAGE);
1855                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
1856                                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_PUSH_MESSAGE;
1857                                 } else {
1858                                         g_strlcat(noti_info->sender, tmpAddressInfo.addressVal, sizeof(noti_info->sender)-strlen(noti_info->sender));
1859                                         if (subType == MSG_NOTIFICATIONIND_MMS)
1860                                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_UNRETRIVED_MESSAGE;
1861                                 }
1862
1863                                 if (senderStr) {
1864                                         free(senderStr);
1865                                         senderStr = NULL;
1866                                 }
1867                         }
1868
1869                         if (i == 1) {
1870                                 noti_info->active_subtype = subType;
1871                                 snprintf(noti_info->active_sender, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->sender);
1872                                 snprintf(noti_info->imagePath, sizeof(noti_info->imagePath), "%s", tmpContact.imagePath);
1873                         }
1874                 }
1875
1876                 noti_info->senderCount = normalAddCnt;
1877                 msg_db_free(msg_handle, db_res);
1878
1879                 MSG_MGR_SEC_DEBUG("sender info = [%s]", noti_info->sender);
1880
1881                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1882                 snprintf(sqlQuery, MAX_QUERY_LEN,
1883                                 "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS SMS_UNREAD_CNT, "
1884                                 "(COUNT(DISTINCT(CASE WHEN MAIN_TYPE = %d THEN MSG_ID END))) AS MMS_UNREAD_CNT "
1885                                 "FROM %s WHERE READ_STATUS = 0 AND (FOLDER_ID=%d OR FOLDER_ID=%d) AND STORAGE_ID = %d;",
1886                                 MSG_SMS_TYPE,
1887                                 MSG_MMS_TYPE,
1888                                 MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
1889
1890                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1891
1892                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1893                 if (msg_err != MSG_SUCCESS) {
1894                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1895                         return -1;
1896                 }
1897
1898                 if (row_cnt > 0) {
1899                         smsUnreadCnt = atoi(db_res[col_cnt]);
1900                         mmsUnreadCnt = atoi(db_res[col_cnt+1]);
1901                 }
1902
1903                 msg_db_free(msg_handle, db_res);
1904
1905                 noti_info->count = smsUnreadCnt + mmsUnreadCnt;
1906
1907                 if (noti_info->count == 0) {
1908                         MSG_MGR_DEBUG("No unread message.");
1909                         MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
1910
1911                         if (!isForInstantMessage) {
1912                                 /* No unread message. */
1913                                 if (noti_info->id > 0) {
1914                                         noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
1915                                         if (noti_err != NOTIFICATION_ERROR_NONE) {
1916                                                 MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
1917                                         }
1918                                 }
1919
1920                                 noti_info->id = 0;
1921
1922                                 if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
1923                                         MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
1924
1925                                 vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, 0);
1926                                 vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, 0);
1927                                 MsgMgrInsertBadge(0);
1928                                 MsgMgrSoundSetRepeatAlarm();
1929                         }
1930
1931                         return -1;
1932                 }
1933
1934                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1935 #ifdef MSG_NOTI_INTEGRATION
1936                 snprintf(sqlQuery, sizeof(sqlQuery),
1937                                 "A.ADDRESS_VAL, "
1938                                 "B.DISPLAY_TIME, "
1939                                 "B.MSG_ID, "
1940                                 "(CASE WHEN B.DPM_RESTRICTED = 0 THEN B.SUBJECT ELSE \"restricted message\" END), "
1941                                 "(CASE WHEN B.DPM_RESTRICTED = 0 THEN B.MSG_TEXT ELSE \"restricted message\" END), "
1942                                 "B.MAIN_TYPE, "
1943                                 "B.CONV_ID, "
1944                                 "(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), "
1945                                 "B.ATTACHMENT_COUNT, "
1946                                 "B.SIM_INDEX "
1947                                 "FROM %s B "
1948                                 "LEFT JOIN %s A ON A.CONV_ID=B.CONV_ID "
1949                                 "WHERE B.READ_STATUS=0 AND (B.FOLDER_ID=%d OR B.FOLDER_ID=%d) "
1950                                 "AND B.STORAGE_ID = %d "
1951                                 "ORDER BY B.DISPLAY_TIME DESC;",
1952                                 MSG_MMS_TYPE, MSG_NETWORK_RECEIVED, MMS_PLUGIN_MESSAGE_TABLE_NAME,
1953                                 MSGFW_MESSAGE_TABLE_NAME,
1954                                 MSGFW_ADDRESS_TABLE_NAME,
1955                                 MSG_INBOX_ID, MSG_CBMSGBOX_ID,
1956                                 MSG_STORAGE_PHONE);
1957 #else
1958                 snprintf(sqlQuery, sizeof(sqlQuery),
1959                                 "A.ADDRESS_VAL, "
1960                                 "B.DISPLAY_TIME, "
1961                                 "B.MSG_ID, "
1962                                 "B.SUBJECT, "
1963                                 "B.MSG_TEXT, "
1964                                 "B.MAIN_TYPE, "
1965                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT, "
1966                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS MMS_UNREAD_CNT "
1967                                 "FROM %s A, %s B "
1968                                 "WHERE A.CONV_ID=B.CONV_ID "
1969                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
1970                                 "AND B.STORAGE_ID = %d "
1971                                 "ORDER BY B.DISPLAY_TIME DESC;",
1972                                 MSG_SMS_TYPE,
1973                                 MSG_MMS_TYPE,
1974                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
1975                                 MSG_INBOX_ID,
1976                                 MSG_STORAGE_PHONE);
1977 #endif
1978                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
1979
1980                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
1981                 if (msg_err != MSG_SUCCESS) {
1982                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
1983                         return -1;
1984                 }
1985
1986                 if (row_cnt > 0) {
1987                         msgSize = atoi(db_res[col_cnt+7]);
1988                         attachmentCnt = atoi(db_res[col_cnt+8]);
1989                         noti_info->sim_idx = atoi(db_res[col_cnt+9]);
1990
1991                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", db_res[col_cnt]);
1992
1993                         noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
1994
1995                         noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
1996
1997                         noti_info->conv_id = atoi(db_res[col_cnt+6]);
1998
1999                         mainType = (unsigned char)atoi(db_res[col_cnt+5]);
2000
2001                         if (mainType == MSG_MMS_TYPE) {
2002                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
2003                                 if (noti_info->text[0] == '\0') {
2004                                         char *noti_text = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MSG_NO_SUBJECT);
2005                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", noti_text);
2006                                         g_free(noti_text);
2007                                 }
2008
2009                                 char *prefix_subject = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MSG_SUBJECT_COLON);
2010                                 if (prefix_subject) {
2011                                         snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s%s", prefix_subject, noti_info->text);
2012                                         g_free(prefix_subject);
2013                                 } else {
2014                                         snprintf(noti_info->active_subject, MSG_NOTI_TEXT_LEN_S, "%s", noti_info->text);
2015                                 }
2016
2017                                 if (msgSize > -1) {
2018                                         int kb_msg_size = msgSize / 1024;
2019                                         if (kb_msg_size == 0 && msgSize > 0)
2020                                                 kb_msg_size = 1;
2021                                         else if (msgSize % 1024 >= 512)
2022                                                 kb_msg_size++;
2023
2024                                         char *msg_size_string = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MESSAGE_SIZE_STRING);
2025                                         char *msg_size_unit_kb = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MESSAGE_SIZE_UNIT_KB);
2026
2027                                         snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s : %d%s", msg_size_string, kb_msg_size, msg_size_unit_kb);
2028
2029                                         g_free(msg_size_string);
2030                                         g_free(msg_size_unit_kb);
2031                                 }
2032
2033                                 noti_info->active_media_cnt = attachmentCnt;
2034
2035                         } else {
2036                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
2037                         }
2038
2039                         if (noti_info->active_text[0] == '\0')
2040                                 snprintf(noti_info->active_text, MSG_NOTI_TEXT_LEN, "%s", db_res[col_cnt+4]);
2041
2042                         MSG_MGR_DEBUG("unread message ID [%d].", noti_info->msg_id);
2043
2044                         MSG_MGR_DEBUG("active sender [%s]", noti_info->active_sender);
2045                         MSG_MGR_DEBUG("active subject [%s]", noti_info->active_subject);
2046                         MSG_MGR_DEBUG("active text [%s]", noti_info->active_text);
2047
2048                         if (!isForInstantMessage) {
2049                                 if (noti_info->id > 0 && noti_info->count == 1) {
2050                                         noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2051                                         if (noti_err != NOTIFICATION_ERROR_NONE) {
2052                                                 MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2053                                         }
2054
2055                                         noti_info->id = 0;
2056                                         if (vconf_set_int(NOTIFICATION_PRIV_ID, noti_info->id) != 0)
2057                                                 MSG_MGR_DEBUG("vconf_set_int fail : NOTIFICATION_PRIV_ID");
2058                                 }
2059
2060                                 vconf_set_int(VCONFKEY_MESSAGE_RECV_SMS_STATE, smsUnreadCnt);
2061                                 vconf_set_int(VCONFKEY_MESSAGE_RECV_MMS_STATE, mmsUnreadCnt);
2062                                 MsgMgrInsertBadge(noti_info->count);
2063                                 MsgMgrSoundSetRepeatAlarm();
2064                         }
2065                 } else {
2066                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2067                         msg_db_free(msg_handle, db_res);
2068                         return -1;
2069                 }
2070
2071                 msg_db_free(msg_handle, db_res);
2072                 break;
2073         }
2074
2075 #ifndef MSG_NOTI_INTEGRATION
2076         case MSG_MGR_NOTI_TYPE_CB: {
2077                 char sqlQuery[MAX_QUERY_LEN+1];
2078                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2079
2080                 snprintf(sqlQuery, sizeof(sqlQuery),
2081                                 "A.ADDRESS_VAL, "
2082                                 "B.DISPLAY_TIME, "
2083                                 "B.MSG_ID, "
2084                                 "B.MSG_TEXT "
2085                                 "FROM %s A, %s B "
2086                                 "WHERE A.CONV_ID=B.CONV_ID "
2087                                 "AND B.READ_STATUS=0 "
2088                                 "AND B.FOLDER_ID=%d "
2089                                 "AND B.STORAGE_ID = %d "
2090                                 "ORDER BY B.DISPLAY_TIME DESC;",
2091                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
2092                                 MSG_CBMSGBOX_ID,
2093                                 MSG_STORAGE_PHONE);
2094
2095                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
2096                         return MSG_ERR_DB_PREPARE;
2097
2098                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
2099                         MSG_ADDRESS_INFO_S addrInfo;
2100                         memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
2101
2102                         if (dbhandler->columnText(0) != NULL)
2103                                 snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
2104
2105                         MSG_CONTACT_INFO_S tmpContact;
2106                         memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
2107
2108                         MsgGetContactInfo(&addrInfo, &tmpContact);
2109
2110                         if (tmpContact.firstName[0] != '\0') {
2111                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2112                         } else if (addrInfo.addressVal[0] == '\0') {
2113                                 char *senderStr = NULL;
2114                                 senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MSG_UNKNOWN_SENDER);
2115                                 g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2116                                 if (senderStr) {
2117                                         free(senderStr);
2118                                         senderStr = NULL;
2119                                 }
2120                         } else {
2121                                 snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2122                         }
2123
2124                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2125
2126                         noti_info->time = (time_t)dbhandler->columnInt(1);
2127
2128                         noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
2129
2130                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
2131
2132                         MSG_MGR_DEBUG("unread CB message [%d].", noti_info->msg_id);
2133                 } else {
2134                         MSG_MGR_DEBUG("No unread CB message.");
2135                         MSG_MGR_DEBUG("notiCbId [%d]", noti_info->id);
2136
2137                         dbhandler->finalizeQuery();
2138
2139                         if (!isForInstantMessage) {
2140                                 /* No unread message. */
2141                                 if (noti_info->id > 0) {
2142                                         noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2143                                         if (noti_err != NOTIFICATION_ERROR_NONE) {
2144                                                 MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2145                                         }
2146                                 }
2147
2148                                 noti_info->id = 0;
2149
2150                                 if (MsgSettingSetInt(CB_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
2151                                         MSG_MGR_DEBUG("MsgSettingSetInt fail : CB_NOTI_PRIV_ID");
2152                         }
2153                         return MSG_ERR_DB_STEP;
2154                 }
2155
2156                 dbhandler->finalizeQuery();
2157
2158                 if (dbhandler->getTable(sqlQuery, &noti_info->count, NULL) != MSG_SUCCESS) {
2159                         MSG_MGR_DEBUG("getTable is failed");
2160                         dbhandler->freeTable();
2161                         return MSG_ERR_DB_GETTABLE;
2162                 }
2163
2164                 dbhandler->freeTable();
2165                 MSG_MGR_DEBUG("notiCbId [%d], unreadCbMsgCnt [%d]", noti_info->id, noti_info->count);
2166                 break;
2167         }
2168         case MSG_MGR_NOTI_TYPE_SIM: {
2169                 char sqlQuery[MAX_QUERY_LEN+1];
2170                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2171
2172                 snprintf(sqlQuery, sizeof(sqlQuery),
2173                                 "A.ADDRESS_VAL, "
2174                                 "B.DISPLAY_TIME, "
2175                                 "B.MSG_ID, "
2176                                 "B.MSG_TEXT, "
2177                                 "(COUNT(CASE WHEN B.MAIN_TYPE = %d THEN 1 END)) AS SMS_UNREAD_CNT "
2178                                 "FROM %s A, %s B "
2179                                 "WHERE A.CONV_ID=B.CONV_ID "
2180                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
2181                                 "AND B.STORAGE_ID = %d "
2182                                 "ORDER BY B.DISPLAY_TIME DESC;",
2183                                 MSG_SMS_TYPE,
2184                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
2185                                 MSG_INBOX_ID,
2186                                 MSG_STORAGE_SIM);
2187
2188                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2189
2190                 if (dbhandler->prepareQuery(sqlQuery) != MSG_SUCCESS)
2191                         return MSG_ERR_DB_PREPARE;
2192
2193                 if (dbhandler->stepQuery() == MSG_ERR_DB_ROW) {
2194                         noti_info->count = dbhandler->columnInt(4);
2195
2196                         if (noti_info->count > 0) {
2197                                 MSG_ADDRESS_INFO_S addrInfo;
2198                                 memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
2199
2200                                 if (dbhandler->columnText(0) != NULL)
2201                                         snprintf(addrInfo.addressVal, sizeof(addrInfo.addressVal), "%s", (char*)dbhandler->columnText(0));
2202
2203                                 MSG_CONTACT_INFO_S tmpContact;
2204                                 memset(&tmpContact, 0x00, sizeof(MSG_CONTACT_INFO_S));
2205
2206                                 MsgGetContactInfo(&addrInfo, &tmpContact);
2207
2208                                 if (tmpContact.firstName[0] != '\0') {
2209                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2210                                 } else if (addrInfo.addressVal[0] == '\0') {
2211                                         char *senderStr = NULL;
2212                                         senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MSG_UNKNOWN_SENDER);
2213                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2214                                         if (senderStr) {
2215                                                 free(senderStr);
2216                                                 senderStr = NULL;
2217                                         }
2218                                 } else {
2219                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2220                                 }
2221
2222                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2223
2224                                 noti_info->time = (time_t)dbhandler->columnInt(1);
2225
2226                                 noti_info->msg_id = (msg_message_id_t)dbhandler->columnInt(2);
2227
2228                                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", (char*)dbhandler->columnText(3));
2229
2230                                 MSG_MGR_DEBUG("unread SIM message [%d].", noti_info->msg_id);
2231                         } else {
2232                                 MSG_MGR_DEBUG("No unread SIM message.");
2233                                 MSG_MGR_DEBUG("notiPrivId [%d]", noti_info->id);
2234
2235                                 dbhandler->finalizeQuery();
2236
2237                                 if (!isForInstantMessage) {
2238                                         /* No unread message. */
2239                                         if (noti_info->id > 0) {
2240                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2241                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2242                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2243                                                 }
2244                                         }
2245
2246                                         noti_info->id = 0;
2247
2248                                         if (MsgSettingSetInt(SIM_MSG_NOTI_PRIV_ID, noti_info->id) != MSG_SUCCESS)
2249                                                 MSG_MGR_DEBUG("MsgSettingSetInt fail : SIM_MSG_NOTI_PRIV_ID");
2250                                 }
2251
2252                                 return MSG_ERR_DB_STEP;
2253                         }
2254                 } else {
2255                         MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2256                         dbhandler->finalizeQuery();
2257                         return MSG_ERR_DB_STEP;
2258                 }
2259
2260                 dbhandler->finalizeQuery();
2261                 break;
2262         }
2263 #endif
2264         case MSG_MGR_NOTI_TYPE_FAILED: {
2265                 char sqlQuery[MAX_QUERY_LEN+1];
2266                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2267
2268                 snprintf(sqlQuery, sizeof(sqlQuery),
2269                                 "A.ADDRESS_VAL, "
2270                                 "B.DISPLAY_TIME, "
2271                                 "B.MSG_ID, "
2272                                 "B.MSG_TEXT, "
2273                                 "B.SUBJECT, "
2274                                 "B.MAIN_TYPE, "
2275                                 "(COUNT(CASE WHEN B.NETWORK_STATUS = %d THEN 1 END)) AS SENT_FAILED_CNT "
2276                                 "FROM %s A, %s B "
2277                                 "WHERE A.CONV_ID=B.CONV_ID "
2278                                 "AND B.READ_STATUS=0 AND B.FOLDER_ID=%d "
2279                                 "AND B.STORAGE_ID = %d "
2280                                 "ORDER BY B.DISPLAY_TIME DESC;",
2281                                 MSG_NETWORK_SEND_FAIL,
2282                                 MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME,
2283                                 MSG_OUTBOX_ID,
2284                                 MSG_STORAGE_PHONE);
2285
2286                 MSG_MGR_DEBUG("sqlQuery [%s]", sqlQuery);
2287
2288                 row_cnt = 0, col_cnt = 0;
2289                 msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
2290                 if (msg_err != MSG_SUCCESS) {
2291                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
2292                         return -1;
2293                 }
2294
2295                 if (row_cnt > 0) {
2296                         noti_info->count = atoi(db_res[col_cnt+6]);
2297
2298                         if (noti_info->count > 0) {
2299                                 MSG_MGR_ADDRESS_INFO_S addrInfo = {0, };
2300
2301                                 snprintf(addrInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", db_res[col_cnt]);
2302
2303                                 MSG_MGR_CONTACT_INFO_S tmpContact = {0, };
2304
2305                                 MsgMgrGetContactInfo(&addrInfo, &tmpContact);
2306
2307                                 if (tmpContact.firstName[0] != '\0') {
2308                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", tmpContact.firstName);
2309                                 } else if (addrInfo.addressVal[0] == '\0') {
2310                                         char *senderStr = NULL;
2311                                         senderStr = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, MSG_UNKNOWN_SENDER);
2312                                         g_strlcat(noti_info->sender, senderStr, sizeof(noti_info->sender)-strlen(noti_info->sender));
2313                                         if (senderStr) {
2314                                                 free(senderStr);
2315                                                 senderStr = NULL;
2316                                         }
2317                                 } else {
2318                                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", addrInfo.addressVal);
2319                                 }
2320
2321                                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", addrInfo.addressVal);
2322
2323                                 noti_info->time = (time_t)atoi(db_res[col_cnt+1]);
2324
2325                                 noti_info->msg_id = (msg_message_id_t)atoi(db_res[col_cnt+2]);
2326
2327                                 unsigned char mainType = (unsigned char)atoi(db_res[col_cnt+5]);
2328
2329                                 if (mainType == MSG_TYPE_MMS)
2330                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+4]);
2331                                 else
2332                                         snprintf(noti_info->text, sizeof(noti_info->text), "%s", db_res[col_cnt+3]);
2333
2334                                 MSG_MGR_DEBUG("Sent failed message ID [%d].", noti_info->msg_id);
2335
2336                                 if (!isForInstantMessage) {
2337                                         if (noti_info->id > 0 && noti_info->count == 1) {
2338                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2339                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2340                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2341                                                 }
2342                                                 noti_info->id = 0;
2343                                                 if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2344                                                         MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2345                                         }
2346                                 }
2347                         } else {
2348                                 MSG_MGR_DEBUG("No sent failed message.");
2349                                 MSG_MGR_DEBUG("failedNotiId [%d]", noti_info->id);
2350
2351                                 msg_db_free(msg_handle, db_res);
2352
2353                                 if (!isForInstantMessage) {
2354                                         /* No unread message. */
2355                                         if (noti_info->id > 0) {
2356                                                 noti_err = notification_delete_by_priv_id(MSG_DEFAULT_APP_ID, NOTIFICATION_TYPE_NOTI, noti_info->id);
2357                                                 if (noti_err != NOTIFICATION_ERROR_NONE) {
2358                                                         MSG_MGR_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
2359                                                 }
2360                                         }
2361
2362                                         noti_info->id = 0;
2363
2364                                         if (vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_info->id) != 0)
2365                                                 MSG_MGR_DEBUG("vconf_set_int fail : MSG_SENTFAIL_NOTI_ID");
2366                                 }
2367
2368                                 return -1;
2369                         }
2370                 } else {
2371                         msg_db_free(msg_handle, db_res);
2372                         return -1;
2373                 }
2374
2375                 msg_db_free(msg_handle, db_res);
2376                 break;
2377         }
2378         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2379         case MSG_MGR_NOTI_TYPE_STORAGE_FULL:
2380                 break;
2381         default:
2382                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2383                 return -1;
2384         }
2385
2386         MSG_MGR_END();
2387
2388         return 0;
2389 }
2390
2391
2392 notification_h getHandle(int *noti_id)
2393 {
2394         notification_h noti_h = NULL;
2395
2396         if (*noti_id > 0) {
2397                 MSG_MGR_DEBUG("Notification load");
2398                 noti_h = notification_load(NULL, *noti_id);
2399                 if (noti_h == NULL)
2400                         MSG_MGR_DEBUG("notification_load is failed.");
2401         }
2402
2403         if (noti_h == NULL) {
2404                 MSG_MGR_DEBUG("Notification create");
2405                 noti_h = notification_create(NOTIFICATION_TYPE_NOTI);
2406                 if (noti_h == NULL) {
2407                         MSG_MGR_DEBUG("notification_create is failed.");
2408                         return NULL;
2409                 }
2410
2411                 *noti_id = 0;
2412         }
2413
2414         return noti_h;
2415 }
2416
2417
2418 int getPrivId(msg_mgr_notification_type_t noti_type, int sim_idx)
2419 {
2420         MSG_MGR_BEGIN();
2421
2422         int noti_id = 0;
2423
2424         switch (noti_type) {
2425 #ifdef MSG_NOTI_INTEGRATION
2426         case MSG_MGR_NOTI_TYPE_NORMAL:
2427         case MSG_MGR_NOTI_TYPE_SIM:
2428         case MSG_MGR_NOTI_TYPE_CB:
2429                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2430                 break;
2431 #else
2432         case MSG_MGR_NOTI_TYPE_NORMAL:
2433                 vconf_get_int(NOTIFICATION_PRIV_ID, &noti_id);
2434                 break;
2435         case MSG_MGR_NOTI_TYPE_SIM:
2436                 vconf_get_int(SIM_MSG_NOTI_PRIV_ID, &noti_id);
2437                 break;
2438         case MSG_MGR_NOTI_TYPE_CB:
2439                 vconf_get_int(CB_NOTI_PRIV_ID, &noti_id);
2440                 break;
2441 #endif
2442         case MSG_MGR_NOTI_TYPE_FAILED:
2443                 vconf_get_int(MSG_SENTFAIL_NOTI_ID, &noti_id);
2444                 break;
2445         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT:
2446                 vconf_get_int(VCONFKEY_MESSAGE_READ_REPORT_SENT_NOTI_ID, &noti_id);
2447                 break;
2448         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2449                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2450                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2451                 vconf_get_int(keyName, &noti_id);
2452                 break;
2453         }
2454         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2455                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2456                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2457                 vconf_get_int(keyName, &noti_id);
2458                 break;
2459         }
2460         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2461                 vconf_get_int(SIM_FULL_NOTI_PRIV_ID, &noti_id);
2462                 break;
2463         case MSG_MGR_NOTI_TYPE_STORAGE_FULL:
2464                 vconf_get_int(STORAGE_FULL_NOTI_PRIV_ID, &noti_id);
2465                 break;
2466         default:
2467                 MSG_MGR_DEBUG("No matching noti type [%d]", noti_type);
2468                 break;
2469         }
2470
2471         MSG_MGR_DEBUG("Get noti type = %d, id = %d, sim_idx:%d", noti_type, noti_id, sim_idx);
2472
2473         MSG_MGR_END();
2474
2475         return noti_id;
2476 }
2477
2478
2479 void updatePrivId(msg_mgr_notification_type_t noti_type, int noti_id, int sim_idx)
2480 {
2481         MSG_MGR_BEGIN();
2482
2483         int err = 0;
2484
2485         MSG_MGR_DEBUG("Update noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2486
2487         switch (noti_type) {
2488 #ifdef MSG_NOTI_INTEGRATION
2489         case MSG_MGR_NOTI_TYPE_NORMAL:
2490         case MSG_MGR_NOTI_TYPE_SIM:
2491         case MSG_MGR_NOTI_TYPE_CB:
2492                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2493                 break;
2494 #else
2495         case MSG_MGR_NOTI_TYPE_NORMAL:
2496                 err = vconf_set_int(NOTIFICATION_PRIV_ID, noti_id);
2497                 break;
2498         case MSG_MGR_NOTI_TYPE_SIM:
2499                 err = vconf_set_int(SIM_MSG_NOTI_PRIV_ID, noti_id);
2500                 break;
2501         case MSG_MGR_NOTI_TYPE_CB:
2502                 err = vconf_set_int(CB_NOTI_PRIV_ID, noti_id);
2503                 break;
2504 #endif
2505         case MSG_MGR_NOTI_TYPE_FAILED:
2506                 err = vconf_set_int(MSG_SENTFAIL_NOTI_ID, noti_id);
2507                 break;
2508         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT_SENT:
2509                 err = vconf_set_int(VCONFKEY_MESSAGE_READ_REPORT_SENT_NOTI_ID, noti_id);
2510                 break;
2511         case MSG_MGR_NOTI_TYPE_VOICE_1: {
2512                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2513                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_1, sim_idx);
2514                 err = vconf_set_int(keyName, noti_id);
2515                 break;
2516         }
2517         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2518                 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
2519                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICE_NOTI_ID_2, sim_idx);
2520                 err = vconf_set_int(keyName, noti_id);
2521                 break;
2522         }
2523         case MSG_MGR_NOTI_TYPE_SIM_FULL:
2524                 err = vconf_set_int(SIM_FULL_NOTI_PRIV_ID, noti_id);
2525                 break;
2526         case MSG_MGR_NOTI_TYPE_STORAGE_FULL:
2527                 err = vconf_set_int(STORAGE_FULL_NOTI_PRIV_ID, noti_id);
2528                 break;
2529         default:
2530                 MSG_MGR_DEBUG("No matching type [%d]", noti_type);
2531                 break;
2532         }
2533
2534         if (err != 0)
2535                 MSG_MGR_INFO("vconf_set_int fail : noti type = %d, id = %d, sim_idx = %d", noti_type, noti_id, sim_idx);
2536
2537         MSG_MGR_END();
2538 }
2539
2540
2541 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, MSG_MGR_MESSAGE_INFO_S *msg_info)
2542 {
2543         MSG_MGR_BEGIN();
2544
2545         if (msg_info) {
2546                 noti_info->id = getPrivId(noti_info->type, msg_info->sim_idx);
2547                 noti_info->msg_id = msg_info->msgId;
2548         } else {
2549                 MSG_MGR_DEBUG("msg_info is NULL");
2550                 return;
2551         }
2552
2553         noti_info->sim_idx = msg_info->sim_idx;
2554
2555         createServiceHandle(&noti_info->svc_h);
2556         char keyName[MAX_VCONFKEY_NAME_LEN];
2557
2558         switch (noti_info->type) {
2559         case MSG_MGR_NOTI_TYPE_VOICE_1:
2560         case MSG_MGR_NOTI_TYPE_VOICE_2: {
2561                 memset(keyName, 0x00, sizeof(keyName));
2562                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, msg_info->sim_idx);
2563                 vconf_get_int(keyName, &noti_info->count);
2564                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2565                 noti_info->time = msg_info->displayTime;
2566
2567                 memset(keyName, 0x00, sizeof(keyName));
2568                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msg_info->sim_idx);
2569                 char *voiceNumber = vconf_get_str(keyName);
2570                 memset(keyName, 0x00, sizeof(keyName));
2571                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msg_info->sim_idx);
2572                 char *voiceAlphaId = vconf_get_str(keyName);
2573                 char *dialNumber = NULL;
2574
2575                 MSG_MGR_SEC_DEBUG("Voice mail server - alpha id = [%s], default num = [%s]", voiceAlphaId, voiceNumber);
2576
2577                 if (voiceNumber && strlen(voiceNumber))
2578                         dialNumber = voiceNumber;
2579
2580                 if (voiceAlphaId && strlen(voiceAlphaId) > 0) {
2581                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", voiceAlphaId);
2582                 } else if (dialNumber && strlen(dialNumber) > 0) {
2583                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", dialNumber);
2584                 }
2585
2586                 if (dialNumber && strlen(dialNumber) > 0)
2587                         snprintf(noti_info->number, sizeof(noti_info->number), "%s", dialNumber);
2588
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                 if (voiceNumber)        g_free(voiceNumber);
2599                 if (voiceAlphaId) g_free(voiceAlphaId);
2600                 break;
2601         }
2602         case MSG_MGR_NOTI_TYPE_MWI:
2603         case MSG_MGR_NOTI_TYPE_CLASS0: {
2604                 noti_info->count = 1;
2605                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2606                 noti_info->time = msg_info->displayTime;
2607
2608                 if (msg_info->displayName[0] == '\0')
2609                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2610                 else
2611                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->displayName);
2612
2613                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2614
2615                 snprintf(noti_info->text, sizeof(noti_info->text), "%s", msg_info->msgText);
2616
2617                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MWI) {
2618                         if (noti_info->svc_h) {
2619                                 setServiceOperation(noti_info->svc_h, APP_CONTROL_OPERATION_CALL);
2620                                 setServiceUri(noti_info->svc_h, MSG_TEL_URI_VOICEMAIL);
2621
2622                                 char slot_id[5] = {0, };
2623                                 snprintf(slot_id, sizeof(slot_id), "%d", msg_info->sim_idx - 1);
2624                                 addServiceExtraData(noti_info->svc_h, "slot_id", slot_id);
2625                         }
2626
2627                 } else {
2628                         setServiceAppId(noti_info->svc_h, "org.tizen.msg-ui-class0");
2629                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2630                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2631                 }
2632                 break;
2633         }
2634         case MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT: {
2635                 noti_info->count = 1;
2636                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2637                 noti_info->time = msg_info->displayTime;
2638                 noti_info->extra_data = msg_info->networkStatus;
2639
2640                 MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
2641                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0, };
2642                 if (msg_info->addressVal[0] != '\0') {
2643                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2644                         if (_is_valid_email(msg_info->addressVal)) {
2645                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2646                         } else {
2647                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2648                         }
2649                 }
2650
2651                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2652                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2653                 }
2654
2655                 if (contactInfo.firstName[0] == '\0')
2656                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2657                 else
2658                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2659
2660                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2661
2662                 if (noti_info->msg_id > 0) {
2663                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2664                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2665                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2666                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2667                 }
2668                 break;
2669         }
2670         case MSG_MGR_NOTI_TYPE_MMS_READ_REPORT:
2671         case MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT: {
2672                 noti_info->count = 1;
2673                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2674                 noti_info->time = msg_info->displayTime;
2675
2676                 MSG_MGR_CONTACT_INFO_S contactInfo = {0, };
2677                 MSG_MGR_ADDRESS_INFO_S tmpAddressInfo = {0, };
2678                 if (msg_info->addressVal[0] != '\0') {
2679                         snprintf(tmpAddressInfo.addressVal, MAX_ADDRESS_VAL_LEN, "%s", msg_info->addressVal);
2680                         if (_is_valid_email(msg_info->addressVal)) {
2681                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_EMAIL;
2682                         } else {
2683                                 tmpAddressInfo.addressType = MSG_ADDRESS_TYPE_UNKNOWN;
2684                         }
2685                 }
2686
2687                 if (MsgMgrGetContactInfo(&tmpAddressInfo, &contactInfo) != 0) {
2688                         MSG_MGR_WARN("MsgMgrGetContactInfo() fail.");
2689                 }
2690                 if (contactInfo.firstName[0] == '\0')
2691                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", msg_info->addressVal);
2692                 else
2693                         snprintf(noti_info->sender, sizeof(noti_info->sender), "%s", contactInfo.firstName);
2694
2695                 snprintf(noti_info->number, sizeof(noti_info->number), "%s", msg_info->addressVal);
2696
2697                 char sqlQuery[MAX_QUERY_LEN+1];
2698                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
2699
2700                 int report_status_type;
2701                 int report_status_value;
2702
2703                 if (noti_info->type == MSG_MGR_NOTI_TYPE_MMS_READ_REPORT) {
2704                         report_status_type = MSG_REPORT_TYPE_READ;
2705                 } else {
2706                         report_status_type = MSG_REPORT_TYPE_DELIVERY;
2707                 }
2708
2709                 snprintf(sqlQuery, sizeof(sqlQuery),
2710                                 "STATUS "
2711                                 "FROM %s "
2712                                 "WHERE MSG_ID=%d AND STATUS_TYPE=%d AND ADDRESS_VAL LIKE \"%%%s\";",
2713                                 MSGFW_REPORT_TABLE_NAME, msg_info->msgId, report_status_type, msg_mgr_normalize_number(msg_info->addressVal));
2714
2715                 MSG_MGR_DEBUG("sqlQuery = [%s]", sqlQuery);
2716
2717                 char **db_res = NULL;
2718                 int row_cnt = 0, col_cnt = 0;
2719
2720                 int msg_err = msg_db_select_with_query(msg_handle, sqlQuery, &db_res, &row_cnt, &col_cnt);
2721                 if (msg_err != MSG_SUCCESS || row_cnt <= 0) {
2722                         MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
2723                         return;
2724                 }
2725
2726                 report_status_value = atoi(db_res[col_cnt]);
2727
2728                 MSG_MGR_DEBUG("report status [type = %d, value = %d]", report_status_type, report_status_value);
2729
2730                 msg_err = msg_db_free(msg_handle, db_res);
2731                 if (msg_err != MSG_SUCCESS) {
2732                         MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
2733                         return;
2734                 }
2735
2736                 if (noti_info->msg_id > 0) {
2737                         setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2738                         addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2739                         addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2740                         addServiceExtraData(noti_info->svc_h, "address", msg_info->addressVal);
2741                 }
2742
2743                 noti_info->extra_data = (unsigned char)report_status_value;
2744                 break;
2745         }
2746         default:
2747                 MSG_MGR_DEBUG("No matching type [%d]", noti_info->type);
2748                 break;
2749         }
2750
2751         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2752         MSG_MGR_END();
2753 }
2754
2755
2756 void createInfoData(MSG_MGR_NOTI_INFO_S *noti_info, msg_mgr_active_notification_type_t active_noti)
2757 {
2758         MSG_MGR_BEGIN();
2759
2760         createServiceHandle(&noti_info->svc_h);
2761
2762         switch (noti_info->type) {
2763         case MSG_MGR_NOTI_TYPE_NORMAL: {
2764                 if (noti_info->count > 1) {
2765                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2766                 } else {
2767                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2768                 }
2769
2770                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2771                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2772                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2773                 addServiceExtraData(noti_info->svc_h, "http://tizen.org/appcontrol/data/notification", "new_message");
2774
2775                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE) {
2776                         if (noti_info->active_noti_button_num == MSG_ACTIVE_NOTI_BUTTON_NUM_NONE)
2777                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NORMAL_MESSAGE;
2778
2779                         int activated_conv_id = -1;
2780                         vconf_get_int(VCONFKEY_MESSAGE_ACTIVATED_CONVERSATION_ID, &activated_conv_id);
2781
2782                         if (activated_conv_id == -1) {
2783                                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR;
2784                         } else if (activated_conv_id == 0) {
2785                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NONE;
2786                                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR|NOTIFICATION_DISPLAY_APP_TICKER;
2787                         } else if (activated_conv_id > 0){
2788                                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NONE;
2789
2790                                 if (activated_conv_id != noti_info->conv_id)
2791                                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR|NOTIFICATION_DISPLAY_APP_TICKER;
2792                                 else
2793                                         MSG_MGR_WARN("No adding Notification : activated conv id [%d] / notification conv id [%d]", activated_conv_id, noti_info->conv_id);
2794                         }
2795                 } else {
2796                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_LOCK|NOTIFICATION_DISPLAY_APP_INDICATOR;
2797                 }
2798
2799                 break;
2800         }
2801         case MSG_MGR_NOTI_TYPE_CB: {
2802                 if (noti_info->count > 1) {
2803                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2804                 } else {
2805                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2806                 }
2807
2808                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2809                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2810                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2811
2812                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2813                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2814                 else
2815                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2816
2817                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_CB_MESSAGE;
2818                 break;
2819         }
2820         case MSG_MGR_NOTI_TYPE_SIM: {
2821                 if (noti_info->count > 1) {
2822                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_MULTIPLE;
2823                 } else {
2824                         noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2825                 }
2826
2827                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2828                 addServiceExtraData(noti_info->svc_h, "type", "new_msg");
2829                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2830
2831                 if (active_noti == MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT)
2832                         noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK;
2833                 else
2834                         noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2835
2836                 if (noti_info->active_noti_button_num == MSG_ACTIVE_NOTI_BUTTON_NUM_NONE)
2837                         noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NORMAL_MESSAGE;
2838                 break;
2839         }
2840         case MSG_MGR_NOTI_TYPE_FAILED: {
2841                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2842
2843                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2844                 addServiceExtraData(noti_info->svc_h, "type", "send_failed_msg");
2845                 addServiceExtraData(noti_info->svc_h, "msgId", noti_info->msg_id);
2846
2847                 noti_info->applist = NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER^NOTIFICATION_DISPLAY_APP_LOCK;
2848                 break;
2849         }
2850         case MSG_MGR_NOTI_TYPE_SIM_FULL: {
2851                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2852
2853                 setServiceAppId(noti_info->svc_h, MSG_DEFAULT_APP_ID);
2854                 addServiceExtraData(noti_info->svc_h, "sim_list_show", "sim_setting");
2855
2856                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR;
2857                 break;
2858         }
2859         case MSG_MGR_NOTI_TYPE_STORAGE_FULL: {
2860                 noti_info->layout = NOTIFICATION_LY_NOTI_EVENT_SINGLE;
2861                 noti_info->applist = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR|NOTIFICATION_DISPLAY_APP_TICKER;
2862         }
2863         default:
2864                 break;
2865         }
2866
2867         if (active_noti != MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE)
2868                 noti_info->active_noti_button_num = MSG_ACTIVE_NOTI_BUTTON_NUM_NONE;
2869
2870         MSG_MGR_END();
2871 }
2872
2873
2874 void createServiceHandle(app_control_h *svc_h)
2875 {
2876         int svc_err = APP_CONTROL_ERROR_NONE;
2877
2878         svc_err = app_control_create(svc_h);
2879
2880         if (svc_err != APP_CONTROL_ERROR_NONE)
2881                 MSG_MGR_DEBUG("app_control_create() is failed, [%d]", svc_err);
2882 }
2883
2884
2885 void setServiceAppId(app_control_h svc_h, const char* app_id)
2886 {
2887         int svc_err = APP_CONTROL_ERROR_NONE;
2888
2889         svc_err = app_control_set_app_id(svc_h, app_id);
2890
2891         if (svc_err != APP_CONTROL_ERROR_NONE)
2892                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2893 }
2894
2895
2896 void setServiceUri(app_control_h svc_h, const char* uri)
2897 {
2898         int svc_err = APP_CONTROL_ERROR_NONE;
2899
2900         svc_err = app_control_set_uri(svc_h, uri);
2901
2902         if (svc_err != APP_CONTROL_ERROR_NONE)
2903                 MSG_MGR_DEBUG("app_control_set_uri() was failed, [%d]", svc_err);
2904 }
2905
2906
2907 void setServiceOperation(app_control_h svc_h, const char* operation)
2908 {
2909         int svc_err = APP_CONTROL_ERROR_NONE;
2910
2911         svc_err = app_control_set_operation(svc_h, operation);
2912
2913         if (svc_err != APP_CONTROL_ERROR_NONE)
2914                 MSG_MGR_DEBUG("app_control_set_operation() was failed, [%d]", svc_err);
2915 }
2916
2917
2918 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, const char* bundle_val)
2919 {
2920         int svc_err = APP_CONTROL_ERROR_NONE;
2921
2922         svc_err = app_control_add_extra_data(svc_h, bundle_key, bundle_val);
2923
2924         if (svc_err != APP_CONTROL_ERROR_NONE)
2925                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2926 }
2927
2928
2929 void addServiceExtraData(app_control_h svc_h, const char* bundle_key, int bundle_val)
2930 {
2931         int svc_err = APP_CONTROL_ERROR_NONE;
2932
2933         char tempId[10];
2934         memset(&tempId, 0x00, sizeof(tempId));
2935         snprintf(tempId, sizeof(tempId), "%d", bundle_val);
2936
2937         svc_err = app_control_add_extra_data(svc_h, bundle_key, (const char *)tempId);
2938
2939         if (svc_err != APP_CONTROL_ERROR_NONE)
2940                 MSG_MGR_DEBUG("app_control_add_extra_data() was failed, [%d]", svc_err);
2941 }
2942
2943
2944 void setServicePackageName(app_control_h svc_h, const char* pkg_name)
2945 {
2946         int svc_err = APP_CONTROL_ERROR_NONE;
2947
2948         svc_err = app_control_set_app_id(svc_h, pkg_name);
2949
2950         if (svc_err != APP_CONTROL_ERROR_NONE)
2951                 MSG_MGR_DEBUG("app_control_set_app_id() was failed, [%d]", svc_err);
2952 }
2953
2954
2955 void sendServicelaunchRequest(app_control_h svc_h, app_control_reply_cb callback, void *user_data)
2956 {
2957         int svc_err = APP_CONTROL_ERROR_NONE;
2958
2959         svc_err = app_control_send_launch_request(svc_h, callback, user_data);
2960
2961         if (svc_err != APP_CONTROL_ERROR_NONE)
2962                 MSG_MGR_DEBUG("app_control_send_launch_request() is failed : %d", svc_err);
2963 }
2964
2965
2966 void setNotiTextDomain(notification_h noti_h, const char *pkg_name, const char *loc_dir)
2967 {
2968         int noti_err = NOTIFICATION_ERROR_NONE;
2969
2970         noti_err = notification_set_text_domain(noti_h, pkg_name, loc_dir);
2971         if (noti_err != NOTIFICATION_ERROR_NONE)
2972                 MSG_MGR_DEBUG("notification_set_text_domain() was failed. [%d]", noti_err);
2973 }
2974
2975
2976 void setNotiText(notification_h noti_h, notification_text_type_e type, const char *text, const char *key)
2977 {
2978         int noti_err = NOTIFICATION_ERROR_NONE;
2979
2980         noti_err = notification_set_text(noti_h, type, text, key, NOTIFICATION_VARIABLE_TYPE_NONE);
2981
2982         if (noti_err != NOTIFICATION_ERROR_NONE)
2983                 MSG_MGR_DEBUG("notification_set_text() was failed. [%d]", noti_err);
2984 }
2985
2986
2987 void setNotiTimeToText(notification_h noti_h, notification_text_type_e type, time_t time)
2988 {
2989         int noti_err = NOTIFICATION_ERROR_NONE;
2990
2991         noti_err = notification_set_time_to_text(noti_h, type, time);
2992
2993         if (noti_err != NOTIFICATION_ERROR_NONE)
2994                 MSG_MGR_DEBUG("notification_set_time_to_text() was failed. [%d]", noti_err);
2995 }
2996
2997
2998 void setNotiTime(notification_h noti_h, time_t time)
2999 {
3000         int noti_err = NOTIFICATION_ERROR_NONE;
3001
3002         noti_err = notification_set_time(noti_h, time);
3003
3004         if (noti_err != NOTIFICATION_ERROR_NONE)
3005                 MSG_MGR_DEBUG("notification_set_time() was failed. [%d]", noti_err);
3006 }
3007
3008
3009
3010 void setNotiImage(notification_h noti_h, notification_image_type_e type, const char *image_path)
3011 {
3012         int noti_err = NOTIFICATION_ERROR_NONE;
3013
3014         noti_err = notification_set_image(noti_h, type, image_path);
3015
3016         if (noti_err != NOTIFICATION_ERROR_NONE)
3017                 MSG_MGR_DEBUG("notification_set_image() was failed. [%d]", noti_err);
3018 }
3019
3020
3021 void setNotiSound(notification_h noti_h, notification_sound_type_e type, const char *path)
3022 {
3023         int noti_err = NOTIFICATION_ERROR_NONE;
3024
3025         noti_err = notification_set_sound(noti_h, type, path);
3026
3027         if (noti_err != NOTIFICATION_ERROR_NONE)
3028                 MSG_MGR_DEBUG("notification_set_sound() was failed. [%d]", noti_err);
3029 }
3030
3031
3032 void setNotiVibration(notification_h noti_h, notification_vibration_type_e type, const char *path)
3033 {
3034         int noti_err = NOTIFICATION_ERROR_NONE;
3035
3036         noti_err = notification_set_vibration(noti_h, type, path);
3037
3038         if (noti_err != NOTIFICATION_ERROR_NONE)
3039                 MSG_MGR_DEBUG("notification_set_vibration() was failed. [%d]", noti_err);
3040 }
3041
3042
3043 void setNotiEventHandler(notification_h noti_h, notification_event_type_e type, app_control_h event_handler)
3044 {
3045         int noti_err = NOTIFICATION_ERROR_NONE;
3046
3047         noti_err = notification_set_event_handler(noti_h, type, event_handler);
3048
3049         if (noti_err != NOTIFICATION_ERROR_NONE)
3050                 MSG_MGR_DEBUG("notification_set_event_handler() was failed. [%d]", noti_err);
3051 }
3052
3053
3054 int MsgMgrInsertInstantMessage(msg_mgr_notification_type_t noti_type)
3055 {
3056         MSG_MGR_BEGIN();
3057
3058         char *notiMsg = NULL;
3059
3060         notification_h noti = notification_create(NOTIFICATION_TYPE_NOTI);
3061
3062         switch (noti_type) {
3063         case MSG_MGR_NOTI_TYPE_NORMAL:
3064         case MSG_MGR_NOTI_TYPE_SIM:
3065         case MSG_MGR_NOTI_TYPE_CB: {
3066                 MSG_MGR_NOTI_INFO_S noti_info;
3067                 memset(&noti_info, 0x00, sizeof(MSG_MGR_NOTI_INFO_S));
3068
3069                 noti_info.type = noti_type;
3070                 int err = getLatestMsgInfo(&noti_info, true);
3071
3072                 if (err == 0) {
3073                         MSG_MGR_DEBUG("Unread count [%d]", noti_info.count);
3074                         if (noti_info.count == 1) {
3075                                 MSG_MGR_SEC_DEBUG("noti_info.sender [%s]", noti_info.sender);
3076                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, noti_info.sender, NULL);
3077                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.text, NULL);
3078                         } else if (noti_info.count > 1) {
3079                                 gchar *cnt_string = g_strdup_printf("%i", noti_info.count);
3080
3081                                 notiMsg = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, NEW_MESSAGES);
3082                                 gchar *outString = g_strconcat(cnt_string, " ", notiMsg, NULL);
3083                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, outString, NULL);
3084                                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_CONTENT, noti_info.sender, NULL);
3085                                 g_free(outString);
3086                                 g_free(cnt_string);
3087                         }
3088
3089                         setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_NORMAL_ICON_PATH);
3090                 }
3091                 break;
3092         }
3093         case MSG_MGR_NOTI_TYPE_FAILED: {
3094                 notiMsg = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, FAILED_TO_SEND_MESSAGE);
3095                 setNotiText(noti, NOTIFICATION_TEXT_TYPE_TITLE, notiMsg, NULL);
3096                 setNotiImage(noti, NOTIFICATION_IMAGE_TYPE_ICON, MSG_SMS_SENDING_FAILED_ICON_PATH);
3097                 break;
3098         }
3099         default:
3100                 MSG_MGR_DEBUG("No matching type for MsgNotiType%d]", noti_type);
3101                 goto _END_OF_INSTANT_NOTI;
3102                 break;
3103         }
3104
3105         if (notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_TICKER) != NOTIFICATION_ERROR_NONE)
3106                 MSG_MGR_DEBUG("Fail to notification_set_display_applist");
3107
3108         if (notification_set_pkgname(noti, MSG_DEFAULT_APP_ID) != NOTIFICATION_ERROR_NONE)
3109                 MSG_MGR_DEBUG("Fail to notification_set_pkgname");
3110
3111         if (notification_post(noti) != NOTIFICATION_ERROR_NONE)
3112                 MSG_MGR_DEBUG("Fail to notification_post");
3113
3114 _END_OF_INSTANT_NOTI:
3115
3116         if (notification_delete(noti) != NOTIFICATION_ERROR_NONE)
3117                 MSG_MGR_DEBUG("Fail to notification_delete");
3118         if (notiMsg) {
3119                 free(notiMsg);
3120                 notiMsg = NULL;
3121         }
3122
3123         if (noti) {
3124                 if (notification_free(noti) != NOTIFICATION_ERROR_NONE)
3125                         MSG_MGR_DEBUG("Fail to notification_free");
3126                 noti = NULL;
3127         }
3128
3129         MSG_MGR_END();
3130         return 0;
3131 }
3132
3133
3134 bool MsgMgrCheckNotificationSettingEnable()
3135 {
3136         bool msg_noti_enabled = false;
3137         notification_system_setting_h system_setting = NULL;
3138         notification_setting_h setting = NULL;
3139
3140         int err = NOTIFICATION_ERROR_NONE;
3141
3142         err = notification_setting_get_setting_by_package_name(MSG_DEFAULT_APP_ID, &setting);
3143
3144         if (err != NOTIFICATION_ERROR_NONE || setting == NULL) {
3145                 MSG_MGR_ERR("getting setting handle for [%s] is failed. err = %d", MSG_DEFAULT_APP_ID, err);
3146         } else {
3147                 msg_noti_enabled = true;
3148
3149                 bool allow_to_notify = false;
3150                 err = notification_setting_get_allow_to_notify(setting, &allow_to_notify);
3151
3152                 if (err != NOTIFICATION_ERROR_NONE) {
3153                         MSG_MGR_ERR("getting do not disturb setting is failed. err = %d", err);
3154                         goto EXIT;
3155                 }
3156
3157                 if (allow_to_notify) {
3158                         MSG_MGR_DEBUG("message notification is allowed");
3159
3160                         /* check do not disturb mode */
3161                         err = notification_system_setting_load_system_setting(&system_setting);
3162
3163                         if (err != NOTIFICATION_ERROR_NONE || system_setting == NULL) {
3164                                 MSG_MGR_ERR("getting system setting is failed. err = %d", err);
3165                                 goto EXIT;
3166                         }
3167
3168                         bool do_not_disturb_mode = false;
3169                         err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb_mode);
3170
3171                         if (err != NOTIFICATION_ERROR_NONE) {
3172                                 MSG_MGR_ERR("getting do not disturb setting is failed. err = %d", err);
3173                                 goto EXIT;
3174                         }
3175
3176                         if (do_not_disturb_mode) {
3177                                 bool is_msg_excepted = false;
3178                                 err = notification_setting_get_do_not_disturb_except(setting, &is_msg_excepted);
3179                                 if (err != NOTIFICATION_ERROR_NONE) {
3180                                         MSG_MGR_ERR("getting do not disturb except status for [%s] is failed. err = %d", MSG_DEFAULT_APP_ID, err);
3181                                         msg_noti_enabled = false;
3182                                 } else {
3183                                         MSG_MGR_INFO("do not disturb mode status for [%s] : %d", MSG_DEFAULT_APP_ID, is_msg_excepted);
3184                                         msg_noti_enabled = (is_msg_excepted) ? true : false;
3185                                 }
3186                         } else {
3187                                 MSG_MGR_DEBUG("do not disturb mode is off");
3188                         }
3189                 } else {
3190                         MSG_MGR_INFO("message notification is not allowed");
3191                         msg_noti_enabled = false;
3192                 }
3193         }
3194
3195 EXIT:
3196         if (system_setting)
3197                 notification_system_setting_free_system_setting(system_setting);
3198
3199         if (setting)
3200                 notification_setting_free_notification(setting);
3201
3202         return msg_noti_enabled;
3203 }
3204
3205
3206 int MsgMgrInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId)
3207 {
3208         MSG_MGR_DEBUG("pTickerMsg=[%s], pLocaleTickerMsg=[%s]", pTickerMsg, pLocaleTickerMsg);
3209         MSG_MGR_DEBUG("play feedback=[%d], msgId=[%d]", bPlayFeedback, msgId);
3210
3211         MsgMgrChangePmState();
3212
3213         char *notiMsg = NULL;
3214         msg_mgr_active_notification_type_t active_type = MSG_MGR_ACTIVE_NOTI_TYPE_NONE;
3215         int err = 0;
3216
3217         notiMsg = get_translate_text(MSG_MGR_PACKAGE_NAME, MSG_MGR_LOCALEDIR, pLocaleTickerMsg);
3218         MSG_MGR_DEBUG("notiMsg %s", notiMsg);
3219
3220         if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) != 0 &&
3221                 g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) != 0 &&
3222                 g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_MEMORY_FULL) != 0 &&
3223                 g_strcmp0(pLocaleTickerMsg, MESSAGE_RETRIEVED) != 0) {
3224                 if (g_strcmp0(pLocaleTickerMsg, notiMsg) == 0) {
3225                         notification_status_message_post(pTickerMsg);
3226                 } else {
3227                         notification_status_message_post(notiMsg);
3228                 }
3229         } else {
3230                 /* Show ticker popup for sending failed msg. */
3231                 active_type = MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT;
3232         }
3233
3234         if (notiMsg) {
3235                 free(notiMsg);
3236                 notiMsg = NULL;
3237         }
3238
3239         if (bPlayFeedback) {
3240                 if (msgId > 0 &&
3241                         (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SENDING_FAIL) == 0 || g_strcmp0(pLocaleTickerMsg, SENDING_MULTIMEDIA_MESSAGE_FAILED) == 0)) {
3242                         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_FAILED, true, active_type);
3243                         if (err != 0) {
3244                                 MSG_MGR_DEBUG("MsgRefreshFailedNoti err=[%d]", err);
3245                         }
3246 #if 0 /* Below codes are blocked because of change of UX guide. And it will be removed later. */
3247                 } else if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_SIM_MESSAGE_FULL) == 0) {
3248                         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM_FULL, true, MSG_MGR_ACTIVE_NOTI_TYPE_NONE);
3249                         if (err != 0) {
3250                                 MSG_MGR_DEBUG("MsgRefreshSimFullNoti err=[%d]", err);
3251                         }
3252 #endif
3253                 } else if (g_strcmp0(pLocaleTickerMsg, SMS_MESSAGE_MEMORY_FULL) == 0) {
3254                         err = MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_STORAGE_FULL, true, MSG_MGR_ACTIVE_NOTI_TYPE_NONE);
3255                         if (err != 0) {
3256                                 MSG_MGR_DEBUG("MsgRefreshFailedNoti err=[%d]", err);
3257                         }
3258                 } else {
3259                         MsgMgrSoundPlayStart(NULL, MSG_MGR_SOUND_PLAY_DEFAULT);
3260                 }
3261         }
3262
3263         return err;
3264 }
3265
3266
3267 int MsgMgrInsertBadge(unsigned int unreadMsgCnt)
3268 {
3269         MSG_MGR_DEBUG("Start to set badge to [%d].", unreadMsgCnt);
3270
3271         int err = BADGE_ERROR_NONE;
3272         bool exist = false;
3273
3274         err = badge_is_existing(MSG_DEFAULT_APP_ID, &exist);
3275
3276         if (err != BADGE_ERROR_NONE) {
3277                 MSG_MGR_ERR("Fail to badge_is_existing : %d", err);
3278                 return -1;
3279         }
3280
3281         if (!exist) {
3282                 /* create badge */
3283                 err = badge_add(MSG_DEFAULT_APP_ID);
3284                 if (err != BADGE_ERROR_NONE) {
3285                         MSG_MGR_ERR("Fail to badge_add : %d", err);
3286                         return -1;
3287                 }
3288         }
3289
3290         err = badge_set_count(MSG_DEFAULT_APP_ID, unreadMsgCnt);
3291
3292         if (err != BADGE_ERROR_NONE) {
3293                 MSG_MGR_ERR("Fail to badge_set_count : %d", err);
3294                 return -1;
3295         }
3296
3297         return 0;
3298 }
3299
3300
3301 void MsgMgrNotiSoundRepeatAlarmCB(int alarmId)
3302 {
3303         MSG_MGR_BEGIN();
3304
3305         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_NORMAL, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3306
3307 #ifndef MSG_NOTI_INTEGRATION
3308         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_SIM, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3309         MsgMgrRefreshNotification(MSG_MGR_NOTI_TYPE_CB, true, MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE);
3310 #endif
3311
3312         MSG_MGR_END();
3313         return;
3314 }
3315
3316
3317 void MsgMgrSoundCreateRepeatAlarm(int RepeatTime)
3318 {
3319         MSG_MGR_BEGIN();
3320
3321         int tmpAlarmId = 0;
3322         time_t tmp_time;
3323         struct tm repeat_tm;
3324
3325         time(&tmp_time);
3326
3327         tmp_time += (RepeatTime*60);
3328         tzset();
3329         localtime_r(&tmp_time, &repeat_tm);
3330
3331         if (MsgMgrAlarmRegistration(&repeat_tm, MsgMgrNotiSoundRepeatAlarmCB, &tmpAlarmId) != 0) {
3332                 MSG_MGR_DEBUG("MsgAlarmRegistration fail.");
3333                 return;
3334         }
3335
3336         g_alarmId = tmpAlarmId;
3337         MSG_MGR_DEBUG("Set alarmId to [%d]", g_alarmId);
3338
3339         MSG_MGR_END();
3340
3341         return;
3342 }
3343
3344
3345 void MsgMgrSoundSetRepeatAlarm()
3346 {
3347         int nRepeatValue = 0;
3348         long nRepeatTime = 0;
3349
3350         if (vconf_get_int(MSG_ALERT_REP_TYPE, &nRepeatValue) != 0) {
3351                 MSG_MGR_INFO("vconf_get_int() is failed");
3352         }
3353
3354         switch (nRepeatValue) {
3355         case MSG_ALERT_TONE_ONCE:
3356                 nRepeatTime = 0;
3357                 break;
3358         case MSG_ALERT_TONE_2MINS:
3359                 nRepeatTime = 2;
3360                 break;
3361         case MSG_ALERT_TONE_5MINS:
3362                 nRepeatTime = 5;
3363                 break;
3364         case MSG_ALERT_TONE_10MINS:
3365                 nRepeatTime = 10;
3366                 break;
3367         default:
3368                 MSG_MGR_DEBUG("Invalid Repetition time");
3369                 break;
3370         }
3371
3372         MSG_MGR_DEBUG("nRepeatTime = %d", nRepeatTime);
3373
3374         if (nRepeatTime > 0) {
3375                 if (g_alarmId > 0) {
3376                         if (MsgMgrAlarmRemove(g_alarmId) != 0) {
3377                                 MSG_MGR_FATAL("MsgAlarmRemove fail.");
3378                         }
3379                         g_alarmId = 0;
3380                 }
3381                 MsgMgrSoundCreateRepeatAlarm(nRepeatTime);
3382         }
3383
3384         return;
3385 }
3386
3387
3388 char *get_translate_text(const char *pkg_name, const char *locale_dir, const char *text)
3389 {
3390         char *notiMsg = NULL;
3391         char *lang = NULL;
3392
3393         lang = vconf_get_str(VCONFKEY_LANGSET);
3394
3395         setlocale(LC_MESSAGES, lang);
3396
3397         bindtextdomain(pkg_name, locale_dir);
3398
3399         notiMsg = dgettext(pkg_name, text);
3400
3401         if (lang) {
3402                 free(lang);
3403                 lang = NULL;
3404         }
3405
3406         return g_strdup(notiMsg);
3407 }
3408