+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file PhnTelephonyManager.cpp
+ * @brief Call log item provider
+ */
+#include <stdio.h>
+#include <FBaseSys.h>
+#include <FSystem.h>
+#include "ITapiModem.h"
+#include "ITapiSim.h"
+#include "PhnCallInfo.h"
+#include "PhnTelephonyManager.h"
+#include "PhnSettingsManager.h"
+#include "PhnTypes.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Graphics;
+using namespace Tizen::Social;
+using namespace Tizen::System;
+using namespace Tizen::Base::Collection;
+
+const char* callEventList[] = {
+ TAPI_NOTI_VOICE_CALL_STATUS_IDLE,
+ TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE,
+ TAPI_NOTI_VOICE_CALL_STATUS_HELD,
+ TAPI_NOTI_VOICE_CALL_STATUS_DIALING,
+ TAPI_NOTI_VOICE_CALL_STATUS_ALERT,
+ /*TAPI_NOTI_VOICE_CALL_STATUS_INCOMING,*/
+ TAPI_NOTI_VOICE_CALL_STATUS_WAITING,
+ TAPI_NOTI_CALL_INFO_CALL_CONNECTED_LINE,
+ TAPI_NOTI_CALL_INFO_WAITING,
+ TAPI_NOTI_CALL_INFO_CUG,
+ TAPI_NOTI_CALL_INFO_FORWARDED,
+ TAPI_NOTI_CALL_INFO_BARRED_INCOMING,
+ TAPI_NOTI_CALL_INFO_BARRED_OUTGOING,
+ TAPI_NOTI_CALL_INFO_DEFLECTED,
+ TAPI_NOTI_CALL_INFO_CLIR_SUPPRESSION_REJECT,
+ TAPI_NOTI_CALL_INFO_FORWARD_UNCONDITIONAL,
+ TAPI_NOTI_CALL_INFO_FORWARD_CONDITIONAL,
+ TAPI_NOTI_CALL_INFO_CALL_LINE_IDENTITY,
+ TAPI_NOTI_CALL_INFO_CALL_NAME_INFORMATION,
+ TAPI_NOTI_CALL_INFO_FORWARDED_CALL,
+ TAPI_NOTI_CALL_INFO_CUG_CALL,
+ TAPI_NOTI_CALL_INFO_DEFLECTED_CALL,
+ TAPI_NOTI_CALL_INFO_TRANSFERED_CALL,
+ TAPI_NOTI_CALL_INFO_HELD,
+ TAPI_NOTI_CALL_INFO_ACTIVE,
+ TAPI_NOTI_CALL_INFO_JOINED,
+ TAPI_NOTI_CALL_INFO_RELEASED_ON_HOLD,
+ TAPI_NOTI_CALL_INFO_TRANSFER_ALERT,
+ TAPI_NOTI_CALL_INFO_TRANSFERED,
+ TAPI_NOTI_CALL_INFO_CF_CHECK_MESSAGE,
+};
+
+TelephonyManager* TelephonyManager::__pManager = null;
+
+TelephonyManager::TelephonyManager(ITelephonyEventListener* pEventListener)
+: __pEventListener(pEventListener)
+{
+ __pDialedCall = null;
+ __pIncomingCall = null;
+ __pActiveCallList = null;
+ __pSettingsManager = null;
+ __pTapiHandle = null;
+ __isIncomingCallPresent = false;
+ __pAddressBook = null;
+ __pCachedContact = null;
+ __isMuted = false;
+ __isSpeakerOn = false;
+ __pSoundManager = null;
+ __pCalllogMgr = null;
+}
+
+TelephonyManager::~TelephonyManager(void)
+{
+ if (__pActiveCallList != null)
+ {
+ delete __pActiveCallList;
+ }
+
+ if (__pDialedCall != null)
+ {
+ delete __pDialedCall;
+ __pDialedCall = null;
+ }
+
+ if (__pIncomingCall != null)
+ {
+ delete __pIncomingCall;
+ __pIncomingCall = null;
+ }
+
+ if (__pAddressBook != null)
+ {
+ delete __pAddressBook;
+ __pAddressBook = null;
+ }
+ if (__pCachedContact != null)
+ {
+ delete __pCachedContact;
+ __pCachedContact = null;
+ }
+
+ //unregister for events from TAPI Lib.
+ UnregisterEvents();
+
+ //De-initialize the TAPI Library
+ if(__pTapiHandle != null)
+ {
+ tel_deinit(__pTapiHandle);
+ }
+
+ if (__pSoundManager != null)
+ {
+ delete __pSoundManager;
+ }
+
+ if (__pCalllogMgr)
+ {
+ __pCalllogMgr = null;
+ }
+}
+
+TelephonyManager*
+TelephonyManager::GetInstance(ITelephonyEventListener* pEventListener)
+{
+ if (__pManager == null)
+ {
+ CreateInstance(pEventListener);
+ }
+ return __pManager;
+}
+
+void
+TelephonyManager::CreateInstance(ITelephonyEventListener* pEventListener)
+{
+ __pManager = new (std::nothrow) TelephonyManager(pEventListener);
+ result r = __pManager->Initialize();
+ if (IsFailed(r))
+ {
+ delete __pManager;
+ __pManager = null;
+ }
+ atexit(&(TelephonyManager::DestroyInstance));
+}
+
+void
+TelephonyManager::DestroyInstance(void)
+{
+ if (__pManager != null)
+ {
+ __pManager->EndAllCalls();
+ delete __pManager;
+ __pManager = null;
+ }
+}
+
+result
+TelephonyManager::Initialize(void)
+{
+ //Initialize telephony library
+ result r = InitializeTelephonyLibrary();
+ if (IsFailed(r))
+ {
+ return r;
+ }
+ __pActiveCallList = new (std::nothrow) HashMapT<long, CallInfo>();
+ __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
+
+ //Initialize the Settings Manager to fetch call settings
+ __pSettingsManager = SettingsManager::GetInstance();
+
+ //initialize address book to fetch contacts information
+ __pAddressBook = new (std::nothrow) Addressbook();
+ r = __pAddressBook->Construct();
+ if (IsFailed(r))
+ {
+ //TODO: handle the issue: Out of memory, etx.
+ return r;
+ }
+ __pSoundManager = new (std::nothrow) SoundManager();
+ __pCalllogMgr = CallLogManager::GetInstance();
+ return r;
+}
+
+result
+TelephonyManager::InitializeTelephonyLibrary(void)
+{
+ result r = E_FAILURE;
+
+ __pTapiHandle = tel_init(null);
+ if (__pTapiHandle != null)
+ {
+ //register telephony events
+ int errorCode = RegisterEvents();
+ if (errorCode == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ }
+
+ //TAPI Library is initialized and events registered successfully
+ return r;
+}
+
+int
+TelephonyManager::RegisterEvents(void)
+{
+ int errCode = -1;
+ int eventCount = sizeof(callEventList) / sizeof(char *);
+ for (int index = 0; index < eventCount; index++)
+ {
+ errCode = tel_register_noti_event(__pTapiHandle, callEventList[index], &HandleCallback, this);
+ if (errCode != TAPI_API_SUCCESS)
+ {
+ return errCode;
+ }
+ }
+ return errCode;
+}
+
+void
+TelephonyManager::UnregisterEvents(void)
+{
+ int eventCount = sizeof(callEventList) / sizeof(char *);
+ for (int index = 0; index < eventCount; index++)
+ {
+ tel_deregister_noti_event(__pTapiHandle, callEventList[index]);
+ }
+}
+
+ErrorCodes
+TelephonyManager::SetupMoCall(String& contactNumber, bool isEmergency)
+{
+ ErrorCodes r = ERROR_TAPI_ERROR;
+ result res = E_SUCCESS;
+
+ res = CheckValidTelePhoneNumber(contactNumber);
+ if (IsFailed(res))
+ {
+ return ERROR_INVALID_NUMBER;
+ }
+
+ //if dialing an emeregency call and active calls exist
+ //then end all active calls.
+ if (isEmergency && __pActiveCallList->GetCount() > 0)
+ {
+ //Get first call handle
+ CallInfo endCallInfo;
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ pCallList->GetAt(0, endCallInfo);
+ int callHandle = endCallInfo.GetCallHandle()->ToLong();
+ delete pCallList;
+ pCallList = null;
+
+ //release all active or held calls
+ int tapires = tel_end_call(__pTapiHandle, callHandle, TAPI_CALL_END_ALL, &HandleCallbackResponse, this);
+ if (tapires == TAPI_CAUSE_SUCCESS)
+ {
+ __pActiveCallList->RemoveAll();
+ r = ERROR_NONE;
+ res = E_SUCCESS;
+ }
+ else
+ {
+ r = ERROR_TAPI_ERROR;
+ return r;
+ }
+ }
+ else if (__pActiveCallList->GetCount() == 1)
+ {
+ //Check if there is already an active call,
+ //Put the already active call on hold.
+ CallInfo holdCallInfo;
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+
+ pCallList->GetAt(0, holdCallInfo);
+ //Check if call is active, then put on hold
+ if (holdCallInfo.IsOnHold() == false)
+ {
+ res = HoldActiveCall(&holdCallInfo, true);
+ }
+ delete pCallList;
+ pCallList = null;
+ }
+
+ //make the next call, only if any existing active call
+ //is successfully put on hold or is already on hold.
+ //make the next call, only if any existing active call
+ //is successfully put on hold or is already on hold.
+ if (res == E_SUCCESS)
+ {
+ res = DialOutgoingCall(contactNumber, isEmergency);
+ }
+ if(res == E_SUCCESS)
+ {
+ return ERROR_NONE;
+ }
+ {
+ return ERROR_TAPI_ERROR;
+ }
+}
+
+void
+TelephonyManager::EndAllCalls(void)
+{
+ if(__pDialedCall != null)
+ {
+ if(__pDialedCall->GetCallHandle() != null)
+ {
+ tel_end_call(__pTapiHandle, __pDialedCall->GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
+ }
+ }
+ tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_HOLD_ALL, &HandleCallbackResponse, this);
+ //end all active calls before terminating application
+ tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_ALL, &HandleCallbackResponse, this);
+}
+
+result
+TelephonyManager::EndCall(Long callHandle)
+{
+ result r = E_SUCCESS;
+ CallInfo endCall;
+ bool endDialedCall = false;
+
+ //fetch ended callInfo
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, endCall);
+ if(endCall.GetCallHandle()->Equals(callHandle))
+ {
+ //Found the call to be ended.
+ r = E_SUCCESS;
+ break;
+ }
+
+ }
+ delete pCallList;
+ pCallList = null;
+
+ if (r == E_SUCCESS && __pDialedCall != null)
+ {
+ if (__pDialedCall->GetCallHandle()->Equals(callHandle) )
+ {
+ r = E_SUCCESS;
+ endCall = *__pDialedCall;
+ endDialedCall = true;
+ }
+
+ }
+
+ if (r == E_SUCCESS)
+ {
+ unsigned int callHandle = -1;
+ if (endCall.GetCallHandle() != null)
+ {
+ callHandle = endCall.GetCallHandle()->ToLong();
+ TelCallEndType_t endType = TAPI_CALL_END;
+ int res = -1;
+ res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndDialedCallResponse, this);
+
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ if (endDialedCall == true)
+ {
+ String endCause(L"Call Rejected");
+ __pDialedCall->SetEndCallCause(endCause);
+ }
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ }
+ return r;
+}
+
+result
+TelephonyManager::EndCall(String& contactNumber)
+{
+ result r = E_SUCCESS;
+ CallInfo endCall;
+ bool endDialedCall = false;
+ if (contactNumber.IsEmpty())
+ {
+ return E_FAILURE;
+ }
+
+ //fetch ended callInfo
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, endCall);
+ if (endCall.GetContactNumber().Equals(contactNumber))
+ {
+ //Found the call to be ended.
+ r = E_SUCCESS;
+ break;
+ }
+ }
+ delete pCallList;
+ pCallList = null;
+
+ if (r == E_SUCCESS && __pDialedCall != null)
+ {
+ if (__pDialedCall->GetContactNumber().Equals(contactNumber))
+ {
+ r = E_SUCCESS;
+ endCall = *__pDialedCall;
+ endDialedCall = true;
+ }
+ }
+
+ if (r == E_SUCCESS)
+ {
+ unsigned int callHandle = -1;
+ if (endCall.GetCallHandle() != null)
+ {
+ callHandle = endCall.GetCallHandle()->ToLong();
+ TelCallEndType_t endType = TAPI_CALL_END;
+ int res = -1;
+ res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndDialedCallResponse, this);
+
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ if (endDialedCall == true)
+ {
+ String endCause(L"Call Rejected");
+ __pDialedCall->SetEndCallCause(endCause);
+ }
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ }
+ return r;
+}
+
+result
+TelephonyManager::AnswerCall(int callHandle, bool acceptCall)
+{
+ result r = E_FAILURE;
+ __pSoundManager->StopAlert();
+ TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_ACCEPT;
+ int res = -1;
+ if (acceptCall == true)
+ {
+ answerType = TAPI_CALL_ANSWER_ACCEPT;
+ // redirect to dummy call back handler as the flow already handled in registered event callback
+ res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
+ }
+ else
+ {
+ answerType = TAPI_CALL_ANSWER_REJECT;
+ // redirect to reject call back handler as the flow has to be handled
+ res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleRejectCallbackResponse, this);
+ }
+
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ return r;
+}
+
+result
+TelephonyManager::AcceptCall(CallAnswerOptions answerOptions,int callHandle)
+{
+ result r = E_FAILURE;
+ __pSoundManager->StopAlert();
+ __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
+
+ if (__pActiveCallList->GetCount())
+ {
+ if (__pActiveCallList->GetCount() == 1)
+ {
+ r = AcceptSecondCall(answerOptions,callHandle);
+ }
+ else
+ {
+ r = AcceptMultipleCall(answerOptions,callHandle);
+ if (__pIncomingCall != null)
+ {
+ delete __pIncomingCall;
+ __pIncomingCall = null;
+ }
+ }
+
+ return r;
+ }
+ else
+ {
+ return r;
+ }
+}
+
+result
+TelephonyManager::AcceptSecondCall(CallAnswerOptions answerOptions,int callHandle)
+{
+ result r = E_FAILURE;
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int res = -1;
+ CallInfo* pFirstCallInfo = new (std::nothrow) CallInfo();
+ pCallList->GetAt(0,*pFirstCallInfo);
+ delete pCallList;
+ pCallList = null;
+ switch (answerOptions)
+ {
+ case CALL_ANSWER_HOLD_ACCEPT:
+ {
+ //todo: try answering call with option as TAPI_CALL_ANSWER_HOLD_AND_ACCEPT
+ if (pFirstCallInfo->IsConferenceCall() == false)
+ {
+ r = HoldActiveCall(pFirstCallInfo,true);
+ }
+ else
+ {
+ r = HoldConferenceCall(true);
+ }
+
+ if (callHandle == (unsigned int)__pIncomingCall->GetCallHandle()->ToLong())
+ {
+ //handle call connected - save info
+ String contactNo;
+ contactNo.Append(__pIncomingCall->GetContactNumber());
+ result r = FetchContactInfoForNumber(contactNo);
+ if (!IsFailed(r))
+ {
+ __pIncomingCall->SetContactInfo(*__pCachedContact);
+ }
+ }
+ else
+ {
+ delete __pIncomingCall;
+ TelCallStatus_t callStatus;
+ tel_get_call_status(__pTapiHandle, callHandle, &callStatus);
+ __pIncomingCall = new (std::nothrow) CallInfo();
+ __pIncomingCall->SetCallHandle(callHandle);
+ __pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ String contactNumber(callStatus.pNumber);
+ __pIncomingCall->SetContactNumber(contactNumber);
+ result r = FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ __pIncomingCall->SetContactInfo(*__pCachedContact);
+ }
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ __pIncomingCall->SetEmergency(true);
+ }
+ else
+ {
+ __pIncomingCall->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ __pIncomingCall->SetCallNotificationTime(startTime);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ __pIncomingCall->SetCallConnectTime(startTime);
+ r = E_SUCCESS;
+ break;
+ }
+ case CALL_ANSWER_END_ACTIVE_ACCEPT:
+ {
+ //todo: try answering call with option as TAPI_CALL_ANSWER_REPLACE
+ __pActiveCallList->RemoveAll();
+ if (pFirstCallInfo->IsConferenceCall() == false)
+ {
+ r = HoldActiveCall(pFirstCallInfo,true);
+ }
+ else
+ {
+ res = tel_hold_call(__pTapiHandle, pFirstCallInfo->GetCallHandle()->ToLong(), &HandleCallbackResponse, this);
+ }
+ // call should be active now. end the active call now
+ if (pFirstCallInfo->IsConferenceCall() == false)
+ {
+ TelCallEndType_t endType = TAPI_CALL_END;
+ unsigned int callHandleToBeEnded = pFirstCallInfo->GetCallHandle()->ToLong();
+ tel_end_call(__pTapiHandle, callHandleToBeEnded, endType, &HandleCallbackResponse, this);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(pFirstCallInfo);
+ }
+ else
+ {
+ int confCallCount = pFirstCallInfo->GetCallerListCount();
+ IListT<CallInfo>* pCallList = pFirstCallInfo->GetCallerList();
+ for (int index = 0; index < confCallCount; index++)
+ {
+ CallInfo callInfo;
+ pCallList->GetAt(index, callInfo);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&callInfo);
+ }
+ unsigned int callHandleToBeEnded = pFirstCallInfo->GetCallHandle()->ToLong();
+ TelCallEndType_t endType = TAPI_CALL_END_HOLD_ALL;
+ tel_end_call(__pTapiHandle, callHandleToBeEnded, endType, &HandleCallbackResponse, this);
+ }
+ r = E_SUCCESS;
+
+ if (callHandle == (unsigned int)__pIncomingCall->GetCallHandle()->ToLong())
+ {
+ //handle call connected - save info
+ String contactNo;
+ contactNo.Append(__pIncomingCall->GetContactNumber());
+ result r = FetchContactInfoForNumber(contactNo);
+ if (!IsFailed(r))
+ {
+ __pIncomingCall->SetContactInfo(*__pCachedContact);
+ }
+ }
+ else
+ {
+ delete __pIncomingCall;
+ TelCallStatus_t callStatus;
+ tel_get_call_status(__pTapiHandle, callHandle, &callStatus);
+ __pIncomingCall = new (std::nothrow) CallInfo();
+ __pIncomingCall->SetCallHandle(callHandle);
+ __pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ String contactNumber(callStatus.pNumber);
+ __pIncomingCall->SetContactNumber(contactNumber);
+ result r = FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ __pIncomingCall->SetContactInfo(*__pCachedContact);
+ }
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ __pIncomingCall->SetEmergency(true);
+ }
+ else
+ {
+ __pIncomingCall->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ __pIncomingCall->SetCallNotificationTime(startTime);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ __pIncomingCall->SetCallConnectTime(startTime);
+ break;
+ }
+ default:
+ break;
+ }
+ delete pFirstCallInfo;
+ return r;
+}
+
+result
+TelephonyManager::AcceptMultipleCall(CallAnswerOptions answerOptions,int callHandle)
+{
+ result r = E_FAILURE;
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ IListT<long>* pKeyList = __pActiveCallList->GetKeysN();
+ long firstKey;
+ long secondKey;
+ long activeCallKey;
+ long heldCallKey;
+ CallInfo* pFirstCallInfo = new (std::nothrow) CallInfo();
+ pCallList->GetAt(0,*pFirstCallInfo);
+ pKeyList->GetAt(0,firstKey);
+ CallInfo* pSecondCallInfo = new (std::nothrow) CallInfo();
+ pCallList->GetAt(1,*pSecondCallInfo);
+ pKeyList->GetAt(1,secondKey);
+ delete pCallList;
+ delete pKeyList;
+ CallInfo heldCall;
+ CallInfo activeCall;
+ if (pFirstCallInfo->IsOnHold() == false)
+ {
+ activeCall = *pFirstCallInfo;
+ activeCallKey = firstKey;
+ heldCall = *pSecondCallInfo;
+ heldCallKey = secondKey;
+ }
+ else
+ {
+ activeCall = *pSecondCallInfo;
+ activeCallKey = secondKey;
+ heldCall = *pFirstCallInfo;
+ heldCallKey = firstKey;
+ }
+ delete pFirstCallInfo;
+ delete pSecondCallInfo;
+
+ switch (answerOptions)
+ {
+ case CALL_ANSWER_END_ACTIVE_ACCEPT:
+ {
+ //todo: try answering call with option as TAPI_CALL_ANSWER_REPLACE
+ __pActiveCallList->Remove(activeCallKey);
+ TelCallStatus_t callStatus;
+ int res = tel_get_call_status(__pTapiHandle, callHandle, &callStatus);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ CallInfo* pCallInfo = new (std::nothrow) CallInfo();
+ pCallInfo->SetCallHandle(callHandle);
+
+ String contactNumber(callStatus.pNumber);
+ pCallInfo->SetContactNumber(contactNumber);
+ result r = FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ pCallInfo->SetContactInfo(*__pCachedContact);
+ }
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ pCallInfo->SetEmergency(true);
+ }
+ else
+ {
+ pCallInfo->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pCallInfo->SetCallConnectTime(startTime);
+ pCallInfo->SetCallNotificationTime(startTime);
+
+ //transfer ownership to Active calls list
+ __pActiveCallList->Add(callHandle, *(pCallInfo));
+ pCallInfo = null;
+ }
+
+ TelCallEndType_t endType = TAPI_CALL_END;
+ if (activeCall.IsConferenceCall() == false)
+ {
+ unsigned int callHandleToBeEnded = activeCall.GetCallHandle()->ToLong();
+ tel_end_call(__pTapiHandle, callHandleToBeEnded, endType, &HandleCallbackResponse, this);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&activeCall);
+ }
+ else
+ {
+ int confCallCount = activeCall.GetCallerListCount();
+ IListT<CallInfo>* pCallList = activeCall.GetCallerList();
+ for (int index = 0; index < confCallCount; index++)
+ {
+ CallInfo callInfo;
+ pCallList->GetAt(index, callInfo);
+ unsigned int calloBeEnded = callInfo.GetCallHandle()->ToLong();
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&callInfo);
+ tel_end_call(__pTapiHandle, calloBeEnded, endType, &HandleCallbackResponse, this);
+ }
+ }
+ if (callStatus.CallState == TAPI_CALL_STATE_WAITING || callStatus.CallState == TAPI_CALL_STATE_INCOMING)
+ {
+ res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ }
+ break;
+ }
+ case CALL_ANSWER_END_HELD_ACCEPT:
+ {
+ unsigned int callHandleToBeEnded = heldCall.GetCallHandle()->ToLong();
+ __pActiveCallList->Remove(heldCallKey);
+ TelCallStatus_t callStatus;
+ int res = tel_get_call_status(__pTapiHandle, callHandle, &callStatus);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ CallInfo* pCallInfo = new (std::nothrow) CallInfo();
+ pCallInfo->SetCallHandle(callHandle);
+
+ String contactNumber(callStatus.pNumber);
+ pCallInfo->SetContactNumber(contactNumber);
+ result r = FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ pCallInfo->SetContactInfo(*__pCachedContact);
+ }
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ pCallInfo->SetEmergency(true);
+ }
+ else
+ {
+ pCallInfo->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pCallInfo->SetCallConnectTime(startTime);
+ pCallInfo->SetCallNotificationTime(__pIncomingCall->GetCallNotificationTime());
+
+ //transfer ownership to Active calls list
+ __pActiveCallList->Add(callHandle, *(pCallInfo));
+ pCallInfo = null;
+ }
+ TelCallEndType_t endType = TAPI_CALL_END;
+ if (heldCall.IsConferenceCall() == false)
+ {
+ tel_end_call(__pTapiHandle, callHandleToBeEnded, endType, &HandleCallbackResponse, this);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&heldCall);
+ }
+ else
+ {
+ int confCallCount = heldCall.GetCallerListCount();
+ IListT<CallInfo>* pCallList = heldCall.GetCallerList();
+ for (int index = 0; index < confCallCount; index++)
+ {
+ CallInfo callInfo;
+ pCallList->GetAt(index, callInfo);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&callInfo);
+ unsigned int calloBeEnded = callInfo.GetCallHandle()->ToLong();
+ tel_end_call(__pTapiHandle, calloBeEnded, endType, &HandleCallbackResponse, this);
+ }
+ }
+ //Set held flag on active call
+ CallInfo* pHeldCallInfo = new (std::nothrow) CallInfo();
+ //copy state into new callinfo object
+ *pHeldCallInfo = activeCall;
+ //set call to hold state
+ pHeldCallInfo->SetOnHold(true);
+ //replace old object with new
+ __pActiveCallList->SetValue(activeCallKey, *pHeldCallInfo);
+ if (callStatus.CallState == TAPI_CALL_STATE_WAITING || callStatus.CallState == TAPI_CALL_STATE_INCOMING)
+ {
+ res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ }
+ break;
+ }
+ case CALL_ANSWER_END_ALL_ACCEPT:
+ {
+ unsigned int callHandleToBeEnded = activeCall.GetCallHandle()->ToLong();
+ __pActiveCallList->RemoveAll();
+ TelCallEndType_t endType = TAPI_CALL_END;
+ if (activeCall.IsConferenceCall() == false)
+ {
+ tel_end_call(__pTapiHandle, callHandleToBeEnded, endType, &HandleCallbackResponse, this);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&activeCall);
+ }
+ else
+ {
+ int confCallCount = activeCall.GetCallerListCount();
+ IListT<CallInfo>* pCallList = activeCall.GetCallerList();
+ for (int index = 0; index < confCallCount; index++)
+ {
+ CallInfo callInfo;
+ pCallList->GetAt(index, callInfo);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&callInfo);
+ unsigned int calloBeEnded = callInfo.GetCallHandle()->ToLong();
+ tel_end_call(__pTapiHandle, calloBeEnded, endType, &HandleCallbackResponse, this);
+ }
+ }
+ callHandleToBeEnded = heldCall.GetCallHandle()->ToLong();
+ if (heldCall.IsConferenceCall() == false)
+ {
+ tel_end_call(__pTapiHandle, callHandleToBeEnded, endType, &HandleCallbackResponse, this);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&heldCall);
+ }
+ else
+ {
+ int confCallCount = heldCall.GetCallerListCount();
+ IListT<CallInfo>* pCallList = heldCall.GetCallerList();
+ for (int index = 0; index < confCallCount; index++)
+ {
+ CallInfo callInfo;
+ pCallList->GetAt(index, callInfo);
+ //Add call ended to call log database
+ __pCalllogMgr->AddCallogInfoToDatabase(&callInfo);
+ unsigned int calloBeEnded = callInfo.GetCallHandle()->ToLong();
+ tel_end_call(__pTapiHandle, calloBeEnded, endType, &HandleCallbackResponse, this);
+ }
+ }
+ TelCallStatus_t callStatus;
+ int res = tel_get_call_status(__pTapiHandle, callHandle, &callStatus);
+ if (callStatus.CallState == TAPI_CALL_STATE_WAITING || callStatus.CallState == TAPI_CALL_STATE_INCOMING)
+ {
+ res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ CallInfo* pCallInfo = null;
+ if (callHandle == (unsigned int)__pIncomingCall->GetCallHandle()->ToLong())
+ {
+ //handle call connected - save info
+ pCallInfo = new (std::nothrow) CallInfo();
+ *pCallInfo = *(__pIncomingCall);
+ String contactNo;
+ contactNo.Append(pCallInfo->GetContactNumber());
+ result r = FetchContactInfoForNumber(contactNo);
+ if (!IsFailed(r))
+ {
+ pCallInfo->SetContactInfo(*__pCachedContact);
+ }
+ }
+ else
+ {
+ TelCallStatus_t callStatus;
+ tel_get_call_status(__pTapiHandle, callHandle, &callStatus);
+ pCallInfo = new (std::nothrow) CallInfo();
+ pCallInfo->SetCallHandle(callHandle);
+ pCallInfo->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ String contactNumber(callStatus.pNumber);
+ pCallInfo->SetContactNumber(contactNumber);
+ result r = FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ pCallInfo->SetContactInfo(*__pCachedContact);
+ }
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ pCallInfo->SetEmergency(true);
+ }
+ else
+ {
+ pCallInfo->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pCallInfo->SetCallNotificationTime(startTime);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pCallInfo->SetCallConnectTime(startTime);
+
+ //transfer ownership to Active calls list
+ __pActiveCallList->Add(callHandle, *(pCallInfo));
+ pCallInfo = null;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ return r;
+}
+
+result
+TelephonyManager::HoldCall(Tizen::Base::Long callHandle, bool holdCall)
+{
+ result r = E_SUCCESS;
+ //Check if there are any existing active calls
+ if (__pActiveCallList->GetCount())
+ {
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ CallInfo holdCallInfo;
+
+ r = pCallList->GetAt(index, holdCallInfo);
+ //check if an active call is found with matching contact no.
+ if ((r == E_SUCCESS) && (holdCallInfo.GetCallHandle()->Equals(callHandle)))
+ {
+ r = HoldActiveCall(&holdCallInfo, holdCall);
+ break;
+ }
+ }
+ delete pCallList;
+ pCallList = null;
+ }
+
+ return r;
+}
+
+result
+TelephonyManager::EndConferenceCall(void)
+{
+ result r = E_FAILURE;
+ //fetch ended callInfo
+ CallInfo endConfCall;
+ int res = -1;
+ bool isConferenceCallFound = false;
+
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, endConfCall);
+ if (endConfCall.IsConferenceCall() == true)
+ {
+ isConferenceCallFound = true;
+ break;
+ }
+ }
+ if (isConferenceCallFound == false)
+ {
+ delete pCallList;
+ pCallList = null;
+ return r;
+ }
+ unsigned int callHandle = endConfCall.GetCallHandle()->ToLong();
+ if (callCount == 1)
+ {
+ if (endConfCall.IsOnHold() == false)
+ {
+ TelCallEndType_t endType = TAPI_CALL_END_ACTIVE_ALL;
+ res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndDialedCallResponse, this);
+ }
+ else
+ {
+ TelCallEndType_t endType = TAPI_CALL_END_HOLD_ALL;
+ res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndDialedCallResponse, this);
+ }
+ }
+ else
+ {
+ //End each call in conference as using the end_all/Hold_all
+ //automatically activates the held call
+ TelCallEndType_t endType = TAPI_CALL_END;
+ int confCallCount = endConfCall.GetCallerListCount();
+ IListT<CallInfo>* pConfCallList = endConfCall.GetCallerList();
+ for (int index = 0; index < confCallCount; index++)
+ {
+ CallInfo callInfo;
+ pConfCallList->GetAt(index, callInfo);
+ unsigned int calloBeEnded = callInfo.GetCallHandle()->ToLong();
+ res = tel_end_call(__pTapiHandle, calloBeEnded, endType, &HandleEndDialedCallResponse, this);
+ }
+ }
+
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+ *pConfCallInfo = endConfCall;
+ __pActiveCallList->Remove(callHandle);
+ __pActiveCallList->Add(callHandle, *pConfCallInfo);
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+
+ delete pCallList;
+ pCallList = null;
+ return r;
+}
+
+result
+TelephonyManager::HoldConferenceCall(bool holdCall)
+{
+ result r = E_FAILURE;
+ int confCallIndex = -1;
+ CallInfo endConfCall;
+ bool isConferenceCallFound = false;
+
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int confCallCount = pCallList->GetCount();
+
+ for (int index = 0; index < confCallCount; index++)
+ {
+ pCallList->GetAt(index, endConfCall);
+ if (endConfCall.IsConferenceCall() == true)
+ {
+ isConferenceCallFound = true;
+ confCallIndex = index;
+ //Found the Conference call to be ended.
+ break;
+ }
+ }
+
+ if (isConferenceCallFound == false)
+ {
+ delete pCallList;
+ pCallList = null;
+ return r;
+ }
+
+ unsigned int callHandle = endConfCall.GetCallHandle()->ToLong();
+ int res = TAPI_API_INVALID_INPUT;
+ if (holdCall == true)
+ {
+ res = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
+ }
+ else
+ {
+ res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
+ }
+ if (res == TAPI_API_SUCCESS)
+ {
+ r = E_SUCCESS;
+ if (holdCall == true)
+ {
+ endConfCall.SetOnHold(true);
+ }
+ else
+ {
+ endConfCall.SetOnHold(false);
+ }
+ CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+ *pConfCallInfo = endConfCall;
+ __pActiveCallList->Remove(callHandle);
+ __pActiveCallList->Add(callHandle, *pConfCallInfo);
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+
+ delete pCallList;
+ pCallList = null;
+ return r;
+}
+
+result
+TelephonyManager::JoinCall(void)
+{
+ result r = E_FAILURE;
+ int res = -1;
+ CallInfo activeCall;
+ CallInfo heldCall;
+ // Use enumerator to access elements in the map
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ r = pCallList->GetAt(0, activeCall);
+
+ if (r == E_SUCCESS)
+ {
+ r = pCallList->GetAt(1, heldCall);
+ if (r == E_SUCCESS)
+ {
+ unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
+ unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
+
+ //Check if participants in conference call are under limit.
+ if ((heldCall.IsConferenceCall() == true) && (heldCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS))
+ {
+ res = tel_join_call(__pTapiHandle, heldCallHandle, activeCallHandle, &HandleJoinCallbackResponse, this);
+ }
+ else if (activeCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS)
+ {
+ res = tel_join_call(__pTapiHandle, activeCallHandle, heldCallHandle, &HandleJoinCallbackResponse, this);
+ }
+ }
+ }
+ delete pCallList;
+ pCallList = null;
+ if (res == TAPI_API_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ return r;
+}
+
+result
+TelephonyManager::HoldActiveCall(CallInfo* pActiveCallInfo, bool holdCall)
+{
+ unsigned int callHandle = pActiveCallInfo->GetCallHandle()->ToLong();
+ int retStatus = -1;
+ if (holdCall == true)
+ {
+ retStatus = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
+ }
+ else
+ {
+ retStatus = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
+ }
+
+ if (retStatus == TAPI_CAUSE_SUCCESS)
+ {
+ CallInfo* pHeldCallInfo = new (std::nothrow) CallInfo();
+ //copy state into new callinfo object
+ *pHeldCallInfo = *pActiveCallInfo;
+
+ //set call to hold state
+ pHeldCallInfo->SetOnHold(holdCall);
+
+ __pActiveCallList->Remove(callHandle);
+ //replace old object with new
+ __pActiveCallList->Add(callHandle, *pHeldCallInfo);
+ return E_SUCCESS;
+ }
+ else
+ {
+ return E_FAILURE;
+ }
+}
+
+result
+TelephonyManager::DialOutgoingCall(String& contactNumber, bool isEmergency)
+{
+ TelCallDial_t structDialCall;
+
+ //conversion "contactNumber" to char*
+ const wchar_t* pContact = contactNumber.GetPointer();
+ int len = contactNumber.GetLength()+1;
+ char* pNumber = new (std::nothrow) char[len];
+ wcstombs(pNumber, pContact, len);
+
+ //initialize request parameter
+ memset(&structDialCall, '\0', sizeof(TelCallDial_t));
+ memcpy(structDialCall.szNumber, pNumber, strlen(pNumber));
+
+ if(isEmergency == true)
+ {
+ structDialCall.CallType = TAPI_CALL_TYPE_E911;
+ }
+ else
+ {
+ structDialCall.CallType = TAPI_CALL_TYPE_VOICE;
+ }
+
+ int res = tel_dial_call(__pTapiHandle, &structDialCall, &HandleDialCallbackResponse, this);
+ if (__pSoundManager == null)
+ {
+ __pSoundManager = new (std::nothrow) SoundManager();
+ }
+ __pSoundManager->StartSession();
+ delete[] pNumber;
+ pNumber = null;
+
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ if (__pDialedCall != null)
+ {
+ delete __pDialedCall;
+ __pDialedCall = null;
+ }
+ __pDialedCall = new (std::nothrow) CallInfo();
+ __pDialedCall->SetContactNumber(contactNumber);
+ __pDialedCall->SetEmergency(isEmergency);
+ result r = FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ __pDialedCall->SetContactInfo(*__pCachedContact);
+ }
+ return E_SUCCESS;
+ }
+ else
+ {
+ return E_FAILURE;
+ }
+}
+
+result
+TelephonyManager::SwapCalls(void)
+{
+ result r = E_FAILURE;
+
+ //check if there are atleast 2 active calls
+ if (__pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
+ {
+ int retStatus = 0;
+
+ //fetch call handles
+ IListT<long>* pCallHandleList = __pActiveCallList->GetKeysN();
+ long callHandle1 = 0;
+ pCallHandleList->GetAt(0, callHandle1);
+ long callHandle2 = 0;
+ pCallHandleList->GetAt(1, callHandle2);
+
+ retStatus = tel_swap_call(__pTapiHandle, callHandle1, callHandle2, &HandleSwapCallbackResponse, this);
+
+ if (retStatus == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ delete pCallHandleList;
+ pCallHandleList = null;
+ }
+
+ return r;
+}
+
+result
+TelephonyManager::SendCallDTMF(String& textToBeSent)
+{
+ result r = E_FAILURE;
+ //check if there is an active Call
+ if (__pActiveCallList->GetCount() > 0)
+ {
+ //conversion "textToBeSent" to char*
+ const wchar_t* pTextToBeSent = textToBeSent.GetPointer();
+ int len = textToBeSent.GetLength() + 1;
+ char* pNumber = new (std::nothrow) char[len];
+ wcstombs(pNumber, pTextToBeSent, len);
+ int retStatus = tel_call_dtmf(__pTapiHandle, pNumber, &HandleCallbackResponse, this);
+ delete []pNumber;
+ pNumber = null;
+ if (retStatus == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ }
+ return r;
+}
+
+result
+TelephonyManager::EndFromConference(int callHandle)
+{
+ result r = E_FAILURE;
+ int confCallIndex = -1;
+ CallInfo endConfCall;
+ bool isConferenceCallFound = false;
+
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, endConfCall);
+ if (endConfCall.IsConferenceCall() == true)
+ {
+ isConferenceCallFound = true;
+ confCallIndex = index;
+ //Found the Conference call to be ended.
+ break;
+ }
+ }
+
+ if (isConferenceCallFound == false)
+ {
+ delete pCallList;
+ pCallList = null;
+ return r;
+ }
+ delete pCallList;
+ pCallList = null;
+ //Identify the call to be ended and remove from list on API success
+ CallInfo callToBeEnded;
+ pCallList = endConfCall.GetCallerList();
+ callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, callToBeEnded);
+ if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
+ {
+ //Identify the call to be ended and remove from list on API success
+ TelCallEndType_t endType = TAPI_CALL_END;
+
+ int res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndFromConferenceCallbackResponse, this);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ break;
+ }
+ }
+
+ return r;
+}
+
+result
+TelephonyManager::SplitFromConference(int callHandle)
+{
+ result r = E_FAILURE;
+ int confCallIndex = -1;
+ CallInfo endConfCall;
+ bool isConferenceCallFound = false;
+
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, endConfCall);
+ if (endConfCall.IsConferenceCall() == true)
+ {
+ isConferenceCallFound = true;
+ confCallIndex = index;
+ //Found the Conference call to be ended.
+ break;
+ }
+ }
+
+ if (isConferenceCallFound == false)
+ {
+ delete pCallList;
+ pCallList = null;
+ return r;
+ }
+ pCallList = null;
+ //Identify the call to be ended and remove from list on API success
+ CallInfo callToBeEnded;
+ pCallList = endConfCall.GetCallerList();
+ callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, callToBeEnded);
+ if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
+ {
+ int res = tel_split_call(__pTapiHandle, callHandle, &HandleSplitFromConferenceCallbackResponse, this);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ break;
+ }
+ }
+
+ return r;
+}
+
+result
+TelephonyManager::SetMuteStatus(bool setMute)
+{
+ TelSoundMuteStatus_t muteStatus;
+ result r = E_FAILURE;
+ if (setMute == true)
+ {
+ muteStatus = TAPI_SOUND_MUTE_STATUS_ON;
+ }
+ else
+ {
+ muteStatus = TAPI_SOUND_MUTE_STATUS_OFF;
+ }
+ int res = tel_set_call_mute_status(__pTapiHandle, muteStatus, &HandleCallbackResponse, this);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ __isMuted = setMute;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ return r;
+}
+
+bool
+TelephonyManager::IsCallMuted(void)
+{
+ return __isMuted;
+}
+
+result
+TelephonyManager::SetSpeakerStatus(bool setSpeaker)
+{
+ result r = E_FAILURE;
+ TelCallSoundPathInfo_t callSoundPathInfo;
+ __pSoundManager->SetSpeakerStatus(setSpeaker);
+ if (setSpeaker == true)
+ {
+ callSoundPathInfo.path = TAPI_SOUND_PATH_SPK_PHONE;
+ }
+ else
+ {
+ callSoundPathInfo.path = TAPI_SOUND_PATH_HANDSET;
+ }
+ callSoundPathInfo.ex_volume = TelCallSoundPathInfo_t::TAPI_SOUND_EX_VOLUME_ON;
+
+ int res = tel_set_call_sound_path(__pTapiHandle, &callSoundPathInfo, &HandleCallbackResponse, this);
+
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ __isSpeakerOn = setSpeaker;
+ r = E_SUCCESS;
+ }
+ else
+ {
+ r = E_FAILURE;
+ }
+ return r;
+}
+
+bool
+TelephonyManager::IsSpeakerOn(void)
+{
+ return __isSpeakerOn;
+}
+
+bool
+TelephonyManager::IsSplitAllowed(void)
+{
+ // Split functionality is allowed only if a one call is present.
+ // The call can be a single call or a conference call
+ if (__pActiveCallList->GetCount() == 1)
+ {
+ return true;
+ }
+ return false;
+}
+//Currently does nothing
+void
+TelephonyManager::HandleCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+}
+
+void
+TelephonyManager::HandleEndDialedCallResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+ TelCallEndCnf_t callEndInfo;
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ //Handle ending of dialed call
+ if (pTelManager->__pDialedCall != null)
+ {
+ unsigned int dialedCallHandle = (unsigned int)pTelManager->__pDialedCall->GetCallHandle()->ToLong();
+ memset(&callEndInfo, 0,sizeof(TelCallEndCnf_t));
+ memcpy(&callEndInfo, pData,sizeof(TelCallEndCnf_t));
+ if (callEndInfo.id == dialedCallHandle)
+ {
+ //Get current status of the call. idle callback received if call has been ended
+ TelCallStatus_t callStatus;
+ tel_get_call_status(pTelManager->__pTapiHandle,callEndInfo.id,&callStatus);
+ if (callStatus.CallState == TAPI_CALL_STATE_IDLE)
+ {
+ //check if the ended call was the last call
+ bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
+ ArrayListT<CallInfo>* pCallList = null;
+ if (isLastCall)
+ {
+ pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+ }
+ else
+ {
+ pCallList = static_cast<ArrayListT<CallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+ }
+ //notify listener that call is connected.
+ pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
+ delete pCallList;
+ pCallList = null;
+ delete pTelManager->__pDialedCall;
+ pTelManager->__pDialedCall = null;
+ pTelManager->__pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
+ }
+ }
+ }
+}
+
+void
+TelephonyManager::HandleDialCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (callBackResult != TAPI_CAUSE_SUCCESS)
+ {
+ if (pTelManager->__pDialedCall != null)
+ {
+ delete pTelManager->__pDialedCall;
+ pTelManager->__pDialedCall = null;
+ }
+ pTelManager->__pEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
+ }
+}
+
+void
+TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+ // This callback comes only if user has either rejected an incoming call from IncomingCallForm.
+ // or the incoming call was automatically rejected.
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (pData != null && callBackResult == TAPI_API_SUCCESS)
+ {
+ unsigned int tempHandle = 0;
+ TelCallStatus_t callStatus;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ int res = tel_get_call_status(pTelManager->__pTapiHandle, tempHandle, &callStatus);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ String contactNumber(callStatus.pNumber);
+ //Fetch contact details from address book.
+ Contact* pContactDetails = pTelManager->GetContactN(contactNumber);
+
+ //Check if number was automatically rejected using settings, then don't give any notification to user.
+ bool showIncomingCallRejectedNotification = true;
+ if (((pTelManager->__pSettingsManager->GetUnknownRejectStatus() == true) && (pContactDetails == null))
+ || (pTelManager->__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
+ {
+ showIncomingCallRejectedNotification = false;
+ }
+
+ if (showIncomingCallRejectedNotification == true)
+ {
+ long long phNumber = 0;
+ LongLong::Parse(contactNumber, phNumber);
+ //handle call connected - save info
+ if (pTelManager->__pIncomingCall != null)
+ {
+ CallInfo* pIncomingCall = new (std::nothrow) CallInfo();
+ *pIncomingCall = *(pTelManager->__pIncomingCall);
+ pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_REJECTED);
+ result r = pTelManager->FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ pIncomingCall->SetContactInfo(*(pTelManager->__pCachedContact));
+ }
+ //check if the ended call was the last call
+ bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
+ ArrayListT<CallInfo>* pCallList = null;
+ if (isLastCall)
+ {
+ pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+ pCallList->Construct(1);
+
+ //save end call details
+ String endCause(L"Call Rejected");
+ pIncomingCall->SetEndCallCause(endCause);
+
+ //save to list
+ pCallList->Add(*pIncomingCall);
+ }
+ else
+ {
+ pCallList = static_cast<ArrayListT<CallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+ }
+
+ //Add to call log
+ pTelManager->__pCalllogMgr->AddCallogInfoToDatabase(pIncomingCall);
+
+ delete pTelManager->__pIncomingCall;
+ pTelManager->__pIncomingCall = null;
+
+ if (pTelManager->__isIncomingCallPresent == true)
+ {
+ if(pTelManager->__pSoundManager != null)
+ {
+ pTelManager->__pSoundManager->StopAlert();
+ //Do not call stop session if there is already a call going on
+ if(pTelManager->__pActiveCallList->GetCount() == 0)
+ {
+ pTelManager->__pSoundManager->StopSession();
+ }
+ }
+ pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
+ delete pCallList;
+ pCallList = null;
+ }
+ pTelManager->__isIncomingCallPresent = false;
+ delete pIncomingCall;
+ pIncomingCall = null;
+ }
+ }
+ }
+ }
+ else
+ {
+ pTelManager->__pEventListener->HandleTelephonyError(ERROR_REJECT_FAILED);
+ }
+}
+
+void
+TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (callBackResult == TAPI_API_SUCCESS && pData != null)
+ {
+ unsigned int tempHandle = 0;
+ TelCallInfoJoinedNoti_t joinedInfoNotification;
+ CallInfo confCallInfo;
+
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ joinedInfoNotification.id = tempHandle;
+ CallInfo activeCall;
+ CallInfo heldCall;
+ // Use enumerator to access elements in the map
+ IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ result r = pCallList->GetAt(0, activeCall);
+
+ if (r == E_SUCCESS)
+ {
+ r = pCallList->GetAt(1, heldCall);
+ if (r == E_SUCCESS)
+ {
+ CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+ unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
+ unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
+ if (activeCall.IsConferenceCall() == true)
+ {
+ r = E_SUCCESS;
+ //When joined both become active
+ activeCall.SetOnHold(false);
+ heldCall.SetOnHold(false);
+ *pConfCallInfo = activeCall;
+ pConfCallInfo->AddCallToCallerList(heldCall);
+ pConfCallInfo->SetCallHandle(activeCallHandle);
+ //Set call start time
+ if (pConfCallInfo->GetCallConnectTime() > heldCall.GetCallConnectTime())
+ {
+ pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
+ pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
+ }
+ }
+ else if (heldCall.IsConferenceCall() == true)
+ {
+ r = E_SUCCESS;
+ heldCall.SetOnHold(false);
+ activeCall.SetOnHold(false);
+ *pConfCallInfo = heldCall;
+ pConfCallInfo->AddCallToCallerList(activeCall);
+ pConfCallInfo->SetCallHandle(heldCallHandle);
+ //Set call start time
+ if (pConfCallInfo->GetCallConnectTime() > activeCall.GetCallConnectTime())
+ {
+ pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
+ pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
+ }
+ }
+ else
+ {
+ r = E_SUCCESS;
+ pConfCallInfo->SetConference(true);
+ heldCall.SetOnHold(false);
+ activeCall.SetOnHold(false);
+ pConfCallInfo->AddCallToCallerList(activeCall);
+ pConfCallInfo->AddCallToCallerList(heldCall);
+ pConfCallInfo->SetCallHandle(activeCallHandle);
+ //Set call start time
+ if (activeCall.GetCallConnectTime() > heldCall.GetCallConnectTime())
+ {
+ pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
+ pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
+ }
+ else
+ {
+ pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
+ pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
+ }
+ }
+ pConfCallInfo->SetCallHandle(joinedInfoNotification.id);
+ pTelManager->__pActiveCallList->RemoveAll();
+ //only one call in the list
+ pTelManager->__pActiveCallList->Add(joinedInfoNotification.id, *pConfCallInfo);
+ //notify listener that call is connected.
+ pTelManager->__pEventListener->HandleConferenceCall(*pConfCallInfo);
+ delete pCallList;
+ pCallList = null;
+ }
+ }
+ }
+ else
+ {
+ pTelManager->__pEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
+ }
+}
+
+void
+TelephonyManager::HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (callBackResult == TAPI_CAUSE_SUCCESS)
+ {
+ IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ IListT<long>* pKeyList = pTelManager->__pActiveCallList->GetKeysN();
+ int callCount = pTelManager->__pActiveCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ CallInfo* pTempCallInfo = new (std::nothrow) CallInfo();
+ pCallList->GetAt(index, *pTempCallInfo);
+ (pTempCallInfo->IsOnHold() == false) ? pTempCallInfo->SetOnHold(true) : pTempCallInfo->SetOnHold(false);
+ long callHandle;
+ pKeyList->GetAt(index, callHandle);
+ pTelManager->__pActiveCallList->SetValue(callHandle, *pTempCallInfo);
+ }
+ delete pCallList;
+ pCallList = null;
+ delete pKeyList;
+ pKeyList = null;
+ pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ pTelManager->__pEventListener->HandleCallSwapOccured(*pCallList);
+ }
+ else
+ {
+ pTelManager->__pEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
+ }
+}
+
+void
+TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
+ {
+ TelCallEndCnf_t callEndNotification;
+ memcpy(&callEndNotification, pData, sizeof(TelCallEndCnf_t));
+ int confCallIndex = -1;
+ CallInfo endConfCall;
+ bool isConferenceCallFound = false;
+
+ IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, endConfCall);
+ if (endConfCall.IsConferenceCall() == true)
+ {
+ isConferenceCallFound = true;
+ confCallIndex = index;
+ //Found the Conference call to be ended.
+ break;
+ }
+ }
+
+ if (isConferenceCallFound == false)
+ {
+ delete pCallList;
+ pCallList = null;
+ return;
+ }
+ delete pCallList;
+ pCallList = null;
+ //Identify the call to be ended and remove from list on API success
+ CallInfo callToBeEnded;
+ pCallList = endConfCall.GetCallerList();
+ callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, callToBeEnded);
+ if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == callEndNotification.id)
+ {
+ //Identified the call to be ended and remove from conference list
+ endConfCall.RemoveCallFromCallerList(index);
+ pTelManager->__pCalllogMgr->AddCallogInfoToDatabase(&callToBeEnded);
+ break;
+ }
+ }
+ unsigned int confCallHandle = (unsigned int)endConfCall.GetCallHandle()->ToLong();
+ //Chk if last participant removed. if so switch to single active view
+ if (endConfCall.GetCallerListCount() == 1)
+ {
+ CallInfo callFromList;
+ pCallList = endConfCall.GetCallerList();
+ pCallList->GetAt(0, callFromList);
+ CallInfo* pActiveCall = new (std::nothrow) CallInfo();
+ *pActiveCall = callFromList;
+ pActiveCall->SetConference(false);
+ pTelManager->__pActiveCallList->Remove(confCallHandle);
+ pTelManager->__pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
+ pActiveCall = null;
+ //using the callConnected to switch to single active screen
+ pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ pTelManager->__pEventListener->HandleCallConnected(*pCallList);
+ pCallList = null;
+ }
+ else
+ {
+ CallInfo callFromList;
+ pCallList = endConfCall.GetCallerList();
+ pCallList->GetAt(0, callFromList);
+
+ CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+ *pConfCallInfo = endConfCall;
+ if (confCallHandle == callEndNotification.id)
+ {
+ //Call Handle is same as conf call handle.
+ //Change conf call handle
+ pTelManager->__pActiveCallList->Remove(confCallHandle);
+ int tmpCallHandle = callFromList.GetCallHandle()->ToLong();
+ pConfCallInfo->SetCallHandle(tmpCallHandle);
+ pTelManager->__pActiveCallList->Add(tmpCallHandle, *pConfCallInfo);
+ }
+ else
+ {
+ pTelManager->__pActiveCallList->SetValue(confCallHandle, *pConfCallInfo );
+ }
+ pTelManager->__pEventListener->HandleConferenceChange();
+ }
+ }
+ else
+ {
+ pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_FROM_CONFERENCE_FAILED);
+ }
+}
+
+void
+TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
+{
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
+ {
+ TelCallSplitCnf_t callSplitNotification;
+ memcpy(&callSplitNotification, pData, sizeof(TelCallSplitCnf_t));
+ int confCallIndex = -1;
+ CallInfo endConfCall;
+ bool isConferenceCallFound = false;
+
+ IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, endConfCall);
+ if (endConfCall.IsConferenceCall() == true)
+ {
+ isConferenceCallFound = true;
+ confCallIndex = index;
+ //Found the Conference call to be ended.
+ break;
+ }
+ }
+
+ if (isConferenceCallFound == false)
+ {
+ delete pCallList;
+ pCallList = null;
+ return;
+ }
+ delete pCallList;
+ pCallList = null;
+ //Identify the call to be ended and remove from list on API success
+ CallInfo callToBeEnded;
+ pCallList = endConfCall.GetCallerList();
+ callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ pCallList->GetAt(index, callToBeEnded);
+ if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == callSplitNotification.id)
+ {
+ //Identified the call to be ended and remove from conference list
+ //Add this to the active call list
+ endConfCall.RemoveCallFromCallerList(index);
+ break;
+ }
+ }
+ unsigned int confCallHandle = (unsigned int)endConfCall.GetCallHandle()->ToLong();
+ //Set the hold flags correctly and make the changes to the active call list
+ if (endConfCall.GetCallerListCount() == 1)
+ {
+ //Set hold for the other single call
+ // and add to the list
+ CallInfo callFromList;
+ pCallList = endConfCall.GetCallerList();
+ pCallList->GetAt(0, callFromList);
+ CallInfo* pHeldCall = new (std::nothrow) CallInfo();
+ *pHeldCall = callFromList;
+ pHeldCall->SetConference(false);
+ pHeldCall->SetOnHold(true);
+ pTelManager->__pActiveCallList->Remove(confCallHandle);
+ pTelManager->__pActiveCallList->Add(pHeldCall->GetCallHandle()->ToLong(), *pHeldCall);
+ pHeldCall = null;
+ }
+ else
+ {
+ //Set hold flag for conference call
+ endConfCall.SetOnHold(true);
+ CallInfo callFromList;
+ pCallList = endConfCall.GetCallerList();
+ pCallList->GetAt(0, callFromList);
+
+ CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+ *pConfCallInfo = endConfCall;
+ if (confCallHandle == callSplitNotification.id)
+ {
+ //Call Handle is same as conf call handle.
+ //Change conf call handle
+ pTelManager->__pActiveCallList->Remove(confCallHandle);
+ int tmpCallHandle = callFromList.GetCallHandle()->ToLong();
+ pConfCallInfo->SetCallHandle(tmpCallHandle);
+ pTelManager->__pActiveCallList->Add(callFromList.GetCallHandle()->ToLong(), *pConfCallInfo);
+ }
+ else
+ {
+ pTelManager->__pActiveCallList->Remove(confCallHandle);
+ pTelManager->__pActiveCallList->Add(confCallHandle, *pConfCallInfo);
+ }
+ }
+ //Add the new active call to active call list
+ CallInfo* pActiveCall = new (std::nothrow) CallInfo();
+ *pActiveCall = callToBeEnded;
+ pActiveCall->SetConference(false);
+ pActiveCall->SetOnHold(false);
+ pTelManager->__pActiveCallList->Remove(pActiveCall->GetCallHandle()->ToLong());
+ pTelManager->__pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
+ pActiveCall = null;
+ //using the callConnected to switch to Multiple active screen
+ pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ pTelManager->__pEventListener->HandleCallConnected(*pCallList);
+ pCallList = null;
+ }
+ else
+ {
+ pTelManager->__pEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
+ }
+}
+
+void
+TelephonyManager::HandleIdleCallBack(void* pData, TelephonyManager* pTelManager)
+{
+ TelCallStatusIdleNoti_t idleNotification;
+ memcpy(&idleNotification, pData, sizeof(TelCallStatusIdleNoti_t));
+ //handle end call event, show next screen
+ unsigned int endCallHandle = idleNotification.id;
+
+ //fetch ended call details
+ CallInfo endCallInfo;
+ result r = pTelManager->__pActiveCallList->GetValue(endCallHandle, endCallInfo);
+
+ if (r == E_SUCCESS)
+ {
+ // if (endCallInfo.IsConferenceCall() == true && endCallInfo.GetCallerListCount() > 0 )
+ // {
+ // pTelManager->__pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
+ // return;
+ // }
+
+ //remove the call handle from active call list
+ pTelManager->__pActiveCallList->Remove(endCallHandle);
+
+ //check if the ended call was the last call
+ bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
+
+ ArrayListT<CallInfo>* pCallList = null;
+ if (isLastCall)
+ {
+ pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+ pCallList->Construct(1);
+
+ //save end call details
+ //TODO: map error cause "idleNotification.cause" to error string.
+ String endCause(L"Call Ended Successfully");
+ endCallInfo.SetEndCallCause(endCause);
+
+ // long callDuration = abs(endInfo.CallEndTime - endInfo.CallStartTime);
+ // endCallInfo.SetEndCallDuration(callDuration);
+ //save to list
+ pCallList->Add(endCallInfo);
+ }
+ else
+ {
+ pCallList = static_cast<ArrayListT<CallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+ }
+
+ if (pTelManager->__isIncomingCallPresent == true)
+ {
+ pTelManager->__pSoundManager->StopAlert();
+ pTelManager->__isIncomingCallPresent = false;
+ }
+ // call should be active now. end the active call now
+ if (endCallInfo.IsConferenceCall() == false)
+ {
+ //Add call ended to call log database
+ pTelManager->__pCalllogMgr->AddCallogInfoToDatabase(&endCallInfo);
+ if(pTelManager->__pIncomingCall != null && ((unsigned int)pTelManager->__pIncomingCall->GetCallHandle()->ToLong() == endCallHandle))
+ {
+ delete pTelManager->__pIncomingCall;
+ pTelManager->__pIncomingCall = null;
+ }
+ }
+ else
+ {
+ int confCallCount = endCallInfo.GetCallerListCount();
+ IListT<CallInfo>* pCallList = endCallInfo.GetCallerList();
+ for (int index = 0; index < confCallCount; index++)
+ {
+ CallInfo callInfo;
+ pCallList->GetAt(index, callInfo);
+ //Add call ended to call log database
+ pTelManager->__pCalllogMgr->AddCallogInfoToDatabase(&callInfo);
+ }
+ //Once conference calls are added delete the incoming call info
+ if(pTelManager->__pIncomingCall != null )
+ {
+ delete pTelManager->__pIncomingCall;
+ pTelManager->__pIncomingCall = null;
+ }
+ }
+ if(pTelManager->__pActiveCallList->GetCount() == 0)
+ {
+ pTelManager->__pSoundManager->StopSession();
+ }
+ //notify listener that call is connected.
+ pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
+ delete pCallList;
+ pCallList = null;
+ }
+ else
+ {
+ //check if the ended call was the dialed call
+ bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
+ ArrayListT<CallInfo>* pCallList = null;
+ if (((pTelManager->__pDialedCall != null) && (((unsigned int)pTelManager->__pDialedCall->GetCallHandle()->ToLong()) == idleNotification.id)))
+ {
+ //Call Ended is the dialed call
+ endCallInfo = *(pTelManager->__pDialedCall);
+ delete pTelManager->__pDialedCall;
+ pTelManager->__pDialedCall = null;
+ pTelManager->__pCalllogMgr->AddCallogInfoToDatabase(&endCallInfo);
+ }
+ else
+ {
+ //Could be incoming call. So notify if incoming call is present
+ if (isLastCall)
+ {
+ pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+ }
+ else
+ {
+ pCallList = static_cast<ArrayListT<CallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+ }
+ if(pTelManager->__pIncomingCall != null && ((unsigned int)pTelManager->__pIncomingCall->GetCallHandle()->ToLong() == endCallHandle))
+ {
+ if((pTelManager->__pSettingsManager->IsCallToBeRejected(pTelManager->__pIncomingCall->GetContactNumber()) == false)
+ && (pTelManager->__pSettingsManager->GetUnknownRejectStatus() == false))
+ {
+ //Missed Call
+ pTelManager->__pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED);
+ pTelManager->__pCalllogMgr->AddCallogInfoToDatabase(pTelManager->__pIncomingCall);
+ }
+
+ delete pTelManager->__pIncomingCall;
+ pTelManager->__pIncomingCall = null;
+ }
+ if (pTelManager->__isIncomingCallPresent == true)
+ {
+ pTelManager->__pSoundManager->StopAlert();
+ pTelManager->__isIncomingCallPresent = false;
+ if(pTelManager->__pActiveCallList->GetCount() == 0)
+ {
+ pTelManager->__pSoundManager->StopSession();
+ }
+ pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
+ }
+ delete pCallList;
+ pCallList = null;
+ pTelManager->__pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
+ return;
+ }
+
+ if (isLastCall)
+ {
+ pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+ pCallList->Construct(1);
+
+ //save end call details
+ //TODO: map error cause "idleNotification.cause" to error string.
+ String endCause(L"Call Ended Successfully");
+ endCallInfo.SetEndCallCause(endCause);
+
+ // long callDuration = abs(endInfo.CallEndTime - endInfo.CallStartTime);
+ // endCallInfo.SetEndCallDuration(callDuration);
+ //save to list
+ pCallList->Add(endCallInfo);
+ }
+ else
+ {
+ pCallList = static_cast<ArrayListT<CallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+ }
+ if(pTelManager->__pActiveCallList->GetCount() == 0)
+ {
+ //notify listener that call is disconnected.
+ pTelManager->__pSoundManager->StopSession();
+ }
+ pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
+ delete pCallList;
+ pCallList = null;
+ }
+ pTelManager->__pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
+}
+
+void
+TelephonyManager::HandleDialingCallBack(void* pData, TelephonyManager* pTelManager)
+{
+ unsigned int tempHandle = 0;
+ TelCallStatusDialingNoti_t dialingNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ dialingNotification.id = tempHandle;
+ if (pTelManager->__pDialedCall)
+ {
+ pTelManager->__pDialedCall->SetCallHandle(dialingNotification.id);
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pTelManager->__pDialedCall->SetCallNotificationTime(startTime);
+ pTelManager->__pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
+ }
+ else
+ {
+ delete pTelManager->__pDialedCall;
+ pTelManager->__pDialedCall = new (std::nothrow) CallInfo();
+ pTelManager->__pDialedCall->SetCallHandle(dialingNotification.id);
+ TelCallStatus_t callStatus;
+ int res = tel_get_call_status(pTelManager->__pTapiHandle, dialingNotification.id, &callStatus);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ String contactNumber(callStatus.pNumber);
+ pTelManager->__pDialedCall->SetContactNumber(contactNumber);
+ result r = pTelManager->FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ pTelManager->__pDialedCall->SetContactInfo(*(pTelManager->__pCachedContact));
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pTelManager->__pDialedCall->SetCallNotificationTime(startTime);
+ pTelManager->__pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ pTelManager->__pDialedCall->SetEmergency(true);
+ }
+ else
+ {
+ pTelManager->__pDialedCall->SetEmergency(false);
+ }
+ }
+ }
+}
+
+void
+TelephonyManager::HandleActiveCallBack(void* pData, TelephonyManager* pTelManager)
+{
+ unsigned int tempHandle = 0;
+ TelCallStatusActiveNoti_t activeNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ activeNotification.id = tempHandle;
+ IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+
+ //Check if the activated call is already present in already activated calls.
+ bool toHandleEvent = true;
+ for (int callIndex = 0; (callIndex < pCallList->GetCount() && toHandleEvent == true); callIndex++ )
+ {
+ CallInfo tempCallInfo;
+ pCallList->GetAt(callIndex, tempCallInfo);
+ unsigned int tempCallHandle = tempCallInfo.GetCallHandle()->ToLong();
+ //Check if active callback came for "HandleJoinCallbackResponse"
+ //or for "UnHold Conf Call or normal call".
+ if(tempCallInfo.IsConferenceCall() == true)
+ {
+ if (tempCallHandle == activeNotification.id)
+ {
+ toHandleEvent = false;
+ }
+ else
+ {
+ //check individual participants of conf call
+ IListT<CallInfo>* pConfCallList = tempCallInfo.GetCallerList();
+ int confCallCount = pConfCallList->GetCount();
+ for (int callIndex = 0; (callIndex < confCallCount && toHandleEvent == true); callIndex++)
+ {
+ CallInfo confCallerInfo;
+ pConfCallList->GetAt(callIndex, confCallerInfo);
+ unsigned int confCallerHandle = confCallerInfo.GetCallHandle()->ToLong();
+ if (confCallerHandle == activeNotification.id)
+ {
+ toHandleEvent = false;
+ }
+ }
+ }
+ }
+ else if(tempCallHandle == activeNotification.id)
+ {
+ //If normal call is UnHold
+ toHandleEvent = false;
+ }
+ }
+ //If duplicate call handle, then to ignore the duplicate event.
+ if(toHandleEvent == false)
+ {
+ delete pCallList;
+ pCallList = null;
+ return;
+ }
+
+ IListT<long>* pKeyList = pTelManager->__pActiveCallList->GetKeysN();
+ if( pKeyList->Contains(activeNotification.id) == false)
+ {
+ //handle call connected - save info
+ if (pTelManager->__pDialedCall != null)
+ {
+ pTelManager->__pDialedCall->SetCallHandle(activeNotification.id);
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pTelManager->__pDialedCall->SetCallConnectTime(startTime);
+
+ if (pTelManager->__pIncomingCall != null && activeNotification.id == (unsigned int)pTelManager->__pIncomingCall->GetCallHandle()->ToLong())
+ {
+ pTelManager->__pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ delete pTelManager->__pIncomingCall;
+ pTelManager->__pIncomingCall = null;
+ }
+ //transfer ownership to Active calls list
+ pTelManager->__pActiveCallList->Add(activeNotification.id, *(pTelManager->__pDialedCall));
+ }
+ else
+ {
+ //Construct a new CallInfo object for call
+ //This case will normally come here with incoming call
+ pTelManager->__pDialedCall = new (std::nothrow) CallInfo();
+ //__pDialedCall->SetRequestId(requestId);
+ pTelManager->__pDialedCall->SetCallHandle(activeNotification.id);
+ TelCallStatus_t callStatus;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ int res = tel_get_call_status(pTelManager->__pTapiHandle, activeNotification.id, &callStatus);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ String contactNumber(callStatus.pNumber);
+ pTelManager->__pDialedCall->SetContactNumber(contactNumber);
+ result r = pTelManager->FetchContactInfoForNumber(contactNumber);
+ if (!IsFailed(r))
+ {
+ pTelManager->__pDialedCall->SetContactInfo(*(pTelManager->__pCachedContact));
+ }
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ pTelManager->__pDialedCall->SetEmergency(true);
+ }
+ else
+ {
+ pTelManager->__pDialedCall->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pTelManager->__pDialedCall->SetCallConnectTime(startTime);
+ if (pTelManager->__pIncomingCall != null && (activeNotification.id == (unsigned int)pTelManager->__pIncomingCall->GetCallHandle()->ToLong()))
+ {
+ pTelManager->__pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ pTelManager->__pDialedCall->SetCallNotificationTime(pTelManager->__pIncomingCall->GetCallNotificationTime());
+ }
+ //transfer ownership to Active calls list
+ pTelManager->__pActiveCallList->Add(activeNotification.id, *(pTelManager->__pDialedCall));
+ }
+ }
+ }
+ delete pKeyList;
+ pKeyList = null;
+ pTelManager->__pDialedCall = null;
+
+ //notify listener that call is connected.
+ pCallList = pTelManager->__pActiveCallList->GetValuesN();
+ pTelManager->__pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
+ pTelManager->__pEventListener->HandleCallConnected(*pCallList);
+ if (pTelManager->__isIncomingCallPresent == true)
+ {
+ pTelManager->__pSoundManager->StopAlert();
+ pTelManager->__isIncomingCallPresent = false;
+ }
+ delete pCallList;
+ pCallList = null;
+}
+
+void
+TelephonyManager::HandleIncomingCallBack(void* pData, TelephonyManager* pTelManager)
+{
+ unsigned int tempHandle = 0;
+ TelCallStatus_t callStatus;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ int res = tel_get_call_status(pTelManager->__pTapiHandle, tempHandle, &callStatus);
+ if (res == TAPI_CAUSE_SUCCESS)
+ {
+ //This case will normally come here with incoming call
+ delete pTelManager->__pIncomingCall;
+ pTelManager->__pIncomingCall = new (std::nothrow) CallInfo();
+ pTelManager->__pIncomingCall->SetCallHandle(tempHandle);
+ String contactNumber(callStatus.pNumber);
+ pTelManager->__pIncomingCall->SetContactNumber(contactNumber);
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ pTelManager->__pIncomingCall->SetEmergency(true);
+ }
+ else
+ {
+ pTelManager->__pIncomingCall->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pTelManager->__pIncomingCall->SetCallNotificationTime(startTime);
+ pTelManager->__pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ //Check whether to reject incoming call or show incoming call screen to user.
+ bool isRejected = pTelManager->CheckIncomingCallToBeRejected(pTelManager->__pIncomingCall);
+ if(isRejected == false)
+ {
+ //show incoming call notification
+ CallInfo* pIncomingCall = new (std::nothrow) CallInfo();
+ *pIncomingCall = *(pTelManager->__pIncomingCall);
+ pTelManager->__pEventListener->HandleIncomingCall(*pIncomingCall);
+ delete pIncomingCall;
+ }
+ }
+}
+
+bool
+TelephonyManager::CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo)
+{
+ int callHandle = pIncomingCallInfo->GetCallHandle()->ToLong();
+ String contactNumber(L"");
+ contactNumber.Append(pIncomingCallInfo->GetContactNumber());
+ //Fetch contact details from address book.
+ Contact* pContactDetails = GetContactN(contactNumber);
+ //Check if "reject unknown calls" is set and contact number is not present in AddressBook
+ //or if contact number is blacklisted
+ __isIncomingCallPresent = true;
+ if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pContactDetails == null))
+ || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
+ {
+ AnswerCall(callHandle,false);
+ //save call rejected info
+ CallInfo* pRejectedCall = new (std::nothrow) CallInfo();
+ *pRejectedCall = *pIncomingCallInfo;
+ pRejectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
+ __pCalllogMgr->AddCallogInfoToDatabase(pRejectedCall);
+ delete pRejectedCall;
+ delete pContactDetails;
+ return true;
+ }
+ else
+ {
+ //update contact person info
+ if (pContactDetails != null)
+ {
+ pIncomingCallInfo->SetContactInfo(*pContactDetails);
+ delete pContactDetails;
+ }
+ return false;
+ }
+}
+
+void
+TelephonyManager::HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
+{
+ unsigned int tempHandle = 0;
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (pTelManager->__pSoundManager == null)
+ {
+ AppLog("Creating Sound Manager");
+ pTelManager->__pSoundManager = new (std::nothrow) SoundManager();
+ }
+
+
+ if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) == 0)
+ {
+ HandleIdleCallBack(pData, pTelManager);
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) == 0)
+ {
+ pTelManager->__pSoundManager->StartSession();
+ HandleActiveCallBack(pData, pTelManager);
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) == 0)
+ {
+ HandleDialingCallBack(pData, pTelManager);
+ }
+ /*else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_INCOMING) == 0)
+ {
+ HandleIncomingCallBack(pData, pTelManager);
+ }*/
+ else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_HELD) == 0)
+ {
+ //TelCallStatusHeldNoti_t heldNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_CALL_INFO_WAITING) == 0)
+ {
+ //TelCallInfoWaitingNoti_t waitingInfoNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_CALL_INFO_HELD) == 0)
+ {
+ //TelCallInfoHeldNoti_t heldInfoNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ALERT) == 0)
+ {
+ //TelCallStatusAlertNoti_t alertNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_WAITING) == 0)
+ {
+ //TelCallStatusWaitingNoti_t waitingNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_CALL_INFO_CALL_CONNECTED_LINE) == 0)
+ {
+ //TelCallConnectedNumberInfo_t connectedNumberInfo;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_CALL_INFO_ACTIVE) == 0)
+ {
+ //TelCallInfoActiveNoti_t activeInfoNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_CALL_INFO_JOINED) == 0)
+ {
+ //TelCallInfoJoinedNoti_t joinedInfoNotification;
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else if (strcmp(pNotiId, TAPI_NOTI_CALL_INFO_RELEASED_ON_HOLD) == 0)
+ {
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+ else
+ {
+ memcpy(&tempHandle, pData, sizeof(TS_UINT));
+ }
+}
+
+CallInfo*
+TelephonyManager::GetConferenceCallInfoN(void)
+{
+ CallInfo* pConfCallInfo = null;
+
+ IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+ int callCount = pCallList->GetCount();
+ for (int index = 0; index < callCount; index++)
+ {
+ CallInfo callInfo;
+ pCallList->GetAt(index, callInfo);
+ if (callInfo.IsConferenceCall() == true)
+ {
+ pConfCallInfo = new (std::nothrow) CallInfo();
+ *pConfCallInfo = callInfo;
+ //Found the Conference call to be ended.
+ break;
+ }
+ }
+ delete pCallList;
+ pCallList = null;
+
+ return pConfCallInfo;
+}
+
+IListT<CallInfo>*
+TelephonyManager::GetCallListN(void)
+{
+ ArrayListT<CallInfo>* pCallList = null;
+ if (__pActiveCallList != null)
+ {
+ pCallList = static_cast<ArrayListT<CallInfo>*>(__pActiveCallList->GetValuesN());
+ }
+ return pCallList;
+}
+
+int
+TelephonyManager::GetCurrentCallCount(void)
+{
+ if (__pActiveCallList != null)
+ {
+ return __pActiveCallList->GetCount();
+ }
+ return 0;
+}
+
+void
+TelephonyManager::StartAlert(CallInfo& incomingCallInfo)
+{
+ __isIncomingCallPresent = true;
+ String contactRingTone(L"");
+ String contactNumber = incomingCallInfo.GetContactNumber();
+ //check if not hidden call
+ if(contactNumber.IsEmpty() == false)
+ {
+ //fetch contact info from Db
+ Contact* foundContact = GetContactN(contactNumber);
+ if(foundContact != null)
+ {
+ //fetch custom ringtone for contact
+ result r = foundContact->GetValue(CONTACT_PROPERTY_ID_RINGTONE, contactRingTone);
+ AppLog("ringtone fetched - r = %d", r);
+ delete foundContact;
+ foundContact = null;
+ }
+ }
+ __pSoundManager->StartAlert(contactRingTone);
+}
+
+void
+TelephonyManager::StopAlert(void)
+{
+ __pSoundManager->StopAlert();
+}
+
+result
+TelephonyManager::CheckValidTelePhoneNumber(const String& contactNumber)
+{
+ result r = E_SUCCESS;
+ if (contactNumber.GetLength() > TAPI_CALL_DIALDIGIT_LEN_MAX)
+ {
+ r = E_FAILURE;
+ }
+ //TODO: check if valid phonenumber else return error message
+ return r;
+}
+
+result
+TelephonyManager::CheckIfMOCallIsPossible()
+{
+ result r = E_SUCCESS;
+
+ //Check modem power status
+ int modemStatus = 0;
+ int errorCode = tel_check_modem_power_status(__pTapiHandle, &modemStatus);
+ if (errorCode != TAPI_API_SUCCESS || modemStatus == TAPI_PHONE_POWER_STATUS_OFF
+ || modemStatus == TAPI_PHONE_POWER_STATUS_ERROR)
+ {
+ r = E_FAILURE;
+ }
+ else
+ {
+ TelSimCardStatus_t simStatus;
+ int simChangedStatus;
+ //fetch sim initialization status
+ int errorCode = tel_get_sim_init_info(__pTapiHandle, &simStatus, &simChangedStatus);
+ if (errorCode != TAPI_API_SUCCESS)
+ {
+ r = E_FAILURE;
+ }
+ else
+ {
+ switch (simStatus)
+ {
+ case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: // Sim Initialization ok
+ r = E_SUCCESS;
+ break;
+
+ case TAPI_SIM_STATUS_UNKNOWN: //initial state
+ case TAPI_SIM_STATUS_CARD_NOT_PRESENT: //Card not present
+ case TAPI_SIM_STATUS_CARD_REMOVED: //Card removed
+ case TAPI_SIM_STATUS_CARD_ERROR: // Bad card / On the fly, SIM gone bad
+ //TODO: might want to set different error code, to give proper message to user
+ r = E_FAILURE;
+ break;
+ default:
+ r = E_FAILURE;
+ break;
+ }
+ }
+ }
+ return r;
+}
+
+bool
+TelephonyManager::CheckIfMOCallIsEmergency(const String& contactNumber, bool isSimInitialized)
+{
+ //TODO: extract actual telephone number from contactNumber
+ //by deleting prefix,'P','W', etx.
+
+ bool isEmergency = false;
+ //conversion "contactNumber" to char*
+ const wchar_t* pContact = contactNumber.GetPointer();
+ int len = contactNumber.GetLength() + 1;
+ char* pNumber = new (std::nothrow) char[len];
+ wcstombs(pNumber, pContact, len);
+
+ if(isSimInitialized)
+ {
+ //used to get Ecc information for 2G and 3G.
+ TelSimEccList_t simEccList;
+ memset(&simEccList, 0x00, sizeof(TelSimEccList_t));
+ //Check if given number matches the sim card's emergency numbers
+ int errorCode = tel_get_sim_ecc(__pTapiHandle, &simEccList);
+ if (errorCode == TAPI_API_SUCCESS && simEccList.ecc_count > 0)
+ {
+ for (int index = 0; index < simEccList.ecc_count; index++)
+ {
+ if ((strcmp(pNumber, simEccList.list[index].number) == 0))
+ {
+ isEmergency = true;
+ }
+ }
+ }
+ }
+ else
+ {
+ //TODO: check if we need to also check SOS call numbers, if sim not present.
+ }
+
+ delete[] pNumber;
+ pNumber = null;
+ return isEmergency;
+}
+
+result
+TelephonyManager::FetchContactInfoForNumber(const String& phoneNumberStr)
+{
+ result r = E_FAILURE;
+
+ //delete previously cached data
+ if (__pCachedContact != null)
+ {
+ delete __pCachedContact;
+ __pCachedContact = null;
+ }
+
+ //Searches contacts by phone number.
+ IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumberStr);
+ if (pContactList == null || IsFailed(GetLastResult()))
+ {
+ return r;
+ }
+
+ //Fetch the contact's info to be displayed
+ IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
+ while ((E_SUCCESS == pContactEnum->MoveNext()) && (__pCachedContact == null))
+ {
+ Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
+
+ IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
+ if (pPhoneNumberList != null)
+ {
+ IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
+ while (E_SUCCESS == pPhoneEnum->MoveNext())
+ {
+ PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
+ //Check if this is the correct contact
+ if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumberStr))
+ {
+ //save newly fetched contact info.
+ __pCachedContact = new (std::nothrow) Contact(*pContact);
+ r = E_SUCCESS;
+ break;
+ }
+ }
+ delete pPhoneEnum;
+ pPhoneNumberList->RemoveAll(true);
+ delete pPhoneNumberList;
+ }
+ }
+ delete pContactEnum;
+ pContactList->RemoveAll(true);
+ delete pContactList;
+
+ return r;
+}
+
+Contact*
+TelephonyManager::GetContactN(const String& phoneNumber)
+{
+ result r = FetchContactInfoForNumber(phoneNumber);
+ if (!IsFailed(r))
+ {
+ return new (std::nothrow) Contact(*__pCachedContact);
+ }
+ return null;
+}
+
+CallInfo*
+TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const String& contactNumber)
+{
+ if(__pIncomingCall != null)
+ {
+ delete __pIncomingCall;
+ __pIncomingCall = null;
+ }
+
+ if(callHandle.IsEmpty() == false)
+ {
+ int incomingHandle;
+ Integer::Parse(callHandle,incomingHandle);
+ //This API call is synchronous
+ TelCallStatus_t callStatus;
+ int errCode = tel_get_call_status(__pTapiHandle, incomingHandle, &callStatus);
+ if (errCode != TAPI_API_SUCCESS)
+ {
+ AppLogDebug("tel_get_call_status_all failed");
+ return null;
+ }
+ //construct incoming call info object
+ __pIncomingCall = new (std::nothrow) CallInfo();
+ __pIncomingCall->SetCallHandle(incomingHandle);
+
+ //contact number
+ String phoneNumber(contactNumber);
+ if(phoneNumber.IsEmpty() == true)
+ {
+ phoneNumber.Append(callStatus.pNumber);
+ }
+ __pIncomingCall->SetContactNumber(phoneNumber);
+ //set emergency state
+ if(callStatus.CallType == TAPI_CALL_TYPE_E911)
+ {
+ __pIncomingCall->SetEmergency(true);
+ }
+ else
+ {
+ __pIncomingCall->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ __pIncomingCall->SetCallNotificationTime(startTime);
+ __pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ }
+ else
+ {
+ //TODO: This 'else' block can be removed once AppControl request API is stabilized.
+ //This API call is synchronous and 'HandleIncomingCallStatusCallBack' is called for each active call.
+ int errCode = tel_get_call_status_all(__pTapiHandle, &HandleIncomingCallStatusCallBack, this);
+ if (errCode != TAPI_API_SUCCESS)
+ {
+ return null;
+ }
+ }
+
+ //construct a new callinfo object to pass its ownership to caller.
+ if(__pIncomingCall != null)
+ {
+ CallInfo* pNewIncomingCall = new (std::nothrow) CallInfo();
+ *pNewIncomingCall = *__pIncomingCall;
+ return pNewIncomingCall;
+ }
+ //return null, if no incoming call found
+ return null;
+}
+
+void
+TelephonyManager::HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus, void* pUserData)
+{
+ TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+ if (pCallStatus != null && pCallStatus->bMoCall == false
+ && ((pCallStatus->CallState == TAPI_CALL_STATE_INCOMING)
+ || (pCallStatus->CallState == TAPI_CALL_STATE_WAITING)))
+ {
+ //construct incoming call details
+ pTelManager->__pIncomingCall = new (std::nothrow) CallInfo();
+ pTelManager->__pIncomingCall->SetCallHandle(pCallStatus->CallHandle);
+ //contact number
+ String contactNumber(pCallStatus->pNumber);
+ pTelManager->__pIncomingCall->SetContactNumber(contactNumber);
+ //set emergency state
+ if(pCallStatus->CallType == TAPI_CALL_TYPE_E911)
+ {
+ pTelManager->__pIncomingCall->SetEmergency(true);
+ }
+ else
+ {
+ pTelManager->__pIncomingCall->SetEmergency(false);
+ }
+ //set start time, when call is connected
+ long long startTime = 0;
+ SystemTime::GetTicks(startTime);
+ pTelManager->__pIncomingCall->SetCallNotificationTime(startTime);
+ pTelManager->__pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
+ }
+}