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