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