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 "CallActiveCallForm.h"
27 #include "CallPresentationModel.h"
28 #include "CallSettingsPresentationModel.h"
29 #include "CallConfCallerListForm.h"
30 #include "CallTelephonyManager.h"
31 #include "CallSceneRegister.h"
32 #include "CallTypes.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::App;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Media;
39 using namespace Tizen::Social;
40 using namespace Tizen::Ui::Scenes;
42 CallPresentationModel* CallPresentationModel::__pInstance = null;
44 CallPresentationModel::CallPresentationModel(void)
46 __pTelephonyMgr = null;
47 __pTelEventListener = null;
48 __pSettingsPresentor = null;
49 __isMessageAppControlRunning = false;
50 __isDialAppControlRunning = false;
53 CallPresentationModel::~CallPresentationModel(void)
55 __pTelephonyMgr = null;
56 __pSettingsPresentor = null;
60 CallPresentationModel::CreateInstance(void)
62 __pInstance = new (std::nothrow) CallPresentationModel();
63 result r = __pInstance->Construct();
71 std::atexit(DestroyInstance);
74 CallPresentationModel*
75 CallPresentationModel::GetInstance(void)
77 if (__pInstance == null)
85 CallPresentationModel::DestroyInstance(void)
87 if (__pInstance != null)
95 CallPresentationModel::Construct(void)
97 //Fetch Telephony Manager
98 __pTelephonyMgr = TelephonyManager::GetInstance(this);
99 __pSettingsPresentor = SettingsPresentationModel::GetInstance();
104 CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventListener)
106 //set form as telephony event listener
107 __pTelEventListener = pTelEventListener;
111 CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
113 int errorCode = ERROR_NONE;
114 //Check if Telephony Manager is initialized
115 TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
117 //check if phone is in flight mode
118 if(__pSettingsPresentor->GetFlightModeStatus() == true)
120 __pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
123 //setup outgoing call
124 errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
125 TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
126 if(__pSettingsPresentor != null)
128 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
133 __pTelEventListener->HandleTelephonyError(errorCode);
137 CallPresentationModel::EndActiveCall(Long callHandle)
139 if(__pTelephonyMgr != null)
141 __pTelephonyMgr->EndActiveCall(callHandle);
146 CallPresentationModel::EndDialingCall(String& contactNumber)
148 if(__pTelephonyMgr != null)
150 __pTelephonyMgr->EndDialingCall(contactNumber);
155 CallPresentationModel::EndConferenceCall(void)
157 result r = __pTelephonyMgr->EndConferenceCall();
160 //TODO: send proper error code
161 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
168 CallPresentationModel::EndAllCall(void)
170 if(__pTelephonyMgr != null)
172 __pTelephonyMgr->EndAllCalls();
176 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
178 result r = __pTelephonyMgr->HoldCall(callHandle, true);
179 return (!IsFailed(r));
183 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
185 result r = __pTelephonyMgr->HoldCall(callHandle, false);
186 return (!IsFailed(r));
190 CallPresentationModel::HoldConferenceCall(void)
192 result r = __pTelephonyMgr->HoldConferenceCall(true);
193 return (!IsFailed(r));
197 CallPresentationModel::ActivateConferenceCall(void)
199 result r = __pTelephonyMgr->HoldConferenceCall(false);
200 return (!IsFailed(r));
204 CallPresentationModel::JoinCall(void)
206 result r = __pTelephonyMgr->JoinCall();
209 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
214 CallPresentationModel::SwapCalls(void)
216 result r = __pTelephonyMgr->SwapCalls();
219 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
224 CallPresentationModel::SetMuteStatus(bool setMute)
226 result r = __pTelephonyMgr->SetMuteStatus(setMute);
227 return (!IsFailed(r));
231 CallPresentationModel::IsCallMuted(void)
233 return __pTelephonyMgr->IsCallMuted();
237 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
239 result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
240 return (!IsFailed(r));
244 CallPresentationModel::IsSpeakerOn(void)
246 return __pTelephonyMgr->IsSpeakerOn();
249 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
251 __pTelephonyMgr->SendCallDTMF(textToBeSent);
255 CallPresentationModel::GetConferenceCallInfoN(void)
257 return __pTelephonyMgr->GetConferenceCallInfoN();
261 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<CallInfo>* pConfCallList)
264 CallInfo callToBeSpli;
265 switch (splitCallerCmdId)
267 case IDA_SPLIT_CALLER1:
271 case IDA_SPLIT_CALLER2:
275 case IDA_SPLIT_CALLER3:
279 case IDA_SPLIT_CALLER4:
283 case IDA_SPLIT_CALLER5:
291 result r = pConfCallList->GetAt(callIndex, callToBeSpli);
292 TryCatch(r == E_SUCCESS,,"conf. call list corrupted");
293 //split single call from conference
294 r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
295 TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
299 __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
304 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<CallInfo>* pConfCallList)
307 CallInfo callToBeEnded;
308 switch (endCallerCmdId)
310 case IDA_END_CALLER1:
314 case IDA_END_CALLER2:
318 case IDA_END_CALLER3:
322 case IDA_END_CALLER4:
326 case IDA_END_CALLER5:
334 result r = pConfCallList->GetAt(callIndex, callToBeEnded);
335 TryCatch(r == E_SUCCESS,,"conference call list corrupted");
337 r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
338 TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
343 __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
348 CallPresentationModel::IsSplitAllowed(void)
350 return __pTelephonyMgr->IsSplitAllowed();
354 CallPresentationModel::AcceptIncomingCall(CallAnsweringOptions answerOptions,int callHandle)
356 result r = E_FAILURE;
357 if (answerOptions == ANSERWING_OPTION_ACCEPT_CALL)
359 r = __pTelephonyMgr->AnswerCall(callHandle, true);
363 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
367 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
372 CallPresentationModel::GetCallListN(void)
374 return __pTelephonyMgr->GetCallListN();
379 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
381 result r = __pTelephonyMgr->AnswerCall(callHandle, false);
384 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
391 result r = E_SUCCESS;
393 extraData.Construct();
395 extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
396 extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(contactNumber));
398 AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
401 r = pAc->Start(null, null, &extraData, this);
402 __isMessageAppControlRunning = true;
406 extraData.RemoveAll(true);
412 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
414 if (__isMessageAppControlRunning == true)
416 //This comes here, when Message AppControl is finished working.
417 __isMessageAppControlRunning = false;
418 //Check if this was the last call, then terminate application.
419 //And if any calls are active, then those cases are already handled from Other places.
420 if( GetCurrentCallCount() == 0)
422 CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
423 pPhoneApp->Terminate();
426 if(appId.Equals(PROVIDER_ID_PHONE,false) == true && operationId.Equals(OPERATION_ID_DIAL,false) == true)
428 __isDialAppControlRunning = false;
430 if(appControlResult == APP_CTRL_RESULT_SUCCEEDED)
432 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
433 if (pExtraData->ContainsKey(*pKey) == true)
435 const String* pPhoneNumber = static_cast<const String*>(pExtraData->GetValue(*pKey));
436 if(pPhoneNumber != null && pPhoneNumber->IsEmpty() == false)
438 AddCall(*pPhoneNumber);
449 CallPresentationModel::AddCall(const String& phoneNumber)
451 ArrayList* pLaunchArgs = null;
452 SceneManager* pSceneManager = SceneManager::GetInstance();
453 int currentActiveCallCount = GetCurrentCallCount();
454 if(currentActiveCallCount <= 1)
456 //make an outgoing call with given number
457 String* contactTxt = new (std::nothrow) String(phoneNumber);
458 pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
459 pLaunchArgs->Construct();
460 pLaunchArgs->Add(contactTxt);
461 bool isEmergencyCall = IsEmergencyNumber(*contactTxt, true);
463 SceneId nextScene = IDSCN_SCENE_OUTCALL;
466 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
468 pSceneManager->GoForward( ForwardSceneTransition( nextScene), pLaunchArgs);
474 CallPresentationModel::GetCurrentCallCount(void)
476 return __pTelephonyMgr->GetCurrentCallCount();
480 CallPresentationModel::CheckSimInitializationIsCompleted()
482 result r = E_FAILURE;
483 if(__pTelephonyMgr != null)
485 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
487 return (!IsFailed(r));
491 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
493 return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
497 CallPresentationModel::StartAlert(CallInfo& incomingCallInfo)
499 //Adding incoming call sate setting here
500 if(__pSettingsPresentor != null)
502 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
504 __pTelephonyMgr->StartAlert(incomingCallInfo);
508 CallPresentationModel::StopAlert(void)
510 __pTelephonyMgr->StopAlert();
514 CallPresentationModel::GetContactN(const String& phoneNumber)
516 return __pTelephonyMgr->GetContactN(phoneNumber);
520 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
523 return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
527 CallPresentationModel::CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo)
529 return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
532 /////////////////////////////////////////////////////////////////
533 ///// Event Listener methods from ITelephonyEventListener /////
534 /////////////////////////////////////////////////////////////////
536 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
538 if (__pTelEventListener != null)
540 __pTelEventListener->HandleCallConnected(pCallList);
542 if(__pSettingsPresentor != null)
544 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
549 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<CallInfo>& pCallList)
551 if (isLastCall == true)
553 SetSpeakerStatus(false);
554 SetMuteStatus(false);
555 if(__pSettingsPresentor != null)
557 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
562 if(__pSettingsPresentor != null)
564 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
567 //Defer from sending call disconnected event to form, in case Msg AppControl is running,
568 //to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
569 if (__pTelEventListener != null && __isMessageAppControlRunning == false)
571 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
577 CallPresentationModel::HandleConferenceCall(CallInfo& pCallInfo)
579 if (__pTelEventListener != null)
581 __pTelEventListener->HandleConferenceCall(pCallInfo);
586 CallPresentationModel::HandleIncomingCall(CallInfo& pCallInfo)
588 AppLogDebug("Error - This will never come here. Since, now we are getting incoming call event through AppControl!!");
592 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
594 if (__pTelEventListener != null)
596 __pTelEventListener->HandleCallSwapOccured(pCallList);
601 CallPresentationModel::HandleConferenceChange(void)
603 if (__pTelEventListener != null)
605 __pTelEventListener->HandleConferenceChange();
610 CallPresentationModel::HandleTelephonyError(int errorCode)
612 if (__pTelEventListener != null)
614 __pTelEventListener->HandleTelephonyError(errorCode);
620 CallPresentationModel::LaunchDialAppControl()
622 result r = E_SUCCESS;
623 AppControl* pAppControl = null;
625 if(__isDialAppControlRunning == true)
627 //Do not allow another app control if already running
632 extraData.Construct();
633 extraData.Add(new (std::nothrow) String(PARAM_PHONE_NUMBER), new (std::nothrow) String(L""));
635 pAppControl = AppManager::FindAppControlN(PROVIDER_ID_PHONE, OPERATION_ID_DIAL);
636 if (pAppControl != null)
638 r = pAppControl->Start(null, null, &extraData, this);
639 __isDialAppControlRunning = true;
642 extraData.RemoveAll(true);