summaryrefslogtreecommitdiff
path: root/framework/deliver-handler/MsgDeliverHandler.cpp
blob: 0674164fce1c7891d4fa24a37d0f178e92db2b69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

#include <bundle.h>
#include <eventsystem.h>

#include "MsgDebug.h"
#include "MsgUtilFile.h"
#include "MsgContact.h"
#include "MsgUtilFunction.h"
#include "MsgUtilStorage.h"
#include "MsgGconfWrapper.h"
#include "MsgSpamFilter.h"
#include "MsgPluginManager.h"
#include "MsgStorageHandler.h"
#include "MsgDeliverHandler.h"
#include "MsgNotificationWrapper.h"
#include "MsgDevicedWrapper.h"

/*==================================================================================================
                                     VARIABLES
==================================================================================================*/

/*==================================================================================================
                                     FUNCTION IMPLEMENTATION
==================================================================================================*/

void MsgLaunchClass0(msg_message_id_t msgId)
{
	MSG_BEGIN();
#ifndef MSG_WEARABLE_PROFILE
	int ret = 0;
	msg_error_t err = MSG_SUCCESS;
	bundle *b = NULL;

	b = bundle_create();
	if (b == NULL) {
		MSG_DEBUG("bundle_create() is failed");
		return;
	}

	ret = bundle_add_str(b, "type", "msg_id");
	if (ret != 0) {
		MSG_DEBUG("bundle_add_str() is failed : %d", ret);
		bundle_free(b);
		return;
	}

	char tmpStrMsgId[10];
	memset(&tmpStrMsgId, 0x00, sizeof(tmpStrMsgId));
	snprintf(tmpStrMsgId, sizeof(tmpStrMsgId), "%d", msgId);
	MSG_DEBUG("tmpStrMsgId [%s]", tmpStrMsgId);
	ret = bundle_add_str(b, "msgId", tmpStrMsgId);
	if (ret != 0) {
		MSG_DEBUG("bundle_add_str() is failed : %d", ret);
		bundle_free(b);
		return;
	}

	err = msg_launch_app("org.tizen.msg-ui-class0", b);
	if (err != MSG_SUCCESS) {
		MSG_DEBUG("msg_launch_app() is failed : %d", err);
	}

	bundle_free(b);
#endif // MSG_WEARABLE_PROFILE
	MSG_END();
}


msg_error_t MsgHandleMmsConfIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_request_id_t reqID)
{
	MSG_BEGIN();

	msg_error_t err = MSG_SUCCESS;
	MsgDbHandler *dbHandle = getDbHandle();

	MSG_DEBUG(" msgtype subtype is [%d]", pMsgInfo->msgType.subType);

	if (pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
		// keep original subType
		MSG_SUB_TYPE_T subType = pMsgInfo->msgType.subType;

		/* If Retrieve Failed, Msg SubType is remained as Notification Ind */
		if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_PENDING) {
			pMsgInfo->folderId = MSG_INBOX_ID;
			pMsgInfo->msgType.subType = MSG_NOTIFICATIONIND_MMS;
		}

//		err = MsgStoUpdateMMSMessage(pMsgInfo);
//
//		if (err == MSG_SUCCESS)
//			MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");

		if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
			MSG_DEBUG("### MSG_NETWORK_RETRIEVE_SUCCESS ###");
			//Update Mms Message to MMS Plugin DB

			// MMS Received Ind Process Func
			MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsgInfo->msgType.mainType);
			if (plg == NULL)
				return MSG_ERR_NULL_POINTER;

			//Contents of msg Data was removed and replaced to retrievedFilePath
			// NOTICE:: now it was moved to handleEvent in MsgListnerThread
			err = plg->updateMessage(pMsgInfo, NULL, NULL);
			if (err != MSG_SUCCESS)
				return MSG_ERR_STORAGE_ERROR;
		}

		err = MsgStoUpdateMMSMessage(pMsgInfo);//For Text Update

		if (err == MSG_SUCCESS)
			MSG_DEBUG("Command Handle Success : MsgStoUpdateMessage()");


		MSG_DEBUG(" ######################### MESSAGE UPDATE COMPLETED!!! ######################");

		bool readStatus = false;

		MsgStoGetReadStatus(pMsgInfo->msgId, &readStatus);
		MSG_DEBUG("### readStatus = %d ###", readStatus);

		//Update Read Status to Unread because Noti is Read
		if (subType == MSG_RETRIEVE_MANUALCONF_MMS && pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
			MSG_DEBUG("###2. subType = %d ###", pMsgInfo->msgType.subType);

			if (readStatus == true) {
				MsgStoSetReadStatus(dbHandle, pMsgInfo->msgId, false);
				MsgRefreshNotification(MSG_NOTI_TYPE_NORMAL, false, MSG_ACTIVE_NOTI_TYPE_NONE);
			}
		}

		if (subType == MSG_RETRIEVE_AUTOCONF_MMS && pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
			// add phone log
			MSG_DEBUG("Enter MsgAddPhoneLog() for mms message.");
			MsgAddPhoneLog(pMsgInfo);
			/* Send system event */
			bundle *b = NULL;
			b = bundle_create();
			if (b) {
				bundle_add_str(b, EVT_KEY_MSG_TYPE, EVT_VAL_MMS);
				char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
				snprintf(msgId, sizeof(msgId), "%u", pMsgInfo->msgId);
				bundle_add_str(b, EVT_KEY_MSG_ID, msgId);
				eventsystem_send_system_event(SYS_EVENT_INCOMMING_MSG, b);
				bundle_add_str(b, "cmd", "incoming_msg");
				msg_launch_app(MSG_MGR_APP_ID, b);
				bundle_free(b);
			}
#endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED

			if (pMsgInfo->folderId == MSG_INBOX_ID)
				MsgInsertNotification(pMsgInfo);

		} else if (subType == MSG_RETRIEVE_MANUALCONF_MMS) {
			if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS) {
				MSG_DEBUG("Manual success");
#if 0 //disable as per UX request to not show success notification : 2015.9.18
				if (pMsgInfo->folderId == MSG_INBOX_ID)
					MsgInsertTicker("Message Retrieved", MESSAGE_RETRIEVED, true, 0);
#endif
			} else if (pMsgInfo->networkStatus == MSG_NETWORK_RETRIEVE_FAIL) {
				MSG_DEBUG("Manual failed");
				MsgInsertTicker("Retrieving message failed", RETRIEVING_MESSAGE_FAILED, true, pMsgInfo->msgId);
			}
		}
	} else if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS || pMsgInfo->msgType.subType == MSG_SENDCONF_MMS) {
		MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(pMsgInfo->msgType.mainType);
		if (plg == NULL)
			return MSG_ERR_NULL_POINTER;

		if (pMsgInfo->networkStatus == MSG_NETWORK_SEND_PENDING)
			pMsgInfo->msgType.subType = MSG_SENDREQ_MMS;
		else
			pMsgInfo->msgType.subType = MSG_SENDCONF_MMS; // change subType for storage update

		err = MsgStoUpdateMMSMessage(pMsgInfo);
		if (err == MSG_SUCCESS)
			MSG_DEBUG("Command Handle Success : MsgStoUpdateMMSMessage()");

		err = plg->updateMessage(pMsgInfo, NULL, NULL);
		if (err != MSG_SUCCESS)
			return MSG_ERR_STORAGE_ERROR;

		MSG_DEBUG("pMsg->networkStatus : %d", pMsgInfo->networkStatus);
		err = MsgStoUpdateNetworkStatus(dbHandle, pMsgInfo, pMsgInfo->networkStatus);
		if (err != MSG_SUCCESS)
			return MSG_ERR_STORAGE_ERROR;

		if (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS) {
			err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SENTBOX_ID);
			if (err != MSG_SUCCESS)
				return MSG_ERR_STORAGE_ERROR;
		}

		// Get subject and text
		MsgStoGetText(pMsgInfo->msgId, pMsgInfo->subject, pMsgInfo->msgText);

		MSG_DEBUG(" ######################### MESSAGE UPDATE COMPLETED!!! ######################");
	}
	return err;
}

msg_error_t MsgHandleIncomingMsg(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti)
{
	MSG_BEGIN();

	msg_error_t err = MSG_SUCCESS;

	MsgDisplayLock();

	if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
		bool bOnlyNoti = false;

		err = MsgHandleSMS(pMsgInfo, pSendNoti, &bOnlyNoti);

		if (err == MSG_SUCCESS && ((*pSendNoti) || bOnlyNoti))
			MsgInsertNotification(pMsgInfo);

	} else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
		err = MsgHandleMMS(pMsgInfo, pSendNoti);
	}

	MsgDisplayUnlock();

	/* Add Phone Log Data */
	if ((err == MSG_SUCCESS) &&
		(pMsgInfo->folderId == MSG_INBOX_ID || pMsgInfo->folderId == MSG_SPAMBOX_ID) &&
		(pMsgInfo->msgType.mainType == MSG_SMS_TYPE) &&
		(pMsgInfo->msgType.subType != MSG_WAP_SL_SMS)) {
#ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
		MSG_DEBUG("Enter MsgAddPhoneLog() : pMsg->folderId [%d]", pMsgInfo->folderId);
		MsgAddPhoneLog(pMsgInfo);
#endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
	}

	int activated_conv_id = -1;
	MsgSettingGetInt(VCONFKEY_MESSAGE_ACTIVATED_CONVERSATION_ID, &activated_conv_id);

	if (activated_conv_id > 0 && (unsigned int)activated_conv_id == pMsgInfo->threadId) {
		MSG_WARN("Update message read status of current activated thread. [%d]", pMsgInfo->threadId);
		err = MsgStoUpdateReadStatus(pMsgInfo->msgId, true);
		if (err != MSG_SUCCESS)
			MSG_ERR("MsgStoUpdateReadStatus() is failed. err = %d", err);
	}
	/* Auto delete
	MsgStoAutoDeleteConversation(pMsgInfo->threadId);
	*/

	MSG_END();

	return err;
}


msg_error_t MsgHandleSMS(MSG_MESSAGE_INFO_S *pMsgInfo, bool *pSendNoti, bool *bOnlyNoti)
{
	msg_error_t err = MSG_SUCCESS;
	MsgDbHandler *dbHandle = getDbHandle();

	if (pMsgInfo->msgPort.valid == true) {
		*pSendNoti = false;
		*bOnlyNoti = false;
		return MSG_SUCCESS;
	}

	// Add SMS message
	MSG_SENDINGOPT_INFO_S send_opt;
	memset(&send_opt, 0x00, sizeof(MSG_SENDINGOPT_INFO_S));

	if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
#ifdef MSG_NOTI_INTEGRATION
		MSG_DEBUG("Copy Class2 message to phone storage.");
		pMsgInfo->msgType.classType = MSG_CLASS_NONE;
		pMsgInfo->storageId = MSG_STORAGE_PHONE;
		pMsgInfo->msgId = 0;
#else
		MSG_DEBUG("Class2 message is already added.");
		return MSG_SUCCESS;
#endif
	}

	if (msg_check_dpm_policy(pMsgInfo->msgType.mainType) == false) {
		MSG_DEBUG("Messaging is restricted by DPM policy.");
		pMsgInfo->bRestricted = true;
	}

	if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
		MSG_DEBUG("Add Normal Message");
		err = MsgStoAddMessage(pMsgInfo, &send_opt);
	} else if ((pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
		MSG_DEBUG("Add Replace Message");

		pMsgInfo->msgId = 0;
		MsgStoGetReplaceMsgId(pMsgInfo);

		if (pMsgInfo->msgId > 0) {
			err = MsgStoUpdateMessage(pMsgInfo, &send_opt);
		} else {
			err = MsgStoAddMessage(pMsgInfo, &send_opt);
			pMsgInfo->msgType.subType = MSG_NORMAL_SMS; // To make 'insert' type for storage change callback.
		}
	} else if ((pMsgInfo->msgType.subType == MSG_WAP_SI_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_CO_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_SL_SMS)) {
		MSG_DEBUG("Add WAP Push Message");
		switch (pMsgInfo->msgType.subType) {
			case MSG_WAP_SI_SMS:
			case MSG_WAP_SL_SMS:
				err = MsgStoAddWAPMsg(pMsgInfo);
				break;
			case MSG_WAP_CO_SMS:
				err = MsgStoAddCOWAPMsg(pMsgInfo);
				break;
			default :
				break;
		}
	} else if ((pMsgInfo->msgType.subType == MSG_CB_SMS) || (pMsgInfo->msgType.subType == MSG_JAVACB_SMS)) {
		/** check add message option */
	} else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
		MSG_DEBUG("Add Report Message");
	} else if (pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS) {
		char keyName[MAX_VCONFKEY_NAME_LEN];
		memset(keyName, 0x00, sizeof(keyName));
		snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, pMsgInfo->sim_idx);
		char *voiceNumber = NULL;
		if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
			MSG_INFO("MsgSettingGetString() is failed");
		}

		if (voiceNumber) {
			MSG_SEC_DEBUG("Voice Mail Number [%s]", voiceNumber);

			memset(pMsgInfo->addressList[0].addressVal, 0x00, sizeof(pMsgInfo->addressList[0].addressVal));
			snprintf(pMsgInfo->addressList[0].addressVal, sizeof(pMsgInfo->addressList[0].addressVal), "%s", voiceNumber);
			memset(keyName, 0x00, sizeof(keyName));
			snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, pMsgInfo->sim_idx);
			char *alphaId = NULL;
			if (MsgSettingGetString(keyName, &alphaId) != MSG_SUCCESS) {
				MSG_INFO("MsgSettingGetString() is failed");
			}
			if (alphaId) {
				memset(pMsgInfo->addressList->displayName, 0x00, sizeof(pMsgInfo->addressList->displayName));
				memcpy(pMsgInfo->addressList->displayName, alphaId, sizeof(pMsgInfo->addressList->displayName)-1);
				g_free(alphaId);
				alphaId = NULL;
			}

			free(voiceNumber);
			voiceNumber = NULL;
		}

		memset(keyName, 0x00, sizeof(keyName));
		snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, pMsgInfo->sim_idx);
		int voicecnt = 0;
		if (MsgSettingGetInt(keyName, &voicecnt) != MSG_SUCCESS) {
			MSG_INFO("MsgSettingGetInt() is failed");
		}
		memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
		snprintf(pMsgInfo->msgText, sizeof(pMsgInfo->msgText), "%d", voicecnt);
		pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
		MSG_DEBUG("Add Voice or other Message");
	} else {
		MSG_DEBUG("No matching type [%d]", pMsgInfo->msgType.subType);
		return err;
	}

	if (err != MSG_SUCCESS)
		MSG_DEBUG("Add message - Error : [%d]", err);

	if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS) {
		if (MsgCheckFilter(dbHandle, pMsgInfo) == true) {
			// Move to SpamBox
			err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);

			if (err != MSG_SUCCESS) {
				MSG_DEBUG("MsgStoMoveMessageToFolder() Error : [%d]", err);
			} else {
				pMsgInfo->folderId = MSG_SPAMBOX_ID;
			}

			*pSendNoti = false;
			*bOnlyNoti = false;
		} else if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
			MsgLaunchClass0(pMsgInfo->msgId);
			MsgSoundPlayStart(&(pMsgInfo->addressList[0]), MSG_SOUND_PLAY_USER);

			*pSendNoti = false;
			*bOnlyNoti = false;

			MsgInsertOnlyActiveNotification(MSG_NOTI_TYPE_CLASS0, pMsgInfo);
		}
	} else if ((pMsgInfo->msgType.subType >= MSG_WAP_SI_SMS) && (pMsgInfo->msgType.subType <= MSG_WAP_CO_SMS)) {
		MSG_DEBUG("Starting WAP Message Incoming.");

#ifndef MSG_WEARABLE_PROFILE
		int tmpVal = 0;
		if (MsgSettingGetInt(PUSH_SERVICE_TYPE, &tmpVal) != MSG_SUCCESS) {
			MSG_INFO("MsgSettingGetInt() is failed");
		}
		MSG_PUSH_SERVICE_TYPE_T serviceType = (MSG_PUSH_SERVICE_TYPE_T)tmpVal;
		switch (pMsgInfo->msgType.subType) {
			case MSG_WAP_SL_SMS: {
				*pSendNoti = true;

				if (serviceType == MSG_PUSH_SERVICE_ALWAYS) {
					bundle *b = NULL;
					b = bundle_create();
					if (b == NULL) {
						MSG_DEBUG("bundle_create() is failed");
						break;
					}

					err = msg_aul_svc_set_operation(b, "http://tizen.org/appcontrol/operation/view");
					if (err != MSG_SUCCESS) {
						MSG_DEBUG("msg_aul_svc_set_operation() is failed : %d", err);
						bundle_free(b);
						break;
					}

					err = msg_aul_svc_set_uri(b, pMsgInfo->msgText);
					if (err != MSG_SUCCESS) {
						MSG_DEBUG("msg_aul_svc_set_uri() is failed : %d", err);
						bundle_free(b);
						break;
					}

					err = msg_launch_app(MSG_SVC_PKG_NAME_BROWSER, b);
					if (err != MSG_SUCCESS) {
						MSG_DEBUG("msg_launch_app() is failed : %d", err);
					}

					bundle_free(b);
				} else if (serviceType == MSG_PUSH_SERVICE_PROMPT) {
					MSG_DEBUG("WAP Message SL(Always Ask) start.");

					int ret = 0;
					bundle *b = NULL;
					b = bundle_create();
					if (b == NULL) {
						MSG_DEBUG("bundle_create() is failed");
						break;
					}

					ret = bundle_add_str(b, "mode", "WAP_PUSH_SL");
					if (ret != 0) {
						MSG_DEBUG("bundle_add_str() is failed : %d", ret);
						bundle_free(b);
						break;
					}

					ret = bundle_add_str(b, "url", pMsgInfo->msgText);
					if (ret != 0) {
						MSG_DEBUG("bundle_add_str() is failed : %d", ret);
						bundle_free(b);
						break;
					}

					ret = bundle_add_str(b, "address", pMsgInfo->addressList[0].addressVal);
					if (ret != 0) {
						MSG_DEBUG("bundle_add_str() is failed : %d", ret);
						bundle_free(b);
						break;
					}

					err = msg_launch_app("org.tizen.message-dialog", b);
					if (err != MSG_SUCCESS) {
						MSG_DEBUG("msg_launch_app() is failed : %d", err);
					}

					bundle_free(b);
				}
			}
			break;

			case MSG_WAP_SI_SMS:
				*pSendNoti = true;
				break;
			case MSG_WAP_CO_SMS:
				*pSendNoti = false;
				MsgInsertOnlyActiveNotification(MSG_NOTI_TYPE_NORMAL, pMsgInfo);
				break;
		}
#endif // MSG_WEARABLE_PROFILE
	} else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
		*pSendNoti = false;
		*bOnlyNoti = true;
	} else if (pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS) {
		if (pMsgInfo->bStore == false) {
			*pSendNoti = false;
			*bOnlyNoti = true;
		}
	}

	// Update Conversation table
	err = MsgStoUpdateConversation(dbHandle, pMsgInfo->threadId);

	if (err != MSG_SUCCESS)
		MSG_DEBUG("MsgStoUpdateConversation() Error : [%d]", err);

	return err;
}


msg_error_t MsgHandleMMS(MSG_MESSAGE_INFO_S *pMsgInfo,  bool *pSendNoti)
{
	msg_error_t err = MSG_SUCCESS;
	MsgDbHandler *dbHandle = getDbHandle();
	MSG_REQUEST_INFO_S request = {0};
	bool bReject = false;
	bool bFiltered = false;

	// MMS Received Ind Process Func
	MSG_MAIN_TYPE_T msgMainType = pMsgInfo->msgType.mainType;
	MsgPlugin *plg = MsgPluginManager::instance()->getPlugin(msgMainType);

	if (plg == NULL)
		return MSG_ERR_NULL_POINTER;

	// Read the default network SIM
	MsgPlugin *sms_plg = MsgPluginManager::instance()->getPlugin(MSG_SMS_TYPE);

	if (sms_plg == NULL)
		return MSG_ERR_NULL_POINTER;

	int defaultNetworkSimId = 0;

	err = sms_plg->getDefaultNetworkSimId(&defaultNetworkSimId);

	MSG_DEBUG("######defaultNetworkSimId = %d, err = %d", defaultNetworkSimId, err);

	if (err != MSG_SUCCESS) {
		MSG_ERR("getDefaultNetworkSimId is failed=[%d]", err);
		return err;
	}

	err = MsgSettingSetInt(MSG_NETWORK_SIM, (int)defaultNetworkSimId);
	if (err != MSG_SUCCESS) {
		MSG_ERR("Error to set config data [%s], err = %d", MSG_NETWORK_SIM, err);
		return err;
	}

	// Need to process m-delivery-ind, m-notification-ind, m-read-orig-ind
	err = plg->processReceivedInd(pMsgInfo, &request, &bReject);

	if (err == MSG_SUCCESS) {
		MSG_DEBUG("Process Message Success : processReceivedInd(), btextsms %d", pMsgInfo->bTextSms);
	} else {
		MSG_DEBUG("Process Message Fail : processReceivedInd()");
		*pSendNoti = false;
		return err;
	}

	// Add into DB
	if ((pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) && bReject == false) {
		/* It should send noti response even if MMS is blocked by sender address. */
		//bFiltered = MsgCheckFilter(dbHandle, pMsgInfo);
		if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
			bFiltered = true;
		}

		if (bFiltered == true) {
			err = MsgStoMoveMessageToFolder(pMsgInfo->msgId, MSG_SPAMBOX_ID);

			if (err != MSG_SUCCESS) {
				MSG_DEBUG("MsgStoMoveMessageToFolder() Error : [%d]", err);
			} else {
				pMsgInfo->folderId = MSG_SPAMBOX_ID;
			}

			pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_FAIL;
			*pSendNoti = false;
		} else {/* If it is not SPAM message, it should be check whether filter option is enable or not. */
			bool filterFlag = false;
			MsgGetFilterOperation(&filterFlag);
			if (filterFlag == true && request.msgInfo.msgType.subType == MSG_GET_MMS) {
				 /* Not to show MMS notification msg until it retrieves. */
				pMsgInfo->folderId = MSG_IOSBOX_ID;
				*pSendNoti = false;
			}
		}

		if (msg_check_dpm_policy(pMsgInfo->msgType.mainType) == false) {
			MSG_DEBUG("Messaging is restricted by DPM policy.");
			pMsgInfo->bRestricted = true;
			*pSendNoti = false;
		}

		err = MsgStoAddMessage(pMsgInfo, NULL);

		if (err != MSG_SUCCESS) {
			MSG_DEBUG("MsgStoAddMessage() Error: [%d]", err);
			return err;
		}
	} else if (pMsgInfo->msgType.subType == MSG_READORGIND_MMS || pMsgInfo->msgType.subType == MSG_DELIVERYIND_MMS) {
		if (MsgInsertNotification(pMsgInfo) == MSG_SUCCESS)
			*pSendNoti = false;
	}

#if 0
	if (pMsgInfo->bTextSms == false) {
		MsgDeleteFile(pMsgInfo->msgData); //ipc
		memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
	}
#endif
	//In the case of m-notification-ind, we should decide whether to send m-notify-response-ind or http 'Get'
	//submit request
	if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
		if (request.msgInfo.msgType.subType == MSG_NOTIFYRESPIND_MMS && bReject == false && bFiltered == false)
			MsgInsertNotification(pMsgInfo);
		else
			*pSendNoti = false;

		MSG_DEBUG("default_sim = %d, pMsgInfo->sim_idx = %d", defaultNetworkSimId, pMsgInfo->sim_idx);

		if (defaultNetworkSimId == pMsgInfo->sim_idx) {
			request.msgInfo.msgId = pMsgInfo->msgId;

			MSG_SEC_DEBUG("-=====================[[[ %s ]]]] =========================", request.msgInfo.msgData);
			err = plg->submitReq(&request);

			if (err == MSG_SUCCESS) {
				MSG_DEBUG("Process Message Success : processReceivedInd()");

				if (request.msgInfo.msgType.subType == MSG_GET_MMS) {
					MSG_DEBUG("Auto Retrieve Mode : update network status retrieving");
					MsgStoUpdateNetworkStatus(dbHandle, &(request.msgInfo), MSG_NETWORK_RETRIEVING);
				}

			} else {
				MSG_DEBUG("Process Message Fail : processReceivedInd()");
			}
		}
	}

	return err;
}