modify msg-service to support dpm feature
[platform/core/messaging/msg-service.git] / framework / deliver-handler / MsgDeliverHandler.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 #include <bundle.h>
18 #include <eventsystem.h>
19
20 #include "MsgDebug.h"
21 #include "MsgUtilFile.h"
22 #include "MsgContact.h"
23 #include "MsgUtilFunction.h"
24 #include "MsgUtilStorage.h"
25 #include "MsgGconfWrapper.h"
26 #include "MsgSpamFilter.h"
27 #include "MsgPluginManager.h"
28 #include "MsgStorageHandler.h"
29 #include "MsgDeliverHandler.h"
30 #include "MsgNotificationWrapper.h"
31 #include "MsgDevicedWrapper.h"
32
33 /*==================================================================================================
34                                      VARIABLES
35 ==================================================================================================*/
36
37 /*==================================================================================================
38                                      FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
40
41 void MsgLaunchClass0(msg_message_id_t msgId)
42 {
43         MSG_BEGIN();
44 #ifndef MSG_WEARABLE_PROFILE
45         int ret = 0;
46         msg_error_t err = MSG_SUCCESS;
47         bundle *b = NULL;
48
49         b = bundle_create();
50         if (b == NULL) {
51                 MSG_DEBUG("bundle_create() is failed");
52                 return;
53         }
54
55         ret = bundle_add_str(b, "type", "msg_id");
56         if (ret != 0) {
57                 MSG_DEBUG("bundle_add_str() is failed : %d", ret);
58                 bundle_free(b);
59                 return;
60         }
61
62         char tmpStrMsgId[10];
63         memset(&tmpStrMsgId, 0x00, sizeof(tmpStrMsgId));
64         snprintf(tmpStrMsgId, sizeof(tmpStrMsgId), "%d", msgId);
65         MSG_DEBUG("tmpStrMsgId [%s]", tmpStrMsgId);
66         ret = bundle_add_str(b, "msgId", tmpStrMsgId);
67         if (ret != 0) {
68                 MSG_DEBUG("bundle_add_str() is failed : %d", ret);
69                 bundle_free(b);
70                 return;
71         }
72
73         err = msg_launch_app("org.tizen.msg-ui-class0", b);
74         if (err != MSG_SUCCESS) {
75                 MSG_DEBUG("msg_launch_app() is failed : %d", err);
76         }
77
78         bundle_free(b);
79 #endif // MSG_WEARABLE_PROFILE
80         MSG_END();
81 }
82
83
84 msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_request_id_t reqID)
85 {
86         MSG_BEGIN();
87
88         msg_error_t err = MSG_SUCCESS;
89         MsgDbHandler *dbHandle = getDbHandle();
90
91         MSG_DEBUG(" msgtype subtype is [%d]", pMsgInfo->msgType.subType);
92
93         if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
94                 // keep original subType
95                 MSG_SUB_TYPE_T subType = pMsgInfo->msgType.subType;
96
97                 /* If Retrieve Failed, Msg SubType is remained as Notification Ind */
98                 if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_PENDING) {
99                         pMsgInfo->folderId = MSG_INBOX_ID;
100                         pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
101                 }
102
103 //              err = MsgStoUpdateMMSMessage(pMsgInfo);
104 //
105 //              if (err == MSG_SUCCESS)
106 //                      MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
107
108                 if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
109                         MSG_DEBUG("### MSG_NETWORK_RETRIEVE_SUCCESS ###");
110                         //Update Mms Message to MMS Plugin DB
111
112                         // MMS Received Ind Process Func
113                         MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsgInfo->msgType.mainType);
114                         if (plg == NULL)
115                                 return MSG_ERR_NULL_POINTER;
116
117                         //Contents of msg Data was removed and replaced to retrievedFilePath
118                         // NOTICE:: now it was moved to handleEvent in MsgListnerThread
119                         err = plg->updateMessage(pMsgInfo, NULL, NULL);
120                         if (err != MSG_SUCCESS)
121                                 return MSG_ERR_STORAGE_ERROR;
122                 }
123
124                 err = MsgStoUpdateMMSMessage(pMsgInfo);//For Text Update
125
126                 if (err == MSG_SUCCESS)
127                         MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");
128
129
130                 MSG_DEBUG(" ######################### MESSAGE UPDATE COMPLETED!!! ######################");
131
132                 bool readStatus = false;
133
134                 MsgStoGetReadStatus(pMsgInfo->msgId, &readStatus);
135                 MSG_DEBUG("### readStatus = %d ###", readStatus);
136
137                 //Update Read Status to Unread because Noti is Read
138                 if (subType == MSG_RETRIEVE_MANUALCONF_MMS && pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
139                         MSG_DEBUG("###2. subType = %d ###", pMsgInfo->msgType.subType);
140
141                         if (readStatus == true) {
142                                 MsgStoSetReadStatus(dbHandle, pMsgInfo->msgId, false);
143                                 MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, false, MSG_ACTIVE_NOTI_TYPE_NONE);
144                         }
145                 }
146
147                 if (subType == MSG_RETRIEVE_AUTOCONF_MMS && pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
148 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
149                         // add phone log
150                         MSG_DEBUG("Enter MsgAddPhoneLog() for mms message.");
151                         MsgAddPhoneLog(pMsgInfo);
152                         /* Send system event */
153                         bundle *b = NULL;
154                         b = bundle_create();
155                         if (b) {
156                                 bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_MMS);
157                                 char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
158                                 snprintf(msgId, sizeof(msgId), "%u", pMsgInfo->msgId);
159                                 bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
160                                 eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
161                                 bundle_add_str(b, "cmd", "incoming_msg");
162                                 msg_launch_app(MSG_MGR_APP_ID, b);
163                                 bundle_free(b);
164                         }
165 #endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
166
167                         if (pMsgInfo->folderId == MSG_INBOX_ID)
168                                 MsgInsertNotification(pMsgInfo);
169
170                 } else if (subType == MSG_RETRIEVE_MANUALCONF_MMS) {
171                         if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
172                                 MSG_DEBUG("Manual success");
173 #if 0 //disable as per UX request to not show success notification : 2015.9.18
174                                 if (pMsgInfo->folderId == MSG_INBOX_ID)
175                                         MsgInsertTicker("Message Retrieved", MESSAGE_RETRIEVED, true, 0);
176 #endif
177                         } else if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL) {
178                                 MSG_DEBUG("Manual failed");
179                                 MsgInsertTicker("Retrieving message failed", RETRIEVING_MESSAGE_FAILED, true, pMsgInfo->msgId);
180                         }
181                 }
182         } else if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS || pMsgInfo->msgType.subType == MSG_SENDCONF_MMS) {
183                 MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsgInfo->msgType.mainType);
184                 if (plg == NULL)
185                         return MSG_ERR_NULL_POINTER;
186
187                 if (pMsgInfo->networkStatus == MSG_NETWORK_SEND_PENDING)
188                         pMsgInfo->msgType.subType = MSG_SENDREQ_MMS;
189                 else
190                         pMsgInfo->msgType.subType = MSG_SENDCONF_MMS; // change subType for storage update
191
192                 err = MsgStoUpdateMMSMessage(pMsgInfo);
193                 if (err == MSG_SUCCESS)
194                         MSG_DEBUG("Command Handle Success : MsgStoUpdateMMSMessage()");
195
196                 err = plg->updateMessage(pMsgInfo, NULL, NULL);
197                 if (err != MSG_SUCCESS)
198                         return MSG_ERR_STORAGE_ERROR;
199
200                 MSG_DEBUG("pMsg->networkStatus : %d", pMsgInfo->networkStatus);
201                 err = MsgStoUpdateNetworkStatus(dbHandle, pMsgInfo, pMsgInfo->networkStatus);
202                 if (err != MSG_SUCCESS)
203                         return MSG_ERR_STORAGE_ERROR;
204
205                 if (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS) {
206                         err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SENTBOX_ID);
207                         if (err != MSG_SUCCESS)
208                                 return MSG_ERR_STORAGE_ERROR;
209                 }
210
211                 // Get subject and text
212                 MsgStoGetText(pMsgInfo->msgId, pMsgInfo->subject, pMsgInfo->msgText);
213
214                 MSG_DEBUG(" ######################### MESSAGE UPDATE COMPLETED!!! ######################");
215         }
216         return err;
217 }
218
219 msg_error_t MsgHandleIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
220 {
221         MSG_BEGIN();
222
223         msg_error_t err = MSG_SUCCESS;
224
225         MsgDisplayLock();
226
227         if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
228                 bool bOnlyNoti = false;
229
230                 err = MsgHandleSMS(pMsgInfo, pSendNoti, &bOnlyNoti);
231
232                 if (err == MSG_SUCCESS && ((*pSendNoti) || bOnlyNoti))
233                         MsgInsertNotification(pMsgInfo);
234
235         } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
236                 err = MsgHandleMMS(pMsgInfo, pSendNoti);
237         }
238
239         MsgDisplayUnlock();
240
241         //Add Phone Log Data
242         if ((err == MSG_SUCCESS) &&
243                 (pMsgInfo->folderId == MSG_INBOX_ID || pMsgInfo->folderId == MSG_SPAMBOX_ID) &&
244                 (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) &&
245                 (pMsgInfo->msgType.subType != MSG_WAP_SL_SMS)) {
246 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
247                 MSG_DEBUG("Enter MsgAddPhoneLog() : pMsg->folderId [%d]", pMsgInfo->folderId);
248                 MsgAddPhoneLog(pMsgInfo);
249 #endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
250         }
251
252         // Auto delete
253         //MsgStoAutoDeleteConversation(pMsgInfo->threadId);
254
255         MSG_END();
256
257         return err;
258 }
259
260
261 msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bOnlyNoti)
262 {
263         msg_error_t err = MSG_SUCCESS;
264         MsgDbHandler *dbHandle = getDbHandle();
265
266         if (pMsgInfo->msgPort.valid == true) {
267                 *pSendNoti = false;
268                 *bOnlyNoti = false;
269                 return MSG_SUCCESS;
270         }
271
272         // Add SMS message
273         MSG_SENDINGOPT_INFO_S send_opt;
274         memset(&send_opt, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));
275
276         if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
277 #ifdef MSG_NOTI_INTEGRATION
278                 MSG_DEBUG("Copy Class2 message to phone storage.");
279                 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
280                 pMsgInfo->storageId = MSG_STORAGE_PHONE;
281                 pMsgInfo->msgId = 0;
282 #else
283                 MSG_DEBUG("Class2 message is already added.");
284                 return MSG_SUCCESS;
285 #endif
286         }
287
288         if (msg_check_dpm_policy(pMsgInfo->msgType.mainType) == false) {
289                 MSG_DEBUG("Messaging is restricted by DPM policy.");
290                 pMsgInfo->bRestricted = true;
291                 *pSendNoti = false;
292                 *bOnlyNoti = false;
293         }
294
295         if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
296                 MSG_DEBUG("Add Normal Message");
297                 err = MsgStoAddMessage(pMsgInfo, &send_opt);
298         } else if ((pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
299                 MSG_DEBUG("Add Replace Message");
300
301                 pMsgInfo->msgId = 0;
302                 MsgStoGetReplaceMsgId(pMsgInfo);
303
304                 if (pMsgInfo->msgId > 0) {
305                         err = MsgStoUpdateMessage(pMsgInfo, &send_opt);
306                 } else {
307                         err = MsgStoAddMessage(pMsgInfo, &send_opt);
308                         pMsgInfo->msgType.subType = MSG_NORMAL_SMS; // To make 'insert' type for storage change callback.
309                 }
310         } else if ((pMsgInfo->msgType.subType == MSG_WAP_SI_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_CO_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_SL_SMS)) {
311                 MSG_DEBUG("Add WAP Push Message");
312                 switch (pMsgInfo->msgType.subType) {
313                         case MSG_WAP_SI_SMS:
314                         case MSG_WAP_SL_SMS:
315                                 err = MsgStoAddWAPMsg(pMsgInfo);
316                                 break;
317                         case MSG_WAP_CO_SMS:
318                                 err = MsgStoAddCOWAPMsg(pMsgInfo);
319                                 break;
320                         default :
321                                 break;
322                 }
323         } else if ((pMsgInfo->msgType.subType == MSG_CB_SMS) || (pMsgInfo->msgType.subType == MSG_JAVACB_SMS)) {
324                 /** check add message option */
325         } else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
326                 MSG_DEBUG("Add Report Message");
327         } else if (pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS) {
328                 char keyName[MAX_VCONFKEY_NAME_LEN];
329                 memset(keyName, 0x00, sizeof(keyName));
330                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, pMsgInfo->sim_idx);
331                 char *voiceNumber = NULL;
332                 if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
333                         MSG_INFO("MsgSettingGetString() is failed");
334                 }
335
336                 if (voiceNumber) {
337                         MSG_SEC_DEBUG("Voice Mail Number [%s]", voiceNumber);
338
339                         memset(pMsgInfo->addressList[0].addressVal, 0x00, sizeof(pMsgInfo->addressList[0].addressVal));
340                         snprintf(pMsgInfo->addressList[0].addressVal, sizeof(pMsgInfo->addressList[0].addressVal), "%s", voiceNumber);
341                         memset(keyName, 0x00, sizeof(keyName));
342                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, pMsgInfo->sim_idx);
343                         char *alphaId = NULL;
344                         if (MsgSettingGetString(keyName, &alphaId) != MSG_SUCCESS) {
345                                 MSG_INFO("MsgSettingGetString() is failed");
346                         }
347                         if (alphaId) {
348                                 memset(pMsgInfo->addressList->displayName, 0x00, sizeof(pMsgInfo->addressList->displayName));
349                                 memcpy(pMsgInfo->addressList->displayName, alphaId, sizeof(pMsgInfo->addressList->displayName)-1);
350                                 g_free(alphaId);
351                                 alphaId = NULL;
352                         }
353
354                         free(voiceNumber);
355                         voiceNumber = NULL;
356                 }
357
358                 memset(keyName, 0x00, sizeof(keyName));
359                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, pMsgInfo->sim_idx);
360                 int voicecnt = 0;
361                 if (MsgSettingGetInt(keyName, &voicecnt) != MSG_SUCCESS) {
362                         MSG_INFO("MsgSettingGetInt() is failed");
363                 }
364                 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
365                 snprintf(pMsgInfo->msgText, sizeof(pMsgInfo->msgText), "%d", voicecnt);
366                 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
367                 MSG_DEBUG("Add Voice or other Message");
368         } else {
369                 MSG_DEBUG("No matching type [%d]", pMsgInfo->msgType.subType);
370                 return err;
371         }
372
373         if (err != MSG_SUCCESS)
374                 MSG_DEBUG("Add message - Error : [%d]", err);
375
376         if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
377                 if (MsgCheckFilter(dbHandle, pMsgInfo) == true) {
378                         // Move to SpamBox
379                         err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);
380
381                         if (err != MSG_SUCCESS) {
382                                 MSG_DEBUG("MsgStoMoveMessageToFolder() Error : [%d]", err);
383                         } else {
384                                 pMsgInfo->folderId = MSG_SPAMBOX_ID;
385                         }
386
387                         *pSendNoti = false;
388                         *bOnlyNoti = false;
389                 } else if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
390                         MsgLaunchClass0(pMsgInfo->msgId);
391                         MsgSoundPlayStart(&(pMsgInfo->addressList[0]), MSG_SOUND_PLAY_USER);
392
393                         *pSendNoti = false;
394                         *bOnlyNoti = false;
395
396                         MsgInsertOnlyActiveNotification(MSG_NOTI_TYPE_CLASS0, pMsgInfo);
397                 }
398         } else if ((pMsgInfo->msgType.subType >= MSG_WAP_SI_SMS) && (pMsgInfo->msgType.subType <= MSG_WAP_CO_SMS)) {
399                 MSG_DEBUG("Starting WAP Message Incoming.");
400
401 #ifndef MSG_WEARABLE_PROFILE
402                 int tmpVal = 0;
403                 if (MsgSettingGetInt(PUSH_SERVICE_TYPE, &tmpVal) != MSG_SUCCESS) {
404                         MSG_INFO("MsgSettingGetInt() is failed");
405                 }
406                 MSG_PUSH_SERVICE_TYPE_T serviceType = (MSG_PUSH_SERVICE_TYPE_T)tmpVal;
407                 switch (pMsgInfo->msgType.subType) {
408                         case MSG_WAP_SL_SMS: {
409                                 *pSendNoti = true;
410
411                                 if (serviceType == MSG_PUSH_SERVICE_ALWAYS) {
412                                         bundle *b = NULL;
413                                         b = bundle_create();
414                                         if (b == NULL) {
415                                                 MSG_DEBUG("bundle_create() is failed");
416                                                 break;
417                                         }
418
419                                         err = msg_aul_svc_set_operation(b, "http://tizen.org/appcontrol/operation/view");
420                                         if (err != MSG_SUCCESS) {
421                                                 MSG_DEBUG("msg_aul_svc_set_operation() is failed : %d", err);
422                                                 bundle_free(b);
423                                                 break;
424                                         }
425
426                                         err = msg_aul_svc_set_uri(b, pMsgInfo->msgText);
427                                         if (err != MSG_SUCCESS) {
428                                                 MSG_DEBUG("msg_aul_svc_set_uri() is failed : %d", err);
429                                                 bundle_free(b);
430                                                 break;
431                                         }
432
433                                         err = msg_launch_app(MSG_SVC_PKG_NAME_BROWSER, b);
434                                         if (err != MSG_SUCCESS) {
435                                                 MSG_DEBUG("msg_launch_app() is failed : %d", err);
436                                         }
437
438                                         bundle_free(b);
439                                 } else if (serviceType == MSG_PUSH_SERVICE_PROMPT) {
440                                         MSG_DEBUG("WAP Message SL(Always Ask) start.");
441
442                                         int ret = 0;
443                                         bundle *b = NULL;
444                                         b = bundle_create();
445                                         if (b == NULL) {
446                                                 MSG_DEBUG("bundle_create() is failed");
447                                                 break;
448                                         }
449
450                                         ret = bundle_add_str(b, "mode", "WAP_PUSH_SL");
451                                         if (ret != 0) {
452                                                 MSG_DEBUG("bundle_add_str() is failed : %d", ret);
453                                                 bundle_free(b);
454                                                 break;
455                                         }
456
457                                         ret = bundle_add_str(b, "url", pMsgInfo->msgText);
458                                         if (ret != 0) {
459                                                 MSG_DEBUG("bundle_add_str() is failed : %d", ret);
460                                                 bundle_free(b);
461                                                 break;
462                                         }
463
464                                         ret = bundle_add_str(b, "address", pMsgInfo->addressList[0].addressVal);
465                                         if (ret != 0) {
466                                                 MSG_DEBUG("bundle_add_str() is failed : %d", ret);
467                                                 bundle_free(b);
468                                                 break;
469                                         }
470
471                                         err = msg_launch_app("org.tizen.message-dialog", b);
472                                         if (err != MSG_SUCCESS) {
473                                                 MSG_DEBUG("msg_launch_app() is failed : %d", err);
474                                         }
475
476                                         bundle_free(b);
477                                 }
478                         }
479                         break;
480
481                         case MSG_WAP_SI_SMS:
482                                 *pSendNoti = true;
483                                 break;
484                         case MSG_WAP_CO_SMS:
485                                 *pSendNoti = false;
486                                 MsgInsertOnlyActiveNotification(MSG_NOTI_TYPE_NORMAL, pMsgInfo);
487                                 break;
488                 }
489 #endif // MSG_WEARABLE_PROFILE
490         } else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
491                 *pSendNoti = false;
492                 *bOnlyNoti = true;
493         } else if (pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS) {
494                 if (pMsgInfo->bStore == false) {
495                         *pSendNoti = false;
496                         *bOnlyNoti = true;
497                 }
498         }
499
500         // Update Conversation table
501         err = MsgStoUpdateConversation(dbHandle, pMsgInfo->threadId);
502
503         if (err != MSG_SUCCESS)
504                 MSG_DEBUG("MsgStoUpdateConversation() Error : [%d]", err);
505
506         return err;
507 }
508
509
510 msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo,  bool *pSendNoti)
511 {
512         msg_error_t err = MSG_SUCCESS;
513         MsgDbHandler *dbHandle = getDbHandle();
514         MSG_REQUEST_INFO_S request = {0};
515         bool bReject = false;
516         bool bFiltered = false;
517
518         // MMS Received Ind Process Func
519         MSG_MAIN_TYPE_T msgMainType = pMsgInfo->msgType.mainType;
520         MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);
521
522         if (plg == NULL)
523                 return MSG_ERR_NULL_POINTER;
524
525         // Read the default network SIM
526         MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);
527
528         if (sms_plg == NULL)
529                 return MSG_ERR_NULL_POINTER;
530
531         int defaultNetworkSimId = 0;
532
533         err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);
534
535         MSG_DEBUG("######defaultNetworkSimId = %d, err = %d", defaultNetworkSimId, err);
536
537         if (err != MSG_SUCCESS) {
538                 MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
539                 return err;
540         }
541
542         err = MsgSettingSetInt(MSG_NETWORK_SIM, (int)defaultNetworkSimId);
543         if (err != MSG_SUCCESS) {
544                 MSG_ERR("Error to set config data [%s], err = %d", MSG_NETWORK_SIM, err);
545                 return err;
546         }
547
548         // Need to process m-delivery-ind, m-notification-ind, m-read-orig-ind
549         err = plg->processReceivedInd(pMsgInfo, &request, &bReject);
550
551         if (err == MSG_SUCCESS) {
552                 MSG_DEBUG("Process Message Success : processReceivedInd(), btextsms %d", pMsgInfo->bTextSms);
553         } else {
554                 MSG_DEBUG("Process Message Fail : processReceivedInd()");
555                 *pSendNoti = false;
556                 return err;
557         }
558
559         // Add into DB
560         if ((pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) && bReject == false) {
561                 /* It should send noti response even if MMS is blocked by sender address. */
562                 //bFiltered = MsgCheckFilter(dbHandle, pMsgInfo);
563                 if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
564                         bFiltered = true;
565                 }
566
567                 if (bFiltered == true) {
568                         err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);
569
570                         if (err != MSG_SUCCESS) {
571                                 MSG_DEBUG("MsgStoMoveMessageToFolder() Error : [%d]", err);
572                         } else {
573                                 pMsgInfo->folderId = MSG_SPAMBOX_ID;
574                         }
575
576                         pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
577                         *pSendNoti = false;
578                 } else {/* If it is not SPAM message, it should be check whether filter option is enable or not. */
579                         bool filterFlag = false;
580                         MsgGetFilterOperation(&filterFlag);
581                         if (filterFlag == true && request.msgInfo.msgType.subType == MSG_GET_MMS) {
582                                  /* Not to show MMS notification msg until it retrieves. */
583                                 pMsgInfo->folderId = MSG_IOSBOX_ID;
584                                 *pSendNoti = false;
585                         }
586                 }
587
588                 if (msg_check_dpm_policy(pMsgInfo->msgType.mainType) == false) {
589                         MSG_DEBUG("Messaging is restricted by DPM policy.");
590                         pMsgInfo->bRestricted = true;
591                         *pSendNoti = false;
592                 }
593
594                 err = MsgStoAddMessage(pMsgInfo, NULL);
595
596                 if (err != MSG_SUCCESS) {
597                         MSG_DEBUG("MsgStoAddMessage() Error: [%d]", err);
598                         return err;
599                 }
600         } else if (pMsgInfo->msgType.subType == MSG_READORGIND_MMS || pMsgInfo->msgType.subType == MSG_DELIVERYIND_MMS) {
601                 if (MsgInsertNotification(pMsgInfo) == MSG_SUCCESS)
602                         *pSendNoti = false;
603         }
604
605 #if 0
606         if (pMsgInfo->bTextSms == false) {
607                 MsgDeleteFile(pMsgInfo->msgData); //ipc
608                 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
609         }
610 #endif
611         //In the case of m-notification-ind, we should decide whether to send m-notify-response-ind or http 'Get'
612         //submit request
613         if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
614                 if (request.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS && bReject == false && bFiltered == false)
615                         MsgInsertNotification(pMsgInfo);
616                 else
617                         *pSendNoti = false;
618
619                 MSG_DEBUG("default_sim = %d, pMsgInfo->sim_idx = %d", defaultNetworkSimId, pMsgInfo->sim_idx);
620
621                 if (defaultNetworkSimId == pMsgInfo->sim_idx) {
622                         request.msgInfo.msgId = pMsgInfo->msgId;
623
624                         MSG_SEC_DEBUG("-=====================[[[ %s ]]]] =========================", request.msgInfo.msgData);
625                         err = plg->submitReq(&request);
626
627                         if (err == MSG_SUCCESS) {
628                                 MSG_DEBUG("Process Message Success : processReceivedInd()");
629
630                                 if (request.msgInfo.msgType.subType == MSG_GET_MMS) {
631                                         MSG_DEBUG("Auto Retrieve Mode : update network status retrieving");
632                                         MsgStoUpdateNetworkStatus(dbHandle, &(request.msgInfo), MSG_NETWORK_RETRIEVING);
633                                 }
634
635                         } else {
636                                 MSG_DEBUG("Process Message Fail : processReceivedInd()");
637                         }
638                 }
639         }
640
641         return err;
642 }