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"
29 #include "CallTelephonyManager.h"
30 #include "CallSettingsManager.h"
31 #include "CallTypes.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Social;
36 using namespace Tizen::System;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Telephony;
39 using namespace Tizen::Base::Utility;
41 const char* callEventList[] = {
42 TAPI_NOTI_VOICE_CALL_STATUS_IDLE,
43 TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE,
44 TAPI_NOTI_VOICE_CALL_STATUS_HELD,
45 TAPI_NOTI_VOICE_CALL_STATUS_DIALING,
46 TAPI_NOTI_VOICE_CALL_STATUS_ALERT,
47 TAPI_NOTI_VOICE_CALL_STATUS_WAITING,
48 TAPI_NOTI_CALL_INFO_CALL_CONNECTED_LINE,
49 TAPI_NOTI_CALL_INFO_WAITING,
50 TAPI_NOTI_CALL_INFO_CUG,
51 TAPI_NOTI_CALL_INFO_FORWARDED,
52 TAPI_NOTI_CALL_INFO_BARRED_INCOMING,
53 TAPI_NOTI_CALL_INFO_BARRED_OUTGOING,
54 TAPI_NOTI_CALL_INFO_DEFLECTED,
55 TAPI_NOTI_CALL_INFO_CLIR_SUPPRESSION_REJECT,
56 TAPI_NOTI_CALL_INFO_FORWARD_UNCONDITIONAL,
57 TAPI_NOTI_CALL_INFO_FORWARD_CONDITIONAL,
58 TAPI_NOTI_CALL_INFO_CALL_LINE_IDENTITY,
59 TAPI_NOTI_CALL_INFO_CALL_NAME_INFORMATION,
60 TAPI_NOTI_CALL_INFO_FORWARDED_CALL,
61 TAPI_NOTI_CALL_INFO_CUG_CALL,
62 TAPI_NOTI_CALL_INFO_DEFLECTED_CALL,
63 TAPI_NOTI_CALL_INFO_TRANSFERED_CALL,
64 TAPI_NOTI_CALL_INFO_HELD,
65 TAPI_NOTI_CALL_INFO_ACTIVE,
66 TAPI_NOTI_CALL_INFO_JOINED,
67 TAPI_NOTI_CALL_INFO_RELEASED_ON_HOLD,
68 TAPI_NOTI_CALL_INFO_TRANSFER_ALERT,
69 TAPI_NOTI_CALL_INFO_TRANSFERED,
70 TAPI_NOTI_CALL_INFO_CF_CHECK_MESSAGE,
73 TelephonyManager* TelephonyManager::__pManager = null;
75 TelephonyManager::TelephonyManager(ITelephonyEventListener* pEventListener)
76 : __pEventListener(pEventListener)
79 __pIncomingCall = null;
80 __pActiveCallList = null;
81 __pSettingsManager = null;
83 __pAddressBook = null;
84 __pCachedContact = null;
86 __isSpeakerOn = false;
87 __pSoundManager = null;
89 __pNetworkManager = null;
92 TelephonyManager::~TelephonyManager(void)
94 if (__pActiveCallList != null)
96 delete __pActiveCallList;
99 if (__pDialedCall != null)
101 delete __pDialedCall;
102 __pDialedCall = null;
105 if (__pIncomingCall != null)
107 delete __pIncomingCall;
108 __pIncomingCall = null;
111 if (__pAddressBook != null)
113 delete __pAddressBook;
114 __pAddressBook = null;
116 if (__pCachedContact != null)
118 delete __pCachedContact;
119 __pCachedContact = null;
122 //unregister for events from TAPI Lib.
125 //De-initialize the TAPI Library
126 if(__pTapiHandle != null)
128 tel_deinit(__pTapiHandle);
131 if (__pSoundManager != null)
133 delete __pSoundManager;
136 if (__pCalllogMgr != null)
138 __pCalllogMgr = null;
143 TelephonyManager::GetInstance(ITelephonyEventListener* pEventListener)
145 if (__pManager == null)
147 CreateInstance(pEventListener);
153 TelephonyManager::CreateInstance(ITelephonyEventListener* pEventListener)
155 __pManager = new (std::nothrow) TelephonyManager(pEventListener);
156 result r = __pManager->Initialize();
162 atexit(&(TelephonyManager::DestroyInstance));
166 TelephonyManager::DestroyInstance(void)
168 if (__pManager != null)
170 __pManager->EndAllCalls();
177 TelephonyManager::Initialize(void)
179 //Initialize telephony library
180 result r = InitializeTelephonyLibrary();
185 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
186 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
188 //Initialize the Settings Manager to fetch call settings
189 __pSettingsManager = SettingsManager::GetInstance();
191 __pSoundManager = new (std::nothrow) SoundManager();
192 __pCalllogMgr = CallLogManager::GetInstance();
194 //initialize address book to fetch contacts information
195 __pAddressBook = AddressbookManager::GetInstance()->GetAddressbookN();
196 if(__pAddressBook == null)
200 __pNetworkManager = new NetworkManager();
201 if(__pNetworkManager != null)
203 __pNetworkManager->Construct(this);
209 TelephonyManager::InitializeTelephonyLibrary(void)
211 result r = E_FAILURE;
213 __pTapiHandle = tel_init(null);
214 if (__pTapiHandle != null)
216 //register telephony events
217 int errorCode = RegisterEvents();
218 if (errorCode == TAPI_CAUSE_SUCCESS)
223 //TAPI Library is initialized and events registered successfully
228 TelephonyManager::RegisterEvents(void)
231 int eventCount = sizeof(callEventList) / sizeof(char *);
232 for (int index = 0; index < eventCount; index++)
234 errCode = tel_register_noti_event(__pTapiHandle, callEventList[index], &HandleCallback, this);
235 if (errCode != TAPI_API_SUCCESS)
244 TelephonyManager::UnregisterEvents(void)
246 int eventCount = sizeof(callEventList) / sizeof(char *);
247 for (int index = 0; index < eventCount; index++)
249 tel_deregister_noti_event(__pTapiHandle, callEventList[index]);
254 TelephonyManager::SetupMoCall(String& contactNumber, bool isEmergency)
256 result res = E_SUCCESS;
257 //check if valid phone number exist
258 res = CheckValidTelePhoneNumber(contactNumber);
261 return ERROR_INVALID_NUMBER;
264 //if dialing an emergency call and active calls exist
265 //then end all active calls.
266 if (isEmergency && __pActiveCallList->GetCount() > 0)
268 //Get first call handle
269 AppCallInfo endCallInfo;
270 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
271 pCallList->GetAt(0, endCallInfo);
272 int callHandle = endCallInfo.GetCallHandle()->ToLong();
276 //release all active or held calls
277 int tapiRes = tel_end_call(__pTapiHandle, callHandle, TAPI_CALL_END_ALL, &HandleCallbackResponse, this);
278 if (tapiRes == TAPI_CAUSE_SUCCESS)
280 __pActiveCallList->RemoveAll();
288 else if (__pActiveCallList->GetCount() == 1)
290 //Check if there is already an active call,
291 //Put the already active call on hold.
292 AppCallInfo holdCallInfo;
293 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
295 pCallList->GetAt(0, holdCallInfo);
296 //Check if call is active, then put on hold
297 if (holdCallInfo.IsOnHold() == false)
299 res = HoldActiveCall(&holdCallInfo, true);
305 //make the next call, only if any existing active call
306 //is successfully put on hold or is already on hold.
307 if (res == E_SUCCESS)
309 res = DialOutgoingCall(contactNumber, isEmergency);
318 return ERROR_TAPI_ERROR;
323 TelephonyManager::EndAllCalls(void)
325 if(__pDialedCall != null)
327 if(__pDialedCall->GetCallHandle() != null)
329 tel_end_call(__pTapiHandle, __pDialedCall->GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
332 tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_HOLD_ALL, &HandleCallbackResponse, this);
333 //end all active calls before terminating application
334 tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_ALL, &HandleCallbackResponse, this);
335 __pSettingsManager->SetCallState(CALL_STATE_CALL_OFF);
339 TelephonyManager::EndActiveCall(Long callHandle)
341 result r = E_FAILURE;
342 //fetch ended callInfo from active call list
344 r = __pActiveCallList->GetValue(callHandle.ToLong(), endCall);
347 r = EndCall(endCall);
354 TelephonyManager::EndDialingCall(String& contactNumber)
356 result r = E_FAILURE;
357 //This is because for a dialing call, call handle is updated with some delay in telephony manager.
358 //And it is not available with outgoing call screen.
359 if (contactNumber.IsEmpty())
364 //Check If Ended call matches Dialed Call.
366 if (__pDialedCall != null && __pDialedCall->GetContactNumber().Equals(contactNumber))
368 endCall = *__pDialedCall;
369 r = EndCall(endCall);
375 TelephonyManager::EndCall(AppCallInfo& endCallInfo)
377 result r = E_FAILURE;
379 if (endCallInfo.GetCallHandle() != null)
381 unsigned int callHandle = endCallInfo.GetCallHandle()->ToLong();
382 //end "dialed but unconnected" call or active call - processing to be handled in HandleIdleCallback().
383 int res = tel_end_call(__pTapiHandle, callHandle, TAPI_CALL_END, &HandleCallbackResponse, this);
384 if (res == TAPI_CAUSE_SUCCESS)
393 TelephonyManager::AnswerAutoRejectCall(int callHandle)
395 //Incoming call automatically blocked is handled here.
396 AppLogDebug("Enter ");
397 result r = E_FAILURE;
398 TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_REJECT;
401 AppLogDebug("tel_answer_call");
403 AppCallInfo rejectedCallInfo;
404 rejectedCallInfo = *(__pIncomingCall);
405 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
406 SaveCallInfoToLogsDb(rejectedCallInfo);
407 delete __pIncomingCall;
408 __pIncomingCall = null;
410 // redirect to reject call back handler as the flow has to be handled
411 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
413 if (res == TAPI_CAUSE_SUCCESS)
425 TelephonyManager::AnswerCall(int callHandle, bool acceptCall)
427 AppLogDebug("Enter %d",acceptCall);
428 result r = E_FAILURE;
429 __pSoundManager->StopAlert();
430 TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_ACCEPT;
432 if (acceptCall == true)
434 answerType = TAPI_CALL_ANSWER_ACCEPT;
435 // redirect to dummy call back handler as the flow already handled in registered event callback
436 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
440 AppLogDebug("tel_answer_call");
441 answerType = TAPI_CALL_ANSWER_REJECT;
442 // redirect to reject call back handler as the flow has to be handled
443 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleRejectCallbackResponse, this);
446 if (res == TAPI_CAUSE_SUCCESS)
458 TelephonyManager::AcceptCall(CallAnsweringOptions answerOptions,int callHandle)
460 result r = E_FAILURE;
461 __pSoundManager->StopAlert();
462 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
464 //Check if this is a new incoming call
465 if(__pIncomingCall == null || (callHandle != (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
467 //construct and fetch new Incoming call Info
468 String incomingHandle;
469 incomingHandle.Append(callHandle);
470 AppCallInfo* pDuplicateCallInfo = FetchIncomingCallHandleN(incomingHandle, String(L""));
471 if(pDuplicateCallInfo == null)
476 delete pDuplicateCallInfo;
477 pDuplicateCallInfo = null;
480 switch(answerOptions)
482 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
483 case ANSERWING_OPTION_END_SINGLE_CALL:
485 r = AcceptSecondCall(answerOptions, callHandle);
489 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
490 case ANSERWING_OPTION_REPLACE_HELD_CALL:
491 case ANSERWING_OPTION_END_ALL_CALLS:
493 r = AcceptMultipleCall(answerOptions, callHandle);
504 TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
506 result r = E_FAILURE;
508 switch (answerOptions)
510 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
512 //accept incoming call by putting active call on Hold with 'TAPI_CALL_ANSWER_HOLD_AND_ACCEPT'
513 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
520 //Call connected successfully
522 //update status of first call to "OnHold"
523 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
524 AppCallInfo firstCallInfo;
525 pCallList->GetAt(0, firstCallInfo);
526 //replace old object with update AppCallInfo
527 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
528 *pHeldCallInfo = firstCallInfo;
529 pHeldCallInfo->SetOnHold(true);
530 __pActiveCallList->Remove(firstCallInfo.GetCallHandle()->ToLong());
531 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
537 case ANSERWING_OPTION_END_SINGLE_CALL:
539 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
540 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
541 //create a new ActiveCallList
542 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
543 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
545 //accept call and reject all active calls with 'TAPI_CALL_ANSWER_REPLACE'
546 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
550 //delete newly constructed list and gain ownership of old list
551 delete __pActiveCallList;
552 __pActiveCallList = pEndCallsList;
556 //Call connected successfully
558 //Add calls information to call log before deleting from active call list.
559 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
560 if(pCallList != null)
562 AppCallInfo endCallInfo;
563 if (pCallList->GetAt(0, endCallInfo) == E_SUCCESS)
565 SaveCallInfoToLogsDb(endCallInfo);
569 pEndCallsList->RemoveAll();
570 delete pEndCallsList;
581 TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
583 result r = E_FAILURE;
585 switch (answerOptions)
587 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
589 //Replace "Active" call by incoming call and save ended call to call logs db.
590 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
591 AppCallInfo callToBeEnded;
592 pCallList->GetAt(0, callToBeEnded);
593 //Check if the call is on "Hold", then fetch 2nd callInfo
594 if (callToBeEnded.IsOnHold() == true)
596 pCallList->GetAt(1, callToBeEnded);
601 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
602 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
604 //Accept incoming call by End Active call with 'TAPI_CALL_ANSWER_REPLACE'
605 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
609 //save the previous call back to active call list
610 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
614 //Incoming Call connected successfully
616 //save to ended call to call logs db.
617 SaveCallInfoToLogsDb(callToBeEnded);
621 case ANSERWING_OPTION_REPLACE_HELD_CALL:
623 //Replace "Held" call by incoming call and save ended call to call logs db.
624 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
625 //"Held" call is to be ended
626 AppCallInfo callToBeEnded;
627 //"Active" call will be put on Hold
628 AppCallInfo callToPutOnHold;
629 pCallList->GetAt(0, callToBeEnded);
630 //Check if the call is NOT "Held", then fetch 2nd callInfo
631 if (callToBeEnded.IsOnHold() == false)
633 callToPutOnHold = callToBeEnded;
634 pCallList->GetAt(1, callToBeEnded);
638 pCallList->GetAt(1, callToPutOnHold);
643 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
644 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
646 //End "Held" Call using 'TAPI_CALL_END'.
648 if (callToBeEnded.IsConferenceCall() == false)
650 res = tel_end_call(__pTapiHandle, callToBeEnded.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
654 IListT<AppCallInfo>* pParticipantsInfo = callToBeEnded.GetCallerList();
655 //need to end every participant individually for conference call
656 for (int index = 0; index < pParticipantsInfo->GetCount(); index++)
658 AppCallInfo memberCallInfo;
659 pParticipantsInfo->GetAt(index, memberCallInfo);
660 res = tel_end_call(__pTapiHandle, memberCallInfo.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
667 //save the previous "callToBeEnded" call back to active call list
668 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
671 //"Held" call successfully ended - Add call ended to call log database
672 SaveCallInfoToLogsDb(callToBeEnded);
674 //accept incoming call by Holding "Active" call using "TAPI_CALL_ANSWER_HOLD_AND_ACCEPT".
675 res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
682 //Call connected successfully and active call is "Onhold"
684 //replace old object with update CallInfo
685 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
686 *pHeldCallInfo = callToPutOnHold;
687 pHeldCallInfo->SetOnHold(true);
688 __pActiveCallList->Remove(callToPutOnHold.GetCallHandle()->ToLong());
689 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
693 case ANSERWING_OPTION_END_ALL_CALLS:
695 //End all active and Held calls after saving to call log. Incoming call is automatically accepted by TAPI engine,
696 // and processing of Incoming call is handled in HandleActiveCallback().
698 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
699 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
700 //create a new ActiveCallList
701 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
702 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
704 //End all active calls and all hold calls
705 int res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_ACTIVE_ALL, &HandleCallbackResponse, this);
708 res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_HOLD_ALL, &HandleCallbackResponse, this);
714 //delete newly constructed list and gain ownership of old list
715 delete __pActiveCallList;
716 __pActiveCallList = pEndCallsList;
720 //all calls ended successfully, Incoming call is automatically accepted.
723 //Add calls information to call log before deleting from active call list.
724 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
725 if(pCallList != null)
727 int callCount = pCallList->GetCount();
728 for (int index = 0; index < callCount; index++)
730 AppCallInfo endCallInfo;
731 if (pCallList->GetAt(index, endCallInfo) == E_SUCCESS)
733 SaveCallInfoToLogsDb(endCallInfo);
739 pEndCallsList->RemoveAll();
740 delete pEndCallsList;
741 pEndCallsList = null;
752 TelephonyManager::HoldCall(Tizen::Base::Long callHandle, bool holdCall)
754 result r = E_SUCCESS;
755 //Check if there are any existing active calls
756 if (__pActiveCallList->GetCount())
758 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
759 int callCount = pCallList->GetCount();
760 for (int index = 0; index < callCount; index++)
762 AppCallInfo holdCallInfo;
764 r = pCallList->GetAt(index, holdCallInfo);
765 //check if an active call is found with matching contact no.
766 if ((r == E_SUCCESS) && (holdCallInfo.GetCallHandle()->Equals(callHandle)))
768 r = HoldActiveCall(&holdCallInfo, holdCall);
780 TelephonyManager::EndConferenceCall(void)
782 result r = E_FAILURE;
783 //fetch conference callInfo to end
784 AppCallInfo confCallToEnd;
785 bool isConferenceCallFound = false;
787 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
788 int callCount = pCallList->GetCount();
789 for (int index = 0; index < callCount; index++)
791 pCallList->GetAt(index, confCallToEnd);
792 if (confCallToEnd.IsConferenceCall() == true)
794 isConferenceCallFound = true;
801 if (isConferenceCallFound == true)
803 //End conference call
804 TelCallEndType_t callEndType = TAPI_CALL_END_ACTIVE_ALL;
805 if (confCallToEnd.IsOnHold() == true)
807 callEndType = TAPI_CALL_END_HOLD_ALL;
809 int res = tel_end_call(__pTapiHandle, confCallToEnd.GetCallHandle()->ToLong(), callEndType, &HandleEndConferenceCallbackResponse, this);
810 if (res == TAPI_CAUSE_SUCCESS)
819 TelephonyManager::HoldConferenceCall(bool holdCall)
821 result r = E_FAILURE;
822 int confCallIndex = -1;
823 AppCallInfo confCallToHold;
824 bool isConferenceCallFound = false;
826 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
827 int confCallCount = pCallList->GetCount();
829 for (int index = 0; index < confCallCount; index++)
831 pCallList->GetAt(index, confCallToHold);
832 if (confCallToHold.IsConferenceCall() == true)
834 isConferenceCallFound = true;
835 confCallIndex = index;
836 //Found the Conference call to be ended.
841 if (isConferenceCallFound == false)
848 unsigned int callHandle = confCallToHold.GetCallHandle()->ToLong();
849 int res = TAPI_API_INVALID_INPUT;
850 if (holdCall == true)
852 res = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
856 res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
858 if (res == TAPI_API_SUCCESS)
861 if (holdCall == true)
863 confCallToHold.SetOnHold(true);
867 confCallToHold.SetOnHold(false);
869 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
870 *pConfCallInfo = confCallToHold;
871 __pActiveCallList->Remove(callHandle);
872 __pActiveCallList->Add(callHandle, *pConfCallInfo);
885 TelephonyManager::JoinCall(void)
887 result r = E_FAILURE;
889 AppCallInfo activeCall;
890 AppCallInfo heldCall;
891 // Use enumerator to access elements in the map
892 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
893 r = pCallList->GetAt(0, activeCall);
897 r = pCallList->GetAt(1, heldCall);
900 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
901 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
903 //Check if participants in conference call are under limit.
904 if ((heldCall.IsConferenceCall() == true) && (heldCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS))
906 res = tel_join_call(__pTapiHandle, heldCallHandle, activeCallHandle, &HandleJoinCallbackResponse, this);
908 else if (activeCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS)
910 res = tel_join_call(__pTapiHandle, activeCallHandle, heldCallHandle, &HandleJoinCallbackResponse, this);
916 if (res == TAPI_API_SUCCESS)
928 TelephonyManager::HoldActiveCall(AppCallInfo* pActiveCallInfo, bool holdCall)
930 unsigned int callHandle = pActiveCallInfo->GetCallHandle()->ToLong();
932 if (holdCall == true)
934 retStatus = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
938 retStatus = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
941 if (retStatus == TAPI_CAUSE_SUCCESS)
943 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
944 //copy state into new callinfo object
945 *pHeldCallInfo = *pActiveCallInfo;
947 //set call to hold state
948 pHeldCallInfo->SetOnHold(holdCall);
950 __pActiveCallList->Remove(callHandle);
951 //replace old object with new
952 __pActiveCallList->Add(callHandle, *pHeldCallInfo);
962 TelephonyManager::DialOutgoingCall(String& contactNumber, bool isEmergency)
964 TelCallDial_t structDialCall;
966 AppLogDebug("Enter %ls",contactNumber.GetPointer());
967 //Temp String to replace , with P and ; with W
968 String TempContactNum;
969 TempContactNum.Append(contactNumber);
970 TempContactNum.Replace(L",",L"W");
971 TempContactNum.Replace(L";",L",");
972 //conversion "contactNumber" to char*
973 const wchar_t* pContact = TempContactNum.GetPointer();
974 int len = TempContactNum.GetLength()+1;
975 char* pNumber = new (std::nothrow) char[len];
976 wcstombs(pNumber, pContact, len);
979 //initialize request parameter
980 memset(&structDialCall, '\0', sizeof(TelCallDial_t));
981 memcpy(structDialCall.szNumber, pNumber, strlen(pNumber));
982 AppLogDebug("%s",structDialCall.szNumber);
983 if(isEmergency == true)
985 structDialCall.CallType = TAPI_CALL_TYPE_E911;
989 structDialCall.CallType = TAPI_CALL_TYPE_VOICE;
992 int res = tel_dial_call(__pTapiHandle, &structDialCall, &HandleDialCallbackResponse, this);
993 if (__pSoundManager == null)
995 __pSoundManager = new (std::nothrow) SoundManager();
997 __pSoundManager->StartSession();
1001 if (res == TAPI_CAUSE_SUCCESS)
1003 if (__pDialedCall != null)
1005 delete __pDialedCall;
1006 __pDialedCall = null;
1008 __pDialedCall = new (std::nothrow) AppCallInfo();
1009 __pDialedCall->SetContactNumber(contactNumber);
1010 __pDialedCall->SetEmergency(isEmergency);
1011 result r = FetchContactInfoForNumber(contactNumber);
1014 __pDialedCall->SetContactInfo(*__pCachedContact);
1025 TelephonyManager::SwapCalls(void)
1027 result r = E_FAILURE;
1029 //check if there are atleast 2 active calls
1030 if (__pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
1034 //fetch call handles
1035 IListT<long>* pCallHandleList = __pActiveCallList->GetKeysN();
1036 long callHandle1 = 0;
1037 pCallHandleList->GetAt(0, callHandle1);
1038 long callHandle2 = 0;
1039 pCallHandleList->GetAt(1, callHandle2);
1041 retStatus = tel_swap_call(__pTapiHandle, callHandle1, callHandle2, &HandleSwapCallbackResponse, this);
1043 if (retStatus == TAPI_CAUSE_SUCCESS)
1047 delete pCallHandleList;
1048 pCallHandleList = null;
1055 TelephonyManager::SendCallDTMF(String& textToBeSent)
1057 result r = E_FAILURE;
1058 //check if there is an active Call
1059 if (__pActiveCallList->GetCount() > 0)
1061 //conversion "textToBeSent" to char*
1062 const wchar_t* pTextToBeSent = textToBeSent.GetPointer();
1063 int len = textToBeSent.GetLength() + 1;
1064 char* pNumber = new (std::nothrow) char[len];
1065 wcstombs(pNumber, pTextToBeSent, len);
1066 int retStatus = tel_call_dtmf(__pTapiHandle, pNumber, &HandleCallbackResponse, this);
1069 if (retStatus == TAPI_CAUSE_SUCCESS)
1078 TelephonyManager::EndFromConference(int callHandle)
1080 result r = E_FAILURE;
1081 int confCallIndex = -1;
1082 AppCallInfo endConfCall;
1083 bool isConferenceCallFound = false;
1085 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1086 int callCount = pCallList->GetCount();
1087 for (int index = 0; index < callCount; index++)
1089 pCallList->GetAt(index, endConfCall);
1090 if (endConfCall.IsConferenceCall() == true)
1092 isConferenceCallFound = true;
1093 confCallIndex = index;
1094 //Found the Conference call to be ended.
1102 if (isConferenceCallFound == false)
1104 //no conference call found
1108 //Identify the call to be ended and remove from list on API success
1109 AppCallInfo callToBeEnded;
1110 IListT<AppCallInfo>* pParticipantList = endConfCall.GetCallerList();
1111 int participantCount = pParticipantList->GetCount();
1112 for (int index = 0; index < participantCount; index++)
1114 pParticipantList->GetAt(index, callToBeEnded);
1115 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1117 //Identify the call to be ended and remove from list on API success
1118 TelCallEndType_t endType = TAPI_CALL_END;
1120 int res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndFromConferenceCallbackResponse, this);
1121 if (res == TAPI_CAUSE_SUCCESS)
1137 TelephonyManager::SplitFromConference(int callHandle)
1139 result r = E_FAILURE;
1140 int confCallIndex = -1;
1141 AppCallInfo endConfCall;
1142 bool isConferenceCallFound = false;
1144 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1145 int callCount = pCallList->GetCount();
1146 for (int index = 0; index < callCount; index++)
1148 pCallList->GetAt(index, endConfCall);
1149 if (endConfCall.IsConferenceCall() == true)
1151 isConferenceCallFound = true;
1152 confCallIndex = index;
1153 //Found the Conference call to be ended.
1159 if (isConferenceCallFound == false)
1161 //no conference call found
1165 //Identify the call to be ended and remove from list on API success
1166 AppCallInfo callToBeEnded;
1167 pCallList = endConfCall.GetCallerList();
1168 callCount = pCallList->GetCount();
1169 for (int index = 0; index < callCount; index++)
1171 pCallList->GetAt(index, callToBeEnded);
1172 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1174 int res = tel_split_call(__pTapiHandle, callHandle, &HandleSplitFromConferenceCallbackResponse, this);
1175 if (res == TAPI_CAUSE_SUCCESS)
1190 TelephonyManager::SetMuteStatus(bool setMute)
1192 TelSoundMuteStatus_t muteStatus;
1193 result r = E_FAILURE;
1194 if (setMute == true)
1196 muteStatus = TAPI_SOUND_MUTE_STATUS_ON;
1200 muteStatus = TAPI_SOUND_MUTE_STATUS_OFF;
1202 int res = tel_set_call_mute_status(__pTapiHandle, muteStatus, &HandleCallbackResponse, this);
1203 if (res == TAPI_CAUSE_SUCCESS)
1205 __isMuted = setMute;
1216 TelephonyManager::IsCallMuted(void)
1222 TelephonyManager::SetSpeakerStatus(bool setSpeaker)
1224 result r = E_FAILURE;
1225 TelCallSoundPathInfo_t callSoundPathInfo;
1226 __pSoundManager->SetSpeakerStatus(setSpeaker);
1227 if (setSpeaker == true)
1229 callSoundPathInfo.path = TAPI_SOUND_PATH_SPK_PHONE;
1233 callSoundPathInfo.path = TAPI_SOUND_PATH_HANDSET;
1235 callSoundPathInfo.ex_volume = TelCallSoundPathInfo_t::TAPI_SOUND_EX_VOLUME_ON;
1237 int res = tel_set_call_sound_path(__pTapiHandle, &callSoundPathInfo, &HandleCallbackResponse, this);
1239 if (res == TAPI_CAUSE_SUCCESS)
1241 __isSpeakerOn = setSpeaker;
1252 TelephonyManager::IsSpeakerOn(void)
1254 return __isSpeakerOn;
1258 TelephonyManager::IsSplitAllowed(void)
1260 // Split functionality is allowed only if a one call is present.
1261 // The call can be a single call or a conference call
1262 if (__pActiveCallList->GetCount() == 1)
1270 TelephonyManager::HandleCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1272 //should not do anything here.
1276 TelephonyManager::HandleDialCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1278 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1279 if (callBackResult != TAPI_CAUSE_SUCCESS)
1281 if (pTelManager->__pDialedCall != null)
1283 delete pTelManager->__pDialedCall;
1284 pTelManager->__pDialedCall = null;
1287 //Check if there are no active connected calls and no incoming call.
1288 if (pTelManager->__pIncomingCall != null)
1290 pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
1292 else if (pTelManager->GetCurrentCallCount() >= 1)
1294 pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
1298 pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_OFF);
1301 pTelManager->__pEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
1306 TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1308 AppLogDebug("ENTER");
1309 // This callback comes only if user has rejected an incoming call from IncomingCallForm.
1310 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1311 if (pData != null && callBackResult == TAPI_API_SUCCESS)
1313 unsigned int rejectedCallHandle = 0;
1314 memcpy(&rejectedCallHandle, pData, sizeof(TS_UINT));
1316 //Check if incoming call is rejected
1317 if (pTelManager->__pIncomingCall != null && (rejectedCallHandle == (unsigned int) pTelManager->__pIncomingCall->GetCallHandle()->ToLong()))
1319 AppLogDebug("Call rejected by user");
1320 AppCallInfo rejectedCallInfo;
1321 rejectedCallInfo = *(pTelManager->__pIncomingCall);
1322 delete pTelManager->__pIncomingCall;
1323 pTelManager->__pIncomingCall = null;
1325 //rejected by user from incoming call form
1326 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_REJECTED);
1327 //Save rejected incoming call to call log db.
1328 pTelManager->SaveCallInfoToLogsDb(rejectedCallInfo);
1330 //check if the ended call was the last call
1331 bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
1332 //Stop alert - started only for incoming calls which are not blocked.
1333 if(pTelManager->__pSoundManager != null)
1335 pTelManager->__pSoundManager->StopAlert();
1336 //Do not call stop session if there is already a call going on
1337 if(isLastCall == true)
1339 pTelManager->__pSoundManager->StopSession();
1342 //Send notification to user
1343 ArrayListT<AppCallInfo>* pCallList = null;
1346 //save 'RejectedCall' to list to show on EndCallForm
1347 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1348 pCallList->Construct(1);
1349 AppCallInfo* pRejectedCall = new (std::nothrow) AppCallInfo();
1350 *pRejectedCall = rejectedCallInfo;
1351 pCallList->Add(*pRejectedCall);
1355 //fetch active calls to show appropriate scene
1356 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1358 pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1365 pTelManager->__pEventListener->HandleTelephonyError(ERROR_REJECT_FAILED);
1367 AppLogDebug("EXIT");
1371 TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1373 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1374 if (callBackResult == TAPI_API_SUCCESS && pData != null)
1376 unsigned int tempHandle = 0;
1377 TelCallInfoJoinedNoti_t joinedInfoNotification;
1378 AppCallInfo confCallInfo;
1380 memcpy(&tempHandle, pData, sizeof(TS_UINT));
1381 joinedInfoNotification.id = tempHandle;
1382 AppCallInfo activeCall;
1383 AppCallInfo heldCall;
1384 // Use enumerator to access elements in the map
1385 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1386 result r = pCallList->GetAt(0, activeCall);
1390 r = pCallList->GetAt(1, heldCall);
1393 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1394 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
1395 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
1396 if (activeCall.IsConferenceCall() == true)
1399 //When joined both become active
1400 activeCall.SetOnHold(false);
1401 heldCall.SetOnHold(false);
1402 *pConfCallInfo = activeCall;
1403 pConfCallInfo->AddCallToCallerList(heldCall);
1404 pConfCallInfo->SetCallHandle(activeCallHandle);
1405 //Set call start time
1406 //if (pConfCallInfo->GetCallConnectTime() > heldCall.GetCallConnectTime())
1407 if (pConfCallInfo->GetDurationTime() > heldCall.GetDurationTime())
1409 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1410 pConfCallInfo->SetDurationTime(heldCall.GetDurationTime());
1411 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1414 else if (heldCall.IsConferenceCall() == true)
1417 heldCall.SetOnHold(false);
1418 activeCall.SetOnHold(false);
1419 *pConfCallInfo = heldCall;
1420 pConfCallInfo->AddCallToCallerList(activeCall);
1421 pConfCallInfo->SetCallHandle(heldCallHandle);
1422 //Set call start time
1423 //if (pConfCallInfo->GetCallConnectTime() > activeCall.GetCallConnectTime())
1424 if (pConfCallInfo->GetDurationTime() > activeCall.GetDurationTime())
1426 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1427 pConfCallInfo->SetDurationTime(activeCall.GetDurationTime());
1428 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1434 pConfCallInfo->SetConference(true);
1435 heldCall.SetOnHold(false);
1436 activeCall.SetOnHold(false);
1437 pConfCallInfo->AddCallToCallerList(activeCall);
1438 pConfCallInfo->AddCallToCallerList(heldCall);
1439 pConfCallInfo->SetCallHandle(activeCallHandle);
1440 //Set call start time
1441 //if (activeCall.GetCallConnectTime() > heldCall.GetCallConnectTime())
1442 if (activeCall.GetDurationTime() > heldCall.GetDurationTime())
1444 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1445 pConfCallInfo->SetDurationTime(heldCall.GetDurationTime());
1446 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1450 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1451 pConfCallInfo->SetDurationTime(activeCall.GetDurationTime());
1452 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1455 pConfCallInfo->SetCallHandle(joinedInfoNotification.id);
1456 pTelManager->__pActiveCallList->RemoveAll();
1457 //only one call in the list
1458 pTelManager->__pActiveCallList->Add(joinedInfoNotification.id, *pConfCallInfo);
1459 //notify listener that call is connected.
1460 pTelManager->__pEventListener->HandleConferenceCall(*pConfCallInfo);
1468 pTelManager->__pEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
1473 TelephonyManager::HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1475 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1476 if (callBackResult == TAPI_CAUSE_SUCCESS)
1478 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1479 IListT<long>* pKeyList = pTelManager->__pActiveCallList->GetKeysN();
1480 int callCount = pTelManager->__pActiveCallList->GetCount();
1481 for (int index = 0; index < callCount; index++)
1483 AppCallInfo* pTempCallInfo = new (std::nothrow) AppCallInfo();
1484 pCallList->GetAt(index, *pTempCallInfo);
1485 (pTempCallInfo->IsOnHold() == false) ? pTempCallInfo->SetOnHold(true) : pTempCallInfo->SetOnHold(false);
1487 pKeyList->GetAt(index, callHandle);
1488 pTelManager->__pActiveCallList->SetValue(callHandle, *pTempCallInfo);
1494 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1495 pTelManager->__pEventListener->HandleCallSwapOccured(*pCallList);
1499 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
1504 TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1506 AppLogDebug("ENTER");
1507 //This callback comes if a single call is ended from Conference call.
1508 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1509 bool isParticipantCallEnded = false;
1511 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1513 //fetch end call handle
1514 TelCallEndCnf_t callEndNotification;
1515 memcpy(&callEndNotification, pData, sizeof(TelCallEndCnf_t));
1516 //Fetch conference call
1517 AppCallInfo endConfCall;
1518 bool isConferenceCallFound = false;
1519 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1520 int callCount = pCallList->GetCount();
1521 for (int index = 0; index < callCount; index++)
1523 pCallList->GetAt(index, endConfCall);
1524 if (endConfCall.IsConferenceCall() == true)
1526 isConferenceCallFound = true;
1527 //Found the Conference call to be changed.
1534 //Identify the call to be ended and remove from list.
1535 if (isConferenceCallFound == true)
1537 isParticipantCallEnded = pTelManager->HandleParticipantEndedFromConference(callEndNotification.id, endConfCall);
1542 AppLog("TAPI Failed - %d", callBackResult);
1545 //Check if participant call or Conference call was not found, then show error
1546 if (isParticipantCallEnded == false)
1548 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_FROM_CONFERENCE_FAILED);
1550 AppLogDebug("EXIT");
1554 TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantCallHandle, AppCallInfo& conferenceCall)
1556 AppLogDebug("ENTER");
1557 //to check if participant call was found and ended.
1558 bool isParticipantCallEnded = false;
1559 //Identify the call to be ended and remove from list.
1560 AppCallInfo callToBeEnded;
1561 IListT<AppCallInfo>* pCallerList = conferenceCall.GetCallerList();
1562 int callerCount = pCallerList->GetCount();
1563 for (int index = 0; index < callerCount; index++)
1565 pCallerList->GetAt(index, callToBeEnded);
1566 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == participantCallHandle)
1568 //Identify the call to be ended and remove from conference list
1569 conferenceCall.RemoveCallFromCallerList(index);
1570 //update its status to individual call before saving to database
1571 callToBeEnded.SetConference(false);
1572 SaveCallInfoToLogsDb(callToBeEnded);
1573 isParticipantCallEnded = true;
1578 if(isParticipantCallEnded == false)
1580 //participant call not found and not ended
1581 return isParticipantCallEnded;
1584 unsigned int confCallHandle = (unsigned int)conferenceCall.GetCallHandle()->ToLong();
1585 //Check if last participant removed. If yes, switch to single active view
1586 if (conferenceCall.GetCallerListCount() == 1)
1588 AppCallInfo callFromList;
1589 pCallerList = conferenceCall.GetCallerList();
1590 pCallerList->GetAt(0, callFromList);
1591 //construct a new single active call
1592 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1593 *pActiveCall = callFromList;
1594 //update conference status and Hold status
1595 pActiveCall->SetConference(false);
1596 pActiveCall->SetOnHold(conferenceCall.IsOnHold());
1598 __pActiveCallList->Remove(confCallHandle);
1599 __pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1602 //using the callConnected to switch to single active screen
1603 //or update multiple active call screen
1604 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1605 __pEventListener->HandleCallConnected(*pActiveCallList);
1606 delete pActiveCallList;
1607 pActiveCallList = null;
1611 AppCallInfo callFromList;
1612 pCallerList = conferenceCall.GetCallerList();
1613 pCallerList->GetAt(0, callFromList);
1614 //construct a new conference call
1615 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1616 *pConfCallInfo = conferenceCall;
1617 if (confCallHandle == participantCallHandle)
1619 //Call Handle is same as conf call handle, so need to change conf call handle
1620 __pActiveCallList->Remove(confCallHandle);
1621 int newConfCallHandle = callFromList.GetCallHandle()->ToLong();
1622 pConfCallInfo->SetCallHandle(newConfCallHandle);
1623 __pActiveCallList->Add(newConfCallHandle, *pConfCallInfo);
1627 __pActiveCallList->SetValue(confCallHandle, *pConfCallInfo);
1629 __pEventListener->HandleConferenceChange();
1631 AppLogDebug("EXIT");
1632 return isParticipantCallEnded;
1636 TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1638 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1639 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1641 TelCallSplitCnf_t callSplitNotification;
1642 memcpy(&callSplitNotification, pData, sizeof(TelCallSplitCnf_t));
1643 int confCallIndex = -1;
1644 AppCallInfo endConfCall;
1645 bool isConferenceCallFound = false;
1647 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1648 int callCount = pCallList->GetCount();
1649 for (int index = 0; index < callCount; index++)
1651 pCallList->GetAt(index, endConfCall);
1652 if (endConfCall.IsConferenceCall() == true)
1654 isConferenceCallFound = true;
1655 confCallIndex = index;
1656 //Found the Conference call to be ended.
1661 if (isConferenceCallFound == false)
1669 //Identify the call to be ended and remove from list on API success
1670 AppCallInfo callToBeEnded;
1671 pCallList = endConfCall.GetCallerList();
1672 callCount = pCallList->GetCount();
1673 for (int index = 0; index < callCount; index++)
1675 pCallList->GetAt(index, callToBeEnded);
1676 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == callSplitNotification.id)
1678 //Identified the call to be ended and remove from conference list
1679 //Add this to the active call list
1680 endConfCall.RemoveCallFromCallerList(index);
1684 unsigned int confCallHandle = (unsigned int)endConfCall.GetCallHandle()->ToLong();
1685 //Set the hold flags correctly and make the changes to the active call list
1686 if (endConfCall.GetCallerListCount() == 1)
1688 //Set hold for the other single call
1689 // and add to the list
1690 AppCallInfo callFromList;
1691 pCallList = endConfCall.GetCallerList();
1692 pCallList->GetAt(0, callFromList);
1693 AppCallInfo* pHeldCall = new (std::nothrow) AppCallInfo();
1694 *pHeldCall = callFromList;
1695 pHeldCall->SetConference(false);
1696 pHeldCall->SetOnHold(true);
1697 pTelManager->__pActiveCallList->Remove(confCallHandle);
1698 pTelManager->__pActiveCallList->Add(pHeldCall->GetCallHandle()->ToLong(), *pHeldCall);
1703 //Set hold flag for conference call
1704 endConfCall.SetOnHold(true);
1705 AppCallInfo callFromList;
1706 pCallList = endConfCall.GetCallerList();
1707 pCallList->GetAt(0, callFromList);
1709 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1710 *pConfCallInfo = endConfCall;
1711 if (confCallHandle == callSplitNotification.id)
1713 //Call Handle is same as conf call handle.
1714 //Change conf call handle
1715 pTelManager->__pActiveCallList->Remove(confCallHandle);
1716 int tmpCallHandle = callFromList.GetCallHandle()->ToLong();
1717 pConfCallInfo->SetCallHandle(tmpCallHandle);
1718 pTelManager->__pActiveCallList->Add(callFromList.GetCallHandle()->ToLong(), *pConfCallInfo);
1722 pTelManager->__pActiveCallList->Remove(confCallHandle);
1723 pTelManager->__pActiveCallList->Add(confCallHandle, *pConfCallInfo);
1726 //Add the new active call to active call list
1727 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1728 *pActiveCall = callToBeEnded;
1729 pActiveCall->SetConference(false);
1730 pActiveCall->SetOnHold(false);
1731 pTelManager->__pActiveCallList->Remove(pActiveCall->GetCallHandle()->ToLong());
1732 pTelManager->__pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1734 //using the callConnected to switch to Multiple active screen
1735 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1736 pTelManager->__pEventListener->HandleCallConnected(*pCallList);
1741 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
1746 TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1749 //This callback comes only if a conference call is ended by user.
1750 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1751 AppCallInfo heldCall;
1752 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1754 //fetch ended confCall details
1755 result r = E_FAILURE;
1756 AppCallInfo endConfCallInfo;
1757 IListT<AppCallInfo>* pActiveCallList = pTelManager->__pActiveCallList->GetValuesN();
1758 if(pActiveCallList != null && pActiveCallList->GetCount() > 0)
1760 for (int index = 0; index < pActiveCallList->GetCount(); index++)
1762 r = pActiveCallList->GetAt(index, endConfCallInfo);
1763 if(r == E_SUCCESS && endConfCallInfo.IsConferenceCall() == true)
1765 //conference call found.
1775 delete pActiveCallList;
1776 pActiveCallList = null;
1778 //check if no conference call found, then return.
1783 //remove the conference call handle from active call list to avoid any processing in HandleIdleCallback().
1784 pTelManager->__pActiveCallList->Remove(endConfCallInfo.GetCallHandle()->ToLong());
1785 //Save "End" Conf. call info to call log database
1786 pTelManager->SaveCallInfoToLogsDb(endConfCallInfo);
1788 //check if the ended call was the last call and show notification to user
1789 bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
1790 ArrayListT<AppCallInfo>* pCallList = null;
1793 pTelManager->__pSoundManager->SetlastEndedConferenceCall();
1794 //stop sound session
1795 pTelManager->__pSoundManager->StopSession();
1796 //send empty call list to show dialer or call log screen
1797 pCallList =new (std::nothrow) ArrayListT<AppCallInfo>();
1798 pCallList->Construct(1);
1799 pCallList->Add(endConfCallInfo);
1803 //fetch active calls to show appropriate scene
1804 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1805 r = pCallList->GetAt(0, heldCall);
1808 //pTelManager->HoldActiveCall(&heldCall, false);
1809 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
1810 unsigned int callHandle = heldCall.GetCallHandle()->ToLong();
1811 //copy state into new callinfo object
1812 *pHeldCallInfo = heldCall;
1814 //set call to hold state
1815 pHeldCallInfo->SetOnHold(false);
1817 pTelManager->__pActiveCallList->Remove(callHandle);
1818 //replace old object with new
1819 pTelManager->__pActiveCallList->Add(callHandle, *pHeldCallInfo);
1821 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1824 //notify listener that call is disconnected.
1825 pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1831 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
1837 TelephonyManager::HandleIdleCallBack(void* pData)
1839 AppLogDebug("ENTER");
1840 //This callback comes when any type of calls are ended
1841 //We do NOT handle below scenarios here -
1842 //1) In incoming call scenarios, if we end any active calls - handled in "AcceptCall()".
1843 //2) Incoming call automatically blocked is handled in "AnswerAutoRejectCall()" and rejection by user scenarios are handled in "HandleRejectCallbackResponse()".
1844 //3) End conference call is handled in "HandleEndConferenceCallbackResponse()".
1845 //4) End Single Call from Conference call by user is handled in "HandleEndFromConferenceCallbackResponse()".
1846 //5) End Single Call from Conference call using eventInjector is diverted to "HandleParticipantEndedFromConference()".
1847 //BUT, we do handle below scenarios here -
1848 //1) "MISSED" incoming call scenario here i.e incoming call is rejected by other caller.
1849 //2) an "unconnected" dialed call is ended by caller or other party.
1850 //3) Any normal active calls(NOT conference calls) ended by user or by other party.
1854 TelCallStatusIdleNoti_t idleNotification;
1855 memcpy(&idleNotification, pData, sizeof(TelCallStatusIdleNoti_t));
1856 //handle end call event, show next screen
1857 unsigned int endCallHandle = idleNotification.id;
1859 //empty active call list or no dialed or incoming calls - ignore this event
1860 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1861 if((pActiveCallList == null || pActiveCallList->GetCount() <= 0) && __pDialedCall == null && __pIncomingCall == null)
1863 delete pActiveCallList;
1864 AppLogDebug("EXIT - no calls exist");
1867 if(__pSoundManager->GetLastConferenceCall() == false)
1869 __pSoundManager->SetDisconnectTone();
1871 //Check if ended call was among conference caller list,
1872 //then divert event to "HandleParticipantEndedFromConference()"
1873 AppCallInfo confCallInfo;
1874 bool isConferenceCallChanged = false;
1875 for (int index = 0; (pActiveCallList != null && index < pActiveCallList->GetCount()); index++)
1877 //fetch conference call
1878 result r = pActiveCallList->GetAt(index, confCallInfo);
1879 if (r == E_SUCCESS && confCallInfo.IsConferenceCall() == true)
1881 //Conference call found - check if ended call is a participant
1882 isConferenceCallChanged = HandleParticipantEndedFromConference(endCallHandle, confCallInfo);
1886 delete pActiveCallList;
1887 pActiveCallList = null;
1888 if (isConferenceCallChanged == true)
1890 //end call event handled - conference call will now either remain as conf. call
1891 //or become single active call, if it has only 1 participant left.
1892 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1893 AppLogDebug("isConferenceCallChanged == true");
1897 //check if ended call was among the active call list and not a conference call
1898 AppCallInfo endCallInfo;
1899 result r = __pActiveCallList->GetValue(endCallHandle, endCallInfo);
1902 bool isHandled = HandleEndNormalActiveCall(endCallInfo);
1903 if (isHandled == true)
1905 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1910 //Check if dialed call is rejected by other party
1911 bool isDialedCallEnded = ((__pDialedCall != null) && (__pDialedCall->GetCallHandle() != null) &&(((unsigned int)__pDialedCall->GetCallHandle()->ToLong()) == idleNotification.id));
1912 //Check if "missed" incoming call is ended
1913 bool isMissedIncomingCallEnded = (__pIncomingCall != null && ((unsigned int)__pIncomingCall->GetCallHandle()->ToLong() == idleNotification.id));
1914 if (isDialedCallEnded == true || isMissedIncomingCallEnded == true)
1916 //It comes here only if the ended call was either a "unconnected" dialed call or an "Missed" incoming call.
1917 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1919 ArrayListT<AppCallInfo>* pCallList = null;
1920 //Check if dialed call was ended
1921 if (isDialedCallEnded == true)
1923 AppLogDebug("Dialed Call Ended");
1924 //Call Ended is the dialed call
1925 endCallInfo = *(__pDialedCall);
1926 delete __pDialedCall;
1927 __pDialedCall = null;
1931 //Here, only "Missed" Incoming call ended by other caller is handled.
1932 AppLogDebug("Missed Call Ended");
1933 __pSoundManager->StopAlert();
1934 endCallInfo = *(__pIncomingCall);
1935 delete __pIncomingCall;
1936 __pIncomingCall = null;
1937 //update missed status
1938 endCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED_UNSEEN);
1939 //save ended call to call log db.
1940 //SaveCallInfoToLogsDb(endCallInfo);
1942 //save ended call to call log db.
1943 SaveCallInfoToLogsDb(endCallInfo);
1945 //notify listener that call is disconnected.
1946 if (isLastCall == true)
1948 __pSoundManager->StopSession();
1949 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1950 pCallList->Construct(1);
1951 //This is done to show end call form in missed call case also
1952 //this was done on request received from HQ to solve a bug in
1953 //camera application. In which if a call comes when camera is
1954 //running and user disconnects before the ui is shown the camera
1956 //if (isMissedIncomingCallEnded == false)
1958 //save to list to show EndCallForm
1959 pCallList->Add(endCallInfo);
1961 __pSoundManager->GetTimer()->Cancel();
1966 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
1968 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1972 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1973 AppLogDebug("EXIT");
1977 TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
1979 AppLogDebug("Enter");
1980 result r = E_FAILURE;
1981 AppCallInfo heldCall;
1982 // This function gets called only from HandleIdleCallback(),
1983 // to handle disconnection of normal active calls.
1984 if (endCallInfo.IsConferenceCall() == false)
1986 //remove the call handle from active call list
1987 __pActiveCallList->Remove(endCallInfo.GetCallHandle()->ToLong());
1988 //check if the ended call was the last call and show notification to user
1989 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1990 ArrayListT<AppCallInfo>* pCallList = null;
1993 __pSoundManager->GetTimer()->Cancel();
1994 //stop sound session
1995 __pSoundManager->StopSession();
1996 //save "End" CallInfo to list to show EndCallForm
1997 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1998 pCallList->Construct(1);
1999 pCallList->Add(endCallInfo);
2003 if(__pIncomingCall == null)
2005 //fetch active calls to show appropriate scene
2006 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
2007 //fetch the held call on disconnecting the active call and activate it.
2008 r = pCallList->GetAt(0, heldCall);
2011 HoldActiveCall(&heldCall, false);
2013 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
2018 //Save "End" call info to call log database
2019 SaveCallInfoToLogsDb(endCallInfo);
2020 //notify listener that call is disconnected.
2021 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
2030 TelephonyManager::HandleDialingCallBack(void* pData)
2032 AppLogDebug("Enter");
2033 unsigned int tempHandle = 0;
2034 TelCallStatusDialingNoti_t dialingNotification;
2035 memcpy(&tempHandle, pData, sizeof(TS_UINT));
2036 dialingNotification.id = tempHandle;
2037 //check if callback is for different dialed call
2038 //Dont check for call handle, since this is the first time, we get call handle for a dialed call.
2039 if (__pDialedCall == null)
2041 AppLogDebug("__pDialedCall == null");
2042 //construct new dialed call
2043 __pDialedCall = new (std::nothrow) AppCallInfo();
2045 TelCallStatus_t callStatus;
2046 int res = tel_get_call_status(__pTapiHandle, dialingNotification.id, &callStatus);
2047 if (res == TAPI_CAUSE_SUCCESS)
2050 String contactNumber(callStatus.pNumber);
2051 __pDialedCall->SetContactNumber(contactNumber);
2052 //set emergency state
2053 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2055 __pDialedCall->SetEmergency(true);
2059 __pDialedCall->SetEmergency(false);
2062 FetchContactInfoForNumber(__pDialedCall->GetContactNumber());
2063 if (__pCachedContact != null)
2065 __pDialedCall->SetContactInfo(*(__pCachedContact));
2069 //set call handle for dialed call
2070 __pDialedCall->SetCallHandle(dialingNotification.id);
2071 __pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
2073 //set call notification time.
2074 long long startTime = 0;
2075 SystemTime::GetTicks(startTime);
2076 __pDialedCall->SetCallNotificationTime(startTime);
2077 //SaveCallInfoToLogsDb(*__pDialedCall);
2081 TelephonyManager::HandleActiveCallBack(void* pData)
2083 // This callback comes whenever any new call is connected
2084 // Or, any "Held" call is activated (we ignore activation of "Held" calls).
2085 unsigned int newCallHandle = 0;
2086 TelCallStatusActiveNoti_t activeNotification;
2087 memcpy(&newCallHandle, pData, sizeof(TS_UINT));
2088 activeNotification.id = newCallHandle;
2089 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2091 //Check if the "Held" call was activated, i.e it is already present in already activated calls list.
2092 bool toHandleEvent = true;
2093 for (int callIndex = 0; (callIndex < pCallList->GetCount() && toHandleEvent == true); callIndex++ )
2095 AppCallInfo tempCallInfo;
2096 pCallList->GetAt(callIndex, tempCallInfo);
2097 unsigned int tempCallHandle = tempCallInfo.GetCallHandle()->ToLong();
2098 //Check if active callback came for "HandleJoinCallbackResponse"
2099 //or for "UnHold Conference Call or normal call".
2100 if(tempCallInfo.IsConferenceCall() == true)
2102 if (tempCallHandle == activeNotification.id)
2104 toHandleEvent = false;
2108 //check individual participants of conf call
2109 IListT<AppCallInfo>* pConfCallList = tempCallInfo.GetCallerList();
2110 int confCallCount = pConfCallList->GetCount();
2111 for (int callIndex = 0; (callIndex < confCallCount && toHandleEvent == true); callIndex++)
2113 AppCallInfo confCallerInfo;
2114 pConfCallList->GetAt(callIndex, confCallerInfo);
2115 unsigned int confCallerHandle = confCallerInfo.GetCallHandle()->ToLong();
2116 if (confCallerHandle == activeNotification.id)
2118 toHandleEvent = false;
2123 else if(tempCallHandle == activeNotification.id)
2125 //If normal call is UnHold
2126 toHandleEvent = false;
2130 //check if we need to handle this event.
2131 if(toHandleEvent == true)
2133 //Here it comes, only if either new dialed or incoming call was connected.
2134 HandleCallConnected( activeNotification.id);
2141 TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
2143 //Here it comes, only if either new dialed or incoming call was connected.
2144 //This function should be called only from "HandleActiveCallback()".
2145 AppCallInfo* pConnectedCall = null;
2146 //to check if incoming call was connected
2147 bool isIncomingCallConnected = false;
2149 __pSoundManager->SetConnectTone();
2150 //Check if dialed call is connected.
2151 if ((__pDialedCall != null) && (connectedCallHandle == (unsigned int)__pDialedCall->GetCallHandle()->ToLong()))
2153 pConnectedCall = __pDialedCall;
2154 __pDialedCall = null;
2156 //Check if connected call is incoming call.
2157 else if (__pIncomingCall != null && (connectedCallHandle == (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
2159 pConnectedCall = __pIncomingCall;
2160 __pIncomingCall = null;
2161 isIncomingCallConnected = true;
2165 // this is just for safety. This scenario should never come.
2166 // Otherwise Correct the code in some other function, if it comes here.
2167 AppLogDebug("Error - Connected call was neither one of active calls nor it was dialed or incoming call");
2168 //Construct a new CallInfo object for call
2169 pConnectedCall = new (std::nothrow) AppCallInfo();
2170 pConnectedCall->SetCallHandle(connectedCallHandle);
2172 TelCallStatus_t callStatus;
2173 int res = tel_get_call_status(__pTapiHandle, connectedCallHandle, &callStatus);
2174 if (res == TAPI_CAUSE_SUCCESS)
2176 String contactNumber(callStatus.pNumber);
2177 pConnectedCall->SetContactNumber(contactNumber);
2178 //set emergency state
2179 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2181 pConnectedCall->SetEmergency(true);
2185 pConnectedCall->SetEmergency(false);
2187 //set call notification time
2188 long long startTime = 0;
2189 SystemTime::GetTicks(startTime);
2190 pConnectedCall->SetCallNotificationTime(startTime);
2191 if (callStatus.bMoCall == true)
2193 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
2197 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2198 isIncomingCallConnected = true;
2201 //delete any dialed or incoming call objects
2202 delete __pDialedCall;
2203 __pDialedCall = null;
2204 delete __pIncomingCall;
2205 __pIncomingCall = null;
2208 //fetch contact info for connected call & it is not a hidden call
2209 if (pConnectedCall->GetContactInfo() == null && pConnectedCall->GetContactNumber().IsEmpty() == false)
2211 FetchContactInfoForNumber(pConnectedCall->GetContactNumber());
2212 if (__pCachedContact != null)
2214 pConnectedCall->SetContactInfo(*(__pCachedContact));
2217 //set Call connect time for newly connected call
2218 long long startTime = 0;
2219 SystemTime::GetTicks(startTime);
2220 pConnectedCall->SetCallConnectTime(startTime);
2221 CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
2222 pConnectedCall->SetDurationTime(pPhoneApp->GetCallAppTicks());
2223 if(GetCurrentCallCount() == 0)
2225 __pSoundManager->SetMinuteReminderTone();
2229 //transfer ownership to Active calls list
2230 __pActiveCallList->Add(connectedCallHandle, *(pConnectedCall));
2231 /* if (pConnectedCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_INCOMING)
2233 SaveCallInfoToLogsDb(*pConnectedCall);
2235 pConnectedCall = null;
2237 //notify listener that call is connected.
2238 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2239 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
2240 __pEventListener->HandleCallConnected(*pCallList);
2241 if (isIncomingCallConnected == true)
2243 __pSoundManager->StopAlert();
2250 TelephonyManager::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
2252 AppLogDebug("Enter");
2253 int callHandle = pIncomingCallInfo->GetCallHandle()->ToLong();
2254 String contactNumber(L"");
2255 contactNumber.Append(pIncomingCallInfo->GetContactNumber());
2256 //Check if "reject unknown calls" is set and contact number is not present in AddressBook
2257 //or if contact number is blacklisted
2258 if(__pSettingsManager != null)
2260 if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pIncomingCallInfo->GetContactInfo() == null))
2261 || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
2263 AnswerAutoRejectCall(callHandle);
2271 TelephonyManager::HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
2273 AppLogDebug("Enter");
2274 unsigned int tempHandle = 0;
2275 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2276 if (pTelManager->__pSoundManager == null)
2278 AppLog("Creating Sound Manager");
2279 pTelManager->__pSoundManager = new (std::nothrow) SoundManager();
2281 //Handle telephony events
2282 if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) == 0)
2284 pTelManager->HandleIdleCallBack(pData);
2286 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) == 0)
2288 pTelManager->__pSoundManager->StartSession();
2289 pTelManager->HandleActiveCallBack(pData);
2291 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) == 0)
2293 pTelManager->HandleDialingCallBack(pData);
2297 memcpy(&tempHandle, pData, sizeof(TS_UINT));
2302 TelephonyManager::GetConferenceCallInfoN(void)
2304 AppCallInfo* pConfCallInfo = null;
2306 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2307 int callCount = pCallList->GetCount();
2308 for (int index = 0; index < callCount; index++)
2310 AppCallInfo callInfo;
2311 pCallList->GetAt(index, callInfo);
2312 if (callInfo.IsConferenceCall() == true)
2314 pConfCallInfo = new (std::nothrow) AppCallInfo();
2315 *pConfCallInfo = callInfo;
2316 //Found the Conference call
2323 return pConfCallInfo;
2326 IListT<AppCallInfo>*
2327 TelephonyManager::GetCallListN(void)
2329 ArrayListT<AppCallInfo>* pCallList = null;
2330 if (__pActiveCallList != null)
2332 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
2338 TelephonyManager::GetCurrentCallCount(void)
2340 if (__pActiveCallList != null)
2342 return __pActiveCallList->GetCount();
2348 TelephonyManager::StartAlert(AppCallInfo& incomingCallInfo)
2350 String contactRingTone(L"");
2351 String contactNumber = incomingCallInfo.GetContactNumber();
2352 //check if not hidden call
2353 if(contactNumber.IsEmpty() == false)
2355 //fetch contact info from Db
2356 Contact* foundContact = GetContactN(contactNumber);
2357 if(foundContact != null)
2359 //fetch custom ringtone for contact
2360 result r = foundContact->GetValue(CONTACT_PROPERTY_ID_RINGTONE, contactRingTone);
2361 //Now check if there is a group ring tone
2362 if(contactRingTone.IsEmpty() == true)
2364 IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(foundContact->GetRecordId());
2365 if(pCategoryList != null && pCategoryList->GetCount() > 0)
2367 Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
2368 contactRingTone = pCategory->GetRingtonePath();
2371 AppLog("ringtone fetched - r = %d", r);
2372 delete foundContact;
2373 foundContact = null;
2376 __pSoundManager->StartAlert(contactRingTone);
2380 TelephonyManager::StopAlert(void)
2382 __pSoundManager->StopAlert();
2386 TelephonyManager::CheckValidTelePhoneNumber(const String& contactNumber)
2388 result r = E_SUCCESS;
2389 if (contactNumber.GetLength() > TAPI_CALL_DIALDIGIT_LEN_MAX)
2394 //Pattern to compare all characters except 0-9 * # P ; , +
2395 String phoneNumberPattern(L"[^0-9*#P,p+;]");
2396 RegularExpression checkPhoneNumber;
2397 checkPhoneNumber.Construct(phoneNumberPattern);
2398 //If there is any character other than these listed above then display invalid number
2399 bool resultMatch = checkPhoneNumber.Match(contactNumber,false);
2400 //return false for patterns other than 0-9 * # P ; , +
2401 if(resultMatch == true)
2403 //return phone number is invalid
2406 //TODO: check if valid phone number else return error message
2411 TelephonyManager::CheckIfMOCallIsPossible()
2413 result r = E_SUCCESS;
2415 //Check modem power status
2416 int modemStatus = 0;
2417 int errorCode = tel_check_modem_power_status(__pTapiHandle, &modemStatus);
2418 if (errorCode != TAPI_API_SUCCESS || modemStatus == TAPI_PHONE_POWER_STATUS_OFF
2419 || modemStatus == TAPI_PHONE_POWER_STATUS_ERROR)
2425 TelSimCardStatus_t simStatus;
2426 int simChangedStatus;
2427 //fetch sim initialization status
2428 int errorCode = tel_get_sim_init_info(__pTapiHandle, &simStatus, &simChangedStatus);
2429 if (errorCode != TAPI_API_SUCCESS)
2437 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: // Sim Initialization ok
2441 case TAPI_SIM_STATUS_UNKNOWN: //initial state
2442 case TAPI_SIM_STATUS_CARD_NOT_PRESENT: //Card not present
2443 case TAPI_SIM_STATUS_CARD_REMOVED: //Card removed
2444 case TAPI_SIM_STATUS_CARD_ERROR: // Bad card / On the fly, SIM gone bad
2445 //TODO: might want to set different error code, to give proper message to user
2458 TelephonyManager::CheckIfMOCallIsEmergency(const String& contactNumber, bool isSimInitialized)
2460 //TODO: extract actual telephone number from contactNumber
2461 //by deleting prefix,'P','W', etx.
2463 bool isEmergency = false;
2464 //conversion "contactNumber" to char*
2465 const wchar_t* pContact = contactNumber.GetPointer();
2466 int len = contactNumber.GetLength() + 1;
2467 char* pNumber = new (std::nothrow) char[len];
2468 wcstombs(pNumber, pContact, len);
2470 if(isSimInitialized)
2472 //used to get Ecc information for 2G and 3G.
2473 TelSimEccList_t simEccList;
2474 memset(&simEccList, 0x00, sizeof(TelSimEccList_t));
2475 //Check if given number matches the sim card's emergency numbers
2476 int errorCode = tel_get_sim_ecc(__pTapiHandle, &simEccList);
2477 if (errorCode == TAPI_API_SUCCESS && simEccList.ecc_count > 0)
2479 for (int index = 0; index < simEccList.ecc_count; index++)
2481 if ((strcmp(pNumber, simEccList.list[index].number) == 0))
2490 //TODO: check if we need to also check SOS call numbers, if sim not present.
2499 TelephonyManager::FetchContactInfoForNumber(const String& phoneNumberStr)
2501 result r = E_FAILURE;
2503 //delete previously cached data
2504 if (__pCachedContact != null)
2506 delete __pCachedContact;
2507 __pCachedContact = null;
2510 //Searches contacts by phone number.
2511 IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumberStr);
2512 if (pContactList == null || IsFailed(GetLastResult()))
2517 //Fetch the contact's info to be displayed
2518 IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
2519 while ((E_SUCCESS == pContactEnum->MoveNext()) && (__pCachedContact == null))
2521 Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
2523 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
2524 if (pPhoneNumberList != null)
2526 IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
2527 while (E_SUCCESS == pPhoneEnum->MoveNext())
2529 PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
2530 //Check if this is the correct contact
2531 if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumberStr))
2533 //save newly fetched contact info.
2534 __pCachedContact = new (std::nothrow) Contact(*pContact);
2540 pPhoneNumberList->RemoveAll(true);
2541 delete pPhoneNumberList;
2544 delete pContactEnum;
2545 pContactList->RemoveAll(true);
2546 delete pContactList;
2552 TelephonyManager::GetContactN(const String& phoneNumber)
2554 result r = FetchContactInfoForNumber(phoneNumber);
2557 return new (std::nothrow) Contact(*__pCachedContact);
2563 TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const String& contactNumber)
2565 if(__pIncomingCall != null)
2567 delete __pIncomingCall;
2568 __pIncomingCall = null;
2571 if(callHandle.IsEmpty() == false)
2574 Integer::Parse(callHandle,incomingHandle);
2575 //This API call is synchronous
2576 TelCallStatus_t callStatus;
2577 int errCode = tel_get_call_status(__pTapiHandle, incomingHandle, &callStatus);
2578 if (errCode != TAPI_API_SUCCESS)
2580 AppLogDebug("tel_get_call_status failed");
2583 //construct incoming call info object
2584 __pIncomingCall = new (std::nothrow) AppCallInfo();
2585 __pIncomingCall->SetCallHandle(incomingHandle);
2588 String phoneNumber(contactNumber);
2589 if(phoneNumber.IsEmpty() == true)
2591 phoneNumber.Append(callStatus.pNumber);
2593 __pIncomingCall->SetContactNumber(phoneNumber);
2594 //set emergency state
2595 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2597 __pIncomingCall->SetEmergency(true);
2601 __pIncomingCall->SetEmergency(false);
2603 //set start time, when call is connected
2604 long long startTime = 0;
2605 SystemTime::GetTicks(startTime);
2606 __pIncomingCall->SetCallNotificationTime(startTime);
2607 __pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2611 //TODO: This 'else' block can be removed once AppControl request API is stabilized.
2612 //This API call is synchronous and 'HandleIncomingCallStatusCallBack' is called for each active call.
2613 int errCode = tel_get_call_status_all(__pTapiHandle, &HandleIncomingCallStatusCallBack, this);
2614 if (errCode != TAPI_API_SUCCESS)
2620 if(__pIncomingCall != null)
2622 //set call notification time
2623 long long startTime = 0;
2624 SystemTime::GetTicks(startTime);
2625 __pIncomingCall->SetCallNotificationTime(startTime);
2627 if(__pIncomingCall->GetContactNumber().IsEmpty() == false)
2629 //fetch contact info
2630 FetchContactInfoForNumber(__pIncomingCall->GetContactNumber());
2631 if (__pCachedContact != null)
2633 __pIncomingCall->SetContactInfo(*__pCachedContact);
2637 //construct a new callinfo object to pass its ownership to caller.
2638 AppCallInfo* pNewIncomingCall = new (std::nothrow) AppCallInfo();
2639 *pNewIncomingCall = *__pIncomingCall;
2640 return pNewIncomingCall;
2642 //return null, if no incoming call found
2647 TelephonyManager::HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus, void* pUserData)
2649 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2650 if (pCallStatus != null && pCallStatus->bMoCall == false
2651 && ((pCallStatus->CallState == TAPI_CALL_STATE_INCOMING)
2652 || (pCallStatus->CallState == TAPI_CALL_STATE_WAITING)))
2654 //construct incoming call details
2655 pTelManager->__pIncomingCall = new (std::nothrow) AppCallInfo();
2656 pTelManager->__pIncomingCall->SetCallHandle(pCallStatus->CallHandle);
2658 String contactNumber(pCallStatus->pNumber);
2659 pTelManager->__pIncomingCall->SetContactNumber(contactNumber);
2660 //set emergency state
2661 if(pCallStatus->CallType == TAPI_CALL_TYPE_E911)
2663 pTelManager->__pIncomingCall->SetEmergency(true);
2667 pTelManager->__pIncomingCall->SetEmergency(false);
2670 pTelManager->__pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2675 TelephonyManager::SaveCallInfoToLogsDb(AppCallInfo& endCallInfo)
2677 if (endCallInfo.IsConferenceCall() == false)
2679 //single active call - Add call ended to call log database
2680 __pCalllogMgr->AddCallogInfoToDatabase(&endCallInfo);
2685 int confCallCount = endCallInfo.GetCallerListCount();
2686 IListT<AppCallInfo>* pParticipantList = endCallInfo.GetCallerList();
2687 for (int index = 0; index < confCallCount; index++)
2689 AppCallInfo participantInfo;
2690 if (pParticipantList->GetAt(index, participantInfo) == E_SUCCESS)
2692 //Add call ended to call log database
2693 __pCalllogMgr->AddCallogInfoToDatabase(&participantInfo);
2700 TelephonyManager::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
2702 if(networkStatus.IsCallServiceAvailable() == false)
2709 TelephonyManager::IsIncomingorDialingCallPresent(void)
2711 //returns false, if incoming call or dialed call is present.
2712 return ((__pIncomingCall != null) || (__pDialedCall != null));