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 PhnCallPresentationModel.cpp
19 * @brief Call Presentation model class
24 #include "PhnPhoneApp.h"
25 #include "PhnActiveCallForm.h"
26 #include "PhnCallInfo.h"
27 #include "PhnCallPresentationModel.h"
28 #include "PhnSettingsPresentationModel.h"
29 #include "PhnConfCallerListForm.h"
30 #include "PhnTelephonyManager.h"
31 #include "PhnSceneRegister.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;
52 CallPresentationModel::~CallPresentationModel(void)
54 __pTelephonyMgr = null;
55 __pSettingsPresentor = null;
59 CallPresentationModel::CreateInstance(void)
61 __pInstance = new (std::nothrow) CallPresentationModel();
62 result r = __pInstance->Construct();
70 std::atexit(DestroyInstance);
73 CallPresentationModel*
74 CallPresentationModel::GetInstance(void)
76 if (__pInstance == null)
84 CallPresentationModel::DestroyInstance(void)
86 if (__pInstance != null)
94 CallPresentationModel::Construct(void)
96 //Fetch Telephony Manager
97 __pTelephonyMgr = TelephonyManager::GetInstance(this);
98 __pSettingsPresentor = SettingsPresentationModel::GetInstance();
103 CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventListener)
105 //set form as telephony event listener
106 __pTelEventListener = pTelEventListener;
110 CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
112 int errorCode = ERROR_NONE;
113 //Check if Telephony Manager is initialized
114 TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
116 //check if phone is in flight mode
117 if(__pSettingsPresentor->GetFlightModeStatus() == true)
119 __pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
122 //setup outgoing call
123 errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
124 TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
125 if(__pSettingsPresentor != null)
127 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
132 __pTelEventListener->HandleTelephonyError(errorCode);
136 CallPresentationModel::EndCall(Long callHandle)
138 if(__pTelephonyMgr != null)
140 __pTelephonyMgr->EndCall(callHandle);
145 CallPresentationModel::EndCall(String& contactNumber)
147 if(__pTelephonyMgr != null)
149 __pTelephonyMgr->EndCall(contactNumber);
154 CallPresentationModel::EndConferenceCall(void)
156 result r = __pTelephonyMgr->EndConferenceCall();
159 //TODO: send proper error code
160 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
167 CallPresentationModel::EndAllCall(void)
169 if(__pTelephonyMgr != null)
171 __pTelephonyMgr->EndAllCalls();
175 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
177 result r = __pTelephonyMgr->HoldCall(callHandle, true);
178 return (!IsFailed(r));
182 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
184 result r = __pTelephonyMgr->HoldCall(callHandle, false);
185 return (!IsFailed(r));
189 CallPresentationModel::HoldConferenceCall(void)
191 result r = __pTelephonyMgr->HoldConferenceCall(true);
192 return (!IsFailed(r));
196 CallPresentationModel::ActivateConferenceCall(void)
198 result r = __pTelephonyMgr->HoldConferenceCall(false);
199 return (!IsFailed(r));
203 CallPresentationModel::JoinCall(void)
205 result r = __pTelephonyMgr->JoinCall();
208 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
213 CallPresentationModel::SwapCalls(void)
215 result r = __pTelephonyMgr->SwapCalls();
218 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
223 CallPresentationModel::SetMuteStatus(bool setMute)
225 result r = __pTelephonyMgr->SetMuteStatus(setMute);
226 return (!IsFailed(r));
230 CallPresentationModel::IsCallMuted(void)
232 return __pTelephonyMgr->IsCallMuted();
236 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
238 result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
239 return (!IsFailed(r));
243 CallPresentationModel::IsSpeakerOn(void)
245 return __pTelephonyMgr->IsSpeakerOn();
248 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
250 __pTelephonyMgr->SendCallDTMF(textToBeSent);
254 CallPresentationModel::GetConferenceCallInfoN(void)
256 return __pTelephonyMgr->GetConferenceCallInfoN();
260 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<CallInfo>* pConfCallList)
263 CallInfo callToBeSpli;
264 switch (splitCallerCmdId)
266 case IDA_SPLIT_CALLER1:
270 case IDA_SPLIT_CALLER2:
274 case IDA_SPLIT_CALLER3:
278 case IDA_SPLIT_CALLER4:
282 case IDA_SPLIT_CALLER5:
290 result r = pConfCallList->GetAt(callIndex, callToBeSpli);
291 TryCatch(r == E_SUCCESS,,"conf. call list corrupted");
292 //split single call from conference
293 r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
294 TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
298 __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
303 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<CallInfo>* pConfCallList)
306 CallInfo callToBeEnded;
307 switch (endCallerCmdId)
309 case IDA_END_CALLER1:
313 case IDA_END_CALLER2:
317 case IDA_END_CALLER3:
321 case IDA_END_CALLER4:
325 case IDA_END_CALLER5:
333 result r = pConfCallList->GetAt(callIndex, callToBeEnded);
334 TryCatch(r == E_SUCCESS,,"conference call list corrupted");
336 r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
337 TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
342 __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
347 CallPresentationModel::IsSplitAllowed(void)
349 return __pTelephonyMgr->IsSplitAllowed();
353 CallPresentationModel::AcceptIncomingCall(CallAnswerOptions answerOptions,int callHandle)
355 result r = E_FAILURE;
356 if (answerOptions == CALL_ANSWER_CALL)
358 r = __pTelephonyMgr->AnswerCall(callHandle, true);
362 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
366 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
371 CallPresentationModel::GetCallListN(void)
373 return __pTelephonyMgr->GetCallListN();
378 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
380 result r = __pTelephonyMgr->AnswerCall(callHandle, false);
383 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
390 result r = E_SUCCESS;
392 extraData.Construct();
394 extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
395 extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(contactNumber));
397 AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
400 r = pAc->Start(null, null, &extraData, this);
401 __isMessageAppControlRunning = true;
405 extraData.RemoveAll(true);
411 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
413 if (__isMessageAppControlRunning == true)
415 //This comes here, when Message AppControl is finished working.
416 __isMessageAppControlRunning = false;
417 //Check if this was the last call, then terminate application.
418 //And if any calls are active, then those cases are already handled from Other places.
419 if( GetCurrentCallCount() == 0)
421 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
422 SceneManager* pSceneManager = SceneManager::GetInstance();
423 SceneId startingScene = pPhoneApp->GetInitialScene();
424 //No more calls are active
425 if (startingScene == IDSCN_DIALER || startingScene == IDSCN_CALL_LOG)
427 pSceneManager->GoForward( ForwardSceneTransition(startingScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
428 SCENE_HISTORY_OPTION_NO_HISTORY));
432 pPhoneApp->Terminate();
439 CallPresentationModel::GetCurrentCallCount(void)
441 return __pTelephonyMgr->GetCurrentCallCount();
445 CallPresentationModel::CheckSimInitializationIsCompleted()
447 result r = E_FAILURE;
448 if(__pTelephonyMgr != null)
450 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
452 return (!IsFailed(r));
456 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
458 return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
462 CallPresentationModel::StartAlert(CallInfo& incomingCallInfo)
464 __pTelephonyMgr->StartAlert(incomingCallInfo);
468 CallPresentationModel::StopAlert(void)
470 __pTelephonyMgr->StopAlert();
474 CallPresentationModel::GetContactN(const String& phoneNumber)
476 return __pTelephonyMgr->GetContactN(phoneNumber);
480 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
482 //Adding incoming call sate setting here
483 if(__pSettingsPresentor != null)
485 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
487 return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
491 CallPresentationModel::CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo)
493 return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
496 /////////////////////////////////////////////////////////////////
497 ///// Event Listener methods from ITelephonyEventListener /////
498 /////////////////////////////////////////////////////////////////
500 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
502 if (__pTelEventListener != null)
504 __pTelEventListener->HandleCallConnected(pCallList);
506 if(__pSettingsPresentor != null)
508 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
513 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<CallInfo>& pCallList)
515 if (isLastCall == true)
517 SetSpeakerStatus(false);
518 SetMuteStatus(false);
519 if(__pSettingsPresentor != null)
521 __pSettingsPresentor->SetCallState(CALL_STATE__CALL_OFF);
524 //Defer from sending call disconnected event to form, in case Msg AppControl is running,
525 //to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
526 if (__pTelEventListener != null && __isMessageAppControlRunning == false)
528 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
534 CallPresentationModel::HandleConferenceCall(CallInfo& pCallInfo)
536 if (__pTelEventListener != null)
538 __pTelEventListener->HandleConferenceCall(pCallInfo);
543 CallPresentationModel::HandleIncomingCall(CallInfo& pCallInfo)
545 StartAlert(pCallInfo);
546 if (__pTelEventListener != null)
548 __pTelEventListener->HandleIncomingCall(pCallInfo);
552 //as base form not created. So no listener set.
553 SceneManager* pSceneManager = SceneManager::GetInstance();
555 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
556 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
557 pCallInfoList->Construct(1);
559 //update list to be passed
560 CallInfo* pIncomingCall = new (std::nothrow) CallInfo();
561 *pIncomingCall = pCallInfo;
562 pCallInfoList->Add(pIncomingCall);
564 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), pCallInfoList);
566 if(__pSettingsPresentor != null)
568 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
573 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
575 if (__pTelEventListener != null)
577 __pTelEventListener->HandleCallSwapOccured(pCallList);
582 CallPresentationModel::HandleConferenceChange(void)
584 if (__pTelEventListener != null)
586 __pTelEventListener->HandleConferenceChange();
591 CallPresentationModel::HandleTelephonyError(int errorCode)
593 if (__pTelEventListener != null)
595 __pTelEventListener->HandleTelephonyError(errorCode);