2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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(&dbHandle, 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) {
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(&dbHandle, 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->msgType.subType == MSG_NORMAL_SMS) {
209 if (MsgCheckFilter(&dbHandle, pMsgInfo) == true) {
211 err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);
213 if (err != MSG_SUCCESS) {
214 MSG_DEBUG("MsgStoMoveMessageToFolder() Error : [%d]", err);
216 pMsgInfo->folderId = MSG_SPAMBOX_ID;
219 // Update Conversation table
220 err = MsgStoUpdateConversation(&dbHandle, pMsgInfo->threadId);
222 if (err != MSG_SUCCESS)
223 MSG_DEBUG("MsgStoUpdateConversation() Error : [%d]", err);
227 } else if ((pMsgInfo->msgType.subType >= MSG_WAP_SI_SMS) && (pMsgInfo->msgType.subType <= MSG_WAP_CO_SMS)) {
228 MSG_DEBUG("Starting WAP Message Incoming.");
230 MSG_PUSH_SERVICE_TYPE_T serviceType = (MSG_PUSH_SERVICE_TYPE_T)MsgSettingGetInt(PUSH_SERVICE_TYPE);
231 service_h svc_handle = NULL;
233 switch (pMsgInfo->msgType.subType) {
238 if (serviceType == MSG_PUSH_SERVICE_ALWAYS) {
239 if (service_create(&svc_handle) < 0) {
240 MSG_DEBUG("Fail to create service handle");
244 MSG_DEBUG("Service handle is NULL");
247 if (service_set_operation(svc_handle, SERVICE_OPERATION_VIEW) < 0) {
248 MSG_DEBUG("Fail to create service handle");
249 service_destroy(svc_handle);
252 if (service_set_uri(svc_handle, pMsgInfo->msgText) < 0) {
253 MSG_DEBUG("Fail to set uri");
254 service_destroy(svc_handle);
257 if (service_set_package(svc_handle, MSG_SVC_PKG_NAME_BROWSER) < 0) {
258 MSG_DEBUG("Fail to set package");
259 service_destroy(svc_handle);
262 if (service_send_launch_request(svc_handle, NULL, NULL) < 0) {
263 MSG_DEBUG("Fail to launch browser");
264 service_destroy(svc_handle);
268 service_destroy(svc_handle);
270 } else if (serviceType == MSG_PUSH_SERVICE_PROMPT) {
271 char urlString[MAX_COMMAND_LEN+1];
272 memset(urlString, 0x00, sizeof(urlString));
274 snprintf(urlString, MAX_COMMAND_LEN, "/usr/apps/org.tizen.message/bin/message-dialog -m PUSH_MSG_ALWAYS_ASK -u %s &", pMsgInfo->msgText);
289 } else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
292 } else if (pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS) {
293 if (pMsgInfo->bStore == false) {
304 msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
306 msg_error_t err = MSG_SUCCESS;
308 MSG_REQUEST_INFO_S request = {0};
309 bool bReject = false;
310 bool bFiltered = false;
312 // MMS Received Ind Process Func
313 MSG_MAIN_TYPE_T msgMainType = pMsgInfo->msgType.mainType;
314 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
316 // Need to process m-delivery-ind, m-notification-ind, m-read-orig-ind
317 err = plg->processReceivedInd(pMsgInfo, &request, &bReject);
319 if (err == MSG_SUCCESS) {
320 MSG_DEBUG("Process Message Success : processReceivedInd(), btextsms %d", pMsgInfo->bTextSms);
322 MSG_DEBUG("Process Message Fail : processReceivedInd()");
327 if ((pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) && bReject == false) {
328 bFiltered = MsgCheckFilter(&dbHandle, pMsgInfo);
330 if (bFiltered == true) {
331 pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
335 err = MsgStoAddMessage(pMsgInfo, NULL);
337 if (err != MSG_SUCCESS) {
338 MSG_DEBUG("MsgStoAddMessage() Error: [%d]", err);
341 } else if (pMsgInfo->msgType.subType == MSG_READORGIND_MMS || pMsgInfo->msgType.subType == MSG_DELIVERYIND_MMS) {
342 if (MsgInsertMmsReportToNoti(&dbHandle, pMsgInfo) == MSG_SUCCESS) {
343 MsgSoundPlayStart(false);
348 //In the case of m-notification-ind, we should decide whether to send m-notify-response-ind or http 'Get'
350 if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS && bFiltered == false) {
351 if (request.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS && bReject == false) {
352 MsgSoundPlayStart(false);
357 smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
358 mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
360 MsgSettingHandleNewMsg(smsCnt, mmsCnt);
361 MsgInsertNoti(&dbHandle, pMsgInfo);
364 request.msgInfo.msgId = pMsgInfo->msgId;
366 MSG_DEBUG("-=====================[[[ %s ]]]] =========================", pMsgInfo->msgData);
367 err = plg->submitReq(&request);
369 if (err == MSG_SUCCESS) {
370 MSG_DEBUG("Process Message Success : processReceivedInd()");
372 MSG_DEBUG("Process Message Fail : processReceivedInd()");