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 //setup outgoing call
117 errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
118 TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
119 if(__pSettingsPresentor != null)
121 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
126 __pTelEventListener->HandleTelephonyError(errorCode);
130 CallPresentationModel::EndCall(Long callHandle)
132 if(__pTelephonyMgr != null)
134 __pTelephonyMgr->EndCall(callHandle);
139 CallPresentationModel::EndCall(String& contactNumber)
141 if(__pTelephonyMgr != null)
143 __pTelephonyMgr->EndCall(contactNumber);
148 CallPresentationModel::EndConferenceCall(void)
150 result r = __pTelephonyMgr->EndConferenceCall();
153 //TODO: send proper error code
154 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
161 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
163 result r = __pTelephonyMgr->HoldCall(callHandle, true);
164 return (!IsFailed(r));
168 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
170 result r = __pTelephonyMgr->HoldCall(callHandle, false);
171 return (!IsFailed(r));
175 CallPresentationModel::HoldConferenceCall(void)
177 result r = __pTelephonyMgr->HoldConferenceCall(true);
178 return (!IsFailed(r));
182 CallPresentationModel::ActivateConferenceCall(void)
184 result r = __pTelephonyMgr->HoldConferenceCall(false);
185 return (!IsFailed(r));
189 CallPresentationModel::JoinCall(void)
191 result r = __pTelephonyMgr->JoinCall();
194 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
199 CallPresentationModel::SwapCalls(void)
201 result r = __pTelephonyMgr->SwapCalls();
204 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
209 CallPresentationModel::SetMuteStatus(bool setMute)
211 result r = __pTelephonyMgr->SetMuteStatus(setMute);
212 return (!IsFailed(r));
216 CallPresentationModel::IsCallMuted(void)
218 return __pTelephonyMgr->IsCallMuted();
222 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
224 result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
225 return (!IsFailed(r));
229 CallPresentationModel::IsSpeakerOn(void)
231 return __pTelephonyMgr->IsSpeakerOn();
234 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
236 __pTelephonyMgr->SendCallDTMF(textToBeSent);
240 CallPresentationModel::GetConferenceCallInfoN(void)
242 return __pTelephonyMgr->GetConferenceCallInfoN();
246 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<CallInfo>* pConfCallList)
249 CallInfo callToBeSpli;
250 switch (splitCallerCmdId)
252 case IDA_SPLIT_CALLER1:
256 case IDA_SPLIT_CALLER2:
260 case IDA_SPLIT_CALLER3:
264 case IDA_SPLIT_CALLER4:
268 case IDA_SPLIT_CALLER5:
276 result r = pConfCallList->GetAt(callIndex, callToBeSpli);
277 TryCatch(r == E_SUCCESS,,"conf. call list corrupted");
278 //split single call from conference
279 r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
280 TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
284 __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
289 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<CallInfo>* pConfCallList)
292 CallInfo callToBeEnded;
293 switch (endCallerCmdId)
295 case IDA_END_CALLER1:
299 case IDA_END_CALLER2:
303 case IDA_END_CALLER3:
307 case IDA_END_CALLER4:
311 case IDA_END_CALLER5:
319 result r = pConfCallList->GetAt(callIndex, callToBeEnded);
320 TryCatch(r == E_SUCCESS,,"conference call list corrupted");
322 r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
323 TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
328 __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
333 CallPresentationModel::IsSplitAllowed(void)
335 return __pTelephonyMgr->IsSplitAllowed();
339 CallPresentationModel::AcceptIncomingCall(CallAnswerOptions answerOptions,int callHandle)
341 result r = E_FAILURE;
342 if (answerOptions == CALL_ANSWER_CALL)
344 r = __pTelephonyMgr->AnswerCall(callHandle, true);
348 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
352 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
357 CallPresentationModel::GetCallListN(void)
359 return __pTelephonyMgr->GetCallListN();
364 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
366 result r = __pTelephonyMgr->AnswerCall(callHandle, false);
369 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
376 result r = E_SUCCESS;
378 extraData.Construct();
380 extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
381 extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(contactNumber));
383 AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
386 r = pAc->Start(null, null, &extraData, this);
387 __isMessageAppControlRunning = true;
391 extraData.RemoveAll(true);
397 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
399 if (__isMessageAppControlRunning == true)
401 //This comes here, when Message AppControl is finished working.
402 __isMessageAppControlRunning = false;
403 //Check if this was the last call, then terminate application.
404 //And if any calls are active, then those cases are already handled from Other places.
405 if( GetCurrentCallCount() == 0)
407 PhoneApp* pPhoneApp = static_cast<PhoneApp*>(UiApp::GetInstance());
408 SceneManager* pSceneManager = SceneManager::GetInstance();
409 SceneId startingScene = pPhoneApp->GetInitialScene();
410 //No more calls are active
411 if (startingScene == IDSCN_DIALER || startingScene == IDSCN_CALL_LOG)
413 pSceneManager->GoForward( ForwardSceneTransition(startingScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
414 SCENE_HISTORY_OPTION_NO_HISTORY));
418 pPhoneApp->Terminate();
425 CallPresentationModel::GetCurrentCallCount(void)
427 return __pTelephonyMgr->GetCurrentCallCount();
431 CallPresentationModel::CheckSimInitializationIsCompleted()
433 result r = E_FAILURE;
434 if(__pTelephonyMgr != null)
436 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
438 return (!IsFailed(r));
442 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
444 return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
448 CallPresentationModel::StartAlert(CallInfo& incomingCallInfo)
450 __pTelephonyMgr->StartAlert(incomingCallInfo);
454 CallPresentationModel::StopAlert(void)
456 __pTelephonyMgr->StopAlert();
460 CallPresentationModel::GetContactN(const String& phoneNumber)
462 return __pTelephonyMgr->GetContactN(phoneNumber);
466 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
468 //Adding incoming call sate setting here
469 if(__pSettingsPresentor != null)
471 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
473 return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
477 CallPresentationModel::CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo)
479 return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
482 /////////////////////////////////////////////////////////////////
483 ///// Event Listener methods from ITelephonyEventListener /////
484 /////////////////////////////////////////////////////////////////
486 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
488 if (__pTelEventListener != null)
490 __pTelEventListener->HandleCallConnected(pCallList);
492 if(__pSettingsPresentor != null)
494 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
499 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<CallInfo>& pCallList)
501 if (isLastCall == true)
503 SetSpeakerStatus(false);
504 SetMuteStatus(false);
505 if(__pSettingsPresentor != null)
507 __pSettingsPresentor->SetCallState(CALL_STATE__CALL_OFF);
510 //Defer from sending call disconnected event to form, in case Msg AppControl is running,
511 //to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
512 if (__pTelEventListener != null && __isMessageAppControlRunning == false)
514 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
520 CallPresentationModel::HandleConferenceCall(CallInfo& pCallInfo)
522 if (__pTelEventListener != null)
524 __pTelEventListener->HandleConferenceCall(pCallInfo);
529 CallPresentationModel::HandleIncomingCall(CallInfo& pCallInfo)
531 StartAlert(pCallInfo);
532 if (__pTelEventListener != null)
534 __pTelEventListener->HandleIncomingCall(pCallInfo);
538 //as base form not created. So no listener set.
539 SceneManager* pSceneManager = SceneManager::GetInstance();
541 //Ownership - To be deleted in 'OnSceneActivatedN' of next form
542 ArrayList* pCallInfoList = new (std::nothrow) ArrayList(SingleObjectDeleter);
543 pCallInfoList->Construct(1);
545 //update list to be passed
546 CallInfo* pIncomingCall = new (std::nothrow) CallInfo();
547 *pIncomingCall = pCallInfo;
548 pCallInfoList->Add(pIncomingCall);
550 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), pCallInfoList);
552 if(__pSettingsPresentor != null)
554 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
559 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
561 if (__pTelEventListener != null)
563 __pTelEventListener->HandleCallSwapOccured(pCallList);
568 CallPresentationModel::HandleConferenceChange(void)
570 if (__pTelEventListener != null)
572 __pTelEventListener->HandleConferenceChange();
577 CallPresentationModel::HandleTelephonyError(int errorCode)
579 if (__pTelEventListener != null)
581 __pTelEventListener->HandleTelephonyError(errorCode);