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