X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FCallPresentationModel.cpp;h=468f73275e5ee5f2318755d628c09b17056cdaa8;hb=4f9ce1622ba528aca7834f198a0830bdd1f8cd93;hp=efea53cb4731ad04d7b3a5264a2a0e030a8d1ecd;hpb=ae4a29bb3b9f149b458351feec6e6b1beccd7f86;p=apps%2Fosp%2FCall.git diff --git a/src/CallPresentationModel.cpp b/src/CallPresentationModel.cpp index efea53c..468f732 100644 --- a/src/CallPresentationModel.cpp +++ b/src/CallPresentationModel.cpp @@ -22,6 +22,7 @@ #include #include #include "CallApp.h" +#include "CallAppControlRequestMgr.h" #include "CallActiveCallForm.h" #include "CallInfo.h" #include "CallPresentationModel.h" @@ -38,6 +39,8 @@ using namespace Tizen::Graphics; using namespace Tizen::Media; using namespace Tizen::Social; using namespace Tizen::Ui::Scenes; +using namespace Tizen::Telephony; +using namespace Tizen::Base::Utility; CallPresentationModel* CallPresentationModel::__pInstance = null; @@ -48,12 +51,32 @@ CallPresentationModel::CallPresentationModel(void) __pSettingsPresentor = null; __isMessageAppControlRunning = false; __isDialAppControlRunning = false; + __pAppControlMgr = null; + __pNetworkManager = null; + __psimStateManager = null; + __psimInfo = null; } 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; + } } void @@ -97,6 +120,10 @@ CallPresentationModel::Construct(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; } @@ -107,10 +134,28 @@ CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventLis __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"); @@ -120,6 +165,37 @@ CallPresentationModel::DialCall(String& contactNumber, bool isEmergency) __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"); @@ -257,7 +333,7 @@ CallPresentationModel::GetConferenceCallInfoN(void) return __pTelephonyMgr->GetConferenceCallInfoN(); } -void +bool CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT* pConfCallList) { int callIndex = -1; @@ -293,11 +369,11 @@ CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdI //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 @@ -379,6 +455,11 @@ 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(&contactNumber)), this); + } result r = __pTelephonyMgr->AnswerCall(callHandle, false); if (IsFailed(r)) { @@ -386,37 +467,24 @@ CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& co 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)); - AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_MESSAGE, OPERATION_ID_COMPOSE); - if (pAc != null) - { - AppLogDebug("Start"); - r = pAc->Start(null, null, &extraData, this); - __isMessageAppControlRunning = true; - delete pAc; - } - - extraData.RemoveAll(true); - } AppLogDebug("Exit"); return true; } void CallPresentationModel::OnAppForeground(void) { + 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) @@ -430,10 +498,12 @@ void CallPresentationModel::OnAppForeground(void) 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) @@ -446,6 +516,7 @@ CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, { __isDialAppControlRunning = false; + __pAppControlMgr->AppControlRequestCompleted(); if(appControlResult == APP_CTRL_RESULT_SUCCEEDED) { String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER); @@ -470,7 +541,7 @@ CallPresentationModel::AddCall(const String& phoneNumber) 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); @@ -584,13 +655,13 @@ CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Coll __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 @@ -620,6 +691,7 @@ CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListTHandleConferenceChange(); @@ -635,33 +707,22 @@ CallPresentationModel::HandleTelephonyError(int errorCode) } } - -result +void CallPresentationModel::LaunchDialAppControl() { - result r = E_SUCCESS; - AppControl* pAppControl = null; if(__isDialAppControlRunning == true) { //Do not allow another app control if already running - return r; + return; } - 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) + //Launch dialer AppControl + if (__pAppControlMgr != null) { - r = pAppControl->Start(null, null, &extraData, this); - __isDialAppControlRunning = true; + __isDialAppControlRunning = __pAppControlMgr->LaunchDialerAppControl(this); } - extraData.RemoveAll(true); - - return r; } bool @@ -722,3 +783,152 @@ CallPresentationModel::IsEnableJoinCallButton(void) 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; + } + + +} +