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