2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "MsgUtilFunction.h"
20 #include "MsgGconfWrapper.h"
21 #include "MsgNotificationWrapper.h"
22 #include "MsgDevicedWrapper.h"
23 #include "MsgSqliteWrapper.h"
27 #ifndef MSG_WEARABLE_PROFILE
29 #endif /* MSG_WEARABLE_PROFILE */
32 /*======================================================================================*/
33 /* FUNCTION IMPLEMENTATION */
34 /*======================================================================================*/
37 msg_error_t MsgInsertNotification(MSG_MESSAGE_INFO_S *msg_info)
41 msg_error_t err = MSG_SUCCESS;
43 #ifndef MSG_WEARABLE_PROFILE
45 msg_notification_type_t noti_type;
47 switch (msg_info->msgType.subType) {
48 #ifdef MSG_NOTI_INTEGRATION
51 if (msg_info->msgType.classType == MSG_CLASS_0) {
52 noti_type = MSG_NOTI_TYPE_CLASS0;
54 noti_type = MSG_NOTI_TYPE_NORMAL;
59 case MSG_NORMAL_SMS: {
60 if (msg_info->msgType.classType == MSG_CLASS_0) {
61 noti_type = MSG_NOTI_TYPE_CLASS0;
62 } else if (msg_info->msgType.classType == MSG_CLASS_2) {
63 noti_type = MSG_NOTI_TYPE_SIM;
65 noti_type = MSG_NOTI_TYPE_NORMAL;
70 noti_type = MSG_NOTI_TYPE_CB;
74 case MSG_MWI_EMAIL_SMS:
75 case MSG_MWI_OTHER_SMS:
76 noti_type = MSG_NOTI_TYPE_MWI;
78 case MSG_MWI_VOICE_SMS:
79 noti_type = MSG_NOTI_TYPE_VOICE_1;
81 case MSG_MWI_VOICE2_SMS:
82 noti_type = MSG_NOTI_TYPE_VOICE_2;
84 case MSG_STATUS_REPORT_SMS:
85 noti_type = MSG_NOTI_TYPE_SMS_DELIVERY_REPORT;
87 case MSG_DELIVERYIND_MMS:
88 noti_type = MSG_NOTI_TYPE_MMS_DELIVERY_REPORT;
90 case MSG_READORGIND_MMS:
91 noti_type = MSG_NOTI_TYPE_MMS_READ_REPORT;
93 case MSG_READRECIND_MMS:
94 case MSG_READREPLY_MMS:
95 noti_type = MSG_NOTI_TYPE_MMS_READ_REPORT_SENT;
98 #ifdef MSG_NOTI_INTEGRATION
99 noti_type = MSG_NOTI_TYPE_NORMAL;
101 if (msg_info->msgType.classType == MSG_CLASS_2) {
102 noti_type = MSG_NOTI_TYPE_SIM;
104 noti_type = MSG_NOTI_TYPE_NORMAL;
110 MSG_DEBUG("Notification type = [%d]", noti_type);
113 case MSG_NOTI_TYPE_NORMAL:
114 case MSG_NOTI_TYPE_SIM:
115 case MSG_NOTI_TYPE_CB:
116 err = MsgRefreshNotification(noti_type, true, MSG_ACTIVE_NOTI_TYPE_ACTIVE);
118 case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT:
119 case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT:
120 case MSG_NOTI_TYPE_MMS_READ_REPORT:
121 err = MsgAddReportNotification(noti_type, msg_info);
123 case MSG_NOTI_TYPE_VOICE_1:
124 case MSG_NOTI_TYPE_VOICE_2:
125 case MSG_NOTI_TYPE_MWI:
126 case MSG_NOTI_TYPE_CLASS0:
127 case MSG_NOTI_TYPE_MMS_READ_REPORT_SENT:
128 err = MsgAddNotification(noti_type, msg_info);
131 MSG_DEBUG("No matching type [%d]");
135 #endif /* MSG_WEARABLE_PROFILE */
142 msg_error_t MsgInsertOnlyActiveNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
146 msg_error_t err = MSG_SUCCESS;
148 #ifndef MSG_WEARABLE_PROFILE
149 bundle *bundle_data = bundle_create();
151 bundle_add_str(bundle_data, "cmd", "insert_only_active_noti");
152 if (noti_type == MSG_NOTI_TYPE_NORMAL)
153 bundle_add_str(bundle_data, "type", "normal");
154 else if (noti_type == MSG_NOTI_TYPE_CLASS0)
155 bundle_add_str(bundle_data, "type", "class0");
157 err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
159 bundle_free(bundle_data);
160 #endif /* MSG_WEARABLE_PROFILE */
166 msg_error_t MsgDeleteReportNotification(const char *addr)
170 msg_error_t err = MSG_SUCCESS;
172 #ifndef MSG_WEARABLE_PROFILE
173 bundle *bundle_data = bundle_create();
175 bundle_add_str(bundle_data, "cmd", "del_report_noti");
176 bundle_add_str(bundle_data, "address", addr);
178 err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
180 bundle_free(bundle_data);
181 #endif /* MSG_WEARABLE_PROFILE */
187 msg_error_t MsgIsSentReadReportNotificationExist(int threadId, int *msgId)
191 msg_error_t err = MSG_SUCCESS;
193 #ifndef MSG_WEARABLE_PROFILE
194 char sqlQuery[MAX_QUERY_LEN+1];
195 int readReportSentMsgId = 0;
197 if (MsgSettingGetInt(VCONFKEY_MESSAGE_READ_REPORT_SENT_MSG_ID, &readReportSentMsgId) != MSG_SUCCESS)
198 MSG_INFO("MsgSettingGetInt() is failed");
200 MsgDbHandler *dbHandle = getDbHandle();
202 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE CONV_ID = %d AND MSG_ID = %d;",
203 MSGFW_MESSAGE_TABLE_NAME, threadId, readReportSentMsgId);
205 if (dbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
206 return MSG_ERR_DB_PREPARE;
208 if (dbHandle->stepQuery() == MSG_ERR_DB_ROW) {
209 dbHandle->finalizeQuery();
210 MSG_DEBUG("MsgId[%d] is in ThreadId[%d]", readReportSentMsgId, threadId);
211 *msgId = readReportSentMsgId;
215 dbHandle->finalizeQuery();
217 MSG_DEBUG("MsgId[%d] is not in ThreadId[%d]", readReportSentMsgId, threadId);
219 err = MSG_ERR_UNKNOWN;
220 #endif /* MSG_WEARABLE_PROFILE */
225 msg_error_t MsgDeleteSentReadReportNotification(int msgId)
229 msg_error_t err = MSG_SUCCESS;
231 #ifndef MSG_WEARABLE_PROFILE
232 int readReportSentMsgId = 0;
234 if (MsgSettingGetInt(VCONFKEY_MESSAGE_READ_REPORT_SENT_MSG_ID, &readReportSentMsgId) != MSG_SUCCESS)
235 MSG_INFO("MsgSettingGetInt() is failed");
237 if (readReportSentMsgId != msgId) {
238 MSG_ERR("Invalid read report sent notification msgId, noti msgId[%d], requested msgId[%d]", readReportSentMsgId, msgId);
239 return MSG_ERR_UNKNOWN;
242 bundle *bundle_data = bundle_create();
244 bundle_add_str(bundle_data, "cmd", "del_sent_read_report_noti");
246 err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
248 bundle_free(bundle_data);
250 #endif /* MSG_WEARABLE_PROFILE */
255 msg_error_t MsgAddReportNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
257 msg_error_t err = MSG_SUCCESS;
259 #ifndef MSG_WEARABLE_PROFILE
260 bundle *bundle_data = bundle_create();
262 bundle_add_str(bundle_data, "cmd", "add_report_noti");
264 case MSG_NOTI_TYPE_SMS_DELIVERY_REPORT:
265 bundle_add_str(bundle_data, "type", "sms_delivery");
267 case MSG_NOTI_TYPE_MMS_DELIVERY_REPORT:
268 bundle_add_str(bundle_data, "type", "mms_delivery");
270 case MSG_NOTI_TYPE_MMS_READ_REPORT:
271 bundle_add_str(bundle_data, "type", "mms_read");
277 char *msg_id = g_strdup_printf("%d", msg_info->msgId);
279 bundle_add_str(bundle_data, "msg_id", msg_id);
283 err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
285 bundle_free(bundle_data);
286 #endif /* MSG_WEARABLE_PROFILE */
291 msg_error_t MsgRefreshNotification(msg_notification_type_t noti_type, bool bFeedback, msg_active_notification_type_t active_type)
293 msg_error_t err = MSG_SUCCESS;
295 #ifndef MSG_WEARABLE_PROFILE
296 bundle *bundle_data = bundle_create();
298 bundle_add_str(bundle_data, "cmd", "refresh_noti");
300 case MSG_NOTI_TYPE_NORMAL:
301 bundle_add_str(bundle_data, "type", "normal");
303 case MSG_NOTI_TYPE_CB:
304 bundle_add_str(bundle_data, "type", "cb");
306 case MSG_NOTI_TYPE_SIM:
307 bundle_add_str(bundle_data, "type", "sim");
309 case MSG_NOTI_TYPE_FAILED:
310 bundle_add_str(bundle_data, "type", "failed");
316 switch (active_type) {
317 case MSG_ACTIVE_NOTI_TYPE_NONE:
318 bundle_add_str(bundle_data, "active_type", "none");
320 case MSG_ACTIVE_NOTI_TYPE_ACTIVE:
321 bundle_add_str(bundle_data, "active_type", "active");
323 case MSG_ACTIVE_NOTI_TYPE_INSTANT:
324 bundle_add_str(bundle_data, "active_type", "instant");
331 bundle_add_str(bundle_data, "feedback", "true");
333 bundle_add_str(bundle_data, "feedback", "false");
335 err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
337 bundle_free(bundle_data);
338 #endif /* MSG_WEARABLE_PROFILE */
343 msg_error_t MsgAddNotification(msg_notification_type_t noti_type, MSG_MESSAGE_INFO_S *msg_info)
345 msg_error_t err = MSG_SUCCESS;
347 #ifndef MSG_WEARABLE_PROFILE
348 bundle *bundle_data = bundle_create();
350 bundle_add_str(bundle_data, "cmd", "add_noti");
352 case MSG_NOTI_TYPE_VOICE_1:
353 bundle_add_str(bundle_data, "type", "voice1");
355 case MSG_NOTI_TYPE_VOICE_2:
356 bundle_add_str(bundle_data, "type", "voice2");
358 case MSG_NOTI_TYPE_MWI:
359 bundle_add_str(bundle_data, "type", "mwi");
361 case MSG_NOTI_TYPE_CLASS0:
362 bundle_add_str(bundle_data, "type", "class0");
364 case MSG_NOTI_TYPE_MMS_READ_REPORT_SENT:
365 bundle_add_str(bundle_data, "type", "read_report_sent");
371 char *msg_id = g_strdup_printf("%d", msg_info->msgId);
373 bundle_add_str(bundle_data, "msg_id", msg_id);
377 err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
379 bundle_free(bundle_data);
380 #endif /* MSG_WEARABLE_PROFILE */
385 void MsgRefreshAllNotification(bool bWithSimNoti, bool bFeedback, msg_active_notification_type_t active_type)
389 #ifndef MSG_WEARABLE_PROFILE
390 msg_error_t err = MSG_SUCCESS;
392 /* MsgDeleteNotification(MSG_NOTI_TYPE_SIM); */
394 #ifdef MSG_NOTI_INTEGRATION
395 err = MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, bFeedback, active_type);
396 if (err != MSG_SUCCESS)
397 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_NORMAL, err);
399 err = MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, bFeedback, active_type);
400 if (err != MSG_SUCCESS)
401 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_NORMAL, err);
403 err = MsgRefreshNotification(MSG_NOTI_TYPE_CB, bFeedback, active_type);
404 if (err != MSG_SUCCESS)
405 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_CB, err);
408 err = MsgRefreshNotification(MSG_NOTI_TYPE_SIM, bFeedback, active_type);
409 if (err != MSG_SUCCESS)
410 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_SIM, err);
414 err = MsgRefreshNotification(MSG_NOTI_TYPE_FAILED, bFeedback, active_type);
415 if (err != MSG_SUCCESS)
416 MSG_DEBUG("refreshNoti is failed, [type=%d, err=%d]", MSG_NOTI_TYPE_FAILED, err);
418 #endif /* MSG_WEARABLE_PROFILE */
423 msg_error_t MsgDeleteNoti(msg_notification_type_t noti_type, int simIndex)
425 #ifndef MSG_WEARABLE_PROFILE
426 bundle *bundle_data = bundle_create();
428 bundle_add_str(bundle_data, "cmd", "del_noti");
430 case MSG_NOTI_TYPE_ALL:
431 bundle_add_str(bundle_data, "type", "all");
433 case MSG_NOTI_TYPE_NORMAL:
434 bundle_add_str(bundle_data, "type", "normal");
436 case MSG_NOTI_TYPE_SIM:
437 bundle_add_str(bundle_data, "type", "sim");
439 case MSG_NOTI_TYPE_VOICE_1:
440 bundle_add_str(bundle_data, "type", "voice1");
442 case MSG_NOTI_TYPE_VOICE_2:
443 bundle_add_str(bundle_data, "type", "voice2");
449 char *sim_index = g_strdup_printf("%d", simIndex);
451 bundle_add_str(bundle_data, "sim_index", sim_index);
455 msg_launch_app(MSG_MGR_APP_ID, bundle_data);
457 bundle_free(bundle_data);
458 #endif /* MSG_WEARABLE_PROFILE */
463 void MsgSoundPlayStart(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_SOUND_TYPE_T soundType)
466 #ifndef MSG_WEARABLE_PROFILE
467 bundle *bundle_data = bundle_create();
469 bundle_add_str(bundle_data, "cmd", "sound_play_start");
471 case MSG_SOUND_PLAY_DEFAULT:
472 bundle_add_str(bundle_data, "type", "default");
474 case MSG_SOUND_PLAY_USER:
475 bundle_add_str(bundle_data, "type", "user");
477 case MSG_SOUND_PLAY_EMERGENCY:
478 bundle_add_str(bundle_data, "type", "emergency");
480 case MSG_SOUND_PLAY_VOICEMAIL:
481 bundle_add_str(bundle_data, "type", "voicemail");
487 if (pAddrInfo && pAddrInfo->addressVal[0] != '\0')
488 bundle_add_str(bundle_data, "address", pAddrInfo->addressVal);
490 msg_launch_app(MSG_MGR_APP_ID, bundle_data);
492 bundle_free(bundle_data);
493 #endif /* MSG_WEARABLE_PROFILE */
498 msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg, bool bPlayFeedback, int msgId)
500 msg_error_t err = MSG_SUCCESS;
501 #ifndef MSG_WEARABLE_PROFILE
502 MSG_DEBUG("pTickerMsg=[%s], pLocaleTickerMsg=[%s]", pTickerMsg, pLocaleTickerMsg);
503 MSG_DEBUG("play feedback=[%d], msgId=[%d]", bPlayFeedback, msgId);
505 bundle *bundle_data = bundle_create();
507 bundle_add_str(bundle_data, "cmd", "insert_ticker");
508 bundle_add_str(bundle_data, "ticker_msg", pTickerMsg);
509 bundle_add_str(bundle_data, "locale_ticker_msg", pLocaleTickerMsg);
512 bundle_add_str(bundle_data, "feedback", "true");
514 bundle_add_str(bundle_data, "feedback", "false");
516 char *msg_id = g_strdup_printf("%d", msgId);
518 bundle_add_str(bundle_data, "msg_id", msg_id);
522 err = msg_launch_app(MSG_MGR_APP_ID, bundle_data);
524 bundle_free(bundle_data);
525 #endif /* MSG_WEARABLE_PROFILE */
532 bundle *bundle_data = bundle_create();
534 bundle_add_str(bundle_data, "cmd", "on_boot");
536 msg_launch_app(MSG_MGR_APP_ID, bundle_data);
538 bundle_free(bundle_data);