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