2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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 AppLogDebug("Enter ");
394 result r = E_FAILURE;
395 TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_ACCEPT;
398 AppLogDebug("tel_answer_call");
399 answerType = TAPI_CALL_ANSWER_REJECT;
400 AppCallInfo rejectedCallInfo;
401 rejectedCallInfo = *(__pIncomingCall);
402 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
403 SaveCallInfoToLogsDb(rejectedCallInfo);
404 delete __pIncomingCall;
405 __pIncomingCall = null;
406 // redirect to reject call back handler as the flow has to be handled
407 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
409 if (res == TAPI_CAUSE_SUCCESS)
421 TelephonyManager::AnswerCall(int callHandle, bool acceptCall)
423 AppLogDebug("Enter %d",acceptCall);
424 result r = E_FAILURE;
425 __pSoundManager->StopAlert();
426 TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_ACCEPT;
428 if (acceptCall == true)
430 answerType = TAPI_CALL_ANSWER_ACCEPT;
431 // redirect to dummy call back handler as the flow already handled in registered event callback
432 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
436 AppLogDebug("tel_answer_call");
437 answerType = TAPI_CALL_ANSWER_REJECT;
438 // redirect to reject call back handler as the flow has to be handled
439 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleRejectCallbackResponse, this);
442 if (res == TAPI_CAUSE_SUCCESS)
454 TelephonyManager::AcceptCall(CallAnsweringOptions answerOptions,int callHandle)
456 result r = E_FAILURE;
457 __pSoundManager->StopAlert();
458 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
460 //Check if this is a new incoming call
461 if(__pIncomingCall == null || (callHandle != (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
463 //construct and fetch new Incoming call Info
464 String incomingHandle;
465 incomingHandle.Append(callHandle);
466 AppCallInfo* pDuplicateCallInfo = FetchIncomingCallHandleN(incomingHandle, String(L""));
467 if(pDuplicateCallInfo == null)
472 delete pDuplicateCallInfo;
473 pDuplicateCallInfo = null;
476 switch(answerOptions)
478 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
479 case ANSERWING_OPTION_END_SINGLE_CALL:
481 r = AcceptSecondCall(answerOptions, callHandle);
485 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
486 case ANSERWING_OPTION_REPLACE_HELD_CALL:
487 case ANSERWING_OPTION_END_ALL_CALLS:
489 r = AcceptMultipleCall(answerOptions, callHandle);
500 TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
502 result r = E_FAILURE;
504 switch (answerOptions)
506 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
508 //accept incoming call by putting active call on Hold with 'TAPI_CALL_ANSWER_HOLD_AND_ACCEPT'
509 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
516 //Call connected successfully
518 //update status of first call to "OnHold"
519 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
520 AppCallInfo firstCallInfo;
521 pCallList->GetAt(0, firstCallInfo);
522 //replace old object with update AppCallInfo
523 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
524 *pHeldCallInfo = firstCallInfo;
525 pHeldCallInfo->SetOnHold(true);
526 __pActiveCallList->Remove(firstCallInfo.GetCallHandle()->ToLong());
527 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
533 case ANSERWING_OPTION_END_SINGLE_CALL:
535 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
536 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
537 //create a new ActiveCallList
538 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
539 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
541 //accept call and reject all active calls with 'TAPI_CALL_ANSWER_REPLACE'
542 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
546 //delete newly constructed list and gain ownership of old list
547 delete __pActiveCallList;
548 __pActiveCallList = pEndCallsList;
552 //Call connected successfully
554 //Add calls information to call log before deleting from active call list.
555 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
556 if(pCallList != null)
558 AppCallInfo endCallInfo;
559 if (pCallList->GetAt(0, endCallInfo) == E_SUCCESS)
561 SaveCallInfoToLogsDb(endCallInfo);
565 pEndCallsList->RemoveAll();
566 delete pEndCallsList;
577 TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
579 result r = E_FAILURE;
581 switch (answerOptions)
583 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
585 //Replace "Active" call by incoming call and save ended call to call logs db.
586 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
587 AppCallInfo callToBeEnded;
588 pCallList->GetAt(0, callToBeEnded);
589 //Check if the call is on "Hold", then fetch 2nd callInfo
590 if (callToBeEnded.IsOnHold() == true)
592 pCallList->GetAt(1, callToBeEnded);
597 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
598 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
600 //Accept incoming call by End Active call with 'TAPI_CALL_ANSWER_REPLACE'
601 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
605 //save the previous call back to active call list
606 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
610 //Incoming Call connected successfully
612 //save to ended call to call logs db.
613 SaveCallInfoToLogsDb(callToBeEnded);
617 case ANSERWING_OPTION_REPLACE_HELD_CALL:
619 //Replace "Held" call by incoming call and save ended call to call logs db.
620 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
621 //"Held" call is to be ended
622 AppCallInfo callToBeEnded;
623 //"Active" call will be put on Hold
624 AppCallInfo callToPutOnHold;
625 pCallList->GetAt(0, callToBeEnded);
626 //Check if the call is NOT "Held", then fetch 2nd callInfo
627 if (callToBeEnded.IsOnHold() == false)
629 callToPutOnHold = callToBeEnded;
630 pCallList->GetAt(1, callToBeEnded);
634 pCallList->GetAt(1, callToPutOnHold);
639 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
640 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
642 //End "Held" Call using 'TAPI_CALL_END'.
644 if (callToBeEnded.IsConferenceCall() == false)
646 res = tel_end_call(__pTapiHandle, callToBeEnded.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
650 IListT<AppCallInfo>* pParticipantsInfo = callToBeEnded.GetCallerList();
651 //need to end every participant individually for conference call
652 for (int index = 0; index < pParticipantsInfo->GetCount(); index++)
654 AppCallInfo memberCallInfo;
655 pParticipantsInfo->GetAt(index, memberCallInfo);
656 res = tel_end_call(__pTapiHandle, memberCallInfo.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
663 //save the previous "callToBeEnded" call back to active call list
664 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
667 //"Held" call successfully ended - Add call ended to call log database
668 SaveCallInfoToLogsDb(callToBeEnded);
670 //accept incoming call by Holding "Active" call using "TAPI_CALL_ANSWER_HOLD_AND_ACCEPT".
671 res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
678 //Call connected successfully and active call is "Onhold"
680 //replace old object with update CallInfo
681 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
682 *pHeldCallInfo = callToPutOnHold;
683 pHeldCallInfo->SetOnHold(true);
684 __pActiveCallList->Remove(callToPutOnHold.GetCallHandle()->ToLong());
685 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
689 case ANSERWING_OPTION_END_ALL_CALLS:
691 //End all active and Held calls after saving to call log. Incoming call is automatically accepted by TAPI engine,
692 // and processing of Incoming call is handled in HandleActiveCallback().
694 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
695 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
696 //create a new ActiveCallList
697 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
698 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
700 //End all active calls and all hold calls
701 int res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_ACTIVE_ALL, &HandleCallbackResponse, this);
704 res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_HOLD_ALL, &HandleCallbackResponse, this);
710 //delete newly constructed list and gain ownership of old list
711 delete __pActiveCallList;
712 __pActiveCallList = pEndCallsList;
716 //all calls ended successfully, Incoming call is automatically accepted.
719 //Add calls information to call log before deleting from active call list.
720 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
721 if(pCallList != null)
723 int callCount = pCallList->GetCount();
724 for (int index = 0; index < callCount; index++)
726 AppCallInfo endCallInfo;
727 if (pCallList->GetAt(index, endCallInfo) == E_SUCCESS)
729 SaveCallInfoToLogsDb(endCallInfo);
735 pEndCallsList->RemoveAll();
736 delete pEndCallsList;
737 pEndCallsList = null;
748 TelephonyManager::HoldCall(Tizen::Base::Long callHandle, bool holdCall)
750 result r = E_SUCCESS;
751 //Check if there are any existing active calls
752 if (__pActiveCallList->GetCount())
754 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
755 int callCount = pCallList->GetCount();
756 for (int index = 0; index < callCount; index++)
758 AppCallInfo holdCallInfo;
760 r = pCallList->GetAt(index, holdCallInfo);
761 //check if an active call is found with matching contact no.
762 if ((r == E_SUCCESS) && (holdCallInfo.GetCallHandle()->Equals(callHandle)))
764 r = HoldActiveCall(&holdCallInfo, holdCall);
776 TelephonyManager::EndConferenceCall(void)
778 result r = E_FAILURE;
779 //fetch conference callInfo to end
780 AppCallInfo confCallToEnd;
781 bool isConferenceCallFound = false;
783 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
784 int callCount = pCallList->GetCount();
785 for (int index = 0; index < callCount; index++)
787 pCallList->GetAt(index, confCallToEnd);
788 if (confCallToEnd.IsConferenceCall() == true)
790 isConferenceCallFound = true;
797 if (isConferenceCallFound == true)
799 //End conference call
800 TelCallEndType_t callEndType = TAPI_CALL_END_ACTIVE_ALL;
801 if (confCallToEnd.IsOnHold() == true)
803 callEndType = TAPI_CALL_END_HOLD_ALL;
805 int res = tel_end_call(__pTapiHandle, confCallToEnd.GetCallHandle()->ToLong(), callEndType, &HandleEndConferenceCallbackResponse, this);
806 if (res == TAPI_CAUSE_SUCCESS)
815 TelephonyManager::HoldConferenceCall(bool holdCall)
817 result r = E_FAILURE;
818 int confCallIndex = -1;
819 AppCallInfo confCallToHold;
820 bool isConferenceCallFound = false;
822 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
823 int confCallCount = pCallList->GetCount();
825 for (int index = 0; index < confCallCount; index++)
827 pCallList->GetAt(index, confCallToHold);
828 if (confCallToHold.IsConferenceCall() == true)
830 isConferenceCallFound = true;
831 confCallIndex = index;
832 //Found the Conference call to be ended.
837 if (isConferenceCallFound == false)
844 unsigned int callHandle = confCallToHold.GetCallHandle()->ToLong();
845 int res = TAPI_API_INVALID_INPUT;
846 if (holdCall == true)
848 res = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
852 res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
854 if (res == TAPI_API_SUCCESS)
857 if (holdCall == true)
859 confCallToHold.SetOnHold(true);
863 confCallToHold.SetOnHold(false);
865 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
866 *pConfCallInfo = confCallToHold;
867 __pActiveCallList->Remove(callHandle);
868 __pActiveCallList->Add(callHandle, *pConfCallInfo);
881 TelephonyManager::JoinCall(void)
883 result r = E_FAILURE;
885 AppCallInfo activeCall;
886 AppCallInfo heldCall;
887 // Use enumerator to access elements in the map
888 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
889 r = pCallList->GetAt(0, activeCall);
893 r = pCallList->GetAt(1, heldCall);
896 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
897 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
899 //Check if participants in conference call are under limit.
900 if ((heldCall.IsConferenceCall() == true) && (heldCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS))
902 res = tel_join_call(__pTapiHandle, heldCallHandle, activeCallHandle, &HandleJoinCallbackResponse, this);
904 else if (activeCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS)
906 res = tel_join_call(__pTapiHandle, activeCallHandle, heldCallHandle, &HandleJoinCallbackResponse, this);
912 if (res == TAPI_API_SUCCESS)
924 TelephonyManager::HoldActiveCall(AppCallInfo* pActiveCallInfo, bool holdCall)
926 unsigned int callHandle = pActiveCallInfo->GetCallHandle()->ToLong();
928 if (holdCall == true)
930 retStatus = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
934 retStatus = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
937 if (retStatus == TAPI_CAUSE_SUCCESS)
939 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
940 //copy state into new callinfo object
941 *pHeldCallInfo = *pActiveCallInfo;
943 //set call to hold state
944 pHeldCallInfo->SetOnHold(holdCall);
946 __pActiveCallList->Remove(callHandle);
947 //replace old object with new
948 __pActiveCallList->Add(callHandle, *pHeldCallInfo);
958 TelephonyManager::DialOutgoingCall(String& contactNumber, bool isEmergency)
960 TelCallDial_t structDialCall;
962 AppLogDebug("Enter %ls",contactNumber.GetPointer());
963 //Temp String to replace , with P and ; with W
964 String TempContactNum;
965 TempContactNum.Append(contactNumber);
966 TempContactNum.Replace(L",",L"W");
967 TempContactNum.Replace(L";",L",");
968 //conversion "contactNumber" to char*
969 const wchar_t* pContact = TempContactNum.GetPointer();
970 int len = TempContactNum.GetLength()+1;
971 char* pNumber = new (std::nothrow) char[len];
972 wcstombs(pNumber, pContact, len);
975 //initialize request parameter
976 memset(&structDialCall, '\0', sizeof(TelCallDial_t));
977 memcpy(structDialCall.szNumber, pNumber, strlen(pNumber));
978 AppLogDebug("%s",structDialCall.szNumber);
979 if(isEmergency == true)
981 structDialCall.CallType = TAPI_CALL_TYPE_E911;
985 structDialCall.CallType = TAPI_CALL_TYPE_VOICE;
988 int res = tel_dial_call(__pTapiHandle, &structDialCall, &HandleDialCallbackResponse, this);
989 if (__pSoundManager == null)
991 __pSoundManager = new (std::nothrow) SoundManager();
993 __pSoundManager->StartSession();
997 if (res == TAPI_CAUSE_SUCCESS)
999 if (__pDialedCall != null)
1001 delete __pDialedCall;
1002 __pDialedCall = null;
1004 __pDialedCall = new (std::nothrow) AppCallInfo();
1005 __pDialedCall->SetContactNumber(contactNumber);
1006 __pDialedCall->SetEmergency(isEmergency);
1007 result r = FetchContactInfoForNumber(contactNumber);
1010 __pDialedCall->SetContactInfo(*__pCachedContact);
1021 TelephonyManager::SwapCalls(void)
1023 result r = E_FAILURE;
1025 //check if there are atleast 2 active calls
1026 if (__pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
1030 //fetch call handles
1031 IListT<long>* pCallHandleList = __pActiveCallList->GetKeysN();
1032 long callHandle1 = 0;
1033 pCallHandleList->GetAt(0, callHandle1);
1034 long callHandle2 = 0;
1035 pCallHandleList->GetAt(1, callHandle2);
1037 retStatus = tel_swap_call(__pTapiHandle, callHandle1, callHandle2, &HandleSwapCallbackResponse, this);
1039 if (retStatus == TAPI_CAUSE_SUCCESS)
1043 delete pCallHandleList;
1044 pCallHandleList = null;
1051 TelephonyManager::SendCallDTMF(String& textToBeSent)
1053 result r = E_FAILURE;
1054 //check if there is an active Call
1055 if (__pActiveCallList->GetCount() > 0)
1057 //conversion "textToBeSent" to char*
1058 const wchar_t* pTextToBeSent = textToBeSent.GetPointer();
1059 int len = textToBeSent.GetLength() + 1;
1060 char* pNumber = new (std::nothrow) char[len];
1061 wcstombs(pNumber, pTextToBeSent, len);
1062 int retStatus = tel_call_dtmf(__pTapiHandle, pNumber, &HandleCallbackResponse, this);
1065 if (retStatus == TAPI_CAUSE_SUCCESS)
1074 TelephonyManager::EndFromConference(int callHandle)
1076 result r = E_FAILURE;
1077 int confCallIndex = -1;
1078 AppCallInfo endConfCall;
1079 bool isConferenceCallFound = false;
1081 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1082 int callCount = pCallList->GetCount();
1083 for (int index = 0; index < callCount; index++)
1085 pCallList->GetAt(index, endConfCall);
1086 if (endConfCall.IsConferenceCall() == true)
1088 isConferenceCallFound = true;
1089 confCallIndex = index;
1090 //Found the Conference call to be ended.
1098 if (isConferenceCallFound == false)
1100 //no conference call found
1104 //Identify the call to be ended and remove from list on API success
1105 AppCallInfo callToBeEnded;
1106 IListT<AppCallInfo>* pParticipantList = endConfCall.GetCallerList();
1107 int participantCount = pParticipantList->GetCount();
1108 for (int index = 0; index < participantCount; index++)
1110 pParticipantList->GetAt(index, callToBeEnded);
1111 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1113 //Identify the call to be ended and remove from list on API success
1114 TelCallEndType_t endType = TAPI_CALL_END;
1116 int res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndFromConferenceCallbackResponse, this);
1117 if (res == TAPI_CAUSE_SUCCESS)
1133 TelephonyManager::SplitFromConference(int callHandle)
1135 result r = E_FAILURE;
1136 int confCallIndex = -1;
1137 AppCallInfo endConfCall;
1138 bool isConferenceCallFound = false;
1140 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1141 int callCount = pCallList->GetCount();
1142 for (int index = 0; index < callCount; index++)
1144 pCallList->GetAt(index, endConfCall);
1145 if (endConfCall.IsConferenceCall() == true)
1147 isConferenceCallFound = true;
1148 confCallIndex = index;
1149 //Found the Conference call to be ended.
1155 if (isConferenceCallFound == false)
1157 //no conference call found
1161 //Identify the call to be ended and remove from list on API success
1162 AppCallInfo callToBeEnded;
1163 pCallList = endConfCall.GetCallerList();
1164 callCount = pCallList->GetCount();
1165 for (int index = 0; index < callCount; index++)
1167 pCallList->GetAt(index, callToBeEnded);
1168 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1170 int res = tel_split_call(__pTapiHandle, callHandle, &HandleSplitFromConferenceCallbackResponse, this);
1171 if (res == TAPI_CAUSE_SUCCESS)
1186 TelephonyManager::SetMuteStatus(bool setMute)
1188 TelSoundMuteStatus_t muteStatus;
1189 result r = E_FAILURE;
1190 if (setMute == true)
1192 muteStatus = TAPI_SOUND_MUTE_STATUS_ON;
1196 muteStatus = TAPI_SOUND_MUTE_STATUS_OFF;
1198 int res = tel_set_call_mute_status(__pTapiHandle, muteStatus, &HandleCallbackResponse, this);
1199 if (res == TAPI_CAUSE_SUCCESS)
1201 __isMuted = setMute;
1212 TelephonyManager::IsCallMuted(void)
1218 TelephonyManager::SetSpeakerStatus(bool setSpeaker)
1220 result r = E_FAILURE;
1221 TelCallSoundPathInfo_t callSoundPathInfo;
1222 __pSoundManager->SetSpeakerStatus(setSpeaker);
1223 if (setSpeaker == true)
1225 callSoundPathInfo.path = TAPI_SOUND_PATH_SPK_PHONE;
1229 callSoundPathInfo.path = TAPI_SOUND_PATH_HANDSET;
1231 callSoundPathInfo.ex_volume = TelCallSoundPathInfo_t::TAPI_SOUND_EX_VOLUME_ON;
1233 int res = tel_set_call_sound_path(__pTapiHandle, &callSoundPathInfo, &HandleCallbackResponse, this);
1235 if (res == TAPI_CAUSE_SUCCESS)
1237 __isSpeakerOn = setSpeaker;
1248 TelephonyManager::IsSpeakerOn(void)
1250 return __isSpeakerOn;
1254 TelephonyManager::IsSplitAllowed(void)
1256 // Split functionality is allowed only if a one call is present.
1257 // The call can be a single call or a conference call
1258 if (__pActiveCallList->GetCount() == 1)
1266 TelephonyManager::HandleCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1268 //should not do anything here.
1272 TelephonyManager::HandleDialCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1274 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1275 if (callBackResult != TAPI_CAUSE_SUCCESS)
1277 if (pTelManager->__pDialedCall != null)
1279 delete pTelManager->__pDialedCall;
1280 pTelManager->__pDialedCall = null;
1282 pTelManager->__pEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
1287 TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1289 AppLogDebug("ENTER");
1290 // This callback comes only if user has either rejected an incoming call from IncomingCallForm.
1291 // or the incoming call was automatically blocked.
1292 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1293 if (pData != null && callBackResult == TAPI_API_SUCCESS)
1295 unsigned int rejectedCallHandle = 0;
1296 memcpy(&rejectedCallHandle, pData, sizeof(TS_UINT));
1298 //Check if incoming call is rejected
1299 if (pTelManager->__pIncomingCall != null && (rejectedCallHandle == (unsigned int) pTelManager->__pIncomingCall->GetCallHandle()->ToLong()))
1301 AppCallInfo rejectedCallInfo;
1302 rejectedCallInfo = *(pTelManager->__pIncomingCall);
1303 delete pTelManager->__pIncomingCall;
1304 pTelManager->__pIncomingCall = null;
1306 //Check if number was automatically rejected using settings, then don't give any notification to user.
1307 bool showIncomingCallRejectedNotification = true;
1308 if (((pTelManager->__pSettingsManager->GetUnknownRejectStatus() == true) && (rejectedCallInfo.GetContactInfo() == null))
1309 || (pTelManager->__pSettingsManager->IsCallToBeRejected(rejectedCallInfo.GetContactNumber()) == true))
1312 AppLogDebug("Call blocked");
1313 showIncomingCallRejectedNotification = false;
1314 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
1318 AppLogDebug("Call rejected");
1319 //rejected by user from incoming call form
1320 showIncomingCallRejectedNotification = true;
1321 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_REJECTED);
1323 //Save rejected incoming call to call log db.
1324 pTelManager->SaveCallInfoToLogsDb(rejectedCallInfo);
1326 if (showIncomingCallRejectedNotification == true)
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);
1364 pTelManager->__pEventListener->HandleTelephonyError(ERROR_REJECT_FAILED);
1366 AppLogDebug("EXIT");
1370 TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1372 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1373 if (callBackResult == TAPI_API_SUCCESS && pData != null)
1375 unsigned int tempHandle = 0;
1376 TelCallInfoJoinedNoti_t joinedInfoNotification;
1377 AppCallInfo confCallInfo;
1379 memcpy(&tempHandle, pData, sizeof(TS_UINT));
1380 joinedInfoNotification.id = tempHandle;
1381 AppCallInfo activeCall;
1382 AppCallInfo heldCall;
1383 // Use enumerator to access elements in the map
1384 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1385 result r = pCallList->GetAt(0, activeCall);
1389 r = pCallList->GetAt(1, heldCall);
1392 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1393 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
1394 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
1395 if (activeCall.IsConferenceCall() == true)
1398 //When joined both become active
1399 activeCall.SetOnHold(false);
1400 heldCall.SetOnHold(false);
1401 *pConfCallInfo = activeCall;
1402 pConfCallInfo->AddCallToCallerList(heldCall);
1403 pConfCallInfo->SetCallHandle(activeCallHandle);
1404 //Set call start time
1405 if (pConfCallInfo->GetCallConnectTime() > heldCall.GetCallConnectTime())
1407 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1408 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1411 else if (heldCall.IsConferenceCall() == true)
1414 heldCall.SetOnHold(false);
1415 activeCall.SetOnHold(false);
1416 *pConfCallInfo = heldCall;
1417 pConfCallInfo->AddCallToCallerList(activeCall);
1418 pConfCallInfo->SetCallHandle(heldCallHandle);
1419 //Set call start time
1420 if (pConfCallInfo->GetCallConnectTime() > activeCall.GetCallConnectTime())
1422 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1423 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1429 pConfCallInfo->SetConference(true);
1430 heldCall.SetOnHold(false);
1431 activeCall.SetOnHold(false);
1432 pConfCallInfo->AddCallToCallerList(activeCall);
1433 pConfCallInfo->AddCallToCallerList(heldCall);
1434 pConfCallInfo->SetCallHandle(activeCallHandle);
1435 //Set call start time
1436 if (activeCall.GetCallConnectTime() > heldCall.GetCallConnectTime())
1438 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1439 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1443 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1444 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1447 pConfCallInfo->SetCallHandle(joinedInfoNotification.id);
1448 pTelManager->__pActiveCallList->RemoveAll();
1449 //only one call in the list
1450 pTelManager->__pActiveCallList->Add(joinedInfoNotification.id, *pConfCallInfo);
1451 //notify listener that call is connected.
1452 pTelManager->__pEventListener->HandleConferenceCall(*pConfCallInfo);
1460 pTelManager->__pEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
1465 TelephonyManager::HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1467 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1468 if (callBackResult == TAPI_CAUSE_SUCCESS)
1470 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1471 IListT<long>* pKeyList = pTelManager->__pActiveCallList->GetKeysN();
1472 int callCount = pTelManager->__pActiveCallList->GetCount();
1473 for (int index = 0; index < callCount; index++)
1475 AppCallInfo* pTempCallInfo = new (std::nothrow) AppCallInfo();
1476 pCallList->GetAt(index, *pTempCallInfo);
1477 (pTempCallInfo->IsOnHold() == false) ? pTempCallInfo->SetOnHold(true) : pTempCallInfo->SetOnHold(false);
1479 pKeyList->GetAt(index, callHandle);
1480 pTelManager->__pActiveCallList->SetValue(callHandle, *pTempCallInfo);
1486 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1487 pTelManager->__pEventListener->HandleCallSwapOccured(*pCallList);
1491 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
1496 TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1498 AppLogDebug("ENTER");
1499 //This callback comes if a single call is ended from Conference call.
1500 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1501 bool isParticipantCallEnded = false;
1503 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1505 //fetch end call handle
1506 TelCallEndCnf_t callEndNotification;
1507 memcpy(&callEndNotification, pData, sizeof(TelCallEndCnf_t));
1508 //Fetch conference call
1509 AppCallInfo endConfCall;
1510 bool isConferenceCallFound = false;
1511 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1512 int callCount = pCallList->GetCount();
1513 for (int index = 0; index < callCount; index++)
1515 pCallList->GetAt(index, endConfCall);
1516 if (endConfCall.IsConferenceCall() == true)
1518 isConferenceCallFound = true;
1519 //Found the Conference call to be changed.
1526 //Identify the call to be ended and remove from list.
1527 if (isConferenceCallFound == true)
1529 isParticipantCallEnded = pTelManager->HandleParticipantEndedFromConference(callEndNotification.id, endConfCall);
1534 AppLog("TAPI Failed - %d", callBackResult);
1537 //Check if participant call or Conference call was not found, then show error
1538 if (isParticipantCallEnded == false)
1540 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_FROM_CONFERENCE_FAILED);
1542 AppLogDebug("EXIT");
1546 TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantCallHandle, AppCallInfo& conferenceCall)
1548 AppLogDebug("ENTER");
1549 //to check if participant call was found and ended.
1550 bool isParticipantCallEnded = false;
1551 //Identify the call to be ended and remove from list.
1552 AppCallInfo callToBeEnded;
1553 IListT<AppCallInfo>* pCallerList = conferenceCall.GetCallerList();
1554 int callerCount = pCallerList->GetCount();
1555 for (int index = 0; index < callerCount; index++)
1557 pCallerList->GetAt(index, callToBeEnded);
1558 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == participantCallHandle)
1560 //Identify the call to be ended and remove from conference list
1561 conferenceCall.RemoveCallFromCallerList(index);
1562 //update its status to individual call before saving to database
1563 callToBeEnded.SetConference(false);
1564 SaveCallInfoToLogsDb(callToBeEnded);
1565 isParticipantCallEnded = true;
1570 if(isParticipantCallEnded == false)
1572 //participant call not found and not ended
1573 return isParticipantCallEnded;
1576 unsigned int confCallHandle = (unsigned int)conferenceCall.GetCallHandle()->ToLong();
1577 //Check if last participant removed. If yes, switch to single active view
1578 if (conferenceCall.GetCallerListCount() == 1)
1580 AppCallInfo callFromList;
1581 pCallerList = conferenceCall.GetCallerList();
1582 pCallerList->GetAt(0, callFromList);
1583 //construct a new single active call
1584 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1585 *pActiveCall = callFromList;
1586 //update conference status and Hold status
1587 pActiveCall->SetConference(false);
1588 pActiveCall->SetOnHold(conferenceCall.IsOnHold());
1590 __pActiveCallList->Remove(confCallHandle);
1591 __pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1594 //Check if there is no incoming or dialing call exist, then only notify to change screen, Else ignore
1595 if (IsIncomingorDialingCallPresent() == false)
1597 //using the callConnected to switch to single active screen
1598 //or update multiple active call screen
1599 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1600 __pEventListener->HandleCallConnected(*pActiveCallList);
1601 delete pActiveCallList;
1602 pActiveCallList = null;
1607 AppCallInfo callFromList;
1608 pCallerList = conferenceCall.GetCallerList();
1609 pCallerList->GetAt(0, callFromList);
1610 //construct a new conference call
1611 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1612 *pConfCallInfo = conferenceCall;
1613 if (confCallHandle == participantCallHandle)
1615 //Call Handle is same as conf call handle, so need to change conf call handle
1616 __pActiveCallList->Remove(confCallHandle);
1617 int newConfCallHandle = callFromList.GetCallHandle()->ToLong();
1618 pConfCallInfo->SetCallHandle(newConfCallHandle);
1619 __pActiveCallList->Add(newConfCallHandle, *pConfCallInfo);
1623 __pActiveCallList->SetValue(confCallHandle, *pConfCallInfo);
1625 __pEventListener->HandleConferenceChange();
1627 AppLogDebug("EXIT");
1628 return isParticipantCallEnded;
1632 TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1634 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1635 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1637 TelCallSplitCnf_t callSplitNotification;
1638 memcpy(&callSplitNotification, pData, sizeof(TelCallSplitCnf_t));
1639 int confCallIndex = -1;
1640 AppCallInfo endConfCall;
1641 bool isConferenceCallFound = false;
1643 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1644 int callCount = pCallList->GetCount();
1645 for (int index = 0; index < callCount; index++)
1647 pCallList->GetAt(index, endConfCall);
1648 if (endConfCall.IsConferenceCall() == true)
1650 isConferenceCallFound = true;
1651 confCallIndex = index;
1652 //Found the Conference call to be ended.
1657 if (isConferenceCallFound == false)
1665 //Identify the call to be ended and remove from list on API success
1666 AppCallInfo callToBeEnded;
1667 pCallList = endConfCall.GetCallerList();
1668 callCount = pCallList->GetCount();
1669 for (int index = 0; index < callCount; index++)
1671 pCallList->GetAt(index, callToBeEnded);
1672 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == callSplitNotification.id)
1674 //Identified the call to be ended and remove from conference list
1675 //Add this to the active call list
1676 endConfCall.RemoveCallFromCallerList(index);
1680 unsigned int confCallHandle = (unsigned int)endConfCall.GetCallHandle()->ToLong();
1681 //Set the hold flags correctly and make the changes to the active call list
1682 if (endConfCall.GetCallerListCount() == 1)
1684 //Set hold for the other single call
1685 // and add to the list
1686 AppCallInfo callFromList;
1687 pCallList = endConfCall.GetCallerList();
1688 pCallList->GetAt(0, callFromList);
1689 AppCallInfo* pHeldCall = new (std::nothrow) AppCallInfo();
1690 *pHeldCall = callFromList;
1691 pHeldCall->SetConference(false);
1692 pHeldCall->SetOnHold(true);
1693 pTelManager->__pActiveCallList->Remove(confCallHandle);
1694 pTelManager->__pActiveCallList->Add(pHeldCall->GetCallHandle()->ToLong(), *pHeldCall);
1699 //Set hold flag for conference call
1700 endConfCall.SetOnHold(true);
1701 AppCallInfo callFromList;
1702 pCallList = endConfCall.GetCallerList();
1703 pCallList->GetAt(0, callFromList);
1705 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1706 *pConfCallInfo = endConfCall;
1707 if (confCallHandle == callSplitNotification.id)
1709 //Call Handle is same as conf call handle.
1710 //Change conf call handle
1711 pTelManager->__pActiveCallList->Remove(confCallHandle);
1712 int tmpCallHandle = callFromList.GetCallHandle()->ToLong();
1713 pConfCallInfo->SetCallHandle(tmpCallHandle);
1714 pTelManager->__pActiveCallList->Add(callFromList.GetCallHandle()->ToLong(), *pConfCallInfo);
1718 pTelManager->__pActiveCallList->Remove(confCallHandle);
1719 pTelManager->__pActiveCallList->Add(confCallHandle, *pConfCallInfo);
1722 //Add the new active call to active call list
1723 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1724 *pActiveCall = callToBeEnded;
1725 pActiveCall->SetConference(false);
1726 pActiveCall->SetOnHold(false);
1727 pTelManager->__pActiveCallList->Remove(pActiveCall->GetCallHandle()->ToLong());
1728 pTelManager->__pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1730 //using the callConnected to switch to Multiple active screen
1731 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1732 pTelManager->__pEventListener->HandleCallConnected(*pCallList);
1737 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
1742 TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1745 //This callback comes only if a conference call is ended by user.
1746 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1747 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1749 //fetch ended confCall details
1750 result r = E_FAILURE;
1751 AppCallInfo endConfCallInfo;
1752 IListT<AppCallInfo>* pActiveCallList = pTelManager->__pActiveCallList->GetValuesN();
1753 if(pActiveCallList != null && pActiveCallList->GetCount() > 0)
1755 for (int index = 0; index < pActiveCallList->GetCount(); index++)
1757 r = pActiveCallList->GetAt(index, endConfCallInfo);
1758 if(r == E_SUCCESS && endConfCallInfo.IsConferenceCall() == true)
1760 //conference call found.
1770 delete pActiveCallList;
1771 pActiveCallList = null;
1773 //check if no conference call found, then return.
1778 //remove the conference call handle from active call list to avoid any processing in HandleIdleCallback().
1779 pTelManager->__pActiveCallList->Remove(endConfCallInfo.GetCallHandle()->ToLong());
1780 //Save "End" Conf. call info to call log database
1781 pTelManager->SaveCallInfoToLogsDb(endConfCallInfo);
1783 //check if the ended call was the last call and show notification to user
1784 bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
1785 ArrayListT<AppCallInfo>* pCallList = null;
1788 pTelManager->__pSoundManager->SetlastEndedConferenceCall();
1789 //stop sound session
1790 pTelManager->__pSoundManager->StopSession();
1791 //send empty call list to show dialer or call log screen
1792 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1796 //fetch active calls to show appropriate scene
1797 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1799 //notify listener that call is disconnected.
1800 pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1806 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
1812 TelephonyManager::HandleIdleCallBack(void* pData)
1814 AppLogDebug("ENTER");
1815 //This callback comes when any type of calls are ended
1816 //We do NOT handle below scenarios here -
1817 //1) In incoming call scenarios, if we end any active calls - handled in "AcceptCall()".
1818 //2) Incoming call automatically blocked and rejection by user scenarios are handled in "HandleRejectCallbackResponse()".
1819 //3) End conference call is handled in "HandleEndConferenceCallbackResponse()".
1820 //4) End Single Call from Conference call by user is handled in "HandleEndFromConferenceCallbackResponse()".
1821 //5) End Single Call from Conference call using eventInjector is diverted to "HandleParticipantEndedFromConference()".
1822 //BUT, we do handle below scenarios here -
1823 //1) "MISSED" incoming call scenario here i.e incoming call is rejected by other caller.
1824 //2) an "unconnected" dialed call is ended by caller or other party.
1825 //3) Any normal active calls(NOT conference calls) ended by user or by other party.
1827 if(__pSoundManager->GetLastConferenceCall() == false)
1829 __pSoundManager->SetDisconnectTone();
1832 TelCallStatusIdleNoti_t idleNotification;
1833 memcpy(&idleNotification, pData, sizeof(TelCallStatusIdleNoti_t));
1834 //handle end call event, show next screen
1835 unsigned int endCallHandle = idleNotification.id;
1837 //empty active call list or no dialed or incoming calls - ignore this event
1838 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1839 if((pActiveCallList == null || pActiveCallList->GetCount() <= 0) && __pDialedCall == null && __pIncomingCall == null)
1841 delete pActiveCallList;
1842 AppLogDebug("EXIT - no calls exist");
1846 //Check if ended call was among conference caller list,
1847 //then divert event to "HandleParticipantEndedFromConference()"
1848 AppCallInfo confCallInfo;
1849 bool isConferenceCallChanged = false;
1850 for (int index = 0; (pActiveCallList != null && index < pActiveCallList->GetCount()); index++)
1852 //fetch conference call
1853 result r = pActiveCallList->GetAt(index, confCallInfo);
1854 if (r == E_SUCCESS && confCallInfo.IsConferenceCall() == true)
1856 //Conference call found - check if ended call is a participant
1857 isConferenceCallChanged = HandleParticipantEndedFromConference(endCallHandle, confCallInfo);
1861 delete pActiveCallList;
1862 pActiveCallList = null;
1863 if (isConferenceCallChanged == true)
1865 //end call event handled - conference call will now either remain as conf. call
1866 //or become single active call, if it has only 1 participant left.
1867 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1868 AppLogDebug("isConferenceCallChanged == true");
1872 //check if ended call was among the active call list and not a conference call
1873 AppCallInfo endCallInfo;
1874 result r = __pActiveCallList->GetValue(endCallHandle, endCallInfo);
1877 bool isHandled = HandleEndNormalActiveCall(endCallInfo);
1878 if (isHandled == true)
1880 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1885 //Check if dialed call is rejected by other party
1886 bool isDialedCallEnded = ((__pDialedCall != null) && (__pDialedCall->GetCallHandle() != null) &&(((unsigned int)__pDialedCall->GetCallHandle()->ToLong()) == idleNotification.id));
1887 //Check if "missed" incoming call is ended
1888 bool isMissedIncomingCallEnded = (__pIncomingCall != null && ((unsigned int)__pIncomingCall->GetCallHandle()->ToLong() == idleNotification.id));
1889 if (isDialedCallEnded == true || isMissedIncomingCallEnded == true)
1891 //It comes here only if the ended call was either a "unconnected" dialed call or an "Missed" incoming call.
1892 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1894 ArrayListT<AppCallInfo>* pCallList = null;
1895 //Check if dialed call was ended
1896 if (isDialedCallEnded == true)
1898 AppLogDebug("Dialed Call Ended");
1899 //Call Ended is the dialed call
1900 endCallInfo = *(__pDialedCall);
1901 delete __pDialedCall;
1902 __pDialedCall = null;
1906 //Here, only "Missed" Incoming call ended by other caller is handled.
1907 AppLogDebug("Missed Call Ended");
1908 __pSoundManager->StopAlert();
1909 endCallInfo = *(__pIncomingCall);
1910 delete __pIncomingCall;
1911 __pIncomingCall = null;
1912 //update missed status
1913 endCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED_UNSEEN);
1915 //save ended call to call log db.
1916 SaveCallInfoToLogsDb(endCallInfo);
1918 //notify listener that call is disconnected.
1919 if (isLastCall == true)
1921 __pSoundManager->StopSession();
1922 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1923 pCallList->Construct(1);
1924 if (isMissedIncomingCallEnded == false)
1926 //save to list to show EndCallForm
1927 pCallList->Add(endCallInfo);
1929 __pSoundManager->GetTimer()->Cancel();
1934 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
1936 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1940 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1941 AppLogDebug("EXIT");
1945 TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
1947 AppLogDebug("Enter");
1948 // This function gets called only from HandleIdleCallback(),
1949 // to handle disconnection of normal active calls.
1950 if (endCallInfo.IsConferenceCall() == false)
1952 //remove the call handle from active call list
1953 __pActiveCallList->Remove(endCallInfo.GetCallHandle()->ToLong());
1954 //check if the ended call was the last call and show notification to user
1955 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1956 ArrayListT<AppCallInfo>* pCallList = null;
1959 //stop sound session
1960 __pSoundManager->StopSession();
1961 //save "End" CallInfo to list to show EndCallForm
1962 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1963 pCallList->Construct(1);
1964 pCallList->Add(endCallInfo);
1968 //fetch active calls to show appropriate scene
1969 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
1972 //Save "End" call info to call log database
1973 SaveCallInfoToLogsDb(endCallInfo);
1974 //notify listener that call is disconnected.
1975 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1984 TelephonyManager::HandleDialingCallBack(void* pData)
1986 AppLogDebug("Enter");
1987 unsigned int tempHandle = 0;
1988 TelCallStatusDialingNoti_t dialingNotification;
1989 memcpy(&tempHandle, pData, sizeof(TS_UINT));
1990 dialingNotification.id = tempHandle;
1991 //check if callback is for different dialed call
1992 //Dont check for call handle, since this is the first time, we get call handle for a dialed call.
1993 if (__pDialedCall == null)
1995 AppLogDebug("__pDialedCall == null");
1996 //construct new dialed call
1997 __pDialedCall = new (std::nothrow) AppCallInfo();
1999 TelCallStatus_t callStatus;
2000 int res = tel_get_call_status(__pTapiHandle, dialingNotification.id, &callStatus);
2001 if (res == TAPI_CAUSE_SUCCESS)
2004 String contactNumber(callStatus.pNumber);
2005 __pDialedCall->SetContactNumber(contactNumber);
2006 //set emergency state
2007 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2009 __pDialedCall->SetEmergency(true);
2013 __pDialedCall->SetEmergency(false);
2016 FetchContactInfoForNumber(__pDialedCall->GetContactNumber());
2017 if (__pCachedContact != null)
2019 __pDialedCall->SetContactInfo(*(__pCachedContact));
2023 //set call handle for dialed call
2024 __pDialedCall->SetCallHandle(dialingNotification.id);
2025 __pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
2027 //set call notification time.
2028 long long startTime = 0;
2029 SystemTime::GetTicks(startTime);
2030 __pDialedCall->SetCallNotificationTime(startTime);
2034 TelephonyManager::HandleActiveCallBack(void* pData)
2036 // This callback comes whenever any new call is connected
2037 // Or, any "Held" call is activated (we ignore activation of "Held" calls).
2038 unsigned int newCallHandle = 0;
2039 TelCallStatusActiveNoti_t activeNotification;
2040 memcpy(&newCallHandle, pData, sizeof(TS_UINT));
2041 activeNotification.id = newCallHandle;
2042 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2044 //Check if the "Held" call was activated, i.e it is already present in already activated calls list.
2045 bool toHandleEvent = true;
2046 for (int callIndex = 0; (callIndex < pCallList->GetCount() && toHandleEvent == true); callIndex++ )
2048 AppCallInfo tempCallInfo;
2049 pCallList->GetAt(callIndex, tempCallInfo);
2050 unsigned int tempCallHandle = tempCallInfo.GetCallHandle()->ToLong();
2051 //Check if active callback came for "HandleJoinCallbackResponse"
2052 //or for "UnHold Conference Call or normal call".
2053 if(tempCallInfo.IsConferenceCall() == true)
2055 if (tempCallHandle == activeNotification.id)
2057 toHandleEvent = false;
2061 //check individual participants of conf call
2062 IListT<AppCallInfo>* pConfCallList = tempCallInfo.GetCallerList();
2063 int confCallCount = pConfCallList->GetCount();
2064 for (int callIndex = 0; (callIndex < confCallCount && toHandleEvent == true); callIndex++)
2066 AppCallInfo confCallerInfo;
2067 pConfCallList->GetAt(callIndex, confCallerInfo);
2068 unsigned int confCallerHandle = confCallerInfo.GetCallHandle()->ToLong();
2069 if (confCallerHandle == activeNotification.id)
2071 toHandleEvent = false;
2076 else if(tempCallHandle == activeNotification.id)
2078 //If normal call is UnHold
2079 toHandleEvent = false;
2083 //check if we need to handle this event.
2084 if(toHandleEvent == true)
2086 //Here it comes, only if either new dialed or incoming call was connected.
2087 HandleCallConnected( activeNotification.id);
2094 TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
2096 //Here it comes, only if either new dialed or incoming call was connected.
2097 //This function should be called only from "HandleActiveCallback()".
2098 AppCallInfo* pConnectedCall = null;
2099 //to check if incoming call was connected
2100 bool isIncomingCallConnected = false;
2102 __pSoundManager->SetConnectTone();
2103 //Check if dialed call is connected.
2104 if ((__pDialedCall != null) && (connectedCallHandle == (unsigned int)__pDialedCall->GetCallHandle()->ToLong()))
2106 pConnectedCall = __pDialedCall;
2107 __pDialedCall = null;
2109 //Check if connected call is incoming call.
2110 else if (__pIncomingCall != null && (connectedCallHandle == (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
2112 pConnectedCall = __pIncomingCall;
2113 __pIncomingCall = null;
2114 isIncomingCallConnected = true;
2118 // this is just for safety. This scenario should never come.
2119 // Otherwise Correct the code in some other function, if it comes here.
2120 AppLogDebug("Error - Connected call was neither one of active calls nor it was dialed or incoming call");
2121 //Construct a new CallInfo object for call
2122 pConnectedCall = new (std::nothrow) AppCallInfo();
2123 pConnectedCall->SetCallHandle(connectedCallHandle);
2125 TelCallStatus_t callStatus;
2126 int res = tel_get_call_status(__pTapiHandle, connectedCallHandle, &callStatus);
2127 if (res == TAPI_CAUSE_SUCCESS)
2129 String contactNumber(callStatus.pNumber);
2130 pConnectedCall->SetContactNumber(contactNumber);
2131 //set emergency state
2132 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2134 pConnectedCall->SetEmergency(true);
2138 pConnectedCall->SetEmergency(false);
2140 //set call notification time
2141 long long startTime = 0;
2142 SystemTime::GetTicks(startTime);
2143 pConnectedCall->SetCallNotificationTime(startTime);
2144 if (callStatus.bMoCall == true)
2146 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
2150 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2151 isIncomingCallConnected = true;
2154 //delete any dialed or incoming call objects
2155 delete __pDialedCall;
2156 __pDialedCall = null;
2157 delete __pIncomingCall;
2158 __pIncomingCall = null;
2161 //fetch contact info for connected call & it is not a hidden call
2162 if (pConnectedCall->GetContactInfo() == null && pConnectedCall->GetContactNumber().IsEmpty() == false)
2164 FetchContactInfoForNumber(pConnectedCall->GetContactNumber());
2165 if (__pCachedContact != null)
2167 pConnectedCall->SetContactInfo(*(__pCachedContact));
2170 //set Call connect time for newly connected call
2171 long long startTime = 0;
2172 SystemTime::GetTicks(startTime);
2173 pConnectedCall->SetCallConnectTime(startTime);
2174 if(GetCurrentCallCount() == 0)
2176 __pSoundManager->SetMinuteReminderTone();
2180 //transfer ownership to Active calls list
2181 __pActiveCallList->Add(connectedCallHandle, *(pConnectedCall));
2182 pConnectedCall = null;
2184 //notify listener that call is connected.
2185 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2186 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
2187 __pEventListener->HandleCallConnected(*pCallList);
2188 if (isIncomingCallConnected == true)
2190 __pSoundManager->StopAlert();
2197 TelephonyManager::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
2199 AppLogDebug("Enter");
2200 int callHandle = pIncomingCallInfo->GetCallHandle()->ToLong();
2201 String contactNumber(L"");
2202 contactNumber.Append(pIncomingCallInfo->GetContactNumber());
2203 //Check if "reject unknown calls" is set and contact number is not present in AddressBook
2204 //or if contact number is blacklisted
2205 if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pIncomingCallInfo->GetContactInfo() == null))
2206 || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
2208 AnswerAutoRejectCall(callHandle);
2215 TelephonyManager::HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
2217 unsigned int tempHandle = 0;
2218 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2219 if (pTelManager->__pSoundManager == null)
2221 AppLog("Creating Sound Manager");
2222 pTelManager->__pSoundManager = new (std::nothrow) SoundManager();
2224 //Handle telephony events
2225 if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) == 0)
2227 pTelManager->HandleIdleCallBack(pData);
2229 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) == 0)
2231 pTelManager->__pSoundManager->StartSession();
2232 pTelManager->HandleActiveCallBack(pData);
2234 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) == 0)
2236 pTelManager->HandleDialingCallBack(pData);
2240 memcpy(&tempHandle, pData, sizeof(TS_UINT));
2245 TelephonyManager::GetConferenceCallInfoN(void)
2247 AppCallInfo* pConfCallInfo = null;
2249 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2250 int callCount = pCallList->GetCount();
2251 for (int index = 0; index < callCount; index++)
2253 AppCallInfo callInfo;
2254 pCallList->GetAt(index, callInfo);
2255 if (callInfo.IsConferenceCall() == true)
2257 pConfCallInfo = new (std::nothrow) AppCallInfo();
2258 *pConfCallInfo = callInfo;
2259 //Found the Conference call
2266 return pConfCallInfo;
2269 IListT<AppCallInfo>*
2270 TelephonyManager::GetCallListN(void)
2272 ArrayListT<AppCallInfo>* pCallList = null;
2273 if (__pActiveCallList != null)
2275 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
2281 TelephonyManager::GetCurrentCallCount(void)
2283 if (__pActiveCallList != null)
2285 return __pActiveCallList->GetCount();
2291 TelephonyManager::StartAlert(AppCallInfo& incomingCallInfo)
2293 String contactRingTone(L"");
2294 String contactNumber = incomingCallInfo.GetContactNumber();
2295 //check if not hidden call
2296 if(contactNumber.IsEmpty() == false)
2298 //fetch contact info from Db
2299 Contact* foundContact = GetContactN(contactNumber);
2300 if(foundContact != null)
2302 //fetch custom ringtone for contact
2303 result r = foundContact->GetValue(CONTACT_PROPERTY_ID_RINGTONE, contactRingTone);
2304 AppLog("ringtone fetched - r = %d", r);
2305 delete foundContact;
2306 foundContact = null;
2309 __pSoundManager->StartAlert(contactRingTone);
2313 TelephonyManager::StopAlert(void)
2315 __pSoundManager->StopAlert();
2319 TelephonyManager::CheckValidTelePhoneNumber(const String& contactNumber)
2321 result r = E_SUCCESS;
2322 if (contactNumber.GetLength() > TAPI_CALL_DIALDIGIT_LEN_MAX)
2326 //TODO: check if valid phone number else return error message
2331 TelephonyManager::CheckIfMOCallIsPossible()
2333 result r = E_SUCCESS;
2335 //Check modem power status
2336 int modemStatus = 0;
2337 int errorCode = tel_check_modem_power_status(__pTapiHandle, &modemStatus);
2338 if (errorCode != TAPI_API_SUCCESS || modemStatus == TAPI_PHONE_POWER_STATUS_OFF
2339 || modemStatus == TAPI_PHONE_POWER_STATUS_ERROR)
2345 TelSimCardStatus_t simStatus;
2346 int simChangedStatus;
2347 //fetch sim initialization status
2348 int errorCode = tel_get_sim_init_info(__pTapiHandle, &simStatus, &simChangedStatus);
2349 if (errorCode != TAPI_API_SUCCESS)
2357 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: // Sim Initialization ok
2361 case TAPI_SIM_STATUS_UNKNOWN: //initial state
2362 case TAPI_SIM_STATUS_CARD_NOT_PRESENT: //Card not present
2363 case TAPI_SIM_STATUS_CARD_REMOVED: //Card removed
2364 case TAPI_SIM_STATUS_CARD_ERROR: // Bad card / On the fly, SIM gone bad
2365 //TODO: might want to set different error code, to give proper message to user
2378 TelephonyManager::CheckIfMOCallIsEmergency(const String& contactNumber, bool isSimInitialized)
2380 //TODO: extract actual telephone number from contactNumber
2381 //by deleting prefix,'P','W', etx.
2383 bool isEmergency = false;
2384 //conversion "contactNumber" to char*
2385 const wchar_t* pContact = contactNumber.GetPointer();
2386 int len = contactNumber.GetLength() + 1;
2387 char* pNumber = new (std::nothrow) char[len];
2388 wcstombs(pNumber, pContact, len);
2390 if(isSimInitialized)
2392 //used to get Ecc information for 2G and 3G.
2393 TelSimEccList_t simEccList;
2394 memset(&simEccList, 0x00, sizeof(TelSimEccList_t));
2395 //Check if given number matches the sim card's emergency numbers
2396 int errorCode = tel_get_sim_ecc(__pTapiHandle, &simEccList);
2397 if (errorCode == TAPI_API_SUCCESS && simEccList.ecc_count > 0)
2399 for (int index = 0; index < simEccList.ecc_count; index++)
2401 if ((strcmp(pNumber, simEccList.list[index].number) == 0))
2410 //TODO: check if we need to also check SOS call numbers, if sim not present.
2419 TelephonyManager::FetchContactInfoForNumber(const String& phoneNumberStr)
2421 result r = E_FAILURE;
2423 //delete previously cached data
2424 if (__pCachedContact != null)
2426 delete __pCachedContact;
2427 __pCachedContact = null;
2430 //Searches contacts by phone number.
2431 IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumberStr);
2432 if (pContactList == null || IsFailed(GetLastResult()))
2437 //Fetch the contact's info to be displayed
2438 IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
2439 while ((E_SUCCESS == pContactEnum->MoveNext()) && (__pCachedContact == null))
2441 Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
2443 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
2444 if (pPhoneNumberList != null)
2446 IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
2447 while (E_SUCCESS == pPhoneEnum->MoveNext())
2449 PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
2450 //Check if this is the correct contact
2451 if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumberStr))
2453 //save newly fetched contact info.
2454 __pCachedContact = new (std::nothrow) Contact(*pContact);
2460 pPhoneNumberList->RemoveAll(true);
2461 delete pPhoneNumberList;
2464 delete pContactEnum;
2465 pContactList->RemoveAll(true);
2466 delete pContactList;
2472 TelephonyManager::GetContactN(const String& phoneNumber)
2474 result r = FetchContactInfoForNumber(phoneNumber);
2477 return new (std::nothrow) Contact(*__pCachedContact);
2483 TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const String& contactNumber)
2485 if(__pIncomingCall != null)
2487 delete __pIncomingCall;
2488 __pIncomingCall = null;
2491 if(callHandle.IsEmpty() == false)
2494 Integer::Parse(callHandle,incomingHandle);
2495 //This API call is synchronous
2496 TelCallStatus_t callStatus;
2497 int errCode = tel_get_call_status(__pTapiHandle, incomingHandle, &callStatus);
2498 if (errCode != TAPI_API_SUCCESS)
2500 AppLogDebug("tel_get_call_status failed");
2503 //construct incoming call info object
2504 __pIncomingCall = new (std::nothrow) AppCallInfo();
2505 __pIncomingCall->SetCallHandle(incomingHandle);
2508 String phoneNumber(contactNumber);
2509 if(phoneNumber.IsEmpty() == true)
2511 phoneNumber.Append(callStatus.pNumber);
2513 __pIncomingCall->SetContactNumber(phoneNumber);
2514 //set emergency state
2515 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2517 __pIncomingCall->SetEmergency(true);
2521 __pIncomingCall->SetEmergency(false);
2523 //set start time, when call is connected
2524 long long startTime = 0;
2525 SystemTime::GetTicks(startTime);
2526 __pIncomingCall->SetCallNotificationTime(startTime);
2527 __pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2531 //TODO: This 'else' block can be removed once AppControl request API is stabilized.
2532 //This API call is synchronous and 'HandleIncomingCallStatusCallBack' is called for each active call.
2533 int errCode = tel_get_call_status_all(__pTapiHandle, &HandleIncomingCallStatusCallBack, this);
2534 if (errCode != TAPI_API_SUCCESS)
2540 if(__pIncomingCall != null)
2542 //set call notification time
2543 long long startTime = 0;
2544 SystemTime::GetTicks(startTime);
2545 __pIncomingCall->SetCallNotificationTime(startTime);
2547 if(__pIncomingCall->GetContactNumber().IsEmpty() == false)
2549 //fetch contact info
2550 FetchContactInfoForNumber(__pIncomingCall->GetContactNumber());
2551 if (__pCachedContact != null)
2553 __pIncomingCall->SetContactInfo(*__pCachedContact);
2557 //construct a new callinfo object to pass its ownership to caller.
2558 AppCallInfo* pNewIncomingCall = new (std::nothrow) AppCallInfo();
2559 *pNewIncomingCall = *__pIncomingCall;
2560 return pNewIncomingCall;
2562 //return null, if no incoming call found
2567 TelephonyManager::HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus, void* pUserData)
2569 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2570 if (pCallStatus != null && pCallStatus->bMoCall == false
2571 && ((pCallStatus->CallState == TAPI_CALL_STATE_INCOMING)
2572 || (pCallStatus->CallState == TAPI_CALL_STATE_WAITING)))
2574 //construct incoming call details
2575 pTelManager->__pIncomingCall = new (std::nothrow) AppCallInfo();
2576 pTelManager->__pIncomingCall->SetCallHandle(pCallStatus->CallHandle);
2578 String contactNumber(pCallStatus->pNumber);
2579 pTelManager->__pIncomingCall->SetContactNumber(contactNumber);
2580 //set emergency state
2581 if(pCallStatus->CallType == TAPI_CALL_TYPE_E911)
2583 pTelManager->__pIncomingCall->SetEmergency(true);
2587 pTelManager->__pIncomingCall->SetEmergency(false);
2590 pTelManager->__pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2595 TelephonyManager::SaveCallInfoToLogsDb(AppCallInfo& endCallInfo)
2597 if (endCallInfo.IsConferenceCall() == false)
2599 //single active call - Add call ended to call log database
2600 __pCalllogMgr->AddCallogInfoToDatabase(&endCallInfo);
2605 int confCallCount = endCallInfo.GetCallerListCount();
2606 IListT<AppCallInfo>* pParticipantList = endCallInfo.GetCallerList();
2607 for (int index = 0; index < confCallCount; index++)
2609 AppCallInfo participantInfo;
2610 if (pParticipantList->GetAt(index, participantInfo) == E_SUCCESS)
2612 //Add call ended to call log database
2613 __pCalllogMgr->AddCallogInfoToDatabase(&participantInfo);
2620 TelephonyManager::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
2622 if(networkStatus.IsCallServiceAvailable() == false)
2629 TelephonyManager::IsIncomingorDialingCallPresent(void)
2631 //returns false, if incoming call or dialed call is present.
2632 return ((__pIncomingCall != null) || (__pDialedCall != null));