2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file CallTelephonyManager.cpp
19 * @brief Call log item provider
24 #include <FTelephony.h>
25 #include "ITapiModem.h"
28 #include "CallTelephonyManager.h"
29 #include "CallSettingsManager.h"
30 #include "CallTypes.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Social;
35 using namespace Tizen::System;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Telephony;
39 const char* callEventList[] = {
40 TAPI_NOTI_VOICE_CALL_STATUS_IDLE,
41 TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE,
42 TAPI_NOTI_VOICE_CALL_STATUS_HELD,
43 TAPI_NOTI_VOICE_CALL_STATUS_DIALING,
44 TAPI_NOTI_VOICE_CALL_STATUS_ALERT,
45 TAPI_NOTI_VOICE_CALL_STATUS_WAITING,
46 TAPI_NOTI_CALL_INFO_CALL_CONNECTED_LINE,
47 TAPI_NOTI_CALL_INFO_WAITING,
48 TAPI_NOTI_CALL_INFO_CUG,
49 TAPI_NOTI_CALL_INFO_FORWARDED,
50 TAPI_NOTI_CALL_INFO_BARRED_INCOMING,
51 TAPI_NOTI_CALL_INFO_BARRED_OUTGOING,
52 TAPI_NOTI_CALL_INFO_DEFLECTED,
53 TAPI_NOTI_CALL_INFO_CLIR_SUPPRESSION_REJECT,
54 TAPI_NOTI_CALL_INFO_FORWARD_UNCONDITIONAL,
55 TAPI_NOTI_CALL_INFO_FORWARD_CONDITIONAL,
56 TAPI_NOTI_CALL_INFO_CALL_LINE_IDENTITY,
57 TAPI_NOTI_CALL_INFO_CALL_NAME_INFORMATION,
58 TAPI_NOTI_CALL_INFO_FORWARDED_CALL,
59 TAPI_NOTI_CALL_INFO_CUG_CALL,
60 TAPI_NOTI_CALL_INFO_DEFLECTED_CALL,
61 TAPI_NOTI_CALL_INFO_TRANSFERED_CALL,
62 TAPI_NOTI_CALL_INFO_HELD,
63 TAPI_NOTI_CALL_INFO_ACTIVE,
64 TAPI_NOTI_CALL_INFO_JOINED,
65 TAPI_NOTI_CALL_INFO_RELEASED_ON_HOLD,
66 TAPI_NOTI_CALL_INFO_TRANSFER_ALERT,
67 TAPI_NOTI_CALL_INFO_TRANSFERED,
68 TAPI_NOTI_CALL_INFO_CF_CHECK_MESSAGE,
71 TelephonyManager* TelephonyManager::__pManager = null;
73 TelephonyManager::TelephonyManager(ITelephonyEventListener* pEventListener)
74 : __pEventListener(pEventListener)
77 __pIncomingCall = null;
78 __pActiveCallList = null;
79 __pSettingsManager = null;
81 __pAddressBook = null;
82 __pCachedContact = null;
84 __isSpeakerOn = false;
85 __pSoundManager = null;
87 __pNetworkManager = null;
90 TelephonyManager::~TelephonyManager(void)
92 if (__pActiveCallList != null)
94 delete __pActiveCallList;
97 if (__pDialedCall != null)
100 __pDialedCall = null;
103 if (__pIncomingCall != null)
105 delete __pIncomingCall;
106 __pIncomingCall = null;
109 if (__pAddressBook != null)
111 delete __pAddressBook;
112 __pAddressBook = null;
114 if (__pCachedContact != null)
116 delete __pCachedContact;
117 __pCachedContact = null;
120 //unregister for events from TAPI Lib.
123 //De-initialize the TAPI Library
124 if(__pTapiHandle != null)
126 tel_deinit(__pTapiHandle);
129 if (__pSoundManager != null)
131 delete __pSoundManager;
134 if (__pCalllogMgr != null)
136 __pCalllogMgr = null;
141 TelephonyManager::GetInstance(ITelephonyEventListener* pEventListener)
143 if (__pManager == null)
145 CreateInstance(pEventListener);
151 TelephonyManager::CreateInstance(ITelephonyEventListener* pEventListener)
153 __pManager = new (std::nothrow) TelephonyManager(pEventListener);
154 result r = __pManager->Initialize();
160 atexit(&(TelephonyManager::DestroyInstance));
164 TelephonyManager::DestroyInstance(void)
166 if (__pManager != null)
168 __pManager->EndAllCalls();
175 TelephonyManager::Initialize(void)
177 //Initialize telephony library
178 result r = InitializeTelephonyLibrary();
183 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
184 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
186 //Initialize the Settings Manager to fetch call settings
187 __pSettingsManager = SettingsManager::GetInstance();
189 __pSoundManager = new (std::nothrow) SoundManager();
190 __pCalllogMgr = CallLogManager::GetInstance();
192 //initialize address book to fetch contacts information
193 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
194 if(__pAddressBook == null)
198 __pNetworkManager = new NetworkManager();
199 if(__pNetworkManager != null)
201 __pNetworkManager->Construct(this);
207 TelephonyManager::InitializeTelephonyLibrary(void)
209 result r = E_FAILURE;
211 __pTapiHandle = tel_init(null);
212 if (__pTapiHandle != null)
214 //register telephony events
215 int errorCode = RegisterEvents();
216 if (errorCode == TAPI_CAUSE_SUCCESS)
221 //TAPI Library is initialized and events registered successfully
226 TelephonyManager::RegisterEvents(void)
229 int eventCount = sizeof(callEventList) / sizeof(char *);
230 for (int index = 0; index < eventCount; index++)
232 errCode = tel_register_noti_event(__pTapiHandle, callEventList[index], &HandleCallback, this);
233 if (errCode != TAPI_API_SUCCESS)
242 TelephonyManager::UnregisterEvents(void)
244 int eventCount = sizeof(callEventList) / sizeof(char *);
245 for (int index = 0; index < eventCount; index++)
247 tel_deregister_noti_event(__pTapiHandle, callEventList[index]);
252 TelephonyManager::SetupMoCall(String& contactNumber, bool isEmergency)
254 result res = E_SUCCESS;
255 //check if valid phone number exist
256 res = CheckValidTelePhoneNumber(contactNumber);
259 return ERROR_INVALID_NUMBER;
262 //if dialing an emergency call and active calls exist
263 //then end all active calls.
264 if (isEmergency && __pActiveCallList->GetCount() > 0)
266 //Get first call handle
267 AppCallInfo endCallInfo;
268 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
269 pCallList->GetAt(0, endCallInfo);
270 int callHandle = endCallInfo.GetCallHandle()->ToLong();
274 //release all active or held calls
275 int tapiRes = tel_end_call(__pTapiHandle, callHandle, TAPI_CALL_END_ALL, &HandleCallbackResponse, this);
276 if (tapiRes == TAPI_CAUSE_SUCCESS)
278 __pActiveCallList->RemoveAll();
286 else if (__pActiveCallList->GetCount() == 1)
288 //Check if there is already an active call,
289 //Put the already active call on hold.
290 AppCallInfo holdCallInfo;
291 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
293 pCallList->GetAt(0, holdCallInfo);
294 //Check if call is active, then put on hold
295 if (holdCallInfo.IsOnHold() == false)
297 res = HoldActiveCall(&holdCallInfo, true);
303 //make the next call, only if any existing active call
304 //is successfully put on hold or is already on hold.
305 if (res == E_SUCCESS)
307 res = DialOutgoingCall(contactNumber, isEmergency);
316 return ERROR_TAPI_ERROR;
321 TelephonyManager::EndAllCalls(void)
323 if(__pDialedCall != null)
325 if(__pDialedCall->GetCallHandle() != null)
327 tel_end_call(__pTapiHandle, __pDialedCall->GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
330 tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_HOLD_ALL, &HandleCallbackResponse, this);
331 //end all active calls before terminating application
332 tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_ALL, &HandleCallbackResponse, this);
333 __pSettingsManager->SetCallState(CALL_STATE_CALL_OFF);
337 TelephonyManager::EndActiveCall(Long callHandle)
339 result r = E_FAILURE;
341 //fetch ended callInfo from active call list
343 r = __pActiveCallList->GetValue(callHandle.ToLong(), endCall);
346 r = EndCall(endCall);
352 TelephonyManager::EndDialingCall(String& contactNumber)
354 result r = E_FAILURE;
355 //This is because for a dialing call, call handle is updated with some delay in telephony manager.
356 //And it is not available with outgoing call screen.
357 if (contactNumber.IsEmpty())
362 //Check If Ended call matches Dialed Call.
364 if (__pDialedCall != null && __pDialedCall->GetContactNumber().Equals(contactNumber))
366 endCall = *__pDialedCall;
367 r = EndCall(endCall);
373 TelephonyManager::EndCall(AppCallInfo& endCallInfo)
375 result r = E_FAILURE;
377 if (endCallInfo.GetCallHandle() != null)
379 unsigned int callHandle = endCallInfo.GetCallHandle()->ToLong();
380 //end "dialed but unconnected" call or active call - processing to be handled in HandleIdleCallback().
381 int res = tel_end_call(__pTapiHandle, callHandle, TAPI_CALL_END, &HandleCallbackResponse, this);
382 if (res == TAPI_CAUSE_SUCCESS)
391 TelephonyManager::AnswerAutoRejectCall(int callHandle)
393 //Incoming call automatically blocked is handled here.
394 AppLogDebug("Enter ");
395 result r = E_FAILURE;
396 TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_REJECT;
399 AppLogDebug("tel_answer_call");
401 AppCallInfo rejectedCallInfo;
402 rejectedCallInfo = *(__pIncomingCall);
403 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
404 SaveCallInfoToLogsDb(rejectedCallInfo);
405 delete __pIncomingCall;
406 __pIncomingCall = null;
408 // redirect to reject call back handler as the flow has to be handled
409 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
411 if (res == TAPI_CAUSE_SUCCESS)
423 TelephonyManager::AnswerCall(int callHandle, bool acceptCall)
425 AppLogDebug("Enter %d",acceptCall);
426 result r = E_FAILURE;
427 __pSoundManager->StopAlert();
428 TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_ACCEPT;
430 if (acceptCall == true)
432 answerType = TAPI_CALL_ANSWER_ACCEPT;
433 // redirect to dummy call back handler as the flow already handled in registered event callback
434 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
438 AppLogDebug("tel_answer_call");
439 answerType = TAPI_CALL_ANSWER_REJECT;
440 // redirect to reject call back handler as the flow has to be handled
441 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleRejectCallbackResponse, this);
444 if (res == TAPI_CAUSE_SUCCESS)
456 TelephonyManager::AcceptCall(CallAnsweringOptions answerOptions,int callHandle)
458 result r = E_FAILURE;
459 __pSoundManager->StopAlert();
460 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
462 //Check if this is a new incoming call
463 if(__pIncomingCall == null || (callHandle != (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
465 //construct and fetch new Incoming call Info
466 String incomingHandle;
467 incomingHandle.Append(callHandle);
468 AppCallInfo* pDuplicateCallInfo = FetchIncomingCallHandleN(incomingHandle, String(L""));
469 if(pDuplicateCallInfo == null)
474 delete pDuplicateCallInfo;
475 pDuplicateCallInfo = null;
478 switch(answerOptions)
480 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
481 case ANSERWING_OPTION_END_SINGLE_CALL:
483 r = AcceptSecondCall(answerOptions, callHandle);
487 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
488 case ANSERWING_OPTION_REPLACE_HELD_CALL:
489 case ANSERWING_OPTION_END_ALL_CALLS:
491 r = AcceptMultipleCall(answerOptions, callHandle);
502 TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
504 result r = E_FAILURE;
506 switch (answerOptions)
508 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
510 //accept incoming call by putting active call on Hold with 'TAPI_CALL_ANSWER_HOLD_AND_ACCEPT'
511 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
518 //Call connected successfully
520 //update status of first call to "OnHold"
521 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
522 AppCallInfo firstCallInfo;
523 pCallList->GetAt(0, firstCallInfo);
524 //replace old object with update AppCallInfo
525 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
526 *pHeldCallInfo = firstCallInfo;
527 pHeldCallInfo->SetOnHold(true);
528 __pActiveCallList->Remove(firstCallInfo.GetCallHandle()->ToLong());
529 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
535 case ANSERWING_OPTION_END_SINGLE_CALL:
537 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
538 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
539 //create a new ActiveCallList
540 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
541 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
543 //accept call and reject all active calls with 'TAPI_CALL_ANSWER_REPLACE'
544 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
548 //delete newly constructed list and gain ownership of old list
549 delete __pActiveCallList;
550 __pActiveCallList = pEndCallsList;
554 //Call connected successfully
556 //Add calls information to call log before deleting from active call list.
557 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
558 if(pCallList != null)
560 AppCallInfo endCallInfo;
561 if (pCallList->GetAt(0, endCallInfo) == E_SUCCESS)
563 SaveCallInfoToLogsDb(endCallInfo);
567 pEndCallsList->RemoveAll();
568 delete pEndCallsList;
579 TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
581 result r = E_FAILURE;
583 switch (answerOptions)
585 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
587 //Replace "Active" call by incoming call and save ended call to call logs db.
588 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
589 AppCallInfo callToBeEnded;
590 pCallList->GetAt(0, callToBeEnded);
591 //Check if the call is on "Hold", then fetch 2nd callInfo
592 if (callToBeEnded.IsOnHold() == true)
594 pCallList->GetAt(1, callToBeEnded);
599 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
600 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
602 //Accept incoming call by End Active call with 'TAPI_CALL_ANSWER_REPLACE'
603 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
607 //save the previous call back to active call list
608 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
612 //Incoming Call connected successfully
614 //save to ended call to call logs db.
615 SaveCallInfoToLogsDb(callToBeEnded);
619 case ANSERWING_OPTION_REPLACE_HELD_CALL:
621 //Replace "Held" call by incoming call and save ended call to call logs db.
622 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
623 //"Held" call is to be ended
624 AppCallInfo callToBeEnded;
625 //"Active" call will be put on Hold
626 AppCallInfo callToPutOnHold;
627 pCallList->GetAt(0, callToBeEnded);
628 //Check if the call is NOT "Held", then fetch 2nd callInfo
629 if (callToBeEnded.IsOnHold() == false)
631 callToPutOnHold = callToBeEnded;
632 pCallList->GetAt(1, callToBeEnded);
636 pCallList->GetAt(1, callToPutOnHold);
641 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
642 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
644 //End "Held" Call using 'TAPI_CALL_END'.
646 if (callToBeEnded.IsConferenceCall() == false)
648 res = tel_end_call(__pTapiHandle, callToBeEnded.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
652 IListT<AppCallInfo>* pParticipantsInfo = callToBeEnded.GetCallerList();
653 //need to end every participant individually for conference call
654 for (int index = 0; index < pParticipantsInfo->GetCount(); index++)
656 AppCallInfo memberCallInfo;
657 pParticipantsInfo->GetAt(index, memberCallInfo);
658 res = tel_end_call(__pTapiHandle, memberCallInfo.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
665 //save the previous "callToBeEnded" call back to active call list
666 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
669 //"Held" call successfully ended - Add call ended to call log database
670 SaveCallInfoToLogsDb(callToBeEnded);
672 //accept incoming call by Holding "Active" call using "TAPI_CALL_ANSWER_HOLD_AND_ACCEPT".
673 res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
680 //Call connected successfully and active call is "Onhold"
682 //replace old object with update CallInfo
683 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
684 *pHeldCallInfo = callToPutOnHold;
685 pHeldCallInfo->SetOnHold(true);
686 __pActiveCallList->Remove(callToPutOnHold.GetCallHandle()->ToLong());
687 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
691 case ANSERWING_OPTION_END_ALL_CALLS:
693 //End all active and Held calls after saving to call log. Incoming call is automatically accepted by TAPI engine,
694 // and processing of Incoming call is handled in HandleActiveCallback().
696 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
697 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
698 //create a new ActiveCallList
699 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
700 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
702 //End all active calls and all hold calls
703 int res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_ACTIVE_ALL, &HandleCallbackResponse, this);
706 res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_HOLD_ALL, &HandleCallbackResponse, this);
712 //delete newly constructed list and gain ownership of old list
713 delete __pActiveCallList;
714 __pActiveCallList = pEndCallsList;
718 //all calls ended successfully, Incoming call is automatically accepted.
721 //Add calls information to call log before deleting from active call list.
722 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
723 if(pCallList != null)
725 int callCount = pCallList->GetCount();
726 for (int index = 0; index < callCount; index++)
728 AppCallInfo endCallInfo;
729 if (pCallList->GetAt(index, endCallInfo) == E_SUCCESS)
731 SaveCallInfoToLogsDb(endCallInfo);
737 pEndCallsList->RemoveAll();
738 delete pEndCallsList;
739 pEndCallsList = null;
750 TelephonyManager::HoldCall(Tizen::Base::Long callHandle, bool holdCall)
752 result r = E_SUCCESS;
753 //Check if there are any existing active calls
754 if (__pActiveCallList->GetCount())
756 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
757 int callCount = pCallList->GetCount();
758 for (int index = 0; index < callCount; index++)
760 AppCallInfo holdCallInfo;
762 r = pCallList->GetAt(index, holdCallInfo);
763 //check if an active call is found with matching contact no.
764 if ((r == E_SUCCESS) && (holdCallInfo.GetCallHandle()->Equals(callHandle)))
766 r = HoldActiveCall(&holdCallInfo, holdCall);
778 TelephonyManager::EndConferenceCall(void)
780 result r = E_FAILURE;
781 //fetch conference callInfo to end
782 AppCallInfo confCallToEnd;
783 bool isConferenceCallFound = false;
785 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
786 int callCount = pCallList->GetCount();
787 for (int index = 0; index < callCount; index++)
789 pCallList->GetAt(index, confCallToEnd);
790 if (confCallToEnd.IsConferenceCall() == true)
792 isConferenceCallFound = true;
799 if (isConferenceCallFound == true)
801 //End conference call
802 TelCallEndType_t callEndType = TAPI_CALL_END_ACTIVE_ALL;
803 if (confCallToEnd.IsOnHold() == true)
805 callEndType = TAPI_CALL_END_HOLD_ALL;
807 int res = tel_end_call(__pTapiHandle, confCallToEnd.GetCallHandle()->ToLong(), callEndType, &HandleEndConferenceCallbackResponse, this);
808 if (res == TAPI_CAUSE_SUCCESS)
817 TelephonyManager::HoldConferenceCall(bool holdCall)
819 result r = E_FAILURE;
820 int confCallIndex = -1;
821 AppCallInfo confCallToHold;
822 bool isConferenceCallFound = false;
824 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
825 int confCallCount = pCallList->GetCount();
827 for (int index = 0; index < confCallCount; index++)
829 pCallList->GetAt(index, confCallToHold);
830 if (confCallToHold.IsConferenceCall() == true)
832 isConferenceCallFound = true;
833 confCallIndex = index;
834 //Found the Conference call to be ended.
839 if (isConferenceCallFound == false)
846 unsigned int callHandle = confCallToHold.GetCallHandle()->ToLong();
847 int res = TAPI_API_INVALID_INPUT;
848 if (holdCall == true)
850 res = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
854 res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
856 if (res == TAPI_API_SUCCESS)
859 if (holdCall == true)
861 confCallToHold.SetOnHold(true);
865 confCallToHold.SetOnHold(false);
867 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
868 *pConfCallInfo = confCallToHold;
869 __pActiveCallList->Remove(callHandle);
870 __pActiveCallList->Add(callHandle, *pConfCallInfo);
883 TelephonyManager::JoinCall(void)
885 result r = E_FAILURE;
887 AppCallInfo activeCall;
888 AppCallInfo heldCall;
889 // Use enumerator to access elements in the map
890 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
891 r = pCallList->GetAt(0, activeCall);
895 r = pCallList->GetAt(1, heldCall);
898 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
899 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
901 //Check if participants in conference call are under limit.
902 if ((heldCall.IsConferenceCall() == true) && (heldCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS))
904 res = tel_join_call(__pTapiHandle, heldCallHandle, activeCallHandle, &HandleJoinCallbackResponse, this);
906 else if (activeCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS)
908 res = tel_join_call(__pTapiHandle, activeCallHandle, heldCallHandle, &HandleJoinCallbackResponse, this);
914 if (res == TAPI_API_SUCCESS)
926 TelephonyManager::HoldActiveCall(AppCallInfo* pActiveCallInfo, bool holdCall)
928 unsigned int callHandle = pActiveCallInfo->GetCallHandle()->ToLong();
930 if (holdCall == true)
932 retStatus = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
936 retStatus = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
939 if (retStatus == TAPI_CAUSE_SUCCESS)
941 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
942 //copy state into new callinfo object
943 *pHeldCallInfo = *pActiveCallInfo;
945 //set call to hold state
946 pHeldCallInfo->SetOnHold(holdCall);
948 __pActiveCallList->Remove(callHandle);
949 //replace old object with new
950 __pActiveCallList->Add(callHandle, *pHeldCallInfo);
960 TelephonyManager::DialOutgoingCall(String& contactNumber, bool isEmergency)
962 TelCallDial_t structDialCall;
964 AppLogDebug("Enter %ls",contactNumber.GetPointer());
965 //Temp String to replace , with P and ; with W
966 String TempContactNum;
967 TempContactNum.Append(contactNumber);
968 TempContactNum.Replace(L",",L"W");
969 TempContactNum.Replace(L";",L",");
970 //conversion "contactNumber" to char*
971 const wchar_t* pContact = TempContactNum.GetPointer();
972 int len = TempContactNum.GetLength()+1;
973 char* pNumber = new (std::nothrow) char[len];
974 wcstombs(pNumber, pContact, len);
977 //initialize request parameter
978 memset(&structDialCall, '\0', sizeof(TelCallDial_t));
979 memcpy(structDialCall.szNumber, pNumber, strlen(pNumber));
980 AppLogDebug("%s",structDialCall.szNumber);
981 if(isEmergency == true)
983 structDialCall.CallType = TAPI_CALL_TYPE_E911;
987 structDialCall.CallType = TAPI_CALL_TYPE_VOICE;
990 int res = tel_dial_call(__pTapiHandle, &structDialCall, &HandleDialCallbackResponse, this);
991 if (__pSoundManager == null)
993 __pSoundManager = new (std::nothrow) SoundManager();
995 __pSoundManager->StartSession();
999 if (res == TAPI_CAUSE_SUCCESS)
1001 if (__pDialedCall != null)
1003 delete __pDialedCall;
1004 __pDialedCall = null;
1006 __pDialedCall = new (std::nothrow) AppCallInfo();
1007 __pDialedCall->SetContactNumber(contactNumber);
1008 __pDialedCall->SetEmergency(isEmergency);
1009 result r = FetchContactInfoForNumber(contactNumber);
1012 __pDialedCall->SetContactInfo(*__pCachedContact);
1023 TelephonyManager::SwapCalls(void)
1025 result r = E_FAILURE;
1027 //check if there are atleast 2 active calls
1028 if (__pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
1032 //fetch call handles
1033 IListT<long>* pCallHandleList = __pActiveCallList->GetKeysN();
1034 long callHandle1 = 0;
1035 pCallHandleList->GetAt(0, callHandle1);
1036 long callHandle2 = 0;
1037 pCallHandleList->GetAt(1, callHandle2);
1039 retStatus = tel_swap_call(__pTapiHandle, callHandle1, callHandle2, &HandleSwapCallbackResponse, this);
1041 if (retStatus == TAPI_CAUSE_SUCCESS)
1045 delete pCallHandleList;
1046 pCallHandleList = null;
1053 TelephonyManager::SendCallDTMF(String& textToBeSent)
1055 result r = E_FAILURE;
1056 //check if there is an active Call
1057 if (__pActiveCallList->GetCount() > 0)
1059 //conversion "textToBeSent" to char*
1060 const wchar_t* pTextToBeSent = textToBeSent.GetPointer();
1061 int len = textToBeSent.GetLength() + 1;
1062 char* pNumber = new (std::nothrow) char[len];
1063 wcstombs(pNumber, pTextToBeSent, len);
1064 int retStatus = tel_call_dtmf(__pTapiHandle, pNumber, &HandleCallbackResponse, this);
1067 if (retStatus == TAPI_CAUSE_SUCCESS)
1076 TelephonyManager::EndFromConference(int callHandle)
1078 result r = E_FAILURE;
1079 int confCallIndex = -1;
1080 AppCallInfo endConfCall;
1081 bool isConferenceCallFound = false;
1083 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1084 int callCount = pCallList->GetCount();
1085 for (int index = 0; index < callCount; index++)
1087 pCallList->GetAt(index, endConfCall);
1088 if (endConfCall.IsConferenceCall() == true)
1090 isConferenceCallFound = true;
1091 confCallIndex = index;
1092 //Found the Conference call to be ended.
1100 if (isConferenceCallFound == false)
1102 //no conference call found
1106 //Identify the call to be ended and remove from list on API success
1107 AppCallInfo callToBeEnded;
1108 IListT<AppCallInfo>* pParticipantList = endConfCall.GetCallerList();
1109 int participantCount = pParticipantList->GetCount();
1110 for (int index = 0; index < participantCount; index++)
1112 pParticipantList->GetAt(index, callToBeEnded);
1113 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1115 //Identify the call to be ended and remove from list on API success
1116 TelCallEndType_t endType = TAPI_CALL_END;
1118 int res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndFromConferenceCallbackResponse, this);
1119 if (res == TAPI_CAUSE_SUCCESS)
1135 TelephonyManager::SplitFromConference(int callHandle)
1137 result r = E_FAILURE;
1138 int confCallIndex = -1;
1139 AppCallInfo endConfCall;
1140 bool isConferenceCallFound = false;
1142 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1143 int callCount = pCallList->GetCount();
1144 for (int index = 0; index < callCount; index++)
1146 pCallList->GetAt(index, endConfCall);
1147 if (endConfCall.IsConferenceCall() == true)
1149 isConferenceCallFound = true;
1150 confCallIndex = index;
1151 //Found the Conference call to be ended.
1157 if (isConferenceCallFound == false)
1159 //no conference call found
1163 //Identify the call to be ended and remove from list on API success
1164 AppCallInfo callToBeEnded;
1165 pCallList = endConfCall.GetCallerList();
1166 callCount = pCallList->GetCount();
1167 for (int index = 0; index < callCount; index++)
1169 pCallList->GetAt(index, callToBeEnded);
1170 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1172 int res = tel_split_call(__pTapiHandle, callHandle, &HandleSplitFromConferenceCallbackResponse, this);
1173 if (res == TAPI_CAUSE_SUCCESS)
1188 TelephonyManager::SetMuteStatus(bool setMute)
1190 TelSoundMuteStatus_t muteStatus;
1191 result r = E_FAILURE;
1192 if (setMute == true)
1194 muteStatus = TAPI_SOUND_MUTE_STATUS_ON;
1198 muteStatus = TAPI_SOUND_MUTE_STATUS_OFF;
1200 int res = tel_set_call_mute_status(__pTapiHandle, muteStatus, &HandleCallbackResponse, this);
1201 if (res == TAPI_CAUSE_SUCCESS)
1203 __isMuted = setMute;
1214 TelephonyManager::IsCallMuted(void)
1220 TelephonyManager::SetSpeakerStatus(bool setSpeaker)
1222 result r = E_FAILURE;
1223 TelCallSoundPathInfo_t callSoundPathInfo;
1224 __pSoundManager->SetSpeakerStatus(setSpeaker);
1225 if (setSpeaker == true)
1227 callSoundPathInfo.path = TAPI_SOUND_PATH_SPK_PHONE;
1231 callSoundPathInfo.path = TAPI_SOUND_PATH_HANDSET;
1233 callSoundPathInfo.ex_volume = TelCallSoundPathInfo_t::TAPI_SOUND_EX_VOLUME_ON;
1235 int res = tel_set_call_sound_path(__pTapiHandle, &callSoundPathInfo, &HandleCallbackResponse, this);
1237 if (res == TAPI_CAUSE_SUCCESS)
1239 __isSpeakerOn = setSpeaker;
1250 TelephonyManager::IsSpeakerOn(void)
1252 return __isSpeakerOn;
1256 TelephonyManager::IsSplitAllowed(void)
1258 // Split functionality is allowed only if a one call is present.
1259 // The call can be a single call or a conference call
1260 if (__pActiveCallList->GetCount() == 1)
1268 TelephonyManager::HandleCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1270 //should not do anything here.
1274 TelephonyManager::HandleDialCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1276 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1277 if (callBackResult != TAPI_CAUSE_SUCCESS)
1279 if (pTelManager->__pDialedCall != null)
1281 delete pTelManager->__pDialedCall;
1282 pTelManager->__pDialedCall = null;
1285 //Check if there are no active connected calls and no incoming call.
1286 if (pTelManager->__pIncomingCall != null)
1288 pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
1290 else if (pTelManager->GetCurrentCallCount() >= 1)
1292 pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
1296 pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_OFF);
1299 pTelManager->__pEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
1304 TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1306 AppLogDebug("ENTER");
1307 // This callback comes only if user has rejected an incoming call from IncomingCallForm.
1308 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1309 if (pData != null && callBackResult == TAPI_API_SUCCESS)
1311 unsigned int rejectedCallHandle = 0;
1312 memcpy(&rejectedCallHandle, pData, sizeof(TS_UINT));
1314 //Check if incoming call is rejected
1315 if (pTelManager->__pIncomingCall != null && (rejectedCallHandle == (unsigned int) pTelManager->__pIncomingCall->GetCallHandle()->ToLong()))
1317 AppLogDebug("Call rejected by user");
1318 AppCallInfo rejectedCallInfo;
1319 rejectedCallInfo = *(pTelManager->__pIncomingCall);
1320 delete pTelManager->__pIncomingCall;
1321 pTelManager->__pIncomingCall = null;
1323 //rejected by user from incoming call form
1324 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_REJECTED);
1325 //Save rejected incoming call to call log db.
1326 pTelManager->SaveCallInfoToLogsDb(rejectedCallInfo);
1328 //check if the ended call was the last call
1329 bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
1330 //Stop alert - started only for incoming calls which are not blocked.
1331 if(pTelManager->__pSoundManager != null)
1333 pTelManager->__pSoundManager->StopAlert();
1334 //Do not call stop session if there is already a call going on
1335 if(isLastCall == true)
1337 pTelManager->__pSoundManager->StopSession();
1340 //Send notification to user
1341 ArrayListT<AppCallInfo>* pCallList = null;
1344 //save 'RejectedCall' to list to show on EndCallForm
1345 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1346 pCallList->Construct(1);
1347 AppCallInfo* pRejectedCall = new (std::nothrow) AppCallInfo();
1348 *pRejectedCall = rejectedCallInfo;
1349 pCallList->Add(*pRejectedCall);
1353 //fetch active calls to show appropriate scene
1354 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1356 pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1363 pTelManager->__pEventListener->HandleTelephonyError(ERROR_REJECT_FAILED);
1365 AppLogDebug("EXIT");
1369 TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1371 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1372 if (callBackResult == TAPI_API_SUCCESS && pData != null)
1374 unsigned int tempHandle = 0;
1375 TelCallInfoJoinedNoti_t joinedInfoNotification;
1376 AppCallInfo confCallInfo;
1378 memcpy(&tempHandle, pData, sizeof(TS_UINT));
1379 joinedInfoNotification.id = tempHandle;
1380 AppCallInfo activeCall;
1381 AppCallInfo heldCall;
1382 // Use enumerator to access elements in the map
1383 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1384 result r = pCallList->GetAt(0, activeCall);
1388 r = pCallList->GetAt(1, heldCall);
1391 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1392 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
1393 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
1394 if (activeCall.IsConferenceCall() == true)
1397 //When joined both become active
1398 activeCall.SetOnHold(false);
1399 heldCall.SetOnHold(false);
1400 *pConfCallInfo = activeCall;
1401 pConfCallInfo->AddCallToCallerList(heldCall);
1402 pConfCallInfo->SetCallHandle(activeCallHandle);
1403 //Set call start time
1404 if (pConfCallInfo->GetCallConnectTime() > heldCall.GetCallConnectTime())
1406 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1407 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1410 else if (heldCall.IsConferenceCall() == true)
1413 heldCall.SetOnHold(false);
1414 activeCall.SetOnHold(false);
1415 *pConfCallInfo = heldCall;
1416 pConfCallInfo->AddCallToCallerList(activeCall);
1417 pConfCallInfo->SetCallHandle(heldCallHandle);
1418 //Set call start time
1419 if (pConfCallInfo->GetCallConnectTime() > activeCall.GetCallConnectTime())
1421 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1422 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1428 pConfCallInfo->SetConference(true);
1429 heldCall.SetOnHold(false);
1430 activeCall.SetOnHold(false);
1431 pConfCallInfo->AddCallToCallerList(activeCall);
1432 pConfCallInfo->AddCallToCallerList(heldCall);
1433 pConfCallInfo->SetCallHandle(activeCallHandle);
1434 //Set call start time
1435 if (activeCall.GetCallConnectTime() > heldCall.GetCallConnectTime())
1437 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1438 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1442 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1443 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1446 pConfCallInfo->SetCallHandle(joinedInfoNotification.id);
1447 pTelManager->__pActiveCallList->RemoveAll();
1448 //only one call in the list
1449 pTelManager->__pActiveCallList->Add(joinedInfoNotification.id, *pConfCallInfo);
1450 //notify listener that call is connected.
1451 pTelManager->__pEventListener->HandleConferenceCall(*pConfCallInfo);
1459 pTelManager->__pEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
1464 TelephonyManager::HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1466 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1467 if (callBackResult == TAPI_CAUSE_SUCCESS)
1469 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1470 IListT<long>* pKeyList = pTelManager->__pActiveCallList->GetKeysN();
1471 int callCount = pTelManager->__pActiveCallList->GetCount();
1472 for (int index = 0; index < callCount; index++)
1474 AppCallInfo* pTempCallInfo = new (std::nothrow) AppCallInfo();
1475 pCallList->GetAt(index, *pTempCallInfo);
1476 (pTempCallInfo->IsOnHold() == false) ? pTempCallInfo->SetOnHold(true) : pTempCallInfo->SetOnHold(false);
1478 pKeyList->GetAt(index, callHandle);
1479 pTelManager->__pActiveCallList->SetValue(callHandle, *pTempCallInfo);
1485 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1486 pTelManager->__pEventListener->HandleCallSwapOccured(*pCallList);
1490 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
1495 TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1497 AppLogDebug("ENTER");
1498 //This callback comes if a single call is ended from Conference call.
1499 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1500 bool isParticipantCallEnded = false;
1502 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1504 //fetch end call handle
1505 TelCallEndCnf_t callEndNotification;
1506 memcpy(&callEndNotification, pData, sizeof(TelCallEndCnf_t));
1507 //Fetch conference call
1508 AppCallInfo endConfCall;
1509 bool isConferenceCallFound = false;
1510 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1511 int callCount = pCallList->GetCount();
1512 for (int index = 0; index < callCount; index++)
1514 pCallList->GetAt(index, endConfCall);
1515 if (endConfCall.IsConferenceCall() == true)
1517 isConferenceCallFound = true;
1518 //Found the Conference call to be changed.
1525 //Identify the call to be ended and remove from list.
1526 if (isConferenceCallFound == true)
1528 isParticipantCallEnded = pTelManager->HandleParticipantEndedFromConference(callEndNotification.id, endConfCall);
1533 AppLog("TAPI Failed - %d", callBackResult);
1536 //Check if participant call or Conference call was not found, then show error
1537 if (isParticipantCallEnded == false)
1539 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_FROM_CONFERENCE_FAILED);
1541 AppLogDebug("EXIT");
1545 TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantCallHandle, AppCallInfo& conferenceCall)
1547 AppLogDebug("ENTER");
1548 //to check if participant call was found and ended.
1549 bool isParticipantCallEnded = false;
1550 //Identify the call to be ended and remove from list.
1551 AppCallInfo callToBeEnded;
1552 IListT<AppCallInfo>* pCallerList = conferenceCall.GetCallerList();
1553 int callerCount = pCallerList->GetCount();
1554 for (int index = 0; index < callerCount; index++)
1556 pCallerList->GetAt(index, callToBeEnded);
1557 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == participantCallHandle)
1559 //Identify the call to be ended and remove from conference list
1560 conferenceCall.RemoveCallFromCallerList(index);
1561 //update its status to individual call before saving to database
1562 callToBeEnded.SetConference(false);
1563 SaveCallInfoToLogsDb(callToBeEnded);
1564 isParticipantCallEnded = true;
1569 if(isParticipantCallEnded == false)
1571 //participant call not found and not ended
1572 return isParticipantCallEnded;
1575 unsigned int confCallHandle = (unsigned int)conferenceCall.GetCallHandle()->ToLong();
1576 //Check if last participant removed. If yes, switch to single active view
1577 if (conferenceCall.GetCallerListCount() == 1)
1579 AppCallInfo callFromList;
1580 pCallerList = conferenceCall.GetCallerList();
1581 pCallerList->GetAt(0, callFromList);
1582 //construct a new single active call
1583 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1584 *pActiveCall = callFromList;
1585 //update conference status and Hold status
1586 pActiveCall->SetConference(false);
1587 pActiveCall->SetOnHold(conferenceCall.IsOnHold());
1589 __pActiveCallList->Remove(confCallHandle);
1590 __pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1593 //using the callConnected to switch to single active screen
1594 //or update multiple active call screen
1595 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1596 __pEventListener->HandleCallConnected(*pActiveCallList);
1597 delete pActiveCallList;
1598 pActiveCallList = null;
1602 AppCallInfo callFromList;
1603 pCallerList = conferenceCall.GetCallerList();
1604 pCallerList->GetAt(0, callFromList);
1605 //construct a new conference call
1606 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1607 *pConfCallInfo = conferenceCall;
1608 if (confCallHandle == participantCallHandle)
1610 //Call Handle is same as conf call handle, so need to change conf call handle
1611 __pActiveCallList->Remove(confCallHandle);
1612 int newConfCallHandle = callFromList.GetCallHandle()->ToLong();
1613 pConfCallInfo->SetCallHandle(newConfCallHandle);
1614 __pActiveCallList->Add(newConfCallHandle, *pConfCallInfo);
1618 __pActiveCallList->SetValue(confCallHandle, *pConfCallInfo);
1620 __pEventListener->HandleConferenceChange();
1622 AppLogDebug("EXIT");
1623 return isParticipantCallEnded;
1627 TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1629 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1630 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1632 TelCallSplitCnf_t callSplitNotification;
1633 memcpy(&callSplitNotification, pData, sizeof(TelCallSplitCnf_t));
1634 int confCallIndex = -1;
1635 AppCallInfo endConfCall;
1636 bool isConferenceCallFound = false;
1638 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1639 int callCount = pCallList->GetCount();
1640 for (int index = 0; index < callCount; index++)
1642 pCallList->GetAt(index, endConfCall);
1643 if (endConfCall.IsConferenceCall() == true)
1645 isConferenceCallFound = true;
1646 confCallIndex = index;
1647 //Found the Conference call to be ended.
1652 if (isConferenceCallFound == false)
1660 //Identify the call to be ended and remove from list on API success
1661 AppCallInfo callToBeEnded;
1662 pCallList = endConfCall.GetCallerList();
1663 callCount = pCallList->GetCount();
1664 for (int index = 0; index < callCount; index++)
1666 pCallList->GetAt(index, callToBeEnded);
1667 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == callSplitNotification.id)
1669 //Identified the call to be ended and remove from conference list
1670 //Add this to the active call list
1671 endConfCall.RemoveCallFromCallerList(index);
1675 unsigned int confCallHandle = (unsigned int)endConfCall.GetCallHandle()->ToLong();
1676 //Set the hold flags correctly and make the changes to the active call list
1677 if (endConfCall.GetCallerListCount() == 1)
1679 //Set hold for the other single call
1680 // and add to the list
1681 AppCallInfo callFromList;
1682 pCallList = endConfCall.GetCallerList();
1683 pCallList->GetAt(0, callFromList);
1684 AppCallInfo* pHeldCall = new (std::nothrow) AppCallInfo();
1685 *pHeldCall = callFromList;
1686 pHeldCall->SetConference(false);
1687 pHeldCall->SetOnHold(true);
1688 pTelManager->__pActiveCallList->Remove(confCallHandle);
1689 pTelManager->__pActiveCallList->Add(pHeldCall->GetCallHandle()->ToLong(), *pHeldCall);
1694 //Set hold flag for conference call
1695 endConfCall.SetOnHold(true);
1696 AppCallInfo callFromList;
1697 pCallList = endConfCall.GetCallerList();
1698 pCallList->GetAt(0, callFromList);
1700 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1701 *pConfCallInfo = endConfCall;
1702 if (confCallHandle == callSplitNotification.id)
1704 //Call Handle is same as conf call handle.
1705 //Change conf call handle
1706 pTelManager->__pActiveCallList->Remove(confCallHandle);
1707 int tmpCallHandle = callFromList.GetCallHandle()->ToLong();
1708 pConfCallInfo->SetCallHandle(tmpCallHandle);
1709 pTelManager->__pActiveCallList->Add(callFromList.GetCallHandle()->ToLong(), *pConfCallInfo);
1713 pTelManager->__pActiveCallList->Remove(confCallHandle);
1714 pTelManager->__pActiveCallList->Add(confCallHandle, *pConfCallInfo);
1717 //Add the new active call to active call list
1718 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1719 *pActiveCall = callToBeEnded;
1720 pActiveCall->SetConference(false);
1721 pActiveCall->SetOnHold(false);
1722 pTelManager->__pActiveCallList->Remove(pActiveCall->GetCallHandle()->ToLong());
1723 pTelManager->__pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1725 //using the callConnected to switch to Multiple active screen
1726 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1727 pTelManager->__pEventListener->HandleCallConnected(*pCallList);
1732 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
1737 TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1740 //This callback comes only if a conference call is ended by user.
1741 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1742 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1744 //fetch ended confCall details
1745 result r = E_FAILURE;
1746 AppCallInfo endConfCallInfo;
1747 IListT<AppCallInfo>* pActiveCallList = pTelManager->__pActiveCallList->GetValuesN();
1748 if(pActiveCallList != null && pActiveCallList->GetCount() > 0)
1750 for (int index = 0; index < pActiveCallList->GetCount(); index++)
1752 r = pActiveCallList->GetAt(index, endConfCallInfo);
1753 if(r == E_SUCCESS && endConfCallInfo.IsConferenceCall() == true)
1755 //conference call found.
1765 delete pActiveCallList;
1766 pActiveCallList = null;
1768 //check if no conference call found, then return.
1773 //remove the conference call handle from active call list to avoid any processing in HandleIdleCallback().
1774 pTelManager->__pActiveCallList->Remove(endConfCallInfo.GetCallHandle()->ToLong());
1775 //Save "End" Conf. call info to call log database
1776 pTelManager->SaveCallInfoToLogsDb(endConfCallInfo);
1778 //check if the ended call was the last call and show notification to user
1779 bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
1780 ArrayListT<AppCallInfo>* pCallList = null;
1783 pTelManager->__pSoundManager->SetlastEndedConferenceCall();
1784 //stop sound session
1785 pTelManager->__pSoundManager->StopSession();
1786 //send empty call list to show dialer or call log screen
1787 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1791 //fetch active calls to show appropriate scene
1792 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1794 //notify listener that call is disconnected.
1795 pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1801 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
1807 TelephonyManager::HandleIdleCallBack(void* pData)
1809 AppLogDebug("ENTER");
1810 //This callback comes when any type of calls are ended
1811 //We do NOT handle below scenarios here -
1812 //1) In incoming call scenarios, if we end any active calls - handled in "AcceptCall()".
1813 //2) Incoming call automatically blocked is handled in "AnswerAutoRejectCall()" and rejection by user scenarios are handled in "HandleRejectCallbackResponse()".
1814 //3) End conference call is handled in "HandleEndConferenceCallbackResponse()".
1815 //4) End Single Call from Conference call by user is handled in "HandleEndFromConferenceCallbackResponse()".
1816 //5) End Single Call from Conference call using eventInjector is diverted to "HandleParticipantEndedFromConference()".
1817 //BUT, we do handle below scenarios here -
1818 //1) "MISSED" incoming call scenario here i.e incoming call is rejected by other caller.
1819 //2) an "unconnected" dialed call is ended by caller or other party.
1820 //3) Any normal active calls(NOT conference calls) ended by user or by other party.
1822 if(__pSoundManager->GetLastConferenceCall() == false)
1824 __pSoundManager->SetDisconnectTone();
1827 TelCallStatusIdleNoti_t idleNotification;
1828 memcpy(&idleNotification, pData, sizeof(TelCallStatusIdleNoti_t));
1829 //handle end call event, show next screen
1830 unsigned int endCallHandle = idleNotification.id;
1832 //empty active call list or no dialed or incoming calls - ignore this event
1833 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1834 if((pActiveCallList == null || pActiveCallList->GetCount() <= 0) && __pDialedCall == null && __pIncomingCall == null)
1836 delete pActiveCallList;
1837 AppLogDebug("EXIT - no calls exist");
1841 //Check if ended call was among conference caller list,
1842 //then divert event to "HandleParticipantEndedFromConference()"
1843 AppCallInfo confCallInfo;
1844 bool isConferenceCallChanged = false;
1845 for (int index = 0; (pActiveCallList != null && index < pActiveCallList->GetCount()); index++)
1847 //fetch conference call
1848 result r = pActiveCallList->GetAt(index, confCallInfo);
1849 if (r == E_SUCCESS && confCallInfo.IsConferenceCall() == true)
1851 //Conference call found - check if ended call is a participant
1852 isConferenceCallChanged = HandleParticipantEndedFromConference(endCallHandle, confCallInfo);
1856 delete pActiveCallList;
1857 pActiveCallList = null;
1858 if (isConferenceCallChanged == true)
1860 //end call event handled - conference call will now either remain as conf. call
1861 //or become single active call, if it has only 1 participant left.
1862 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1863 AppLogDebug("isConferenceCallChanged == true");
1867 //check if ended call was among the active call list and not a conference call
1868 AppCallInfo endCallInfo;
1869 result r = __pActiveCallList->GetValue(endCallHandle, endCallInfo);
1872 bool isHandled = HandleEndNormalActiveCall(endCallInfo);
1873 if (isHandled == true)
1875 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1880 //Check if dialed call is rejected by other party
1881 bool isDialedCallEnded = ((__pDialedCall != null) && (__pDialedCall->GetCallHandle() != null) &&(((unsigned int)__pDialedCall->GetCallHandle()->ToLong()) == idleNotification.id));
1882 //Check if "missed" incoming call is ended
1883 bool isMissedIncomingCallEnded = (__pIncomingCall != null && ((unsigned int)__pIncomingCall->GetCallHandle()->ToLong() == idleNotification.id));
1884 if (isDialedCallEnded == true || isMissedIncomingCallEnded == true)
1886 //It comes here only if the ended call was either a "unconnected" dialed call or an "Missed" incoming call.
1887 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1889 ArrayListT<AppCallInfo>* pCallList = null;
1890 //Check if dialed call was ended
1891 if (isDialedCallEnded == true)
1893 AppLogDebug("Dialed Call Ended");
1894 //Call Ended is the dialed call
1895 endCallInfo = *(__pDialedCall);
1896 delete __pDialedCall;
1897 __pDialedCall = null;
1901 //Here, only "Missed" Incoming call ended by other caller is handled.
1902 AppLogDebug("Missed Call Ended");
1903 __pSoundManager->StopAlert();
1904 endCallInfo = *(__pIncomingCall);
1905 delete __pIncomingCall;
1906 __pIncomingCall = null;
1907 //update missed status
1908 endCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED_UNSEEN);
1910 //save ended call to call log db.
1911 SaveCallInfoToLogsDb(endCallInfo);
1913 //notify listener that call is disconnected.
1914 if (isLastCall == true)
1916 __pSoundManager->StopSession();
1917 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1918 pCallList->Construct(1);
1919 if (isMissedIncomingCallEnded == false)
1921 //save to list to show EndCallForm
1922 pCallList->Add(endCallInfo);
1924 __pSoundManager->GetTimer()->Cancel();
1929 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
1931 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1935 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1936 AppLogDebug("EXIT");
1940 TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
1942 AppLogDebug("Enter");
1943 // This function gets called only from HandleIdleCallback(),
1944 // to handle disconnection of normal active calls.
1945 if (endCallInfo.IsConferenceCall() == false)
1947 //remove the call handle from active call list
1948 __pActiveCallList->Remove(endCallInfo.GetCallHandle()->ToLong());
1949 //check if the ended call was the last call and show notification to user
1950 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1951 ArrayListT<AppCallInfo>* pCallList = null;
1954 //stop sound session
1955 __pSoundManager->StopSession();
1956 //save "End" CallInfo to list to show EndCallForm
1957 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1958 pCallList->Construct(1);
1959 pCallList->Add(endCallInfo);
1963 //fetch active calls to show appropriate scene
1964 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
1967 //Save "End" call info to call log database
1968 SaveCallInfoToLogsDb(endCallInfo);
1969 //notify listener that call is disconnected.
1970 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1979 TelephonyManager::HandleDialingCallBack(void* pData)
1981 AppLogDebug("Enter");
1982 unsigned int tempHandle = 0;
1983 TelCallStatusDialingNoti_t dialingNotification;
1984 memcpy(&tempHandle, pData, sizeof(TS_UINT));
1985 dialingNotification.id = tempHandle;
1986 //check if callback is for different dialed call
1987 //Dont check for call handle, since this is the first time, we get call handle for a dialed call.
1988 if (__pDialedCall == null)
1990 AppLogDebug("__pDialedCall == null");
1991 //construct new dialed call
1992 __pDialedCall = new (std::nothrow) AppCallInfo();
1994 TelCallStatus_t callStatus;
1995 int res = tel_get_call_status(__pTapiHandle, dialingNotification.id, &callStatus);
1996 if (res == TAPI_CAUSE_SUCCESS)
1999 String contactNumber(callStatus.pNumber);
2000 __pDialedCall->SetContactNumber(contactNumber);
2001 //set emergency state
2002 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2004 __pDialedCall->SetEmergency(true);
2008 __pDialedCall->SetEmergency(false);
2011 FetchContactInfoForNumber(__pDialedCall->GetContactNumber());
2012 if (__pCachedContact != null)
2014 __pDialedCall->SetContactInfo(*(__pCachedContact));
2018 //set call handle for dialed call
2019 __pDialedCall->SetCallHandle(dialingNotification.id);
2020 __pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
2022 //set call notification time.
2023 long long startTime = 0;
2024 SystemTime::GetTicks(startTime);
2025 __pDialedCall->SetCallNotificationTime(startTime);
2029 TelephonyManager::HandleActiveCallBack(void* pData)
2031 // This callback comes whenever any new call is connected
2032 // Or, any "Held" call is activated (we ignore activation of "Held" calls).
2033 unsigned int newCallHandle = 0;
2034 TelCallStatusActiveNoti_t activeNotification;
2035 memcpy(&newCallHandle, pData, sizeof(TS_UINT));
2036 activeNotification.id = newCallHandle;
2037 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2039 //Check if the "Held" call was activated, i.e it is already present in already activated calls list.
2040 bool toHandleEvent = true;
2041 for (int callIndex = 0; (callIndex < pCallList->GetCount() && toHandleEvent == true); callIndex++ )
2043 AppCallInfo tempCallInfo;
2044 pCallList->GetAt(callIndex, tempCallInfo);
2045 unsigned int tempCallHandle = tempCallInfo.GetCallHandle()->ToLong();
2046 //Check if active callback came for "HandleJoinCallbackResponse"
2047 //or for "UnHold Conference Call or normal call".
2048 if(tempCallInfo.IsConferenceCall() == true)
2050 if (tempCallHandle == activeNotification.id)
2052 toHandleEvent = false;
2056 //check individual participants of conf call
2057 IListT<AppCallInfo>* pConfCallList = tempCallInfo.GetCallerList();
2058 int confCallCount = pConfCallList->GetCount();
2059 for (int callIndex = 0; (callIndex < confCallCount && toHandleEvent == true); callIndex++)
2061 AppCallInfo confCallerInfo;
2062 pConfCallList->GetAt(callIndex, confCallerInfo);
2063 unsigned int confCallerHandle = confCallerInfo.GetCallHandle()->ToLong();
2064 if (confCallerHandle == activeNotification.id)
2066 toHandleEvent = false;
2071 else if(tempCallHandle == activeNotification.id)
2073 //If normal call is UnHold
2074 toHandleEvent = false;
2078 //check if we need to handle this event.
2079 if(toHandleEvent == true)
2081 //Here it comes, only if either new dialed or incoming call was connected.
2082 HandleCallConnected( activeNotification.id);
2089 TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
2091 //Here it comes, only if either new dialed or incoming call was connected.
2092 //This function should be called only from "HandleActiveCallback()".
2093 AppCallInfo* pConnectedCall = null;
2094 //to check if incoming call was connected
2095 bool isIncomingCallConnected = false;
2097 __pSoundManager->SetConnectTone();
2098 //Check if dialed call is connected.
2099 if ((__pDialedCall != null) && (connectedCallHandle == (unsigned int)__pDialedCall->GetCallHandle()->ToLong()))
2101 pConnectedCall = __pDialedCall;
2102 __pDialedCall = null;
2104 //Check if connected call is incoming call.
2105 else if (__pIncomingCall != null && (connectedCallHandle == (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
2107 pConnectedCall = __pIncomingCall;
2108 __pIncomingCall = null;
2109 isIncomingCallConnected = true;
2113 // this is just for safety. This scenario should never come.
2114 // Otherwise Correct the code in some other function, if it comes here.
2115 AppLogDebug("Error - Connected call was neither one of active calls nor it was dialed or incoming call");
2116 //Construct a new CallInfo object for call
2117 pConnectedCall = new (std::nothrow) AppCallInfo();
2118 pConnectedCall->SetCallHandle(connectedCallHandle);
2120 TelCallStatus_t callStatus;
2121 int res = tel_get_call_status(__pTapiHandle, connectedCallHandle, &callStatus);
2122 if (res == TAPI_CAUSE_SUCCESS)
2124 String contactNumber(callStatus.pNumber);
2125 pConnectedCall->SetContactNumber(contactNumber);
2126 //set emergency state
2127 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2129 pConnectedCall->SetEmergency(true);
2133 pConnectedCall->SetEmergency(false);
2135 //set call notification time
2136 long long startTime = 0;
2137 SystemTime::GetTicks(startTime);
2138 pConnectedCall->SetCallNotificationTime(startTime);
2139 if (callStatus.bMoCall == true)
2141 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
2145 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2146 isIncomingCallConnected = true;
2149 //delete any dialed or incoming call objects
2150 delete __pDialedCall;
2151 __pDialedCall = null;
2152 delete __pIncomingCall;
2153 __pIncomingCall = null;
2156 //fetch contact info for connected call & it is not a hidden call
2157 if (pConnectedCall->GetContactInfo() == null && pConnectedCall->GetContactNumber().IsEmpty() == false)
2159 FetchContactInfoForNumber(pConnectedCall->GetContactNumber());
2160 if (__pCachedContact != null)
2162 pConnectedCall->SetContactInfo(*(__pCachedContact));
2165 //set Call connect time for newly connected call
2166 long long startTime = 0;
2167 SystemTime::GetTicks(startTime);
2168 pConnectedCall->SetCallConnectTime(startTime);
2169 if(GetCurrentCallCount() == 0)
2171 __pSoundManager->SetMinuteReminderTone();
2175 //transfer ownership to Active calls list
2176 __pActiveCallList->Add(connectedCallHandle, *(pConnectedCall));
2177 pConnectedCall = null;
2179 //notify listener that call is connected.
2180 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2181 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
2182 __pEventListener->HandleCallConnected(*pCallList);
2183 if (isIncomingCallConnected == true)
2185 __pSoundManager->StopAlert();
2192 TelephonyManager::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
2194 AppLogDebug("Enter");
2195 int callHandle = pIncomingCallInfo->GetCallHandle()->ToLong();
2196 String contactNumber(L"");
2197 contactNumber.Append(pIncomingCallInfo->GetContactNumber());
2198 //Check if "reject unknown calls" is set and contact number is not present in AddressBook
2199 //or if contact number is blacklisted
2200 if(__pSettingsManager != null)
2202 if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pIncomingCallInfo->GetContactInfo() == null))
2203 || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
2205 AnswerAutoRejectCall(callHandle);
2213 TelephonyManager::HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
2215 AppLogDebug("Enter");
2216 unsigned int tempHandle = 0;
2217 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2218 if (pTelManager->__pSoundManager == null)
2220 AppLog("Creating Sound Manager");
2221 pTelManager->__pSoundManager = new (std::nothrow) SoundManager();
2223 //Handle telephony events
2224 if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) == 0)
2226 pTelManager->HandleIdleCallBack(pData);
2228 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) == 0)
2230 pTelManager->__pSoundManager->StartSession();
2231 pTelManager->HandleActiveCallBack(pData);
2233 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) == 0)
2235 pTelManager->HandleDialingCallBack(pData);
2239 memcpy(&tempHandle, pData, sizeof(TS_UINT));
2244 TelephonyManager::GetConferenceCallInfoN(void)
2246 AppCallInfo* pConfCallInfo = null;
2248 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2249 int callCount = pCallList->GetCount();
2250 for (int index = 0; index < callCount; index++)
2252 AppCallInfo callInfo;
2253 pCallList->GetAt(index, callInfo);
2254 if (callInfo.IsConferenceCall() == true)
2256 pConfCallInfo = new (std::nothrow) AppCallInfo();
2257 *pConfCallInfo = callInfo;
2258 //Found the Conference call
2265 return pConfCallInfo;
2268 IListT<AppCallInfo>*
2269 TelephonyManager::GetCallListN(void)
2271 ArrayListT<AppCallInfo>* pCallList = null;
2272 if (__pActiveCallList != null)
2274 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
2280 TelephonyManager::GetCurrentCallCount(void)
2282 if (__pActiveCallList != null)
2284 return __pActiveCallList->GetCount();
2290 TelephonyManager::StartAlert(AppCallInfo& incomingCallInfo)
2292 String contactRingTone(L"");
2293 String contactNumber = incomingCallInfo.GetContactNumber();
2294 //check if not hidden call
2295 if(contactNumber.IsEmpty() == false)
2297 //fetch contact info from Db
2298 Contact* foundContact = GetContactN(contactNumber);
2299 if(foundContact != null)
2301 //fetch custom ringtone for contact
2302 result r = foundContact->GetValue(CONTACT_PROPERTY_ID_RINGTONE, contactRingTone);
2303 //Now check if there is a group ring tone
2304 if(contactRingTone.IsEmpty() == true)
2306 IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(foundContact->GetRecordId());
2307 if(pCategoryList != null && pCategoryList->GetCount() > 0)
2309 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
2310 contactRingTone = pCategory->GetRingtonePath();
2313 AppLog("ringtone fetched - r = %d", r);
2314 delete foundContact;
2315 foundContact = null;
2318 __pSoundManager->StartAlert(contactRingTone);
2322 TelephonyManager::StopAlert(void)
2324 __pSoundManager->StopAlert();
2328 TelephonyManager::CheckValidTelePhoneNumber(const String& contactNumber)
2330 result r = E_SUCCESS;
2331 if (contactNumber.GetLength() > TAPI_CALL_DIALDIGIT_LEN_MAX)
2335 //TODO: check if valid phone number else return error message
2340 TelephonyManager::CheckIfMOCallIsPossible()
2342 result r = E_SUCCESS;
2344 //Check modem power status
2345 int modemStatus = 0;
2346 int errorCode = tel_check_modem_power_status(__pTapiHandle, &modemStatus);
2347 if (errorCode != TAPI_API_SUCCESS || modemStatus == TAPI_PHONE_POWER_STATUS_OFF
2348 || modemStatus == TAPI_PHONE_POWER_STATUS_ERROR)
2354 TelSimCardStatus_t simStatus;
2355 int simChangedStatus;
2356 //fetch sim initialization status
2357 int errorCode = tel_get_sim_init_info(__pTapiHandle, &simStatus, &simChangedStatus);
2358 if (errorCode != TAPI_API_SUCCESS)
2366 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: // Sim Initialization ok
2370 case TAPI_SIM_STATUS_UNKNOWN: //initial state
2371 case TAPI_SIM_STATUS_CARD_NOT_PRESENT: //Card not present
2372 case TAPI_SIM_STATUS_CARD_REMOVED: //Card removed
2373 case TAPI_SIM_STATUS_CARD_ERROR: // Bad card / On the fly, SIM gone bad
2374 //TODO: might want to set different error code, to give proper message to user
2387 TelephonyManager::CheckIfMOCallIsEmergency(const String& contactNumber, bool isSimInitialized)
2389 //TODO: extract actual telephone number from contactNumber
2390 //by deleting prefix,'P','W', etx.
2392 bool isEmergency = false;
2393 //conversion "contactNumber" to char*
2394 const wchar_t* pContact = contactNumber.GetPointer();
2395 int len = contactNumber.GetLength() + 1;
2396 char* pNumber = new (std::nothrow) char[len];
2397 wcstombs(pNumber, pContact, len);
2399 if(isSimInitialized)
2401 //used to get Ecc information for 2G and 3G.
2402 TelSimEccList_t simEccList;
2403 memset(&simEccList, 0x00, sizeof(TelSimEccList_t));
2404 //Check if given number matches the sim card's emergency numbers
2405 int errorCode = tel_get_sim_ecc(__pTapiHandle, &simEccList);
2406 if (errorCode == TAPI_API_SUCCESS && simEccList.ecc_count > 0)
2408 for (int index = 0; index < simEccList.ecc_count; index++)
2410 if ((strcmp(pNumber, simEccList.list[index].number) == 0))
2419 //TODO: check if we need to also check SOS call numbers, if sim not present.
2428 TelephonyManager::FetchContactInfoForNumber(const String& phoneNumberStr)
2430 result r = E_FAILURE;
2432 //delete previously cached data
2433 if (__pCachedContact != null)
2435 delete __pCachedContact;
2436 __pCachedContact = null;
2439 //Searches contacts by phone number.
2440 IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumberStr);
2441 if (pContactList == null || IsFailed(GetLastResult()))
2446 //Fetch the contact's info to be displayed
2447 IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
2448 while ((E_SUCCESS == pContactEnum->MoveNext()) && (__pCachedContact == null))
2450 Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
2452 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
2453 if (pPhoneNumberList != null)
2455 IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
2456 while (E_SUCCESS == pPhoneEnum->MoveNext())
2458 PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
2459 //Check if this is the correct contact
2460 if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumberStr))
2462 //save newly fetched contact info.
2463 __pCachedContact = new (std::nothrow) Contact(*pContact);
2469 pPhoneNumberList->RemoveAll(true);
2470 delete pPhoneNumberList;
2473 delete pContactEnum;
2474 pContactList->RemoveAll(true);
2475 delete pContactList;
2481 TelephonyManager::GetContactN(const String& phoneNumber)
2483 result r = FetchContactInfoForNumber(phoneNumber);
2486 return new (std::nothrow) Contact(*__pCachedContact);
2492 TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const String& contactNumber)
2494 if(__pIncomingCall != null)
2496 delete __pIncomingCall;
2497 __pIncomingCall = null;
2500 if(callHandle.IsEmpty() == false)
2503 Integer::Parse(callHandle,incomingHandle);
2504 //This API call is synchronous
2505 TelCallStatus_t callStatus;
2506 int errCode = tel_get_call_status(__pTapiHandle, incomingHandle, &callStatus);
2507 if (errCode != TAPI_API_SUCCESS)
2509 AppLogDebug("tel_get_call_status failed");
2512 //construct incoming call info object
2513 __pIncomingCall = new (std::nothrow) AppCallInfo();
2514 __pIncomingCall->SetCallHandle(incomingHandle);
2517 String phoneNumber(contactNumber);
2518 if(phoneNumber.IsEmpty() == true)
2520 phoneNumber.Append(callStatus.pNumber);
2522 __pIncomingCall->SetContactNumber(phoneNumber);
2523 //set emergency state
2524 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2526 __pIncomingCall->SetEmergency(true);
2530 __pIncomingCall->SetEmergency(false);
2532 //set start time, when call is connected
2533 long long startTime = 0;
2534 SystemTime::GetTicks(startTime);
2535 __pIncomingCall->SetCallNotificationTime(startTime);
2536 __pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2540 //TODO: This 'else' block can be removed once AppControl request API is stabilized.
2541 //This API call is synchronous and 'HandleIncomingCallStatusCallBack' is called for each active call.
2542 int errCode = tel_get_call_status_all(__pTapiHandle, &HandleIncomingCallStatusCallBack, this);
2543 if (errCode != TAPI_API_SUCCESS)
2549 if(__pIncomingCall != null)
2551 //set call notification time
2552 long long startTime = 0;
2553 SystemTime::GetTicks(startTime);
2554 __pIncomingCall->SetCallNotificationTime(startTime);
2556 if(__pIncomingCall->GetContactNumber().IsEmpty() == false)
2558 //fetch contact info
2559 FetchContactInfoForNumber(__pIncomingCall->GetContactNumber());
2560 if (__pCachedContact != null)
2562 __pIncomingCall->SetContactInfo(*__pCachedContact);
2566 //construct a new callinfo object to pass its ownership to caller.
2567 AppCallInfo* pNewIncomingCall = new (std::nothrow) AppCallInfo();
2568 *pNewIncomingCall = *__pIncomingCall;
2569 return pNewIncomingCall;
2571 //return null, if no incoming call found
2576 TelephonyManager::HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus, void* pUserData)
2578 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2579 if (pCallStatus != null && pCallStatus->bMoCall == false
2580 && ((pCallStatus->CallState == TAPI_CALL_STATE_INCOMING)
2581 || (pCallStatus->CallState == TAPI_CALL_STATE_WAITING)))
2583 //construct incoming call details
2584 pTelManager->__pIncomingCall = new (std::nothrow) AppCallInfo();
2585 pTelManager->__pIncomingCall->SetCallHandle(pCallStatus->CallHandle);
2587 String contactNumber(pCallStatus->pNumber);
2588 pTelManager->__pIncomingCall->SetContactNumber(contactNumber);
2589 //set emergency state
2590 if(pCallStatus->CallType == TAPI_CALL_TYPE_E911)
2592 pTelManager->__pIncomingCall->SetEmergency(true);
2596 pTelManager->__pIncomingCall->SetEmergency(false);
2599 pTelManager->__pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2604 TelephonyManager::SaveCallInfoToLogsDb(AppCallInfo& endCallInfo)
2606 if (endCallInfo.IsConferenceCall() == false)
2608 //single active call - Add call ended to call log database
2609 __pCalllogMgr->AddCallogInfoToDatabase(&endCallInfo);
2614 int confCallCount = endCallInfo.GetCallerListCount();
2615 IListT<AppCallInfo>* pParticipantList = endCallInfo.GetCallerList();
2616 for (int index = 0; index < confCallCount; index++)
2618 AppCallInfo participantInfo;
2619 if (pParticipantList->GetAt(index, participantInfo) == E_SUCCESS)
2621 //Add call ended to call log database
2622 __pCalllogMgr->AddCallogInfoToDatabase(&participantInfo);
2629 TelephonyManager::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
2631 if(networkStatus.IsCallServiceAvailable() == false)
2638 TelephonyManager::IsIncomingorDialingCallPresent(void)
2640 //returns false, if incoming call or dialed call is present.
2641 return ((__pIncomingCall != null) || (__pDialedCall != null));