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;
56 CallPresentationModel::~CallPresentationModel(void)
58 __pTelephonyMgr = null;
59 __pSettingsPresentor = null;
60 __pAppControlMgr =null;
64 CallPresentationModel::CreateInstance(void)
66 __pInstance = new (std::nothrow) CallPresentationModel();
67 result r = __pInstance->Construct();
75 std::atexit(DestroyInstance);
78 CallPresentationModel*
79 CallPresentationModel::GetInstance(void)
81 if (__pInstance == null)
89 CallPresentationModel::DestroyInstance(void)
91 if (__pInstance != null)
99 CallPresentationModel::Construct(void)
101 //Fetch Telephony Manager
102 __pTelephonyMgr = TelephonyManager::GetInstance(this);
103 __pSettingsPresentor = SettingsPresentationModel::GetInstance();
104 __pAppControlMgr = CallAppControlRequestMgr::GetInstance();
109 CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventListener)
111 //set form as telephony event listener
112 __pTelEventListener = pTelEventListener;
116 CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
118 int errorCode = ERROR_NONE;
119 bool isCallServiceAvailable = false;
120 NetworkStatus networkStatus;
121 NetworkManager* pNetworkManager = new NetworkManager();
123 //Check if Telephony Manager is initialized
124 TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
126 //check if phone is in flight mode
127 if(__pSettingsPresentor != null && __pSettingsPresentor->GetFlightModeStatus() == true)
129 __pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
132 //Check if dialing a call is possible - Check if sim is available
133 if (GetSimInfo() == E_FAILURE)
135 __pTelEventListener->HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
139 //fetch call service status
140 r = pNetworkManager->Construct(null);
143 r = pNetworkManager->GetNetworkStatus(networkStatus);
146 isCallServiceAvailable = networkStatus.IsCallServiceAvailable();
149 delete pNetworkManager;
151 if (isCallServiceAvailable == false)
153 __pTelEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
156 //setup outgoing call
157 errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
158 TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
159 if(__pSettingsPresentor != null)
161 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
166 __pTelEventListener->HandleTelephonyError(errorCode);
170 CallPresentationModel::EndActiveCall(Long callHandle)
172 if(__pTelephonyMgr != null)
174 __pTelephonyMgr->EndActiveCall(callHandle);
179 CallPresentationModel::EndDialingCall(String& contactNumber)
181 if(__pTelephonyMgr != null)
183 __pTelephonyMgr->EndDialingCall(contactNumber);
188 CallPresentationModel::EndConferenceCall(void)
190 result r = __pTelephonyMgr->EndConferenceCall();
193 //TODO: send proper error code
194 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
201 CallPresentationModel::EndAllCall(void)
203 if(__pTelephonyMgr != null)
205 __pTelephonyMgr->EndAllCalls();
209 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
211 result r = __pTelephonyMgr->HoldCall(callHandle, true);
212 return (!IsFailed(r));
216 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
218 result r = __pTelephonyMgr->HoldCall(callHandle, false);
219 return (!IsFailed(r));
223 CallPresentationModel::HoldConferenceCall(void)
225 result r = __pTelephonyMgr->HoldConferenceCall(true);
226 return (!IsFailed(r));
230 CallPresentationModel::ActivateConferenceCall(void)
232 result r = __pTelephonyMgr->HoldConferenceCall(false);
233 return (!IsFailed(r));
237 CallPresentationModel::JoinCall(void)
239 result r = __pTelephonyMgr->JoinCall();
242 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
247 CallPresentationModel::SwapCalls(void)
249 result r = __pTelephonyMgr->SwapCalls();
252 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
257 CallPresentationModel::SetMuteStatus(bool setMute)
259 result r = __pTelephonyMgr->SetMuteStatus(setMute);
260 return (!IsFailed(r));
264 CallPresentationModel::IsCallMuted(void)
266 return __pTelephonyMgr->IsCallMuted();
270 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
272 result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
273 return (!IsFailed(r));
277 CallPresentationModel::IsSpeakerOn(void)
279 return __pTelephonyMgr->IsSpeakerOn();
282 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
284 __pTelephonyMgr->SendCallDTMF(textToBeSent);
288 CallPresentationModel::GetConferenceCallInfoN(void)
290 return __pTelephonyMgr->GetConferenceCallInfoN();
294 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<AppCallInfo>* pConfCallList)
297 AppCallInfo callToBeSpli;
298 switch (splitCallerCmdId)
300 case IDA_SPLIT_CALLER1:
304 case IDA_SPLIT_CALLER2:
308 case IDA_SPLIT_CALLER3:
312 case IDA_SPLIT_CALLER4:
316 case IDA_SPLIT_CALLER5:
324 result r = pConfCallList->GetAt(callIndex, callToBeSpli);
325 TryCatch(r == E_SUCCESS,,"conf. call list corrupted");
326 //split single call from conference
327 r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
328 TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
332 __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
337 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<AppCallInfo>* pConfCallList)
340 AppCallInfo callToBeEnded;
341 switch (endCallerCmdId)
343 case IDA_END_CALLER1:
347 case IDA_END_CALLER2:
351 case IDA_END_CALLER3:
355 case IDA_END_CALLER4:
359 case IDA_END_CALLER5:
367 result r = pConfCallList->GetAt(callIndex, callToBeEnded);
368 TryCatch(r == E_SUCCESS,,"conference call list corrupted");
370 r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
371 TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
376 __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
381 CallPresentationModel::IsSplitAllowed(void)
383 return __pTelephonyMgr->IsSplitAllowed();
387 CallPresentationModel::AcceptIncomingCall(CallAnsweringOptions answerOptions,int callHandle)
389 result r = E_FAILURE;
390 if (answerOptions == ANSERWING_OPTION_ACCEPT_CALL)
392 r = __pTelephonyMgr->AnswerCall(callHandle, true);
396 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
400 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
405 CallPresentationModel::GetCallListN(void)
407 return __pTelephonyMgr->GetCallListN();
412 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
414 AppLogDebug("Enter");
415 if (sendMsg == true && __pAppControlMgr != null)
417 //launch compose message AppControl
418 __isMessageAppControlRunning = __pAppControlMgr->LaunchComposeMessageAppControl(*(const_cast<String*>(&contactNumber)), this);
420 result r = __pTelephonyMgr->AnswerCall(callHandle, false);
423 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
432 void CallPresentationModel::OnAppForeground(void)
434 if (__isDialAppControlRunning == true)
436 //This comes here, when Dialer AppControl is finished working.
437 __isDialAppControlRunning = false;
438 __pAppControlMgr->AppControlRequestCompleted();
440 if (__isMessageAppControlRunning == true)
442 //This comes here, when Message AppControl is finished working.
443 __isMessageAppControlRunning = false;
444 __pAppControlMgr->AppControlRequestCompleted();
445 //Check if this was the last call, then terminate application.
446 //And if any calls are active, then those cases are already handled from Other places.
447 if( GetCurrentCallCount() == 0)
449 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
450 pPhoneApp->Terminate();
456 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
458 AppLogDebug("Enter");
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();
472 if(appId.Equals(PROVIDER_ID_PHONE,false) == true && operationId.Equals(OPERATION_ID_DIAL,false) == true)
474 __isDialAppControlRunning = false;
476 __pAppControlMgr->AppControlRequestCompleted();
477 if(appControlResult == APP_CTRL_RESULT_SUCCEEDED)
479 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
480 if (pExtraData->ContainsKey(*pKey) == true)
482 const String* pPhoneNumber = static_cast<const String*>(pExtraData->GetValue(*pKey));
483 if(pPhoneNumber != null && pPhoneNumber->IsEmpty() == false)
485 AddCall(*pPhoneNumber);
496 CallPresentationModel::AddCall(const String& phoneNumber)
498 ArrayList* pLaunchArgs = null;
499 SceneManager* pSceneManager = SceneManager::GetInstance();
500 int currentActiveCallCount = GetCurrentCallCount();
501 if(currentActiveCallCount <= 1 && IsIncomingorDialingCallPresent() == false)
503 //make an outgoing call with given number
504 String* contactTxt = new (std::nothrow) String(phoneNumber);
505 pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
506 pLaunchArgs->Construct();
507 pLaunchArgs->Add(contactTxt);
508 bool isEmergencyCall = IsEmergencyNumber(*contactTxt, true);
510 SceneId nextScene = IDSCN_SCENE_OUTCALL;
513 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
515 pSceneManager->GoForward( ForwardSceneTransition( nextScene), pLaunchArgs);
521 CallPresentationModel::GetCurrentCallCount(void)
523 return __pTelephonyMgr->GetCurrentCallCount();
527 CallPresentationModel::CheckSimInitializationIsCompleted()
529 result r = E_FAILURE;
530 if(__pTelephonyMgr != null)
532 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
534 return (!IsFailed(r));
538 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
540 return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
544 CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
546 //Adding incoming call sate setting here
547 if(__pSettingsPresentor != null)
549 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
551 __pTelephonyMgr->StartAlert(incomingCallInfo);
555 CallPresentationModel::StopAlert(void)
557 __pTelephonyMgr->StopAlert();
561 CallPresentationModel::GetContactN(const String& phoneNumber)
563 return __pTelephonyMgr->GetContactN(phoneNumber);
567 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
570 return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
574 CallPresentationModel::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
576 return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
579 /////////////////////////////////////////////////////////////////
580 ///// Event Listener methods from ITelephonyEventListener /////
581 /////////////////////////////////////////////////////////////////
583 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
585 if (__pTelEventListener != null)
587 __pTelEventListener->HandleCallConnected(pCallList);
589 if(__pSettingsPresentor != null)
591 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
596 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
598 AppLogDebug("Enter");
599 if (isLastCall == true)
601 SetSpeakerStatus(false);
602 SetMuteStatus(false);
603 if(__pSettingsPresentor != null)
605 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
610 if(__pSettingsPresentor != null)
612 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
615 //1) Defer from sending call disconnected event to form, in case Msg AppControl is running,
616 //to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
617 //2) Do not send call disconnected event to any form, in case an incoming call or dialing call is present.
618 if (__pTelEventListener != null /*&& __isMessageAppControlRunning == false*/ )
620 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
625 CallPresentationModel::HandleConferenceCall(AppCallInfo& pCallInfo)
627 if (__pTelEventListener != null)
629 __pTelEventListener->HandleConferenceCall(pCallInfo);
634 CallPresentationModel::HandleIncomingCall(AppCallInfo& pCallInfo)
636 AppLogDebug("Error - This will never come here. Since, now we are getting incoming call event through AppControl!!");
640 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
642 if (__pTelEventListener != null)
644 __pTelEventListener->HandleCallSwapOccured(pCallList);
649 CallPresentationModel::HandleConferenceChange(void)
651 //1) Do not send conf. call changed event to any form, in case an incoming call or dialing call is present.
652 if (__pTelEventListener != null)
654 __pTelEventListener->HandleConferenceChange();
659 CallPresentationModel::HandleTelephonyError(int errorCode)
661 if (__pTelEventListener != null)
663 __pTelEventListener->HandleTelephonyError(errorCode);
668 CallPresentationModel::LaunchDialAppControl()
671 if(__isDialAppControlRunning == true)
673 //Do not allow another app control if already running
677 //Launch dialer AppControl
678 if (__pAppControlMgr != null)
680 __isDialAppControlRunning = __pAppControlMgr->LaunchDialerAppControl(this);
686 CallPresentationModel::IsEnableJoinCallButton(void)
688 //Check if conf. call has maximum participants
689 AppCallInfo* pConfCallInfo = GetConferenceCallInfoN();
690 if(pConfCallInfo != null && pConfCallInfo->GetCallerListCount() >= IDI_MAX_CONF_CALL_PARTICIPANTS)
695 //check if either of the caller is same or present in conf call.
696 IListT<AppCallInfo>* pActiveCallList = GetCallListN();
697 if ( pActiveCallList != null && pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
699 AppCallInfo firstCall;
700 AppCallInfo secondCall;
701 pActiveCallList->GetAt(0, firstCall);
702 pActiveCallList->GetAt(1, secondCall);
704 if (firstCall.IsConferenceCall() == true)
706 IListT<AppCallInfo>* pConfMemberList = firstCall.GetCallerList();
707 for (int index = 0; index < pConfMemberList->GetCount(); index++)
709 AppCallInfo singleConfMember;
710 pConfMemberList->GetAt(index, singleConfMember);
711 if (secondCall.GetContactNumber().IsEmpty() == false && secondCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
717 else if (secondCall.IsConferenceCall() == true)
719 IListT<AppCallInfo>* pConfMemberList = secondCall.GetCallerList();
720 for (int index = 0; index < pConfMemberList->GetCount(); index++)
722 AppCallInfo singleConfMember;
723 pConfMemberList->GetAt(index, singleConfMember);
724 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
732 //Now, we definitely know that both are single active calls.
733 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(secondCall.GetContactNumber()) == true)
739 delete pConfCallInfo;
740 pConfCallInfo = null;
745 CallPresentationModel::IsIncomingorDialingCallPresent(void)
747 //returns false, if incoming call or dialed call is present.
748 return __pTelephonyMgr->IsIncomingorDialingCallPresent();
752 CallPresentationModel::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
754 if (__pAppControlMgr != null)
756 return __pAppControlMgr->LaunchComposeMessageAppControl(contactNumber, pListener);
762 CallPresentationModel::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
764 if (__pAppControlMgr != null)
766 return __pAppControlMgr->LaunchViewContactAppControl(contactId, pListener);
772 CallPresentationModel::LaunchAddContactAppControl(Tizen::Base::String& contactNumber, Tizen::App::IAppControlResponseListener* pListener)
774 if (__pAppControlMgr != null)
776 return __pAppControlMgr->LaunchAddContactAppControl(contactNumber, pListener);
782 CallPresentationModel::IsAppControlRunning(void)
784 if (__pAppControlMgr != null)
786 return __pAppControlMgr->IsAppControlRunning();
792 CallPresentationModel::AbortAppControlRequest(void)
794 if (__pAppControlMgr != null)
796 __pAppControlMgr->AbortAppControlRequest();
801 CallPresentationModel::AppControlRequestCompleted(void)
803 if (__pAppControlMgr != null)
805 __pAppControlMgr->AppControlRequestCompleted();
810 CallPresentationModel::GetSimInfo(void)
819 SimStateManager simStateManager;
822 result r = simStateManager.Construct();
828 r = simStateManager.GetSimInfo(simInfo);
834 mnc = simInfo.GetMnc();
835 mcc = simInfo.GetMcc();
836 spn = simInfo.GetSpn();
837 iccId = simInfo.GetIccId();
838 operatorName = simInfo.GetOperatorName();
839 //Checks whether a SIM card is present in the device or not
840 isAvailable = simInfo.IsAvailable();
841 if(isAvailable == true)