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