2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
17 // for sl message browser launch
18 #include <app_service.h>
21 #include "MsgUtilFile.h"
22 #include "MsgContact.h"
23 #include "MsgUtilStorage.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgSoundPlayer.h"
26 #include "MsgSpamFilter.h"
27 #include "MsgPluginManager.h"
28 #include "MsgStorageHandler.h"
29 #include "MsgDeliverHandler.h"
30 #include "MsgNotificationWrapper.h"
32 /*==================================================================================================
34 ==================================================================================================*/
35 extern MsgDbHandler dbHandle;
38 /*==================================================================================================
39 FUNCTION IMPLEMENTATION
40 ==================================================================================================*/
41 msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_request_id_t reqID)
45 msg_error_t err = MSG_SUCCESS;
47 MSG_DEBUG(" msgtype subtype is [%d]", pMsgInfo->msgType.subType);
49 if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
50 // keep origianl subType
51 MSG_SUB_TYPE_T subType = pMsgInfo->msgType.subType;
53 /* If Retrieve Failed, Msg SubType is remained as Notification Ind */
54 if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL)
55 pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
57 err = MsgStoUpdateMMSMessage(pMsgInfo);
59 if (err == MSG_SUCCESS)
60 MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
62 if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
63 MSG_DEBUG("### MSG_NETWORK_RETRIEVE_SUCCESS ###");
64 //Update Mms Message to MMS Plugin DB
66 // MMS Received Ind Process Func
67 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsgInfo->msgType.mainType);
69 //Contents of msg Data was removed and replaced to retrievedFilePath
70 // NOTICE:: now it was moved to handleEvent in MsgListnerThread
71 err = plg->updateMessage(pMsgInfo, NULL, NULL);
72 if (err != MSG_SUCCESS)
73 return MSG_ERR_STORAGE_ERROR;
76 MSG_DEBUG(" ######################### MESSAGE UPDATE COMPLETED!!! ######################");
78 bool readStatus = false;
80 MsgStoGetReadStatus(pMsgInfo->msgId, &readStatus);
81 MSG_DEBUG("### readStatus = %d ###", readStatus);
83 //Update Read Status to Unread beacaus Noti is Read
84 if (subType == MSG_RETRIEVE_MANUALCONF_MMS && pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
85 MSG_DEBUG("###2. subType = %d ###", pMsgInfo->msgType.subType);
87 if (readStatus == true)
88 MsgStoSetReadStatus(&dbHandle, pMsgInfo->msgId, false);
92 if (subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
96 smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
97 mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
99 MsgSettingHandleNewMsg(smsCnt, mmsCnt);
102 if (subType == MSG_RETRIEVE_AUTOCONF_MMS) {
103 // play message-tone when MMS retrieved
104 MsgSoundPlayStart(false);
107 MSG_DEBUG("Enter MsgAddPhoneLog() for mms message.");
108 MsgAddPhoneLog(pMsgInfo);
110 MsgInsertNoti(pMsgInfo);
111 } else if (subType == MSG_RETRIEVE_MANUALCONF_MMS) {
112 if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
113 MSG_DEBUG("Manual success");
114 MsgInsertTicker("Message Retrieved", MESSAGE_RETRIEVED);
115 } else if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL) {
116 MSG_DEBUG("Manual failed");
117 MsgInsertTicker("Retrieving message failed", RETRIEVING_MESSAGE_FAILED);
121 else if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS || pMsgInfo->msgType.subType == MSG_SENDCONF_MMS)
123 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsgInfo->msgType.mainType);
124 // change subType for storage update
125 pMsgInfo->msgType.subType = MSG_SENDCONF_MMS;
127 err = MsgStoUpdateMMSMessage(pMsgInfo);
128 if (err == MSG_SUCCESS)
129 MSG_DEBUG("Command Handle Success : MsgStoUpdateMMSMessage()");
131 err = plg->updateMessage(pMsgInfo, NULL, NULL);
132 if (err != MSG_SUCCESS)
133 return MSG_ERR_STORAGE_ERROR;
135 MSG_DEBUG("pMsg->networkStatus : %d", pMsgInfo->networkStatus);
136 err = MsgStoUpdateNetworkStatus(&dbHandle, pMsgInfo, pMsgInfo->networkStatus);
137 if (err != MSG_SUCCESS)
138 return MSG_ERR_STORAGE_ERROR;
140 if (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS)
142 err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SENTBOX_ID);
143 if (err != MSG_SUCCESS)
144 return MSG_ERR_STORAGE_ERROR;
147 // Get subject and text
148 MsgStoGetText(pMsgInfo->msgId, pMsgInfo->subject, pMsgInfo->msgText);
150 MSG_DEBUG(" ######################### MESSAGE UPDATE COMPLETED!!! ######################");
155 msg_error_t MsgHandleIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
159 msg_error_t err = MSG_SUCCESS;
161 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
163 bool bOnlyNoti = false;
165 err = MsgHandleSMS(pMsgInfo, pSendNoti, &bOnlyNoti);
167 if (err == MSG_SUCCESS&& ((*pSendNoti)||bOnlyNoti)) {
168 MsgSoundPlayStart(false);
169 if (*pSendNoti == true) {
170 int smsCnt = 0, mmsCnt = 0;
172 smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
173 mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
175 MsgSettingHandleNewMsg(smsCnt, mmsCnt);
176 MsgInsertNoti(pMsgInfo);
177 } else if (bOnlyNoti == true) {
178 MsgInsertNoti(pMsgInfo);
182 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
184 err = MsgHandleMMS(pMsgInfo, pSendNoti);
188 if ((err == MSG_SUCCESS) &&
189 (pMsgInfo->folderId == MSG_INBOX_ID || pMsgInfo->folderId == MSG_SPAMBOX_ID) &&
190 (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) &&
191 (pMsgInfo->msgType.subType != MSG_WAP_SL_SMS)) {
193 MSG_DEBUG("Enter MsgAddPhoneLog() : pMsg->folderId [%d]", pMsgInfo->folderId);
195 MsgAddPhoneLog(pMsgInfo);
204 msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bOnlyNoti)
206 msg_error_t err = MSG_SUCCESS;
208 if (pMsgInfo->msgPort.valid == true) {
213 if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
214 if (MsgCheckFilter(&dbHandle, pMsgInfo) == true) {
216 err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);
218 if (err != MSG_SUCCESS) {
219 MSG_DEBUG("MsgStoMoveMessageToFolder() Error : [%d]", err);
221 pMsgInfo->folderId = MSG_SPAMBOX_ID;
224 // Update Conversation table
225 err = MsgStoUpdateConversation(&dbHandle, pMsgInfo->threadId);
227 if (err != MSG_SUCCESS)
228 MSG_DEBUG("MsgStoUpdateConversation() Error : [%d]", err);
233 } else if ((pMsgInfo->msgType.subType >= MSG_WAP_SI_SMS) && (pMsgInfo->msgType.subType <= MSG_WAP_CO_SMS)) {
234 MSG_DEBUG("Starting WAP Message Incoming.");
236 MSG_PUSH_SERVICE_TYPE_T serviceType = (MSG_PUSH_SERVICE_TYPE_T)MsgSettingGetInt(PUSH_SERVICE_TYPE);
237 service_h svc_handle = NULL;
239 switch (pMsgInfo->msgType.subType) {
244 if (serviceType == MSG_PUSH_SERVICE_ALWAYS) {
245 if (service_create(&svc_handle) < 0) {
246 MSG_DEBUG("Fail to create service handle");
250 MSG_DEBUG("Service handle is NULL");
253 if (service_set_operation(svc_handle, SERVICE_OPERATION_VIEW) < 0) {
254 MSG_DEBUG("Fail to create service handle");
255 service_destroy(svc_handle);
258 if (service_set_uri(svc_handle, pMsgInfo->msgText) < 0) {
259 MSG_DEBUG("Fail to set uri");
260 service_destroy(svc_handle);
263 if (service_set_package(svc_handle, MSG_SVC_PKG_NAME_BROWSER) < 0) {
264 MSG_DEBUG("Fail to set package");
265 service_destroy(svc_handle);
268 if (service_send_launch_request(svc_handle, NULL, NULL) < 0) {
269 MSG_DEBUG("Fail to launch browser");
270 service_destroy(svc_handle);
274 service_destroy(svc_handle);
276 } else if (serviceType == MSG_PUSH_SERVICE_PROMPT) {
277 char urlString[MAX_COMMAND_LEN+1];
278 memset(urlString, 0x00, sizeof(urlString));
280 snprintf(urlString, MAX_COMMAND_LEN, "/usr/apps/org.tizen.message/bin/message-dialog -m PUSH_MSG_ALWAYS_ASK -u %s &", pMsgInfo->msgText);
295 } else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
298 } else if (pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS) {
299 if (pMsgInfo->bStore == false) {
310 msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
312 msg_error_t err = MSG_SUCCESS;
314 MSG_REQUEST_INFO_S request = {0};
315 bool bReject = false;
316 bool bFiltered = false;
318 // MMS Received Ind Process Func
319 MSG_MAIN_TYPE_T msgMainType = pMsgInfo->msgType.mainType;
320 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
322 // Need to process m-delivery-ind, m-notification-ind, m-read-orig-ind
323 err = plg->processReceivedInd(pMsgInfo, &request, &bReject);
325 if (err == MSG_SUCCESS) {
326 MSG_DEBUG("Process Message Success : processReceivedInd(), btextsms %d", pMsgInfo->bTextSms);
328 MSG_DEBUG("Process Message Fail : processReceivedInd()");
333 if ((pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) && bReject == false) {
334 bFiltered = MsgCheckFilter(&dbHandle, pMsgInfo);
336 if (bFiltered == true) {
337 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
341 err = MsgStoAddMessage(pMsgInfo, NULL);
343 if (err != MSG_SUCCESS) {
344 MSG_DEBUG("MsgStoAddMessage() Error: [%d]", err);
347 } else if (pMsgInfo->msgType.subType == MSG_READORGIND_MMS || pMsgInfo->msgType.subType == MSG_DELIVERYIND_MMS) {
348 if (MsgInsertMmsReportToNoti(&dbHandle, pMsgInfo) == MSG_SUCCESS) {
349 MsgSoundPlayStart(false);
354 //In the case of m-notification-ind, we should decide whether to send m-notify-response-ind or http 'Get'
356 if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS && bFiltered == false) {
357 if (request.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS && bReject == false) {
358 MsgSoundPlayStart(false);
363 smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
364 mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
366 MsgSettingHandleNewMsg(smsCnt, mmsCnt);
367 MsgInsertNoti(pMsgInfo);
370 request.msgInfo.msgId = pMsgInfo->msgId;
372 MSG_DEBUG("-=====================[[[ %s ]]]] =========================", pMsgInfo->msgData);
373 err = plg->submitReq(&request);
375 if (err == MSG_SUCCESS) {
376 MSG_DEBUG("Process Message Success : processReceivedInd()");
378 MSG_DEBUG("Process Message Fail : processReceivedInd()");