2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file CallCallPresentationModel.cpp
19 * @brief Call Presentation model class
25 #include "CallAppControlRequestMgr.h"
26 #include "CallActiveCallForm.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"
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;
43 CallPresentationModel* CallPresentationModel::__pInstance = null;
45 CallPresentationModel::CallPresentationModel(void)
47 __pTelephonyMgr = null;
48 __pTelEventListener = null;
49 __pSettingsPresentor = null;
50 __isMessageAppControlRunning = false;
51 __isDialAppControlRunning = false;
52 __pAppControlMgr = null;
55 CallPresentationModel::~CallPresentationModel(void)
57 __pTelephonyMgr = null;
58 __pSettingsPresentor = null;
59 __pAppControlMgr =null;
63 CallPresentationModel::CreateInstance(void)
65 __pInstance = new (std::nothrow) CallPresentationModel();
66 result r = __pInstance->Construct();
74 std::atexit(DestroyInstance);
77 CallPresentationModel*
78 CallPresentationModel::GetInstance(void)
80 if (__pInstance == null)
88 CallPresentationModel::DestroyInstance(void)
90 if (__pInstance != null)
98 CallPresentationModel::Construct(void)
100 //Fetch Telephony Manager
101 __pTelephonyMgr = TelephonyManager::GetInstance(this);
102 __pSettingsPresentor = SettingsPresentationModel::GetInstance();
103 __pAppControlMgr = CallAppControlRequestMgr::GetInstance();
108 CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventListener)
110 //set form as telephony event listener
111 __pTelEventListener = pTelEventListener;
115 CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
117 int errorCode = ERROR_NONE;
118 //Check if Telephony Manager is initialized
119 TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
121 //check if phone is in flight mode
122 if(__pSettingsPresentor != null && __pSettingsPresentor->GetFlightModeStatus() == true)
124 __pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
127 //setup outgoing call
128 errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
129 TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
130 if(__pSettingsPresentor != null)
132 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
137 __pTelEventListener->HandleTelephonyError(errorCode);
141 CallPresentationModel::EndActiveCall(Long callHandle)
143 if(__pTelephonyMgr != null)
145 __pTelephonyMgr->EndActiveCall(callHandle);
150 CallPresentationModel::EndDialingCall(String& contactNumber)
152 if(__pTelephonyMgr != null)
154 __pTelephonyMgr->EndDialingCall(contactNumber);
159 CallPresentationModel::EndConferenceCall(void)
161 result r = __pTelephonyMgr->EndConferenceCall();
164 //TODO: send proper error code
165 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
172 CallPresentationModel::EndAllCall(void)
174 if(__pTelephonyMgr != null)
176 __pTelephonyMgr->EndAllCalls();
180 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
182 result r = __pTelephonyMgr->HoldCall(callHandle, true);
183 return (!IsFailed(r));
187 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
189 result r = __pTelephonyMgr->HoldCall(callHandle, false);
190 return (!IsFailed(r));
194 CallPresentationModel::HoldConferenceCall(void)
196 result r = __pTelephonyMgr->HoldConferenceCall(true);
197 return (!IsFailed(r));
201 CallPresentationModel::ActivateConferenceCall(void)
203 result r = __pTelephonyMgr->HoldConferenceCall(false);
204 return (!IsFailed(r));
208 CallPresentationModel::JoinCall(void)
210 result r = __pTelephonyMgr->JoinCall();
213 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
218 CallPresentationModel::SwapCalls(void)
220 result r = __pTelephonyMgr->SwapCalls();
223 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
228 CallPresentationModel::SetMuteStatus(bool setMute)
230 result r = __pTelephonyMgr->SetMuteStatus(setMute);
231 return (!IsFailed(r));
235 CallPresentationModel::IsCallMuted(void)
237 return __pTelephonyMgr->IsCallMuted();
241 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
243 result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
244 return (!IsFailed(r));
248 CallPresentationModel::IsSpeakerOn(void)
250 return __pTelephonyMgr->IsSpeakerOn();
253 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
255 __pTelephonyMgr->SendCallDTMF(textToBeSent);
259 CallPresentationModel::GetConferenceCallInfoN(void)
261 return __pTelephonyMgr->GetConferenceCallInfoN();
265 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<AppCallInfo>* pConfCallList)
268 AppCallInfo callToBeSpli;
269 switch (splitCallerCmdId)
271 case IDA_SPLIT_CALLER1:
275 case IDA_SPLIT_CALLER2:
279 case IDA_SPLIT_CALLER3:
283 case IDA_SPLIT_CALLER4:
287 case IDA_SPLIT_CALLER5:
295 result r = pConfCallList->GetAt(callIndex, callToBeSpli);
296 TryCatch(r == E_SUCCESS,,"conf. call list corrupted");
297 //split single call from conference
298 r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
299 TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
303 __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
308 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<AppCallInfo>* pConfCallList)
311 AppCallInfo callToBeEnded;
312 switch (endCallerCmdId)
314 case IDA_END_CALLER1:
318 case IDA_END_CALLER2:
322 case IDA_END_CALLER3:
326 case IDA_END_CALLER4:
330 case IDA_END_CALLER5:
338 result r = pConfCallList->GetAt(callIndex, callToBeEnded);
339 TryCatch(r == E_SUCCESS,,"conference call list corrupted");
341 r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
342 TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
347 __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
352 CallPresentationModel::IsSplitAllowed(void)
354 return __pTelephonyMgr->IsSplitAllowed();
358 CallPresentationModel::AcceptIncomingCall(CallAnsweringOptions answerOptions,int callHandle)
360 result r = E_FAILURE;
361 if (answerOptions == ANSERWING_OPTION_ACCEPT_CALL)
363 r = __pTelephonyMgr->AnswerCall(callHandle, true);
367 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
371 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
376 CallPresentationModel::GetCallListN(void)
378 return __pTelephonyMgr->GetCallListN();
383 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
385 AppLogDebug("Enter");
386 result r = __pTelephonyMgr->AnswerCall(callHandle, false);
389 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
393 if (sendMsg == true && __pAppControlMgr != null)
395 //launch compose message AppControl
396 __isMessageAppControlRunning = __pAppControlMgr->LaunchComposeMessageAppControl(*(const_cast<String*>(&contactNumber)), this);
402 void CallPresentationModel::OnAppForeground(void)
404 if (__isMessageAppControlRunning == true)
406 //This comes here, when Message AppControl is finished working.
407 __isMessageAppControlRunning = false;
408 __pAppControlMgr->AppControlRequestCompleted();
409 //Check if this was the last call, then terminate application.
410 //And if any calls are active, then those cases are already handled from Other places.
411 if( GetCurrentCallCount() == 0)
413 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
414 pPhoneApp->Terminate();
420 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
422 if (__isMessageAppControlRunning == true)
424 //This comes here, when Message AppControl is finished working.
425 __isMessageAppControlRunning = false;
426 __pAppControlMgr->AppControlRequestCompleted();
427 //Check if this was the last call, then terminate application.
428 //And if any calls are active, then those cases are already handled from Other places.
429 if( GetCurrentCallCount() == 0)
431 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
432 pPhoneApp->Terminate();
435 if(appId.Equals(PROVIDER_ID_PHONE,false) == true && operationId.Equals(OPERATION_ID_DIAL,false) == true)
437 __isDialAppControlRunning = false;
439 __pAppControlMgr->AppControlRequestCompleted();
440 if(appControlResult == APP_CTRL_RESULT_SUCCEEDED)
442 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
443 if (pExtraData->ContainsKey(*pKey) == true)
445 const String* pPhoneNumber = static_cast<const String*>(pExtraData->GetValue(*pKey));
446 if(pPhoneNumber != null && pPhoneNumber->IsEmpty() == false)
448 AddCall(*pPhoneNumber);
459 CallPresentationModel::AddCall(const String& phoneNumber)
461 ArrayList* pLaunchArgs = null;
462 SceneManager* pSceneManager = SceneManager::GetInstance();
463 int currentActiveCallCount = GetCurrentCallCount();
464 if(currentActiveCallCount <= 1)
466 //make an outgoing call with given number
467 String* contactTxt = new (std::nothrow) String(phoneNumber);
468 pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
469 pLaunchArgs->Construct();
470 pLaunchArgs->Add(contactTxt);
471 bool isEmergencyCall = IsEmergencyNumber(*contactTxt, true);
473 SceneId nextScene = IDSCN_SCENE_OUTCALL;
476 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
478 pSceneManager->GoForward( ForwardSceneTransition( nextScene), pLaunchArgs);
484 CallPresentationModel::GetCurrentCallCount(void)
486 return __pTelephonyMgr->GetCurrentCallCount();
490 CallPresentationModel::CheckSimInitializationIsCompleted()
492 result r = E_FAILURE;
493 if(__pTelephonyMgr != null)
495 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
497 return (!IsFailed(r));
501 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
503 return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
507 CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
509 //Adding incoming call sate setting here
510 if(__pSettingsPresentor != null)
512 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
514 __pTelephonyMgr->StartAlert(incomingCallInfo);
518 CallPresentationModel::StopAlert(void)
520 __pTelephonyMgr->StopAlert();
524 CallPresentationModel::GetContactN(const String& phoneNumber)
526 return __pTelephonyMgr->GetContactN(phoneNumber);
530 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
533 return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
537 CallPresentationModel::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
539 return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
542 /////////////////////////////////////////////////////////////////
543 ///// Event Listener methods from ITelephonyEventListener /////
544 /////////////////////////////////////////////////////////////////
546 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
548 if (__pTelEventListener != null)
550 __pTelEventListener->HandleCallConnected(pCallList);
552 if(__pSettingsPresentor != null)
554 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
559 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
561 AppLogDebug("Enter");
562 if (isLastCall == true)
564 SetSpeakerStatus(false);
565 SetMuteStatus(false);
566 if(__pSettingsPresentor != null)
568 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
573 if(__pSettingsPresentor != null)
575 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
578 //1) Defer from sending call disconnected event to form, in case Msg AppControl is running,
579 //to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
580 //2) Do not send call disconnected event to any form, in case an incoming call or dialing call is present.
581 if (__pTelEventListener != null && __isMessageAppControlRunning == false )
583 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
588 CallPresentationModel::HandleConferenceCall(AppCallInfo& pCallInfo)
590 if (__pTelEventListener != null)
592 __pTelEventListener->HandleConferenceCall(pCallInfo);
597 CallPresentationModel::HandleIncomingCall(AppCallInfo& pCallInfo)
599 AppLogDebug("Error - This will never come here. Since, now we are getting incoming call event through AppControl!!");
603 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
605 if (__pTelEventListener != null)
607 __pTelEventListener->HandleCallSwapOccured(pCallList);
612 CallPresentationModel::HandleConferenceChange(void)
614 //1) Do not send conf. call changed event to any form, in case an incoming call or dialing call is present.
615 if (__pTelEventListener != null)
617 __pTelEventListener->HandleConferenceChange();
622 CallPresentationModel::HandleTelephonyError(int errorCode)
624 if (__pTelEventListener != null)
626 __pTelEventListener->HandleTelephonyError(errorCode);
631 CallPresentationModel::LaunchDialAppControl()
634 if(__isDialAppControlRunning == true)
636 //Do not allow another app control if already running
640 //Launch dialer AppControl
641 if (__pAppControlMgr != null)
643 __isDialAppControlRunning = __pAppControlMgr->LaunchDialerAppControl(this);
649 CallPresentationModel::IsEnableJoinCallButton(void)
651 //Check if conf. call has maximum participants
652 AppCallInfo* pConfCallInfo = GetConferenceCallInfoN();
653 if(pConfCallInfo != null && pConfCallInfo->GetCallerListCount() >= IDI_MAX_CONF_CALL_PARTICIPANTS)
658 //check if either of the caller is same or present in conf call.
659 IListT<AppCallInfo>* pActiveCallList = GetCallListN();
660 if ( pActiveCallList != null && pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
662 AppCallInfo firstCall;
663 AppCallInfo secondCall;
664 pActiveCallList->GetAt(0, firstCall);
665 pActiveCallList->GetAt(1, secondCall);
667 if (firstCall.IsConferenceCall() == true)
669 IListT<AppCallInfo>* pConfMemberList = firstCall.GetCallerList();
670 for (int index = 0; index < pConfMemberList->GetCount(); index++)
672 AppCallInfo singleConfMember;
673 pConfMemberList->GetAt(index, singleConfMember);
674 if (secondCall.GetContactNumber().IsEmpty() == false && secondCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
680 else if (secondCall.IsConferenceCall() == true)
682 IListT<AppCallInfo>* pConfMemberList = secondCall.GetCallerList();
683 for (int index = 0; index < pConfMemberList->GetCount(); index++)
685 AppCallInfo singleConfMember;
686 pConfMemberList->GetAt(index, singleConfMember);
687 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
695 //Now, we definitely know that both are single active calls.
696 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(secondCall.GetContactNumber()) == true)
702 delete pConfCallInfo;
703 pConfCallInfo = null;
708 CallPresentationModel::IsIncomingorDialingCallPresent(void)
710 //returns false, if incoming call or dialed call is present.
711 return __pTelephonyMgr->IsIncomingorDialingCallPresent();
715 CallPresentationModel::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
717 if (__pAppControlMgr != null)
719 return __pAppControlMgr->LaunchComposeMessageAppControl(contactNumber, pListener);
725 CallPresentationModel::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
727 if (__pAppControlMgr != null)
729 return __pAppControlMgr->LaunchViewContactAppControl(contactId, pListener);
735 CallPresentationModel::LaunchAddContactAppControl(Tizen::Base::String& contactNumber, Tizen::App::IAppControlResponseListener* pListener)
737 if (__pAppControlMgr != null)
739 return __pAppControlMgr->LaunchAddContactAppControl(contactNumber, pListener);
745 CallPresentationModel::IsAppControlRunning(void)
747 if (__pAppControlMgr != null)
749 return __pAppControlMgr->IsAppControlRunning();
755 CallPresentationModel::AbortAppControlRequest(void)
757 if (__pAppControlMgr != null)
759 __pAppControlMgr->AbortAppControlRequest();
764 CallPresentationModel::AppControlRequestCompleted(void)
766 if (__pAppControlMgr != null)
768 __pAppControlMgr->AppControlRequestCompleted();