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;
42 using namespace Tizen::Telephony;
44 CallPresentationModel* CallPresentationModel::__pInstance = null;
46 CallPresentationModel::CallPresentationModel(void)
48 __pTelephonyMgr = null;
49 __pTelEventListener = null;
50 __pSettingsPresentor = null;
51 __isMessageAppControlRunning = false;
52 __isDialAppControlRunning = false;
53 __pAppControlMgr = null;
54 __pNetworkManager = null;
55 __psimStateManager = null;
59 CallPresentationModel::~CallPresentationModel(void)
61 __pTelephonyMgr = null;
62 __pSettingsPresentor = null;
63 __pAppControlMgr =null;
64 if(__pNetworkManager != null)
66 delete __pNetworkManager;
67 __pNetworkManager = null;
69 if(__psimStateManager != null)
71 delete __psimStateManager;
72 __psimStateManager = null;
74 if(__psimInfo != null)
82 CallPresentationModel::CreateInstance(void)
84 __pInstance = new (std::nothrow) CallPresentationModel();
85 result r = __pInstance->Construct();
93 std::atexit(DestroyInstance);
96 CallPresentationModel*
97 CallPresentationModel::GetInstance(void)
99 if (__pInstance == null)
107 CallPresentationModel::DestroyInstance(void)
109 if (__pInstance != null)
117 CallPresentationModel::Construct(void)
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);
130 CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventListener)
132 //set form as telephony event listener
133 __pTelEventListener = pTelEventListener;
137 CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
139 int errorCode = ERROR_NONE;
140 bool isCallServiceAvailable = false;
141 NetworkStatus networkStatus;
143 //Check if Telephony Manager is initialized
144 TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
146 //check if phone is in flight mode
147 if(__pSettingsPresentor != null && __pSettingsPresentor->GetFlightModeStatus() == true)
149 __pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
152 //Check if dialing a call is possible - Check if sim is available
153 if (IsSimAvailable() == false)
155 __pTelEventListener->HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
159 //fetch call service status
160 if(__pNetworkManager != null)
162 r = __pNetworkManager->GetNetworkStatus(networkStatus);
165 isCallServiceAvailable = networkStatus.IsCallServiceAvailable();
170 if (isCallServiceAvailable == false)
172 __pTelEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
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)
180 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
185 __pTelEventListener->HandleTelephonyError(errorCode);
189 CallPresentationModel::EndActiveCall(Long callHandle)
191 if(__pTelephonyMgr != null)
193 __pTelephonyMgr->EndActiveCall(callHandle);
198 CallPresentationModel::EndDialingCall(String& contactNumber)
200 if(__pTelephonyMgr != null)
202 __pTelephonyMgr->EndDialingCall(contactNumber);
207 CallPresentationModel::EndConferenceCall(void)
209 result r = __pTelephonyMgr->EndConferenceCall();
212 //TODO: send proper error code
213 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
220 CallPresentationModel::EndAllCall(void)
222 if(__pTelephonyMgr != null)
224 __pTelephonyMgr->EndAllCalls();
228 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
230 result r = __pTelephonyMgr->HoldCall(callHandle, true);
231 return (!IsFailed(r));
235 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
237 result r = __pTelephonyMgr->HoldCall(callHandle, false);
238 return (!IsFailed(r));
242 CallPresentationModel::HoldConferenceCall(void)
244 result r = __pTelephonyMgr->HoldConferenceCall(true);
245 return (!IsFailed(r));
249 CallPresentationModel::ActivateConferenceCall(void)
251 result r = __pTelephonyMgr->HoldConferenceCall(false);
252 return (!IsFailed(r));
256 CallPresentationModel::JoinCall(void)
258 result r = __pTelephonyMgr->JoinCall();
261 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
266 CallPresentationModel::SwapCalls(void)
268 result r = __pTelephonyMgr->SwapCalls();
271 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
276 CallPresentationModel::SetMuteStatus(bool setMute)
278 result r = __pTelephonyMgr->SetMuteStatus(setMute);
279 return (!IsFailed(r));
283 CallPresentationModel::IsCallMuted(void)
285 return __pTelephonyMgr->IsCallMuted();
289 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
291 result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
292 return (!IsFailed(r));
296 CallPresentationModel::IsSpeakerOn(void)
298 return __pTelephonyMgr->IsSpeakerOn();
301 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
303 __pTelephonyMgr->SendCallDTMF(textToBeSent);
307 CallPresentationModel::GetConferenceCallInfoN(void)
309 return __pTelephonyMgr->GetConferenceCallInfoN();
313 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<AppCallInfo>* pConfCallList)
316 AppCallInfo callToBeSpli;
317 switch (splitCallerCmdId)
319 case IDA_SPLIT_CALLER1:
323 case IDA_SPLIT_CALLER2:
327 case IDA_SPLIT_CALLER3:
331 case IDA_SPLIT_CALLER4:
335 case IDA_SPLIT_CALLER5:
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");
351 __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
356 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<AppCallInfo>* pConfCallList)
359 AppCallInfo callToBeEnded;
360 switch (endCallerCmdId)
362 case IDA_END_CALLER1:
366 case IDA_END_CALLER2:
370 case IDA_END_CALLER3:
374 case IDA_END_CALLER4:
378 case IDA_END_CALLER5:
386 result r = pConfCallList->GetAt(callIndex, callToBeEnded);
387 TryCatch(r == E_SUCCESS,,"conference call list corrupted");
389 r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
390 TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
395 __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
400 CallPresentationModel::IsSplitAllowed(void)
402 return __pTelephonyMgr->IsSplitAllowed();
406 CallPresentationModel::AcceptIncomingCall(CallAnsweringOptions answerOptions,int callHandle)
408 result r = E_FAILURE;
409 if (answerOptions == ANSERWING_OPTION_ACCEPT_CALL)
411 r = __pTelephonyMgr->AnswerCall(callHandle, true);
415 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
419 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
424 CallPresentationModel::GetCallListN(void)
426 return __pTelephonyMgr->GetCallListN();
431 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
433 AppLogDebug("Enter");
434 if (sendMsg == true && __pAppControlMgr != null)
436 //launch compose message AppControl
437 __isMessageAppControlRunning = __pAppControlMgr->LaunchComposeMessageAppControl(*(const_cast<String*>(&contactNumber)), this);
439 result r = __pTelephonyMgr->AnswerCall(callHandle, false);
442 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
451 void CallPresentationModel::OnAppForeground(void)
453 if (__isDialAppControlRunning == true)
455 //This comes here, when Dialer AppControl is finished working.
456 __isDialAppControlRunning = false;
457 __pAppControlMgr->AppControlRequestCompleted();
459 if (__isMessageAppControlRunning == true)
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)
468 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
469 pPhoneApp->Terminate();
475 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
477 AppLogDebug("Enter");
478 if (__isMessageAppControlRunning == true)
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)
487 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
488 pPhoneApp->Terminate();
491 if(appId.Equals(PROVIDER_ID_PHONE,false) == true && operationId.Equals(OPERATION_ID_DIAL,false) == true)
493 __isDialAppControlRunning = false;
495 __pAppControlMgr->AppControlRequestCompleted();
496 if(appControlResult == APP_CTRL_RESULT_SUCCEEDED)
498 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
499 if (pExtraData->ContainsKey(*pKey) == true)
501 const String* pPhoneNumber = static_cast<const String*>(pExtraData->GetValue(*pKey));
502 if(pPhoneNumber != null && pPhoneNumber->IsEmpty() == false)
504 AddCall(*pPhoneNumber);
515 CallPresentationModel::AddCall(const String& phoneNumber)
517 ArrayList* pLaunchArgs = null;
518 SceneManager* pSceneManager = SceneManager::GetInstance();
519 int currentActiveCallCount = GetCurrentCallCount();
520 if(currentActiveCallCount <= 1 && IsIncomingorDialingCallPresent() == false)
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);
529 SceneId nextScene = IDSCN_SCENE_OUTCALL;
532 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
534 pSceneManager->GoForward( ForwardSceneTransition( nextScene), pLaunchArgs);
540 CallPresentationModel::GetCurrentCallCount(void)
542 return __pTelephonyMgr->GetCurrentCallCount();
546 CallPresentationModel::CheckSimInitializationIsCompleted()
548 result r = E_FAILURE;
549 if(__pTelephonyMgr != null)
551 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
553 return (!IsFailed(r));
557 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
559 return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
563 CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
565 //Adding incoming call sate setting here
566 if(__pSettingsPresentor != null)
568 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
570 __pTelephonyMgr->StartAlert(incomingCallInfo);
574 CallPresentationModel::StopAlert(void)
576 __pTelephonyMgr->StopAlert();
580 CallPresentationModel::GetContactN(const String& phoneNumber)
582 return __pTelephonyMgr->GetContactN(phoneNumber);
586 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
589 return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
593 CallPresentationModel::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
595 return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
598 /////////////////////////////////////////////////////////////////
599 ///// Event Listener methods from ITelephonyEventListener /////
600 /////////////////////////////////////////////////////////////////
602 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
604 if (__pTelEventListener != null)
606 __pTelEventListener->HandleCallConnected(pCallList);
608 if(__pSettingsPresentor != null)
610 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
615 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
617 AppLogDebug("Enter");
618 if (isLastCall == true)
620 SetSpeakerStatus(false);
621 SetMuteStatus(false);
622 if(__pSettingsPresentor != null)
624 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
629 if(__pSettingsPresentor != null)
631 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
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*/ )
639 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
644 CallPresentationModel::HandleConferenceCall(AppCallInfo& pCallInfo)
646 if (__pTelEventListener != null)
648 __pTelEventListener->HandleConferenceCall(pCallInfo);
653 CallPresentationModel::HandleIncomingCall(AppCallInfo& pCallInfo)
655 AppLogDebug("Error - This will never come here. Since, now we are getting incoming call event through AppControl!!");
659 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
661 if (__pTelEventListener != null)
663 __pTelEventListener->HandleCallSwapOccured(pCallList);
668 CallPresentationModel::HandleConferenceChange(void)
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)
673 __pTelEventListener->HandleConferenceChange();
678 CallPresentationModel::HandleTelephonyError(int errorCode)
680 if (__pTelEventListener != null)
682 __pTelEventListener->HandleTelephonyError(errorCode);
687 CallPresentationModel::LaunchDialAppControl()
690 if(__isDialAppControlRunning == true)
692 //Do not allow another app control if already running
696 //Launch dialer AppControl
697 if (__pAppControlMgr != null)
699 __isDialAppControlRunning = __pAppControlMgr->LaunchDialerAppControl(this);
705 CallPresentationModel::IsEnableJoinCallButton(void)
707 //Check if conf. call has maximum participants
708 AppCallInfo* pConfCallInfo = GetConferenceCallInfoN();
709 if(pConfCallInfo != null && pConfCallInfo->GetCallerListCount() >= IDI_MAX_CONF_CALL_PARTICIPANTS)
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)
718 AppCallInfo firstCall;
719 AppCallInfo secondCall;
720 pActiveCallList->GetAt(0, firstCall);
721 pActiveCallList->GetAt(1, secondCall);
723 if (firstCall.IsConferenceCall() == true)
725 IListT<AppCallInfo>* pConfMemberList = firstCall.GetCallerList();
726 for (int index = 0; index < pConfMemberList->GetCount(); index++)
728 AppCallInfo singleConfMember;
729 pConfMemberList->GetAt(index, singleConfMember);
730 if (secondCall.GetContactNumber().IsEmpty() == false && secondCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
736 else if (secondCall.IsConferenceCall() == true)
738 IListT<AppCallInfo>* pConfMemberList = secondCall.GetCallerList();
739 for (int index = 0; index < pConfMemberList->GetCount(); index++)
741 AppCallInfo singleConfMember;
742 pConfMemberList->GetAt(index, singleConfMember);
743 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
751 //Now, we definitely know that both are single active calls.
752 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(secondCall.GetContactNumber()) == true)
758 delete pConfCallInfo;
759 pConfCallInfo = null;
764 CallPresentationModel::IsIncomingorDialingCallPresent(void)
766 //returns false, if incoming call or dialed call is present.
767 return __pTelephonyMgr->IsIncomingorDialingCallPresent();
771 CallPresentationModel::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
773 if (__pAppControlMgr != null)
775 return __pAppControlMgr->LaunchComposeMessageAppControl(contactNumber, pListener);
781 CallPresentationModel::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
783 if (__pAppControlMgr != null)
785 return __pAppControlMgr->LaunchViewContactAppControl(contactId, pListener);
791 CallPresentationModel::LaunchAddContactAppControl(Tizen::Base::String& contactNumber, Tizen::App::IAppControlResponseListener* pListener)
793 if (__pAppControlMgr != null)
795 return __pAppControlMgr->LaunchAddContactAppControl(contactNumber, pListener);
801 CallPresentationModel::IsAppControlRunning(void)
803 if (__pAppControlMgr != null)
805 return __pAppControlMgr->IsAppControlRunning();
811 CallPresentationModel::AbortAppControlRequest(void)
813 if (__pAppControlMgr != null)
815 __pAppControlMgr->AbortAppControlRequest();
820 CallPresentationModel::AppControlRequestCompleted(void)
822 if (__pAppControlMgr != null)
824 __pAppControlMgr->AppControlRequestCompleted();
829 CallPresentationModel::GetSimInfo(void)
831 __psimStateManager = new (std::nothrow)SimStateManager();
832 result r = __psimStateManager->Construct();
835 delete __psimStateManager;
836 __psimStateManager = null;
839 __psimStateManager->SetSimEventListener(this);
841 __psimInfo = new (std::nothrow)SimInfo();
842 r = __psimStateManager->GetSimInfo(*__psimInfo);
845 delete __psimStateManager;
846 __psimStateManager = null;
855 CallPresentationModel::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
861 CallPresentationModel::OnTelephonySimStateChanged(Tizen::Telephony::SimState state)
863 if(__psimStateManager != null)
865 delete __psimStateManager;
866 __psimStateManager =null;
868 if(__psimInfo != null)
874 __psimStateManager = new SimStateManager();
875 result r = __psimStateManager->Construct();
878 delete __psimStateManager;
879 __psimStateManager = null;
883 __psimInfo = new SimInfo();
884 r = __psimStateManager->GetSimInfo(*__psimInfo);
887 delete __psimStateManager;
888 __psimStateManager = null;
897 CallPresentationModel::IsSimAvailable(void)
899 if(__psimInfo != null)
901 return __psimInfo->IsAvailable();