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