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