Fix for 37448
[apps/osp/Call.git] / src / CallPresentationModel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
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 /**
18  * @file        CallCallPresentationModel.cpp
19  * @brief       Call Presentation model class
20  */
21 #include <FApp.h>
22 #include <FUi.h>
23 #include <FMedia.h>
24 #include "CallApp.h"
25 #include "CallAppControlRequestMgr.h"
26 #include "CallActiveCallForm.h"
27 #include "CallInfo.h"
28 #include "CallPresentationModel.h"
29 #include "CallSettingsPresentationModel.h"
30 #include "CallConfCallerListForm.h"
31 #include "CallTelephonyManager.h"
32 #include "CallSceneRegister.h"
33 #include "CallTypes.h"
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::App;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Media;
40 using namespace Tizen::Social;
41 using namespace Tizen::Ui::Scenes;
42 using namespace Tizen::Telephony;
43 using namespace Tizen::Base::Utility;
44
45 CallPresentationModel* CallPresentationModel::__pInstance = null;
46
47 CallPresentationModel::CallPresentationModel(void)
48 {
49         __pTelephonyMgr = null;
50         __pTelEventListener = null;
51         __pSettingsPresentor = null;
52         __isMessageAppControlRunning = false;
53         __isDialAppControlRunning = false;
54         __pAppControlMgr = null;
55         __pNetworkManager = null;
56         __psimStateManager = null;
57         __psimInfo = null;
58 }
59
60 CallPresentationModel::~CallPresentationModel(void)
61 {
62         __pTelephonyMgr = null;
63         __pSettingsPresentor = null;
64         __pAppControlMgr =null;
65         if(__pNetworkManager != null)
66         {
67                 delete __pNetworkManager;
68                 __pNetworkManager = null;
69         }
70         if(__psimStateManager != null)
71         {
72                 delete __psimStateManager;
73                 __psimStateManager = null;
74         }
75         if(__psimInfo != null)
76         {
77                 delete __psimInfo;
78                 __psimInfo = null;
79         }
80 }
81
82 void
83 CallPresentationModel::CreateInstance(void)
84 {
85         __pInstance = new (std::nothrow) CallPresentationModel();
86         result r = __pInstance->Construct();
87         if(IsFailed(r))
88         {
89                 delete __pInstance;
90                 __pInstance = null;
91                 return;
92         }
93
94         std::atexit(DestroyInstance);
95 }
96
97 CallPresentationModel*
98 CallPresentationModel::GetInstance(void)
99 {
100         if (__pInstance == null)
101         {
102                 CreateInstance();
103         }
104         return __pInstance;
105 }
106
107 void
108 CallPresentationModel::DestroyInstance(void)
109 {
110         if (__pInstance != null)
111         {
112                 delete __pInstance;
113                 __pInstance = null;
114         }
115 }
116
117 result
118 CallPresentationModel::Construct(void)
119 {
120         //Fetch Telephony Manager
121         __pTelephonyMgr = TelephonyManager::GetInstance(this);
122         __pSettingsPresentor = SettingsPresentationModel::GetInstance();
123         __pAppControlMgr = CallAppControlRequestMgr::GetInstance();
124         __pNetworkManager = new (std::nothrow)NetworkManager();
125         __pNetworkManager->Construct(null);
126         GetSimInfo();
127         return E_SUCCESS;
128 }
129
130 void
131 CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventListener)
132 {
133         //set form as telephony event listener
134         __pTelEventListener = pTelEventListener;
135 }
136
137 bool
138 CallPresentationModel::IfNumberEndsWithHash(Tizen::Base::String& phoneNumber)
139 {
140         String phoneNumberEndingWithHash(L"#$");
141         RegularExpression checkHash;
142         checkHash.Construct(phoneNumberEndingWithHash);
143         bool endsWithHash = checkHash.Match(phoneNumber,false);
144         if(endsWithHash == true)
145         {
146                 return true;
147         }
148         return false;
149 }
150
151 void
152 CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
153 {
154         int errorCode = ERROR_NONE;
155         bool isCallServiceAvailable = false;
156         bool numberEndsWithHash = false;
157         NetworkStatus networkStatus;
158         result r;
159         //Check if Telephony Manager is initialized
160         TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
161
162         //check if phone is in flight mode
163         if(__pSettingsPresentor != null && __pSettingsPresentor->GetFlightModeStatus() == true)
164         {
165                 __pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
166                 return;
167         }
168         //Check if dialing a call is possible - Check if sim is available
169         if (IsSimAvailable() == false)
170         {
171                 __pTelEventListener->HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
172                 return ;
173         }
174
175         //fetch call service status
176         if(__pNetworkManager != null)
177         {
178                 r = __pNetworkManager->GetNetworkStatus(networkStatus);
179                 if (r == E_SUCCESS)
180                 {
181                         isCallServiceAvailable = networkStatus.IsCallServiceAvailable();
182                 }
183         }
184
185
186         if (isCallServiceAvailable == false)
187         {
188                 __pTelEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
189                 return ;
190         }
191         // check if GPRS number
192         numberEndsWithHash = IfNumberEndsWithHash(contactNumber);
193         if(numberEndsWithHash == true)
194         {
195                 __pTelEventListener->HandleTelephonyError(ERROR_GPRS_NUMBER);
196                 return ;
197         }
198
199         //setup outgoing call
200         errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
201         TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
202         if(__pSettingsPresentor != null)
203         {
204                 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
205         }
206         return;
207
208 CATCH:
209         __pTelEventListener->HandleTelephonyError(errorCode);
210 }
211
212 void
213 CallPresentationModel::EndActiveCall(Long callHandle)
214 {
215         if(__pTelephonyMgr != null)
216         {
217                 __pTelephonyMgr->EndActiveCall(callHandle);
218         }
219 }
220
221 void
222 CallPresentationModel::EndDialingCall(String& contactNumber)
223 {
224         if(__pTelephonyMgr != null)
225         {
226                 __pTelephonyMgr->EndDialingCall(contactNumber);
227         }
228 }
229
230 bool
231 CallPresentationModel::EndConferenceCall(void)
232 {
233         result r = __pTelephonyMgr->EndConferenceCall();
234         if (IsFailed(r))
235         {
236                 //TODO: send proper error code
237                 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
238                 return false;
239         }
240         return true;
241 }
242
243 void
244 CallPresentationModel::EndAllCall(void)
245 {
246         if(__pTelephonyMgr != null)
247         {
248                 __pTelephonyMgr->EndAllCalls();
249         }
250 }
251 bool
252 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
253 {
254         result r = __pTelephonyMgr->HoldCall(callHandle, true);
255         return (!IsFailed(r));
256 }
257
258 bool
259 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
260 {
261         result r = __pTelephonyMgr->HoldCall(callHandle, false);
262         return (!IsFailed(r));
263 }
264
265 bool
266 CallPresentationModel::HoldConferenceCall(void)
267 {
268         result r = __pTelephonyMgr->HoldConferenceCall(true);
269         return (!IsFailed(r));
270 }
271
272 bool
273 CallPresentationModel::ActivateConferenceCall(void)
274 {
275         result r = __pTelephonyMgr->HoldConferenceCall(false);
276         return (!IsFailed(r));
277 }
278
279 void
280 CallPresentationModel::JoinCall(void)
281 {
282         result r = __pTelephonyMgr->JoinCall();
283         if (IsFailed(r))
284         {
285                 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
286         }
287 }
288
289 void
290 CallPresentationModel::SwapCalls(void)
291 {
292         result r = __pTelephonyMgr->SwapCalls();
293         if (IsFailed(r))
294         {
295                 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
296         }
297 }
298
299 bool
300 CallPresentationModel::SetMuteStatus(bool setMute)
301 {
302         result r = __pTelephonyMgr->SetMuteStatus(setMute);
303         return (!IsFailed(r));
304 }
305
306 bool
307 CallPresentationModel::IsCallMuted(void)
308 {
309         return __pTelephonyMgr->IsCallMuted();
310 }
311
312 bool
313 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
314 {
315         result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
316         return (!IsFailed(r));
317 }
318
319 bool
320 CallPresentationModel::IsSpeakerOn(void)
321 {
322         return __pTelephonyMgr->IsSpeakerOn();
323 }
324 void
325 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
326 {
327         __pTelephonyMgr->SendCallDTMF(textToBeSent);
328 }
329
330 AppCallInfo*
331 CallPresentationModel::GetConferenceCallInfoN(void)
332 {
333         return __pTelephonyMgr->GetConferenceCallInfoN();
334 }
335
336 bool
337 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<AppCallInfo>* pConfCallList)
338 {
339         int callIndex = -1;
340         AppCallInfo callToBeSpli;
341         switch (splitCallerCmdId)
342         {
343         case IDA_SPLIT_CALLER1:
344                 callIndex = 0;
345                 break;
346
347         case IDA_SPLIT_CALLER2:
348                 callIndex = 1;
349                 break;
350
351         case IDA_SPLIT_CALLER3:
352                 callIndex = 2;
353                 break;
354
355         case IDA_SPLIT_CALLER4:
356                 callIndex = 3;
357                 break;
358
359         case IDA_SPLIT_CALLER5:
360                 callIndex = 4;
361                 break;
362
363         default:
364         break;
365         }
366
367         result r = pConfCallList->GetAt(callIndex, callToBeSpli);
368         TryCatch(r == E_SUCCESS,,"conf. call list corrupted");
369         //split single call from conference
370         r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
371         TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
372         return true;
373
374 CATCH:
375         __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
376         return false;
377 }
378
379 void
380 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<AppCallInfo>* pConfCallList)
381 {
382         int callIndex = -1;
383         AppCallInfo callToBeEnded;
384         switch (endCallerCmdId)
385         {
386         case IDA_END_CALLER1:
387                 callIndex = 0;
388                 break;
389
390         case IDA_END_CALLER2:
391                 callIndex = 1;
392                 break;
393
394         case IDA_END_CALLER3:
395                 callIndex = 2;
396                 break;
397
398         case IDA_END_CALLER4:
399                 callIndex = 3;
400                 break;
401
402         case IDA_END_CALLER5:
403                 callIndex = 4;
404                 break;
405
406         default:
407         break;
408         }
409
410         result r = pConfCallList->GetAt(callIndex, callToBeEnded);
411         TryCatch(r == E_SUCCESS,,"conference call list corrupted");
412         //end single call
413         r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
414         TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
415
416         return;
417
418 CATCH:
419         __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
420         return;
421 }
422
423 bool
424 CallPresentationModel::IsSplitAllowed(void)
425 {
426         return __pTelephonyMgr->IsSplitAllowed();
427 }
428
429 void
430 CallPresentationModel::AcceptIncomingCall(CallAnsweringOptions answerOptions,int callHandle)
431 {
432         result r = E_FAILURE;
433         if (answerOptions == ANSERWING_OPTION_ACCEPT_CALL)
434         {
435                 r = __pTelephonyMgr->AnswerCall(callHandle, true);
436         }
437         else
438         {
439                 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
440         }
441         if (IsFailed(r))
442         {
443                 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
444         }
445 }
446
447 IListT<AppCallInfo>*
448 CallPresentationModel::GetCallListN(void)
449 {
450         return __pTelephonyMgr->GetCallListN();
451 }
452
453
454 bool
455 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
456 {
457         AppLogDebug("Enter");
458         if (sendMsg == true && __pAppControlMgr != null)
459         {
460                 //launch compose message AppControl
461                 __isMessageAppControlRunning = __pAppControlMgr->LaunchComposeMessageAppControl(*(const_cast<String*>(&contactNumber)), this);
462         }
463         result r = __pTelephonyMgr->AnswerCall(callHandle, false);
464         if (IsFailed(r))
465         {
466                 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
467                 return false;
468         }
469
470
471         AppLogDebug("Exit");
472         return true;
473 }
474
475 void CallPresentationModel::OnAppForeground(void)
476 {
477         if (__isDialAppControlRunning == true)
478         {
479                 //This comes here, when Dialer AppControl is finished working.
480                 __isDialAppControlRunning = false;
481                 __pAppControlMgr->AppControlRequestCompleted();
482         }
483         if (__isMessageAppControlRunning == true)
484         {
485                 //This comes here, when Message AppControl is finished working.
486                 __isMessageAppControlRunning = false;
487                 __pAppControlMgr->AppControlRequestCompleted();
488                 //Check if this was the last call, then terminate application.
489                 //And if any calls are active, then those cases are already handled from Other places.
490                 if( GetCurrentCallCount() == 0)
491                 {
492                         CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
493                         pPhoneApp->Terminate();
494                 }
495         }
496 }
497
498 void
499 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
500 {
501         AppLogDebug("Enter");
502         if (__isMessageAppControlRunning == true)
503         {
504                 //This comes here, when Message AppControl is finished working.
505                 __isMessageAppControlRunning = false;
506                 __pAppControlMgr->AppControlRequestCompleted();
507                 //Check if this was the last call, then terminate application.
508                 //And if any calls are active, then those cases are already handled from Other places.
509                 if( GetCurrentCallCount() == 0)
510                 {
511                         CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
512                         pPhoneApp->Terminate();
513                 }
514         }
515         if(appId.Equals(PROVIDER_ID_PHONE,false) == true &&  operationId.Equals(OPERATION_ID_DIAL,false) == true)
516         {
517                 __isDialAppControlRunning = false;
518
519                 __pAppControlMgr->AppControlRequestCompleted();
520                 if(appControlResult == APP_CTRL_RESULT_SUCCEEDED)
521                 {
522                         String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
523                         if (pExtraData->ContainsKey(*pKey) == true)
524                         {
525                                 const String* pPhoneNumber = static_cast<const String*>(pExtraData->GetValue(*pKey));
526                                 if(pPhoneNumber != null && pPhoneNumber->IsEmpty() == false)
527                                 {
528                                         AddCall(*pPhoneNumber);
529                                 }
530
531                         }
532
533                 }
534
535         }
536 }
537
538 void
539 CallPresentationModel::AddCall(const String& phoneNumber)
540 {
541         ArrayList* pLaunchArgs = null;
542         SceneManager* pSceneManager = SceneManager::GetInstance();
543         int currentActiveCallCount = GetCurrentCallCount();
544         if(currentActiveCallCount <= 1 && IsIncomingorDialingCallPresent() == false)
545         {
546                 //make an outgoing call with given number
547                 String* contactTxt = new (std::nothrow) String(phoneNumber);
548                 pLaunchArgs =  new (std::nothrow) ArrayList(SingleObjectDeleter);
549                 pLaunchArgs->Construct();
550                 pLaunchArgs->Add(contactTxt);
551                 bool isEmergencyCall = IsEmergencyNumber(*contactTxt, true);
552
553                 SceneId nextScene = IDSCN_SCENE_OUTCALL;
554                 if (isEmergencyCall)
555                 {
556                         nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
557                 }
558                 pSceneManager->GoForward( ForwardSceneTransition( nextScene), pLaunchArgs);
559
560         }
561 }
562
563 int
564 CallPresentationModel::GetCurrentCallCount(void)
565 {
566         return __pTelephonyMgr->GetCurrentCallCount();
567 }
568
569 bool
570 CallPresentationModel::CheckSimInitializationIsCompleted()
571 {
572         result r = E_FAILURE;
573         if(__pTelephonyMgr != null)
574         {
575                 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
576         }
577         return (!IsFailed(r));
578 }
579
580 bool
581 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
582 {
583         return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
584 }
585
586 void
587 CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
588 {
589         //Adding incoming call sate setting here
590         if(__pSettingsPresentor != null)
591         {
592                 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
593         }
594         __pTelephonyMgr->StartAlert(incomingCallInfo);
595 }
596
597 void
598 CallPresentationModel::StopAlert(void)
599 {
600         __pTelephonyMgr->StopAlert();
601 }
602
603 Contact*
604 CallPresentationModel::GetContactN(const String& phoneNumber)
605 {
606         return __pTelephonyMgr->GetContactN(phoneNumber);
607 }
608
609 AppCallInfo*
610 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
611 {
612
613         return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
614 }
615
616 bool
617 CallPresentationModel::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
618 {
619         return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
620 }
621
622 /////////////////////////////////////////////////////////////////
623 /////  Event Listener methods from ITelephonyEventListener  /////
624 /////////////////////////////////////////////////////////////////
625 void
626 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
627 {
628         if (__pTelEventListener != null)
629         {
630                 __pTelEventListener->HandleCallConnected(pCallList);
631         }
632         if(__pSettingsPresentor != null)
633         {
634                 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
635         }
636 }
637
638 void
639 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
640 {
641         AppLogDebug("Enter");
642         if (isLastCall == true)
643         {
644                 SetSpeakerStatus(false);
645                 SetMuteStatus(false);
646                 if(__pSettingsPresentor != null)
647                 {
648                         __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
649                 }
650         }
651         else
652         {
653                 if(__pSettingsPresentor != null)
654                 {
655                         __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
656                 }
657         }
658         //1) Defer from sending call disconnected event to form, in case Msg AppControl is running,
659         //to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
660         //2) Do not send call disconnected event to any form, in case an incoming call or dialing call is present.
661         if (__pTelEventListener != null /*&& __isMessageAppControlRunning == false*/ )
662         {
663                 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
664         }
665 }
666
667 void
668 CallPresentationModel::HandleConferenceCall(AppCallInfo& pCallInfo)
669 {
670         if (__pTelEventListener != null)
671         {
672                 __pTelEventListener->HandleConferenceCall(pCallInfo);
673         }
674 }
675
676 void
677 CallPresentationModel::HandleIncomingCall(AppCallInfo& pCallInfo)
678 {
679         AppLogDebug("Error - This will never come here. Since, now we are getting incoming call event through AppControl!!");
680 }
681
682 void
683 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
684 {
685         if (__pTelEventListener != null)
686         {
687                 __pTelEventListener->HandleCallSwapOccured(pCallList);
688         }
689 }
690
691 void
692 CallPresentationModel::HandleConferenceChange(void)
693 {
694         //1) Do not send conf. call changed event to any form, in case an incoming call or dialing call is present.
695         if (__pTelEventListener != null)
696         {
697                 __pTelEventListener->HandleConferenceChange();
698         }
699 }
700
701 void
702 CallPresentationModel::HandleTelephonyError(int errorCode)
703 {
704         if (__pTelEventListener != null)
705         {
706                 __pTelEventListener->HandleTelephonyError(errorCode);
707         }
708 }
709
710 void
711 CallPresentationModel::LaunchDialAppControl()
712 {
713
714         if(__isDialAppControlRunning == true)
715         {
716                 //Do not allow another app control if already running
717                 return;
718         }
719
720         //Launch dialer AppControl
721         if (__pAppControlMgr != null)
722         {
723                 __isDialAppControlRunning = __pAppControlMgr->LaunchDialerAppControl(this);
724         }
725
726 }
727
728 bool
729 CallPresentationModel::IsEnableJoinCallButton(void)
730 {
731         //Check if conf. call has maximum participants
732         AppCallInfo* pConfCallInfo = GetConferenceCallInfoN();
733         if(pConfCallInfo != null && pConfCallInfo->GetCallerListCount() >= IDI_MAX_CONF_CALL_PARTICIPANTS)
734         {
735                 return false;
736         }
737
738         //check if either of the caller is same or present in conf call.
739         IListT<AppCallInfo>* pActiveCallList = GetCallListN();
740         if ( pActiveCallList != null && pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
741         {
742                 AppCallInfo firstCall;
743                 AppCallInfo secondCall;
744                 pActiveCallList->GetAt(0, firstCall);
745                 pActiveCallList->GetAt(1, secondCall);
746
747                 if (firstCall.IsConferenceCall() == true)
748                 {
749                         IListT<AppCallInfo>* pConfMemberList = firstCall.GetCallerList();
750                         for (int index = 0; index < pConfMemberList->GetCount(); index++)
751                         {
752                                 AppCallInfo singleConfMember;
753                                 pConfMemberList->GetAt(index, singleConfMember);
754                                 if (secondCall.GetContactNumber().IsEmpty() == false && secondCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
755                                 {
756                                         return false;
757                                 }
758                         }
759                 }
760                 else if (secondCall.IsConferenceCall() == true)
761                 {
762                         IListT<AppCallInfo>* pConfMemberList = secondCall.GetCallerList();
763                         for (int index = 0; index < pConfMemberList->GetCount(); index++)
764                         {
765                                 AppCallInfo singleConfMember;
766                                 pConfMemberList->GetAt(index, singleConfMember);
767                                 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
768                                 {
769                                         return false;
770                                 }
771                         }
772                 }
773                 else
774                 {
775                         //Now, we definitely know that both are single active calls.
776                         if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(secondCall.GetContactNumber()) == true)
777                         {
778                                 return false;
779                         }
780                 }
781         }
782         delete pConfCallInfo;
783         pConfCallInfo = null;
784         return true;
785 }
786
787 bool
788 CallPresentationModel::IsIncomingorDialingCallPresent(void)
789 {
790         //returns false, if incoming call or dialed call is present.
791         return __pTelephonyMgr->IsIncomingorDialingCallPresent();
792 }
793
794 bool
795 CallPresentationModel::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
796 {
797         if (__pAppControlMgr != null)
798         {
799                 return __pAppControlMgr->LaunchComposeMessageAppControl(contactNumber, pListener);
800         }
801         return false;
802 }
803
804 bool
805 CallPresentationModel::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
806 {
807         if (__pAppControlMgr != null)
808         {
809                 return __pAppControlMgr->LaunchViewContactAppControl(contactId, pListener);
810         }
811         return false;
812 }
813
814 bool
815 CallPresentationModel::LaunchAddContactAppControl(Tizen::Base::String& contactNumber, Tizen::App::IAppControlResponseListener* pListener)
816 {
817         if (__pAppControlMgr != null)
818         {
819                 return __pAppControlMgr->LaunchAddContactAppControl(contactNumber, pListener);
820         }
821         return false;
822 }
823
824 bool
825 CallPresentationModel::IsAppControlRunning(void)
826 {
827         if (__pAppControlMgr != null)
828         {
829                 return __pAppControlMgr->IsAppControlRunning();
830         }
831         return false;
832 }
833
834 void
835 CallPresentationModel::AbortAppControlRequest(void)
836 {
837         if (__pAppControlMgr != null)
838         {
839                 __pAppControlMgr->AbortAppControlRequest();
840         }
841 }
842
843 void
844 CallPresentationModel::AppControlRequestCompleted(void)
845 {
846         if (__pAppControlMgr != null)
847         {
848                 __pAppControlMgr->AppControlRequestCompleted();
849         }
850 }
851
852 result
853 CallPresentationModel::GetSimInfo(void)
854 {
855         __psimStateManager = new (std::nothrow)SimStateManager();
856         result r = __psimStateManager->Construct();
857         if (IsFailed(r))
858         {
859                 delete __psimStateManager;
860                 __psimStateManager = null;
861                 return E_FAILURE;
862         }
863         __psimStateManager->SetSimEventListener(this);
864
865         __psimInfo = new (std::nothrow)SimInfo();
866         r = __psimStateManager->GetSimInfo(*__psimInfo);
867         if (IsFailed(r))
868         {
869                 delete __psimStateManager;
870                 __psimStateManager = null;
871                 delete __psimInfo;
872                 __psimInfo = null;
873                 return E_FAILURE;
874         }
875         return E_SUCCESS;
876 }
877
878 void
879 CallPresentationModel::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
880 {
881
882 }
883
884 void
885 CallPresentationModel::OnTelephonySimStateChanged(Tizen::Telephony::SimState state)
886 {
887         if(__psimStateManager != null)
888         {
889                 delete __psimStateManager;
890                 __psimStateManager =null;
891         }
892         if(__psimInfo != null)
893         {
894                 delete __psimInfo;
895                 __psimInfo = null;
896         }
897
898         __psimStateManager = new SimStateManager();
899         result r = __psimStateManager->Construct();
900         if (IsFailed(r))
901         {
902                 delete __psimStateManager;
903                 __psimStateManager = null;
904                 return ;
905         }
906
907         __psimInfo = new SimInfo();
908         r = __psimStateManager->GetSimInfo(*__psimInfo);
909         if (IsFailed(r))
910         {
911                 delete __psimStateManager;
912                 __psimStateManager = null;
913                 delete __psimInfo;
914                 __psimInfo = null;
915                 return ;
916         }
917
918 }
919
920 bool
921 CallPresentationModel::IsSimAvailable(void)
922 {
923         if(__psimInfo != null)
924         {
925                 return __psimInfo->IsAvailable();
926         }
927         else
928         {
929                 return false;
930         }
931
932
933 }
934