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