8 #include <service_app.h>
11 #include <notification_list.h>
12 #include <notification_text_domain.h>
13 #include <notification_internal.h>
15 #include <call-manager.h>
19 #include "msg_storage.h"
21 #include "msg-manager-contact.h"
22 #include "msg-manager-debug.h"
23 #include "msg-manager-notification.h"
24 #include "msg-manager-sound.h"
26 /* below defines will be removed */
27 #define EVENT_KEY_OUT_MSG_TYPE "msg_type"
28 #define EVENT_KEY_OUT_MSG_ID "msg_id"
30 msg_handle_t msg_handle = NULL;
31 cm_client_h cm_handle = NULL;
33 bool service_app_create(void *data)
35 MSG_MGR_INFO("app_create");
37 int msg_server_ready = 0;
38 for (int i = 0; i < 100; i++) {
39 vconf_get_bool(VCONFKEY_MSG_SERVER_READY, &msg_server_ready);
40 if (msg_server_ready == 1) {
41 int msg_err = msg_open_msg_handle(&msg_handle);
42 if (msg_err != MSG_SUCCESS)
43 MSG_MGR_DEBUG("msg_open_msg_handle() failed [%d]", msg_err);
45 MSG_MGR_DEBUG("msg_open_msg_handle() success");
49 MSG_MGR_DEBUG("msg-server is not ready.");
55 initMsgMgrSoundPlayer();
61 void service_app_terminate(void *data)
63 MSG_MGR_INFO("app_terminate");
66 MsgMgrCloseContactSvc();
67 msg_close_msg_handle(&msg_handle);
72 void _incoming_msg_func(app_control_h app_control)
77 char *rcv_msg_type = NULL;
78 char *rcv_msg_id = NULL;
80 ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_ID, &rcv_msg_id);
81 if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_id == NULL) {
82 MSG_MGR_ERR("app_control_get_extra_data failed");
86 ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_TYPE, &rcv_msg_type);
87 if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_type == NULL) {
88 MSG_MGR_ERR("app_control_get_extra_data failed");
93 MSG_MGR_INFO("rcv_msg_type(%s), rcv_msg_id(%s)", rcv_msg_type, rcv_msg_id);
95 int msg_err = MSG_SUCCESS;
96 msg_message_id_t msg_id = atoi(rcv_msg_id);
97 msg_struct_t msg = NULL;
98 msg_struct_t opt = NULL;
99 contactInfo contact_info = {0,};
100 contact_info.msgId = msg_id;
102 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
103 opt = msg_create_struct(MSG_STRUCT_SENDOPT);
104 msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
105 if (msg_err != MSG_SUCCESS) {
106 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
110 msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
111 msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
112 msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
113 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
114 msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, MAX_CONTACT_TEXT_LEN);
116 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
118 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, MAX_CONTACT_TEXT_LEN);
120 if ((contact_info.folderId == MSG_INBOX_ID || contact_info.folderId == MSG_SPAMBOX_ID)) {
121 MsgMgrAddPhoneLog(&contact_info);
124 msg_release_struct(&msg);
125 msg_release_struct(&opt);
128 g_free(rcv_msg_type);
133 void _outgoing_msg_func(app_control_h app_control)
138 char *sent_msg_type = NULL;
139 char *sent_msg_id = NULL;
141 ret = app_control_get_extra_data(app_control, EVENT_KEY_OUT_MSG_ID, &sent_msg_id);
142 if (ret != APP_CONTROL_ERROR_NONE || sent_msg_id == NULL) {
143 MSG_MGR_ERR("app_control_get_extra_data failed");
147 ret = app_control_get_extra_data(app_control, EVENT_KEY_OUT_MSG_TYPE, &sent_msg_type);
148 if (ret != APP_CONTROL_ERROR_NONE || sent_msg_type == NULL) {
149 MSG_MGR_ERR("app_control_get_extra_data failed");
154 MSG_MGR_INFO("sent_msg_type(%s) sent_msg_id(%s)", sent_msg_type, sent_msg_id);
156 int msg_err = MSG_SUCCESS;
157 msg_message_id_t msg_id = atoi(sent_msg_id);
158 msg_struct_t msg = NULL;
159 msg_struct_t opt = NULL;
160 contactInfo contact_info = {0,};
161 contact_info.msgId = msg_id;
163 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
164 opt = msg_create_struct(MSG_STRUCT_SENDOPT);
165 msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
166 if (msg_err != MSG_SUCCESS) {
167 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
171 msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
172 msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
173 msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
174 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
175 msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, 100);
177 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
179 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, 100);
181 MsgMgrAddPhoneLog(&contact_info);
183 msg_release_struct(&msg);
184 msg_release_struct(&opt);
187 g_free(sent_msg_type);
192 void _refresh_noti_func(app_control_h app_control)
195 char *feedback = NULL;
196 char *active_type = NULL;
197 msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_NORMAL;
198 bool bFeedback = true;
199 msg_mgr_active_notification_type_t active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_NONE;
201 int ret = app_control_get_extra_data(app_control, "type", &type);
202 if (ret == APP_CONTROL_ERROR_NONE && type) {
203 MSG_MGR_DEBUG("type [%s]", type);
204 if (g_strcmp0(type, "normal") == 0)
205 noti_type = MSG_MGR_NOTI_TYPE_NORMAL;
209 MSG_MGR_ERR("app_control_get_extra_data failed");
213 ret = app_control_get_extra_data(app_control, "feedback", &feedback);
214 if (ret == APP_CONTROL_ERROR_NONE && feedback) {
215 MSG_MGR_DEBUG("feedback [%s]", feedback);
216 if (g_strcmp0(feedback, "false") == 0)
218 else if (g_strcmp0(feedback, "true") == 0)
224 ret = app_control_get_extra_data(app_control, "active_type", &active_type);
225 if (ret == APP_CONTROL_ERROR_NONE && active_type) {
226 MSG_MGR_DEBUG("active_type [%s]", active_type);
227 if (g_strcmp0(active_type, "none") == 0)
228 active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_NONE;
229 else if (g_strcmp0(active_type, "active") == 0)
230 active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE;
231 else if (g_strcmp0(active_type, "instant") == 0)
232 active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT;
237 MsgMgrRefreshNotification(noti_type, bFeedback, active_noti_type);
240 void _add_noti_func(app_control_h app_control)
243 msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_ALL;
245 int ret = app_control_get_extra_data(app_control, "type", &type);
246 if (ret == APP_CONTROL_ERROR_NONE && type) {
247 if (g_strcmp0(type, "voice1") == 0) {
248 noti_type = MSG_MGR_NOTI_TYPE_VOICE_1;
249 } else if (g_strcmp0(type, "voice2") == 0) {
250 noti_type = MSG_MGR_NOTI_TYPE_VOICE_2;
251 } else if (g_strcmp0(type, "mwi") == 0) {
252 noti_type = MSG_MGR_NOTI_TYPE_MWI;
253 } else if (g_strcmp0(type, "class0") == 0) {
254 noti_type = MSG_MGR_NOTI_TYPE_CLASS0;
259 MSG_MGR_ERR("app_control_get_extra_data failed");
264 ret = app_control_get_extra_data(app_control, "msg_id", &msgId);
265 if (ret != APP_CONTROL_ERROR_NONE || msgId == NULL) {
266 MSG_MGR_ERR("app_control_get_extra_data failed");
270 int msg_err = MSG_SUCCESS;
271 msg_message_id_t msg_id = atoi(msgId);
272 msg_struct_t msg = NULL;
273 msg_struct_t opt = NULL;
274 msg_list_handle_t addr_list = NULL;
275 MSG_MGR_MESSAGE_INFO_S msg_info = {0,};
276 msg_info.msgId = msg_id;
278 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
279 opt = msg_create_struct(MSG_STRUCT_SENDOPT);
280 msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
281 if (msg_err != MSG_SUCCESS) {
282 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
286 msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &msg_info.sim_idx);
287 msg_get_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, (int *)&msg_info.displayTime);
288 msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, (int *)&msg_info.networkStatus);
289 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
291 msg_struct_t addr_data = msg_list_nth_data(addr_list, 0);
292 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, msg_info.addressVal, MAX_ADDRESS_VAL_LEN);
293 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_DISPLAYNAME_STR, msg_info.displayName, MAX_DISPLAY_NAME_LEN);
295 if (noti_type == MSG_MGR_NOTI_TYPE_MWI || noti_type == MSG_MGR_NOTI_TYPE_CLASS0) {
297 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msg_size);
299 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, msg_info.msgText, MAX_MSG_TEXT_LEN);
302 msg_release_struct(&msg);
303 msg_release_struct(&opt);
307 MsgMgrAddNotification(noti_type, &msg_info);
310 void _add_report_noti_func(app_control_h app_control)
313 msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_ALL;
315 int ret = app_control_get_extra_data(app_control, "type", &type);
316 if (ret == APP_CONTROL_ERROR_NONE && type) {
317 if (g_strcmp0(type, "sms_delivery") == 0) {
318 noti_type = MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT;
319 } else if (g_strcmp0(type, "mms_delivery") == 0) {
320 noti_type = MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT;
321 } else if (g_strcmp0(type, "mms_read") == 0) {
322 noti_type = MSG_MGR_NOTI_TYPE_MMS_READ_REPORT;
327 MSG_MGR_ERR("app_control_get_extra_data failed");
332 ret = app_control_get_extra_data(app_control, "msg_id", &msgId);
333 if (ret != APP_CONTROL_ERROR_NONE || msgId == NULL) {
334 MSG_MGR_ERR("app_control_get_extra_data failed");
338 int msg_err = MSG_SUCCESS;
339 msg_message_id_t msg_id = atoi(msgId);
340 msg_struct_t msg = NULL;
341 msg_struct_t opt = NULL;
342 msg_list_handle_t addr_list = NULL;
343 MSG_MGR_MESSAGE_INFO_S msg_info = {0,};
344 msg_info.msgId = msg_id;
346 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
347 opt = msg_create_struct(MSG_STRUCT_SENDOPT);
348 msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
349 if (msg_err != MSG_SUCCESS) {
350 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
354 msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &msg_info.sim_idx);
355 msg_get_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, (int *)&msg_info.displayTime);
356 msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, (int *)&msg_info.networkStatus);
357 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
359 msg_struct_t addr_data = msg_list_nth_data(addr_list, 0);
360 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, msg_info.addressVal, MAX_ADDRESS_VAL_LEN);
361 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_DISPLAYNAME_STR, msg_info.displayName, MAX_DISPLAY_NAME_LEN);
363 msg_release_struct(&msg);
364 msg_release_struct(&opt);
368 MsgMgrAddReportNotification(noti_type, &msg_info);
371 void _del_report_noti_func(app_control_h app_control)
374 int ret = app_control_get_extra_data(app_control, "address", &addr);
375 if (ret != APP_CONTROL_ERROR_NONE || addr == NULL) {
376 MSG_MGR_ERR("app_control_get_extra_data failed");
380 MsgMgrDeleteReportNotification(addr);
385 void _insert_only_active_noti_func(app_control_h app_control)
388 msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_ALL;
390 int ret = app_control_get_extra_data(app_control, "type", &type);
391 if (ret == APP_CONTROL_ERROR_NONE && type) {
392 if (g_strcmp0(type, "normal") == 0) {
393 noti_type = MSG_MGR_NOTI_TYPE_NORMAL;
394 } else if (g_strcmp0(type, "class0") == 0) {
395 noti_type = MSG_MGR_NOTI_TYPE_CLASS0;
400 MSG_MGR_ERR("app_control_get_extra_data failed");
405 ret = app_control_get_extra_data(app_control, "msg_id", &msgId);
406 if (ret != APP_CONTROL_ERROR_NONE || msgId == NULL) {
407 MSG_MGR_ERR("app_control_get_extra_data failed");
411 int msg_err = MSG_SUCCESS;
412 msg_message_id_t msg_id = atoi(msgId);
413 msg_struct_t msg = NULL;
414 msg_struct_t opt = NULL;
415 msg_list_handle_t addr_list = NULL;
416 MSG_MGR_MESSAGE_INFO_S msg_info = {0,};
417 msg_info.msgId = msg_id;
419 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
420 opt = msg_create_struct(MSG_STRUCT_SENDOPT);
421 msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
422 if (msg_err != MSG_SUCCESS) {
423 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
427 msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &msg_info.sim_idx);
429 if (noti_type == MSG_MGR_NOTI_TYPE_CLASS0) {
430 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
432 msg_struct_t addr_data = msg_list_nth_data(addr_list, 0);
433 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, msg_info.addressVal, MAX_ADDRESS_VAL_LEN);
434 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_DISPLAYNAME_STR, msg_info.displayName, MAX_DISPLAY_NAME_LEN);
437 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msg_size);
439 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, msg_info.msgText, MAX_MSG_TEXT_LEN);
442 msg_release_struct(&msg);
443 msg_release_struct(&opt);
447 MsgMgrInsertOnlyActiveNotification(noti_type, &msg_info);
450 void _sound_play_start_func(app_control_h app_control)
453 MSG_MGR_SOUND_TYPE_T sound_type = MSG_MGR_SOUND_PLAY_DEFAULT;
455 int ret = app_control_get_extra_data(app_control, "type", &type);
456 if (ret == APP_CONTROL_ERROR_NONE && type) {
457 if (g_strcmp0(type, "default") == 0) {
458 sound_type = MSG_MGR_SOUND_PLAY_DEFAULT;
459 } else if (g_strcmp0(type, "user") == 0) {
460 sound_type = MSG_MGR_SOUND_PLAY_USER;
461 } else if (g_strcmp0(type, "emergency") == 0) {
462 sound_type = MSG_MGR_SOUND_PLAY_EMERGENCY;
463 } else if (g_strcmp0(type, "voicemail") == 0) {
464 sound_type = MSG_MGR_SOUND_PLAY_VOICEMAIL;
469 MSG_MGR_ERR("app_control_get_extra_data failed");
474 ret = app_control_get_extra_data(app_control, "address", &addr);
477 MSG_MGR_ADDRESS_INFO_S addr_info = {0,};
478 snprintf(addr_info.addressVal, MAX_ADDRESS_VAL_LEN, "%s", addr);
480 MsgMgrSoundPlayStart(&addr_info, sound_type);
484 MsgMgrSoundPlayStart(NULL, sound_type);
488 void service_app_control(app_control_h app_control, void *data)
490 MSG_MGR_INFO("service_app_control called");
493 char *operation = NULL;
496 ret = app_control_get_operation(app_control, &operation);
497 if (ret == APP_CONTROL_ERROR_NONE && operation) {
498 if (g_strcmp0(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
499 ret = app_control_get_extra_data(app_control, "cmd", &cmd);
500 if (ret == APP_CONTROL_ERROR_NONE && cmd) {
501 MSG_MGR_DEBUG("cmd [%s]", cmd);
503 if (g_strcmp0(cmd, "incoming_msg") == 0) {
504 _incoming_msg_func(app_control);
505 } else if (g_strcmp0(cmd, "outgoing_msg") == 0) {
506 _outgoing_msg_func(app_control);
507 } else if (g_strcmp0(cmd, "refresh_noti") == 0) {
508 _refresh_noti_func(app_control);
509 } else if (g_strcmp0(cmd, "add_noti") == 0) {
510 _add_noti_func(app_control);
511 } else if (g_strcmp0(cmd, "add_report_noti") == 0) {
512 _add_report_noti_func(app_control);
513 } else if (g_strcmp0(cmd, "del_report_noti") == 0) {
514 _del_report_noti_func(app_control);
515 } else if (g_strcmp0(cmd, "insert_only_active_noti") == 0) {
516 _insert_only_active_noti_func(app_control);
517 } else if (g_strcmp0(cmd, "sound_play_start") == 0) {
518 _sound_play_start_func(app_control);
530 int main(int argc, char* argv[])
532 service_app_lifecycle_callback_s event_callback = {0,};
534 event_callback.create = service_app_create;
535 event_callback.terminate = service_app_terminate;
536 event_callback.app_control = service_app_control;
538 return service_app_main(argc, argv, &event_callback, NULL);