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