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