//
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
#include <FUi.h>
#include <FMedia.h>
#include "CallApp.h"
+#include "CallAppControlRequestMgr.h"
#include "CallActiveCallForm.h"
#include "CallInfo.h"
#include "CallPresentationModel.h"
using namespace Tizen::Media;
using namespace Tizen::Social;
using namespace Tizen::Ui::Scenes;
+using namespace Tizen::Telephony;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Messaging;
CallPresentationModel* CallPresentationModel::__pInstance = null;
__pSettingsPresentor = null;
__isMessageAppControlRunning = false;
__isDialAppControlRunning = false;
+ __pAppControlMgr = null;
+ __pNetworkManager = null;
+ __psimStateManager = null;
+ __psimInfo = null;
+ __pSmsManager = null;
+ __isMessageSendInProgress = false;
}
CallPresentationModel::~CallPresentationModel(void)
{
__pTelephonyMgr = null;
__pSettingsPresentor = null;
+ __pAppControlMgr =null;
+ if(__pNetworkManager != null)
+ {
+ delete __pNetworkManager;
+ __pNetworkManager = null;
+ }
+ if(__psimStateManager != null)
+ {
+ delete __psimStateManager;
+ __psimStateManager = null;
+ }
+ if(__psimInfo != null)
+ {
+ delete __psimInfo;
+ __psimInfo = null;
+ }
+ if(__pSmsManager != null)
+ {
+ delete __pSmsManager;
+ __pSmsManager = null;
+ }
}
void
//Fetch Telephony Manager
__pTelephonyMgr = TelephonyManager::GetInstance(this);
__pSettingsPresentor = SettingsPresentationModel::GetInstance();
+ __pAppControlMgr = CallAppControlRequestMgr::GetInstance();
+ __pNetworkManager = new (std::nothrow)NetworkManager();
+ __pNetworkManager->Construct(null);
+ GetSimInfo();
return E_SUCCESS;
}
__pTelEventListener = pTelEventListener;
}
+bool
+CallPresentationModel::IfNumberEndsWithHash(Tizen::Base::String& phoneNumber)
+{
+ String phoneNumberEndingWithHash(L"#$");
+ RegularExpression checkHash;
+ checkHash.Construct(phoneNumberEndingWithHash);
+ bool endsWithHash = checkHash.Match(phoneNumber,false);
+ if(endsWithHash == true)
+ {
+ return true;
+ }
+ return false;
+}
+
void
CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
{
int errorCode = ERROR_NONE;
+ bool isCallServiceAvailable = false;
+ bool numberEndsWithHash = false;
+ NetworkStatus networkStatus;
+ result r;
//Check if Telephony Manager is initialized
TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
//check if phone is in flight mode
- if(__pSettingsPresentor->GetFlightModeStatus() == true)
+ if(__pSettingsPresentor != null && __pSettingsPresentor->GetFlightModeStatus() == true)
{
__pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
return;
}
+ //Check if dialing a call is possible - Check if sim is available
+ if (IsSimAvailable() == false)
+ {
+ __pTelEventListener->HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
+ return ;
+ }
+
+ //fetch call service status
+ if(__pNetworkManager != null)
+ {
+ r = __pNetworkManager->GetNetworkStatus(networkStatus);
+ if (r == E_SUCCESS)
+ {
+ isCallServiceAvailable = networkStatus.IsCallServiceAvailable();
+ }
+ }
+
+
+ if (isCallServiceAvailable == false)
+ {
+ __pTelEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
+ return ;
+ }
+ // check if GPRS number
+ numberEndsWithHash = IfNumberEndsWithHash(contactNumber);
+ if(numberEndsWithHash == true)
+ {
+ __pTelEventListener->HandleTelephonyError(ERROR_GPRS_NUMBER);
+ return ;
+ }
+
//setup outgoing call
errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
__pTelephonyMgr->SendCallDTMF(textToBeSent);
}
-CallInfo*
+AppCallInfo*
CallPresentationModel::GetConferenceCallInfoN(void)
{
return __pTelephonyMgr->GetConferenceCallInfoN();
}
-void
-CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<CallInfo>* pConfCallList)
+bool
+CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<AppCallInfo>* pConfCallList)
{
int callIndex = -1;
- CallInfo callToBeSpli;
+ AppCallInfo callToBeSpli;
switch (splitCallerCmdId)
{
case IDA_SPLIT_CALLER1:
//split single call from conference
r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
- return;
+ return true;
CATCH:
__pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
- return;
+ return false;
}
void
-CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<CallInfo>* pConfCallList)
+CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<AppCallInfo>* pConfCallList)
{
int callIndex = -1;
- CallInfo callToBeEnded;
+ AppCallInfo callToBeEnded;
switch (endCallerCmdId)
{
case IDA_END_CALLER1:
}
}
-IListT<CallInfo>*
+IListT<AppCallInfo>*
CallPresentationModel::GetCallListN(void)
{
return __pTelephonyMgr->GetCallListN();
bool
CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
{
+ AppLogDebug("Enter");
+ if (sendMsg == true && __pAppControlMgr != null)
+ {
+ //launch compose message AppControl
+ __isMessageAppControlRunning = __pAppControlMgr->LaunchComposeMessageAppControl(*(const_cast<String*>(&contactNumber)), this);
+ }
result r = __pTelephonyMgr->AnswerCall(callHandle, false);
if (IsFailed(r))
{
return false;
}
- if (sendMsg == true)
- {
- //launch message
- result r = E_SUCCESS;
- HashMap extraData;
- extraData.Construct();
- extraData.Add(new (std::nothrow) String(MESSAGE_TYPE), new (std::nothrow) String(MESSAGE_SMS_TYPE));
- extraData.Add(new (std::nothrow) String(MESSAGE_TO), new (std::nothrow) String(contactNumber));
+ AppLogDebug("Exit");
+ return true;
+}
- AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE);
- if (pAc != null)
+void CallPresentationModel::OnAppForeground(void)
+{
+ AppLogDebug("Enter %d %d",__isDialAppControlRunning ,__isMessageAppControlRunning);
+ if (__isDialAppControlRunning == true)
+ {
+ //This comes here, when Dialer AppControl is finished working.
+ __isDialAppControlRunning = false;
+ __pAppControlMgr->AppControlRequestCompleted();
+ }
+ if (__isMessageAppControlRunning == true)
+ {
+ //This comes here, when Message AppControl is finished working.
+ __isMessageAppControlRunning = false;
+ __pAppControlMgr->AppControlRequestCompleted();
+ //Check if this was the last call, then terminate application.
+ //And if any calls are active, then those cases are already handled from Other places.
+ if( GetCurrentCallCount() == 0 && IsIncomingorDialingCallPresent() == false)
{
- r = pAc->Start(null, null, &extraData, this);
- __isMessageAppControlRunning = true;
- delete pAc;
+ CallApp* pCallApp = static_cast<CallApp*>(UiApp::GetInstance());
+ pCallApp->Terminate();
}
-
- extraData.RemoveAll(true);
}
- return true;
}
void
CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
{
+ AppLogDebug("Enter");
if (__isMessageAppControlRunning == true)
{
//This comes here, when Message AppControl is finished working.
__isMessageAppControlRunning = false;
+ __pAppControlMgr->AppControlRequestCompleted();
//Check if this was the last call, then terminate application.
//And if any calls are active, then those cases are already handled from Other places.
if( GetCurrentCallCount() == 0)
{
__isDialAppControlRunning = false;
+ __pAppControlMgr->AppControlRequestCompleted();
if(appControlResult == APP_CTRL_RESULT_SUCCEEDED)
{
String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
ArrayList* pLaunchArgs = null;
SceneManager* pSceneManager = SceneManager::GetInstance();
int currentActiveCallCount = GetCurrentCallCount();
- if(currentActiveCallCount <= 1)
+ if(currentActiveCallCount <= 1 && IsIncomingorDialingCallPresent() == false)
{
//make an outgoing call with given number
String* contactTxt = new (std::nothrow) String(phoneNumber);
{
nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
}
- pSceneManager->GoForward( ForwardSceneTransition( nextScene), pLaunchArgs);
+ pSceneManager->GoForward( ForwardSceneTransition( nextScene,
+ SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pLaunchArgs);
}
}
}
void
-CallPresentationModel::StartAlert(CallInfo& incomingCallInfo)
+CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
{
//Adding incoming call sate setting here
if(__pSettingsPresentor != null)
return __pTelephonyMgr->GetContactN(phoneNumber);
}
-CallInfo*
+AppCallInfo*
CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
{
}
bool
-CallPresentationModel::CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo)
+CallPresentationModel::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
{
return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
}
///// Event Listener methods from ITelephonyEventListener /////
/////////////////////////////////////////////////////////////////
void
-CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
+CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
{
if (__pTelEventListener != null)
{
}
void
-CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<CallInfo>& pCallList)
+CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
{
+ AppLogDebug("Enter");
if (isLastCall == true)
{
SetSpeakerStatus(false);
__pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
}
}
- //Defer from sending call disconnected event to form, in case Msg AppControl is running,
+ //1) Defer from sending call disconnected event to form, in case Msg AppControl is running,
//to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
- if (__pTelEventListener != null && __isMessageAppControlRunning == false)
+ //2) Do not send call disconnected event to any form, in case an incoming call or dialing call is present.
+ if (__pTelEventListener != null /*&& __isMessageAppControlRunning == false*/ )
{
__pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
}
-
}
void
-CallPresentationModel::HandleConferenceCall(CallInfo& pCallInfo)
+CallPresentationModel::HandleConferenceCall(AppCallInfo& pCallInfo)
{
if (__pTelEventListener != null)
{
}
void
-CallPresentationModel::HandleIncomingCall(CallInfo& pCallInfo)
+CallPresentationModel::HandleIncomingCall(AppCallInfo& pCallInfo)
{
AppLogDebug("Error - This will never come here. Since, now we are getting incoming call event through AppControl!!");
}
void
-CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<CallInfo>& pCallList)
+CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
{
if (__pTelEventListener != null)
{
void
CallPresentationModel::HandleConferenceChange(void)
{
+ //1) Do not send conf. call changed event to any form, in case an incoming call or dialing call is present.
if (__pTelEventListener != null)
{
__pTelEventListener->HandleConferenceChange();
}
}
-
-result
+void
CallPresentationModel::LaunchDialAppControl()
{
- result r = E_SUCCESS;
- AppControl* pAppControl = null;
if(__isDialAppControlRunning == true)
{
+ AppLogDebug("__isDialAppControlRunning == true");
//Do not allow another app control if already running
- return r;
+ return;
+ }
+
+ //Launch dialer AppControl
+ if (__pAppControlMgr != null)
+ {
+ __isDialAppControlRunning = __pAppControlMgr->LaunchDialerAppControl(this);
}
- HashMap extraData;
- extraData.Construct();
- extraData.Add(new (std::nothrow) String(PARAM_PHONE_NUMBER), new (std::nothrow) String(L""));
+}
- pAppControl = AppManager::FindAppControlN(PROVIDER_ID_PHONE, OPERATION_ID_DIAL);
- if (pAppControl != null)
+bool
+CallPresentationModel::IsEnableJoinCallButton(void)
+{
+ //Check if conf. call has maximum participants
+ AppCallInfo* pConfCallInfo = GetConferenceCallInfoN();
+ if(pConfCallInfo != null && pConfCallInfo->GetCallerListCount() >= IDI_MAX_CONF_CALL_PARTICIPANTS)
{
- r = pAppControl->Start(null, null, &extraData, this);
- __isDialAppControlRunning = true;
+ return false;
}
- extraData.RemoveAll(true);
+ //check if either of the caller is same or present in conf call.
+ IListT<AppCallInfo>* pActiveCallList = GetCallListN();
+ if ( pActiveCallList != null && pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
+ {
+ AppCallInfo firstCall;
+ AppCallInfo secondCall;
+ pActiveCallList->GetAt(0, firstCall);
+ pActiveCallList->GetAt(1, secondCall);
- return r;
+ if (firstCall.IsConferenceCall() == true)
+ {
+ IListT<AppCallInfo>* pConfMemberList = firstCall.GetCallerList();
+ for (int index = 0; index < pConfMemberList->GetCount(); index++)
+ {
+ AppCallInfo singleConfMember;
+ pConfMemberList->GetAt(index, singleConfMember);
+ if (secondCall.GetContactNumber().IsEmpty() == false && secondCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
+ {
+ return false;
+ }
+ }
+ }
+ else if (secondCall.IsConferenceCall() == true)
+ {
+ IListT<AppCallInfo>* pConfMemberList = secondCall.GetCallerList();
+ for (int index = 0; index < pConfMemberList->GetCount(); index++)
+ {
+ AppCallInfo singleConfMember;
+ pConfMemberList->GetAt(index, singleConfMember);
+ if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
+ {
+ return false;
+ }
+ }
+ }
+ else
+ {
+ //Now, we definitely know that both are single active calls.
+ if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(secondCall.GetContactNumber()) == true)
+ {
+ return false;
+ }
+ }
+ }
+ delete pConfCallInfo;
+ pConfCallInfo = null;
+ return true;
+}
+bool
+CallPresentationModel::IsIncomingorDialingCallPresent(void)
+{
+ //returns false, if incoming call or dialed call is present.
+ return __pTelephonyMgr->IsIncomingorDialingCallPresent();
+}
+
+bool
+CallPresentationModel::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
+{
+ if (__pAppControlMgr != null)
+ {
+ return __pAppControlMgr->LaunchComposeMessageAppControl(contactNumber, pListener);
+ }
+ return false;
+}
+
+bool
+CallPresentationModel::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
+{
+ if (__pAppControlMgr != null)
+ {
+ return __pAppControlMgr->LaunchViewContactAppControl(contactId, pListener);
+ }
+ return false;
+}
+
+bool
+CallPresentationModel::LaunchAddContactAppControl(Tizen::Base::String& contactNumber, Tizen::App::IAppControlResponseListener* pListener)
+{
+ if (__pAppControlMgr != null)
+ {
+ return __pAppControlMgr->LaunchAddContactAppControl(contactNumber, pListener);
+ }
+ return false;
+}
+
+bool
+CallPresentationModel::IsAppControlRunning(void)
+{
+ if (__pAppControlMgr != null)
+ {
+ return __pAppControlMgr->IsAppControlRunning();
+ }
+ return false;
+}
+
+void
+CallPresentationModel::AbortAppControlRequest(void)
+{
+ if (__pAppControlMgr != null)
+ {
+ __pAppControlMgr->AbortAppControlRequest();
+ }
+}
+
+void
+CallPresentationModel::AppControlRequestCompleted(void)
+{
+ if (__pAppControlMgr != null)
+ {
+ __pAppControlMgr->AppControlRequestCompleted();
+ }
+}
+
+result
+CallPresentationModel::GetSimInfo(void)
+{
+ __psimStateManager = new (std::nothrow)SimStateManager();
+ result r = __psimStateManager->Construct();
+ if (IsFailed(r))
+ {
+ delete __psimStateManager;
+ __psimStateManager = null;
+ return E_FAILURE;
+ }
+ __psimStateManager->SetSimEventListener(this);
+
+ __psimInfo = new (std::nothrow)SimInfo();
+ r = __psimStateManager->GetSimInfo(*__psimInfo);
+ if (IsFailed(r))
+ {
+ delete __psimStateManager;
+ __psimStateManager = null;
+ delete __psimInfo;
+ __psimInfo = null;
+ return E_FAILURE;
+ }
+ return E_SUCCESS;
+}
+
+void
+CallPresentationModel::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
+{
+
+}
+
+void
+CallPresentationModel::OnTelephonySimStateChanged(Tizen::Telephony::SimState state)
+{
+ if(__psimStateManager != null)
+ {
+ delete __psimStateManager;
+ __psimStateManager =null;
+ }
+ if(__psimInfo != null)
+ {
+ delete __psimInfo;
+ __psimInfo = null;
+ }
+
+ __psimStateManager = new SimStateManager();
+ result r = __psimStateManager->Construct();
+ if (IsFailed(r))
+ {
+ delete __psimStateManager;
+ __psimStateManager = null;
+ return ;
+ }
+
+ __psimInfo = new SimInfo();
+ r = __psimStateManager->GetSimInfo(*__psimInfo);
+ if (IsFailed(r))
+ {
+ delete __psimStateManager;
+ __psimStateManager = null;
+ delete __psimInfo;
+ __psimInfo = null;
+ return ;
+ }
+
+}
+
+bool
+CallPresentationModel::IsSimAvailable(void)
+{
+ if(__psimInfo != null)
+ {
+ return __psimInfo->IsAvailable();
+ }
+ else
+ {
+ return false;
+ }
+
+
+}
+
+void
+CallPresentationModel::SendMessage(String& strMsg,String& recpientNum)
+{
+ AppLogDebug("Enter");
+ result r;
+ if(__pSmsManager == null)
+ {
+ __pSmsManager = new (std::nothrow) SmsManager();
+ result r = __pSmsManager->Construct(*this);
+ if (IsFailed(r) == true)
+ {
+ delete __pSmsManager;
+ __pSmsManager = null;
+ return;
+ }
+
+ }
+ RecipientList recipient;
+ recipient.Add(RECIPIENT_TYPE_TO,recpientNum);
+ SmsMessage smsMessage;
+ r = smsMessage.SetText(strMsg);
+ if (IsFailed(r) == false)
+ {
+ r = __pSmsManager->Send(smsMessage,recipient,true);
+ if (IsFailed(r) == false)
+ {
+ __isMessageSendInProgress = true;
+ }
+
+ }
+
+}
+
+bool
+CallPresentationModel::IsMessageSendingInProgress(void)
+{
+ AppLogDebug("Enter %d",__isMessageSendInProgress);
+ return __isMessageSendInProgress;
+}
+
+void
+CallPresentationModel::OnSmsMessageSent(result r)
+{
+ AppLogDebug("Enter");
+ __isMessageSendInProgress = false;
}