5 #include <msg_storage.h>
7 #include <service_app.h>
10 #include <notification_list.h>
11 #include <notification_text_domain.h>
12 #include <notification_internal.h>
14 #include "msg-manager.h"
15 #include "msg-manager-contact.h"
16 #include "msg-manager-debug.h"
19 bool service_app_create(void *data)
21 MSG_MGR_DEBUG("app_create");
26 void service_app_terminate(void *data)
28 // Todo: add your code here.
32 void _incoming_msg_func(app_control_h app_control)
37 char *rcv_msg_type = NULL;
38 char *rcv_msg_id = NULL;
40 ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_TYPE, &rcv_msg_type);
41 if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_type == NULL)
44 MSG_MGR_INFO("rcv_msg_type(%s)", rcv_msg_type);
45 if (g_strcmp0(rcv_msg_type, EVENT_VAL_SMS) != 0)
48 ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_ID, &rcv_msg_id);
49 if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_id == NULL)
52 MSG_MGR_INFO("rcv_msg_id(%s)", rcv_msg_id);
54 int msg_err = MSG_SUCCESS;
55 msg_message_id_t msg_id = atoi(rcv_msg_id);
56 msg_handle_t msg_handle = NULL;
57 msg_struct_t msg = NULL;
58 msg_struct_t opt = NULL;
59 contactInfo contact_info = {0,};
60 contact_info.msgId = msg_id;
62 msg_err = msg_open_msg_handle(&msg_handle);
63 if (msg_err != MSG_SUCCESS) {
64 MSG_MGR_ERR("msg_open_msg_handle() failed [%d]", msg_err);
68 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
69 opt = msg_create_struct(MSG_STRUCT_SENDOPT);
70 msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
71 if (msg_err != MSG_SUCCESS) {
72 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
76 msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
77 msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
78 msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
79 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
80 msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, MAX_CONTACT_TEXT_LEN);
82 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
84 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, MAX_CONTACT_TEXT_LEN);
86 if ((contact_info.folderId == MSG_INBOX_ID || contact_info.folderId == MSG_SPAMBOX_ID)) {
87 MsgMgrAddPhoneLog(&contact_info);
90 msg_release_struct(&msg);
91 msg_release_struct(&opt);
95 int row_cnt = 0, col_cnt = 0;
96 msg_err = msg_db_select_with_query(msg_handle, "MSG_ID FROM MSG_MESSAGE_TABLE;", &db_res, &row_cnt, &col_cnt);
97 if (msg_err != MSG_SUCCESS) {
98 MSG_MGR_ERR("msg_db_select_with_query() failed [%d]", msg_err);
102 MSG_MGR_DEBUG("row count [%d] col count [%d]", row_cnt, col_cnt);
103 if (db_res == NULL || *db_res == NULL) {
104 MSG_MGR_DEBUG("NULL");
106 for (int i = col_cnt; i < col_cnt * (row_cnt + 1); i++) {
107 MSG_MGR_DEBUG("db_res[%d] [%s]", i, db_res[i]);
111 msg_err = msg_db_free(msg_handle, db_res);
112 if (msg_err != MSG_SUCCESS) {
113 MSG_MGR_ERR("msg_db_free() failed [%d]", msg_err);
118 msg_close_msg_handle(&msg_handle);
120 g_free(rcv_msg_type);
126 void _outgoing_msg_func(app_control_h app_control)
131 char *sent_msg_id = NULL;
133 ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_ID, &sent_msg_id);
134 if (ret != APP_CONTROL_ERROR_NONE || sent_msg_id == NULL)
137 MSG_MGR_INFO("sent_msg_id(%s)", sent_msg_id);
139 int msg_err = MSG_SUCCESS;
140 msg_message_id_t msg_id = atoi(sent_msg_id);
141 msg_handle_t msg_handle = NULL;
142 msg_struct_t msg = NULL;
143 msg_struct_t opt = NULL;
144 contactInfo contact_info = {0,};
145 contact_info.msgId = msg_id;
147 msg_err = msg_open_msg_handle(&msg_handle);
148 if (msg_err != MSG_SUCCESS) {
149 MSG_MGR_ERR("msg_open_msg_handle() failed [%d]", msg_err);
153 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
154 opt = msg_create_struct(MSG_STRUCT_SENDOPT);
155 msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
156 if (msg_err != MSG_SUCCESS) {
157 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
161 msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
162 msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
163 msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
164 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
165 msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, 100);
167 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
169 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, 100);
171 MsgMgrAddPhoneLog(&contact_info);
173 msg_release_struct(&msg);
174 msg_release_struct(&opt);
176 msg_close_msg_handle(&msg_handle);
183 void _refresh_noti_func(app_control_h app_control)
188 void service_app_control(app_control_h app_control, void *data)
190 MSG_MGR_INFO("service_app_control called");
192 //check "launch on event"
194 const char *incoming_event_uri = "event://tizen.system.event.incoming_msg";
195 const char *outgoing_event_uri = "event://tizen.system.event.outgoing_msg";
196 char *operation = NULL;
199 ret = app_control_get_operation(app_control, &operation);
200 if (ret == APP_CONTROL_ERROR_NONE && operation) {
201 if (g_strcmp0(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT) == 0) {
202 /* launch by system event */
203 ret = app_control_get_uri(app_control, &uri);
204 if (ret == APP_CONTROL_ERROR_NONE && uri) {
205 if (g_strcmp0(uri, incoming_event_uri) == 0) {
206 _incoming_msg_func(app_control);
207 } else if (g_strcmp0(uri, outgoing_event_uri) == 0) {
208 _outgoing_msg_func(app_control);
212 } else if (g_strcmp0(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
213 /* launch by default */
215 ret = app_control_get_extra_data(app_control, "cmd", &cmd);
216 if (ret == APP_CONTROL_ERROR_NONE && cmd) {
217 if (g_strcmp0(cmd, "refresh") == 0)
218 _refresh_noti_func(app_control);
231 service_app_lang_changed(app_event_info_h event_info, void *user_data)
233 /*APP_EVENT_LANGUAGE_CHANGED*/
237 service_app_region_changed(app_event_info_h event_info, void *user_data)
239 /*APP_EVENT_REGION_FORMAT_CHANGED*/
243 service_app_low_battery(app_event_info_h event_info, void *user_data)
245 /*APP_EVENT_LOW_BATTERY*/
249 service_app_low_memory(app_event_info_h event_info, void *user_data)
251 /*APP_EVENT_LOW_MEMORY*/
254 int main(int argc, char* argv[])
257 service_app_lifecycle_callback_s event_callback;
258 app_event_handler_h handlers[5] = {NULL, };
260 event_callback.create = service_app_create;
261 event_callback.terminate = service_app_terminate;
262 event_callback.app_control = service_app_control;
264 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
265 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
266 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
267 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
269 return service_app_main(argc, argv, &event_callback, ad);