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::AnswerCall(int callHandle, bool acceptCall)
393 result r = E_FAILURE;
394 __pSoundManager->StopAlert();
395 TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_ACCEPT;
397 if (acceptCall == true)
399 answerType = TAPI_CALL_ANSWER_ACCEPT;
400 // redirect to dummy call back handler as the flow already handled in registered event callback
401 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
405 answerType = TAPI_CALL_ANSWER_REJECT;
406 // redirect to reject call back handler as the flow has to be handled
407 res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleRejectCallbackResponse, this);
410 if (res == TAPI_CAUSE_SUCCESS)
422 TelephonyManager::AcceptCall(CallAnsweringOptions answerOptions,int callHandle)
424 result r = E_FAILURE;
425 __pSoundManager->StopAlert();
426 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
428 //Check if this is a new incoming call
429 if(__pIncomingCall == null || (callHandle != (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
431 //construct and fetch new Incoming call Info
432 String incomingHandle;
433 incomingHandle.Append(callHandle);
434 AppCallInfo* pDuplicateCallInfo = FetchIncomingCallHandleN(incomingHandle, String(L""));
435 if(pDuplicateCallInfo == null)
440 delete pDuplicateCallInfo;
441 pDuplicateCallInfo = null;
444 switch(answerOptions)
446 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
447 case ANSERWING_OPTION_END_SINGLE_CALL:
449 r = AcceptSecondCall(answerOptions, callHandle);
453 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
454 case ANSERWING_OPTION_REPLACE_HELD_CALL:
455 case ANSERWING_OPTION_END_ALL_CALLS:
457 r = AcceptMultipleCall(answerOptions, callHandle);
468 TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
470 result r = E_FAILURE;
472 switch (answerOptions)
474 case ANSERWING_OPTION_HOLD_SINGLE_CALL:
476 //accept incoming call by putting active call on Hold with 'TAPI_CALL_ANSWER_HOLD_AND_ACCEPT'
477 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
484 //Call connected successfully
486 //update status of first call to "OnHold"
487 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
488 AppCallInfo firstCallInfo;
489 pCallList->GetAt(0, firstCallInfo);
490 //replace old object with update AppCallInfo
491 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
492 *pHeldCallInfo = firstCallInfo;
493 pHeldCallInfo->SetOnHold(true);
494 __pActiveCallList->Remove(firstCallInfo.GetCallHandle()->ToLong());
495 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
501 case ANSERWING_OPTION_END_SINGLE_CALL:
503 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
504 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
505 //create a new ActiveCallList
506 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
507 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
509 //accept call and reject all active calls with 'TAPI_CALL_ANSWER_REPLACE'
510 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
514 //delete newly constructed list and gain ownership of old list
515 delete __pActiveCallList;
516 __pActiveCallList = pEndCallsList;
520 //Call connected successfully
522 //Add calls information to call log before deleting from active call list.
523 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
524 if(pCallList != null)
526 AppCallInfo endCallInfo;
527 if (pCallList->GetAt(0, endCallInfo) == E_SUCCESS)
529 SaveCallInfoToLogsDb(endCallInfo);
533 pEndCallsList->RemoveAll();
534 delete pEndCallsList;
545 TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const int incomingCallHandle)
547 result r = E_FAILURE;
549 switch (answerOptions)
551 case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
553 //Replace "Active" call by incoming call and save ended call to call logs db.
554 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
555 AppCallInfo callToBeEnded;
556 pCallList->GetAt(0, callToBeEnded);
557 //Check if the call is on "Hold", then fetch 2nd callInfo
558 if (callToBeEnded.IsOnHold() == true)
560 pCallList->GetAt(1, callToBeEnded);
565 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
566 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
568 //Accept incoming call by End Active call with 'TAPI_CALL_ANSWER_REPLACE'
569 int res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_REPLACE, &HandleCallbackResponse, this);
573 //save the previous call back to active call list
574 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
578 //Incoming Call connected successfully
580 //save to ended call to call logs db.
581 SaveCallInfoToLogsDb(callToBeEnded);
585 case ANSERWING_OPTION_REPLACE_HELD_CALL:
587 //Replace "Held" call by incoming call and save ended call to call logs db.
588 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
589 //"Held" call is to be ended
590 AppCallInfo callToBeEnded;
591 //"Active" call will be put on Hold
592 AppCallInfo callToPutOnHold;
593 pCallList->GetAt(0, callToBeEnded);
594 //Check if the call is NOT "Held", then fetch 2nd callInfo
595 if (callToBeEnded.IsOnHold() == false)
597 callToPutOnHold = callToBeEnded;
598 pCallList->GetAt(1, callToBeEnded);
602 pCallList->GetAt(1, callToPutOnHold);
607 //remove "CallToBeEnded" from Active call list to avoid processing in HandleIdleCallback().
608 __pActiveCallList->Remove(callToBeEnded.GetCallHandle()->ToLong());
610 //End "Held" Call using 'TAPI_CALL_END'.
612 if (callToBeEnded.IsConferenceCall() == false)
614 res = tel_end_call(__pTapiHandle, callToBeEnded.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
618 IListT<AppCallInfo>* pParticipantsInfo = callToBeEnded.GetCallerList();
619 //need to end every participant individually for conference call
620 for (int index = 0; index < pParticipantsInfo->GetCount(); index++)
622 AppCallInfo memberCallInfo;
623 pParticipantsInfo->GetAt(index, memberCallInfo);
624 res = tel_end_call(__pTapiHandle, memberCallInfo.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
631 //save the previous "callToBeEnded" call back to active call list
632 __pActiveCallList->Add(callToBeEnded.GetCallHandle()->ToLong(), callToBeEnded);
635 //"Held" call successfully ended - Add call ended to call log database
636 SaveCallInfoToLogsDb(callToBeEnded);
638 //accept incoming call by Holding "Active" call using "TAPI_CALL_ANSWER_HOLD_AND_ACCEPT".
639 res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
646 //Call connected successfully and active call is "Onhold"
648 //replace old object with update CallInfo
649 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
650 *pHeldCallInfo = callToPutOnHold;
651 pHeldCallInfo->SetOnHold(true);
652 __pActiveCallList->Remove(callToPutOnHold.GetCallHandle()->ToLong());
653 __pActiveCallList->Add(pHeldCallInfo->GetCallHandle()->ToLong(), *pHeldCallInfo);
657 case ANSERWING_OPTION_END_ALL_CALLS:
659 //End all active and Held calls after saving to call log. Incoming call is automatically accepted by TAPI engine,
660 // and processing of Incoming call is handled in HandleActiveCallback().
662 //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
663 HashMapT<long, AppCallInfo>* pEndCallsList = __pActiveCallList;
664 //create a new ActiveCallList
665 __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
666 __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
668 //End all active calls and all hold calls
669 int res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_ACTIVE_ALL, &HandleCallbackResponse, this);
672 res = tel_end_call(__pTapiHandle, -1, TAPI_CALL_END_HOLD_ALL, &HandleCallbackResponse, this);
678 //delete newly constructed list and gain ownership of old list
679 delete __pActiveCallList;
680 __pActiveCallList = pEndCallsList;
684 //all calls ended successfully, Incoming call is automatically accepted.
687 //Add calls information to call log before deleting from active call list.
688 IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
689 if(pCallList != null)
691 int callCount = pCallList->GetCount();
692 for (int index = 0; index < callCount; index++)
694 AppCallInfo endCallInfo;
695 if (pCallList->GetAt(index, endCallInfo) == E_SUCCESS)
697 SaveCallInfoToLogsDb(endCallInfo);
703 pEndCallsList->RemoveAll();
704 delete pEndCallsList;
705 pEndCallsList = null;
716 TelephonyManager::HoldCall(Tizen::Base::Long callHandle, bool holdCall)
718 result r = E_SUCCESS;
719 //Check if there are any existing active calls
720 if (__pActiveCallList->GetCount())
722 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
723 int callCount = pCallList->GetCount();
724 for (int index = 0; index < callCount; index++)
726 AppCallInfo holdCallInfo;
728 r = pCallList->GetAt(index, holdCallInfo);
729 //check if an active call is found with matching contact no.
730 if ((r == E_SUCCESS) && (holdCallInfo.GetCallHandle()->Equals(callHandle)))
732 r = HoldActiveCall(&holdCallInfo, holdCall);
744 TelephonyManager::EndConferenceCall(void)
746 result r = E_FAILURE;
747 //fetch conference callInfo to end
748 AppCallInfo confCallToEnd;
749 bool isConferenceCallFound = false;
751 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
752 int callCount = pCallList->GetCount();
753 for (int index = 0; index < callCount; index++)
755 pCallList->GetAt(index, confCallToEnd);
756 if (confCallToEnd.IsConferenceCall() == true)
758 isConferenceCallFound = true;
765 if (isConferenceCallFound == true)
767 //End conference call
768 TelCallEndType_t callEndType = TAPI_CALL_END_ACTIVE_ALL;
769 if (confCallToEnd.IsOnHold() == true)
771 callEndType = TAPI_CALL_END_HOLD_ALL;
773 int res = tel_end_call(__pTapiHandle, confCallToEnd.GetCallHandle()->ToLong(), callEndType, &HandleEndConferenceCallbackResponse, this);
774 if (res == TAPI_CAUSE_SUCCESS)
783 TelephonyManager::HoldConferenceCall(bool holdCall)
785 result r = E_FAILURE;
786 int confCallIndex = -1;
787 AppCallInfo confCallToHold;
788 bool isConferenceCallFound = false;
790 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
791 int confCallCount = pCallList->GetCount();
793 for (int index = 0; index < confCallCount; index++)
795 pCallList->GetAt(index, confCallToHold);
796 if (confCallToHold.IsConferenceCall() == true)
798 isConferenceCallFound = true;
799 confCallIndex = index;
800 //Found the Conference call to be ended.
805 if (isConferenceCallFound == false)
812 unsigned int callHandle = confCallToHold.GetCallHandle()->ToLong();
813 int res = TAPI_API_INVALID_INPUT;
814 if (holdCall == true)
816 res = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
820 res = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
822 if (res == TAPI_API_SUCCESS)
825 if (holdCall == true)
827 confCallToHold.SetOnHold(true);
831 confCallToHold.SetOnHold(false);
833 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
834 *pConfCallInfo = confCallToHold;
835 __pActiveCallList->Remove(callHandle);
836 __pActiveCallList->Add(callHandle, *pConfCallInfo);
849 TelephonyManager::JoinCall(void)
851 result r = E_FAILURE;
853 AppCallInfo activeCall;
854 AppCallInfo heldCall;
855 // Use enumerator to access elements in the map
856 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
857 r = pCallList->GetAt(0, activeCall);
861 r = pCallList->GetAt(1, heldCall);
864 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
865 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
867 //Check if participants in conference call are under limit.
868 if ((heldCall.IsConferenceCall() == true) && (heldCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS))
870 res = tel_join_call(__pTapiHandle, heldCallHandle, activeCallHandle, &HandleJoinCallbackResponse, this);
872 else if (activeCall.GetCallerListCount() < IDI_MAX_CONF_CALL_PARTICIPANTS)
874 res = tel_join_call(__pTapiHandle, activeCallHandle, heldCallHandle, &HandleJoinCallbackResponse, this);
880 if (res == TAPI_API_SUCCESS)
892 TelephonyManager::HoldActiveCall(AppCallInfo* pActiveCallInfo, bool holdCall)
894 unsigned int callHandle = pActiveCallInfo->GetCallHandle()->ToLong();
896 if (holdCall == true)
898 retStatus = tel_hold_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
902 retStatus = tel_active_call(__pTapiHandle, callHandle, &HandleCallbackResponse, this);
905 if (retStatus == TAPI_CAUSE_SUCCESS)
907 AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
908 //copy state into new callinfo object
909 *pHeldCallInfo = *pActiveCallInfo;
911 //set call to hold state
912 pHeldCallInfo->SetOnHold(holdCall);
914 __pActiveCallList->Remove(callHandle);
915 //replace old object with new
916 __pActiveCallList->Add(callHandle, *pHeldCallInfo);
926 TelephonyManager::DialOutgoingCall(String& contactNumber, bool isEmergency)
928 TelCallDial_t structDialCall;
930 AppLogDebug("Enter %ls",contactNumber.GetPointer());
931 //Temp String to replace , with P and ; with W
932 String TempContactNum;
933 TempContactNum.Append(contactNumber);
934 TempContactNum.Replace(L",",L"W");
935 TempContactNum.Replace(L";",L",");
936 //conversion "contactNumber" to char*
937 const wchar_t* pContact = TempContactNum.GetPointer();
938 int len = TempContactNum.GetLength()+1;
939 char* pNumber = new (std::nothrow) char[len];
940 wcstombs(pNumber, pContact, len);
943 //initialize request parameter
944 memset(&structDialCall, '\0', sizeof(TelCallDial_t));
945 memcpy(structDialCall.szNumber, pNumber, strlen(pNumber));
946 AppLogDebug("%s",structDialCall.szNumber);
947 if(isEmergency == true)
949 structDialCall.CallType = TAPI_CALL_TYPE_E911;
953 structDialCall.CallType = TAPI_CALL_TYPE_VOICE;
956 int res = tel_dial_call(__pTapiHandle, &structDialCall, &HandleDialCallbackResponse, this);
957 if (__pSoundManager == null)
959 __pSoundManager = new (std::nothrow) SoundManager();
961 __pSoundManager->StartSession();
965 if (res == TAPI_CAUSE_SUCCESS)
967 if (__pDialedCall != null)
969 delete __pDialedCall;
970 __pDialedCall = null;
972 __pDialedCall = new (std::nothrow) AppCallInfo();
973 __pDialedCall->SetContactNumber(contactNumber);
974 __pDialedCall->SetEmergency(isEmergency);
975 result r = FetchContactInfoForNumber(contactNumber);
978 __pDialedCall->SetContactInfo(*__pCachedContact);
989 TelephonyManager::SwapCalls(void)
991 result r = E_FAILURE;
993 //check if there are atleast 2 active calls
994 if (__pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
999 IListT<long>* pCallHandleList = __pActiveCallList->GetKeysN();
1000 long callHandle1 = 0;
1001 pCallHandleList->GetAt(0, callHandle1);
1002 long callHandle2 = 0;
1003 pCallHandleList->GetAt(1, callHandle2);
1005 retStatus = tel_swap_call(__pTapiHandle, callHandle1, callHandle2, &HandleSwapCallbackResponse, this);
1007 if (retStatus == TAPI_CAUSE_SUCCESS)
1011 delete pCallHandleList;
1012 pCallHandleList = null;
1019 TelephonyManager::SendCallDTMF(String& textToBeSent)
1021 result r = E_FAILURE;
1022 //check if there is an active Call
1023 if (__pActiveCallList->GetCount() > 0)
1025 //conversion "textToBeSent" to char*
1026 const wchar_t* pTextToBeSent = textToBeSent.GetPointer();
1027 int len = textToBeSent.GetLength() + 1;
1028 char* pNumber = new (std::nothrow) char[len];
1029 wcstombs(pNumber, pTextToBeSent, len);
1030 int retStatus = tel_call_dtmf(__pTapiHandle, pNumber, &HandleCallbackResponse, this);
1033 if (retStatus == TAPI_CAUSE_SUCCESS)
1042 TelephonyManager::EndFromConference(int callHandle)
1044 result r = E_FAILURE;
1045 int confCallIndex = -1;
1046 AppCallInfo endConfCall;
1047 bool isConferenceCallFound = false;
1049 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1050 int callCount = pCallList->GetCount();
1051 for (int index = 0; index < callCount; index++)
1053 pCallList->GetAt(index, endConfCall);
1054 if (endConfCall.IsConferenceCall() == true)
1056 isConferenceCallFound = true;
1057 confCallIndex = index;
1058 //Found the Conference call to be ended.
1066 if (isConferenceCallFound == false)
1068 //no conference call found
1072 //Identify the call to be ended and remove from list on API success
1073 AppCallInfo callToBeEnded;
1074 IListT<AppCallInfo>* pParticipantList = endConfCall.GetCallerList();
1075 int participantCount = pParticipantList->GetCount();
1076 for (int index = 0; index < participantCount; index++)
1078 pParticipantList->GetAt(index, callToBeEnded);
1079 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1081 //Identify the call to be ended and remove from list on API success
1082 TelCallEndType_t endType = TAPI_CALL_END;
1084 int res = tel_end_call(__pTapiHandle, callHandle, endType, &HandleEndFromConferenceCallbackResponse, this);
1085 if (res == TAPI_CAUSE_SUCCESS)
1101 TelephonyManager::SplitFromConference(int callHandle)
1103 result r = E_FAILURE;
1104 int confCallIndex = -1;
1105 AppCallInfo endConfCall;
1106 bool isConferenceCallFound = false;
1108 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1109 int callCount = pCallList->GetCount();
1110 for (int index = 0; index < callCount; index++)
1112 pCallList->GetAt(index, endConfCall);
1113 if (endConfCall.IsConferenceCall() == true)
1115 isConferenceCallFound = true;
1116 confCallIndex = index;
1117 //Found the Conference call to be ended.
1123 if (isConferenceCallFound == false)
1125 //no conference call found
1129 //Identify the call to be ended and remove from list on API success
1130 AppCallInfo callToBeEnded;
1131 pCallList = endConfCall.GetCallerList();
1132 callCount = pCallList->GetCount();
1133 for (int index = 0; index < callCount; index++)
1135 pCallList->GetAt(index, callToBeEnded);
1136 if (callToBeEnded.GetCallHandle()->ToLong() == callHandle)
1138 int res = tel_split_call(__pTapiHandle, callHandle, &HandleSplitFromConferenceCallbackResponse, this);
1139 if (res == TAPI_CAUSE_SUCCESS)
1154 TelephonyManager::SetMuteStatus(bool setMute)
1156 TelSoundMuteStatus_t muteStatus;
1157 result r = E_FAILURE;
1158 if (setMute == true)
1160 muteStatus = TAPI_SOUND_MUTE_STATUS_ON;
1164 muteStatus = TAPI_SOUND_MUTE_STATUS_OFF;
1166 int res = tel_set_call_mute_status(__pTapiHandle, muteStatus, &HandleCallbackResponse, this);
1167 if (res == TAPI_CAUSE_SUCCESS)
1169 __isMuted = setMute;
1180 TelephonyManager::IsCallMuted(void)
1186 TelephonyManager::SetSpeakerStatus(bool setSpeaker)
1188 result r = E_FAILURE;
1189 TelCallSoundPathInfo_t callSoundPathInfo;
1190 __pSoundManager->SetSpeakerStatus(setSpeaker);
1191 if (setSpeaker == true)
1193 callSoundPathInfo.path = TAPI_SOUND_PATH_SPK_PHONE;
1197 callSoundPathInfo.path = TAPI_SOUND_PATH_HANDSET;
1199 callSoundPathInfo.ex_volume = TelCallSoundPathInfo_t::TAPI_SOUND_EX_VOLUME_ON;
1201 int res = tel_set_call_sound_path(__pTapiHandle, &callSoundPathInfo, &HandleCallbackResponse, this);
1203 if (res == TAPI_CAUSE_SUCCESS)
1205 __isSpeakerOn = setSpeaker;
1216 TelephonyManager::IsSpeakerOn(void)
1218 return __isSpeakerOn;
1222 TelephonyManager::IsSplitAllowed(void)
1224 // Split functionality is allowed only if a one call is present.
1225 // The call can be a single call or a conference call
1226 if (__pActiveCallList->GetCount() == 1)
1234 TelephonyManager::HandleCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1236 //should not do anything here.
1240 TelephonyManager::HandleDialCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1242 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1243 if (callBackResult != TAPI_CAUSE_SUCCESS)
1245 if (pTelManager->__pDialedCall != null)
1247 delete pTelManager->__pDialedCall;
1248 pTelManager->__pDialedCall = null;
1250 pTelManager->__pEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
1255 TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1257 AppLogDebug("ENTER");
1258 // This callback comes only if user has either rejected an incoming call from IncomingCallForm.
1259 // or the incoming call was automatically blocked.
1260 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1261 if (pData != null && callBackResult == TAPI_API_SUCCESS)
1263 unsigned int rejectedCallHandle = 0;
1264 memcpy(&rejectedCallHandle, pData, sizeof(TS_UINT));
1266 //Check if incoming call is rejected
1267 if (pTelManager->__pIncomingCall != null && (rejectedCallHandle == (unsigned int) pTelManager->__pIncomingCall->GetCallHandle()->ToLong()))
1269 AppCallInfo rejectedCallInfo;
1270 rejectedCallInfo = *(pTelManager->__pIncomingCall);
1271 delete pTelManager->__pIncomingCall;
1272 pTelManager->__pIncomingCall = null;
1274 //Check if number was automatically rejected using settings, then don't give any notification to user.
1275 bool showIncomingCallRejectedNotification = true;
1276 if (((pTelManager->__pSettingsManager->GetUnknownRejectStatus() == true) && (rejectedCallInfo.GetContactInfo() == null))
1277 || (pTelManager->__pSettingsManager->IsCallToBeRejected(rejectedCallInfo.GetContactNumber()) == true))
1280 AppLogDebug("Call blocked");
1281 showIncomingCallRejectedNotification = false;
1282 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
1286 AppLogDebug("Call rejected");
1287 //rejected by user from incoming call form
1288 showIncomingCallRejectedNotification = true;
1289 rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_REJECTED);
1291 //Save rejected incoming call to call log db.
1292 pTelManager->SaveCallInfoToLogsDb(rejectedCallInfo);
1294 if (showIncomingCallRejectedNotification == true)
1296 //check if the ended call was the last call
1297 bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
1298 //Stop alert - started only for incoming calls which are not blocked.
1299 if(pTelManager->__pSoundManager != null)
1301 pTelManager->__pSoundManager->StopAlert();
1302 //Do not call stop session if there is already a call going on
1303 if(isLastCall == true)
1305 pTelManager->__pSoundManager->StopSession();
1308 //Send notification to user
1309 ArrayListT<AppCallInfo>* pCallList = null;
1312 //save 'RejectedCall' to list to show on EndCallForm
1313 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1314 pCallList->Construct(1);
1315 AppCallInfo* pRejectedCall = new (std::nothrow) AppCallInfo();
1316 *pRejectedCall = rejectedCallInfo;
1317 pCallList->Add(*pRejectedCall);
1321 //fetch active calls to show appropriate scene
1322 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1324 pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1332 pTelManager->__pEventListener->HandleTelephonyError(ERROR_REJECT_FAILED);
1334 AppLogDebug("EXIT");
1338 TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1340 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1341 if (callBackResult == TAPI_API_SUCCESS && pData != null)
1343 unsigned int tempHandle = 0;
1344 TelCallInfoJoinedNoti_t joinedInfoNotification;
1345 AppCallInfo confCallInfo;
1347 memcpy(&tempHandle, pData, sizeof(TS_UINT));
1348 joinedInfoNotification.id = tempHandle;
1349 AppCallInfo activeCall;
1350 AppCallInfo heldCall;
1351 // Use enumerator to access elements in the map
1352 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1353 result r = pCallList->GetAt(0, activeCall);
1357 r = pCallList->GetAt(1, heldCall);
1360 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1361 unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
1362 unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
1363 if (activeCall.IsConferenceCall() == true)
1366 //When joined both become active
1367 activeCall.SetOnHold(false);
1368 heldCall.SetOnHold(false);
1369 *pConfCallInfo = activeCall;
1370 pConfCallInfo->AddCallToCallerList(heldCall);
1371 pConfCallInfo->SetCallHandle(activeCallHandle);
1372 //Set call start time
1373 if (pConfCallInfo->GetCallConnectTime() > heldCall.GetCallConnectTime())
1375 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1376 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1379 else if (heldCall.IsConferenceCall() == true)
1382 heldCall.SetOnHold(false);
1383 activeCall.SetOnHold(false);
1384 *pConfCallInfo = heldCall;
1385 pConfCallInfo->AddCallToCallerList(activeCall);
1386 pConfCallInfo->SetCallHandle(heldCallHandle);
1387 //Set call start time
1388 if (pConfCallInfo->GetCallConnectTime() > activeCall.GetCallConnectTime())
1390 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1391 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1397 pConfCallInfo->SetConference(true);
1398 heldCall.SetOnHold(false);
1399 activeCall.SetOnHold(false);
1400 pConfCallInfo->AddCallToCallerList(activeCall);
1401 pConfCallInfo->AddCallToCallerList(heldCall);
1402 pConfCallInfo->SetCallHandle(activeCallHandle);
1403 //Set call start time
1404 if (activeCall.GetCallConnectTime() > heldCall.GetCallConnectTime())
1406 pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
1407 pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
1411 pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
1412 pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
1415 pConfCallInfo->SetCallHandle(joinedInfoNotification.id);
1416 pTelManager->__pActiveCallList->RemoveAll();
1417 //only one call in the list
1418 pTelManager->__pActiveCallList->Add(joinedInfoNotification.id, *pConfCallInfo);
1419 //notify listener that call is connected.
1420 pTelManager->__pEventListener->HandleConferenceCall(*pConfCallInfo);
1428 pTelManager->__pEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
1433 TelephonyManager::HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1435 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1436 if (callBackResult == TAPI_CAUSE_SUCCESS)
1438 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1439 IListT<long>* pKeyList = pTelManager->__pActiveCallList->GetKeysN();
1440 int callCount = pTelManager->__pActiveCallList->GetCount();
1441 for (int index = 0; index < callCount; index++)
1443 AppCallInfo* pTempCallInfo = new (std::nothrow) AppCallInfo();
1444 pCallList->GetAt(index, *pTempCallInfo);
1445 (pTempCallInfo->IsOnHold() == false) ? pTempCallInfo->SetOnHold(true) : pTempCallInfo->SetOnHold(false);
1447 pKeyList->GetAt(index, callHandle);
1448 pTelManager->__pActiveCallList->SetValue(callHandle, *pTempCallInfo);
1454 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1455 pTelManager->__pEventListener->HandleCallSwapOccured(*pCallList);
1459 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
1464 TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1466 AppLogDebug("ENTER");
1467 //This callback comes if a single call is ended from Conference call.
1468 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1469 bool isParticipantCallEnded = false;
1471 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1473 //fetch end call handle
1474 TelCallEndCnf_t callEndNotification;
1475 memcpy(&callEndNotification, pData, sizeof(TelCallEndCnf_t));
1476 //Fetch conference call
1477 AppCallInfo endConfCall;
1478 bool isConferenceCallFound = false;
1479 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1480 int callCount = pCallList->GetCount();
1481 for (int index = 0; index < callCount; index++)
1483 pCallList->GetAt(index, endConfCall);
1484 if (endConfCall.IsConferenceCall() == true)
1486 isConferenceCallFound = true;
1487 //Found the Conference call to be changed.
1494 //Identify the call to be ended and remove from list.
1495 if (isConferenceCallFound == true)
1497 isParticipantCallEnded = pTelManager->HandleParticipantEndedFromConference(callEndNotification.id, endConfCall);
1501 //Check if participant call or Conference call was not found, then show error
1502 if (isParticipantCallEnded == false)
1504 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_FROM_CONFERENCE_FAILED);
1506 AppLogDebug("EXIT");
1510 TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantCallHandle, AppCallInfo& conferenceCall)
1512 AppLogDebug("ENTER");
1513 //to check if participant call was found and ended.
1514 bool isParticipantCallEnded = false;
1515 //Identify the call to be ended and remove from list.
1516 AppCallInfo callToBeEnded;
1517 IListT<AppCallInfo>* pCallerList = conferenceCall.GetCallerList();
1518 int callerCount = pCallerList->GetCount();
1519 for (int index = 0; index < callerCount; index++)
1521 pCallerList->GetAt(index, callToBeEnded);
1522 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == participantCallHandle)
1524 //Identify the call to be ended and remove from conference list
1525 conferenceCall.RemoveCallFromCallerList(index);
1526 //update its status to individual call before saving to database
1527 callToBeEnded.SetConference(false);
1528 SaveCallInfoToLogsDb(callToBeEnded);
1529 isParticipantCallEnded = true;
1534 if(isParticipantCallEnded == false)
1536 //participant call not found and not ended
1537 return isParticipantCallEnded;
1540 unsigned int confCallHandle = (unsigned int)conferenceCall.GetCallHandle()->ToLong();
1541 //Check if last participant removed. If yes, switch to single active view
1542 if (conferenceCall.GetCallerListCount() == 1)
1544 AppCallInfo callFromList;
1545 pCallerList = conferenceCall.GetCallerList();
1546 pCallerList->GetAt(0, callFromList);
1547 //construct a new single active call
1548 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1549 *pActiveCall = callFromList;
1550 //update conference status and Hold status
1551 pActiveCall->SetConference(false);
1552 pActiveCall->SetOnHold(conferenceCall.IsOnHold());
1554 __pActiveCallList->Remove(confCallHandle);
1555 __pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1557 //using the callConnected to switch to single active screen
1558 //or update multiple active call screen
1559 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1560 __pEventListener->HandleCallConnected(*pActiveCallList);
1561 delete pActiveCallList;
1562 pActiveCallList = null;
1566 AppCallInfo callFromList;
1567 pCallerList = conferenceCall.GetCallerList();
1568 pCallerList->GetAt(0, callFromList);
1569 //construct a new conference call
1570 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1571 *pConfCallInfo = conferenceCall;
1572 if (confCallHandle == participantCallHandle)
1574 //Call Handle is same as conf call handle, so need to change conf call handle
1575 __pActiveCallList->Remove(confCallHandle);
1576 int newConfCallHandle = callFromList.GetCallHandle()->ToLong();
1577 pConfCallInfo->SetCallHandle(newConfCallHandle);
1578 __pActiveCallList->Add(newConfCallHandle, *pConfCallInfo);
1582 __pActiveCallList->SetValue(confCallHandle, *pConfCallInfo);
1584 __pEventListener->HandleConferenceChange();
1586 AppLogDebug("EXIT");
1587 return isParticipantCallEnded;
1591 TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1593 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1594 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1596 TelCallSplitCnf_t callSplitNotification;
1597 memcpy(&callSplitNotification, pData, sizeof(TelCallSplitCnf_t));
1598 int confCallIndex = -1;
1599 AppCallInfo endConfCall;
1600 bool isConferenceCallFound = false;
1602 IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
1603 int callCount = pCallList->GetCount();
1604 for (int index = 0; index < callCount; index++)
1606 pCallList->GetAt(index, endConfCall);
1607 if (endConfCall.IsConferenceCall() == true)
1609 isConferenceCallFound = true;
1610 confCallIndex = index;
1611 //Found the Conference call to be ended.
1616 if (isConferenceCallFound == false)
1624 //Identify the call to be ended and remove from list on API success
1625 AppCallInfo callToBeEnded;
1626 pCallList = endConfCall.GetCallerList();
1627 callCount = pCallList->GetCount();
1628 for (int index = 0; index < callCount; index++)
1630 pCallList->GetAt(index, callToBeEnded);
1631 if ((unsigned int)callToBeEnded.GetCallHandle()->ToLong() == callSplitNotification.id)
1633 //Identified the call to be ended and remove from conference list
1634 //Add this to the active call list
1635 endConfCall.RemoveCallFromCallerList(index);
1639 unsigned int confCallHandle = (unsigned int)endConfCall.GetCallHandle()->ToLong();
1640 //Set the hold flags correctly and make the changes to the active call list
1641 if (endConfCall.GetCallerListCount() == 1)
1643 //Set hold for the other single call
1644 // and add to the list
1645 AppCallInfo callFromList;
1646 pCallList = endConfCall.GetCallerList();
1647 pCallList->GetAt(0, callFromList);
1648 AppCallInfo* pHeldCall = new (std::nothrow) AppCallInfo();
1649 *pHeldCall = callFromList;
1650 pHeldCall->SetConference(false);
1651 pHeldCall->SetOnHold(true);
1652 pTelManager->__pActiveCallList->Remove(confCallHandle);
1653 pTelManager->__pActiveCallList->Add(pHeldCall->GetCallHandle()->ToLong(), *pHeldCall);
1658 //Set hold flag for conference call
1659 endConfCall.SetOnHold(true);
1660 AppCallInfo callFromList;
1661 pCallList = endConfCall.GetCallerList();
1662 pCallList->GetAt(0, callFromList);
1664 AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
1665 *pConfCallInfo = endConfCall;
1666 if (confCallHandle == callSplitNotification.id)
1668 //Call Handle is same as conf call handle.
1669 //Change conf call handle
1670 pTelManager->__pActiveCallList->Remove(confCallHandle);
1671 int tmpCallHandle = callFromList.GetCallHandle()->ToLong();
1672 pConfCallInfo->SetCallHandle(tmpCallHandle);
1673 pTelManager->__pActiveCallList->Add(callFromList.GetCallHandle()->ToLong(), *pConfCallInfo);
1677 pTelManager->__pActiveCallList->Remove(confCallHandle);
1678 pTelManager->__pActiveCallList->Add(confCallHandle, *pConfCallInfo);
1681 //Add the new active call to active call list
1682 AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
1683 *pActiveCall = callToBeEnded;
1684 pActiveCall->SetConference(false);
1685 pActiveCall->SetOnHold(false);
1686 pTelManager->__pActiveCallList->Remove(pActiveCall->GetCallHandle()->ToLong());
1687 pTelManager->__pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
1689 //using the callConnected to switch to Multiple active screen
1690 pCallList = pTelManager->__pActiveCallList->GetValuesN();
1691 pTelManager->__pEventListener->HandleCallConnected(*pCallList);
1696 pTelManager->__pEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
1701 TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
1704 //This callback comes only if a conference call is ended by user.
1705 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
1706 if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
1708 //fetch ended confCall details
1709 result r = E_FAILURE;
1710 AppCallInfo endConfCallInfo;
1711 IListT<AppCallInfo>* pActiveCallList = pTelManager->__pActiveCallList->GetValuesN();
1712 if(pActiveCallList != null && pActiveCallList->GetCount() > 0)
1714 for (int index = 0; index < pActiveCallList->GetCount(); index++)
1716 r = pActiveCallList->GetAt(index, endConfCallInfo);
1717 if(r == E_SUCCESS && endConfCallInfo.IsConferenceCall() == true)
1719 //conference call found.
1729 delete pActiveCallList;
1730 pActiveCallList = null;
1732 //check if no conference call found, then return.
1737 //remove the conference call handle from active call list to avoid any processing in HandleIdleCallback().
1738 pTelManager->__pActiveCallList->Remove(endConfCallInfo.GetCallHandle()->ToLong());
1739 //Save "End" Conf. call info to call log database
1740 pTelManager->SaveCallInfoToLogsDb(endConfCallInfo);
1742 //check if the ended call was the last call and show notification to user
1743 bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
1744 ArrayListT<AppCallInfo>* pCallList = null;
1747 pTelManager->__pSoundManager->SetlastEndedConferenceCall();
1748 //stop sound session
1749 pTelManager->__pSoundManager->StopSession();
1750 //send empty call list to show dialer or call log screen
1751 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1755 //fetch active calls to show appropriate scene
1756 pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
1758 //notify listener that call is disconnected.
1759 pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1765 pTelManager->__pEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
1771 TelephonyManager::HandleIdleCallBack(void* pData)
1773 AppLogDebug("ENTER");
1774 //This callback comes when any type of calls are ended
1775 //We do NOT handle below scenarios here -
1776 //1) In incoming call scenarios, if we end any active calls - handled in "AcceptCall()".
1777 //2) Incoming call automatically blocked and rejection by user scenarios are handled in "HandleRejectCallbackResponse()".
1778 //3) End conference call is handled in "HandleEndConferenceCallbackResponse()".
1779 //4) End Single Call from Conference call by user is handled in "HandleEndFromConferenceCallbackResponse()".
1780 //5) End Single Call from Conference call using eventInjector is diverted to "HandleParticipantEndedFromConference()".
1781 //BUT, we do handle below scenarios here -
1782 //1) "MISSED" incoming call scenario here i.e incoming call is rejected by other caller.
1783 //2) an "unconnected" dialed call is ended by caller or other party.
1784 //3) Any normal active calls(NOT conference calls) ended by user or by other party.
1786 if(__pSoundManager->GetLastConferenceCall() == false)
1788 __pSoundManager->SetDisconnectTone();
1791 TelCallStatusIdleNoti_t idleNotification;
1792 memcpy(&idleNotification, pData, sizeof(TelCallStatusIdleNoti_t));
1793 //handle end call event, show next screen
1794 unsigned int endCallHandle = idleNotification.id;
1796 //empty active call list or no dialed or incoming calls - ignore this event
1797 IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
1798 if((pActiveCallList == null || pActiveCallList->GetCount() <= 0) && __pDialedCall == null && __pIncomingCall == null)
1800 delete pActiveCallList;
1801 AppLogDebug("EXIT - no calls exist");
1805 //Check if ended call was among conference caller list,
1806 //then divert event to "HandleParticipantEndedFromConference()"
1807 AppCallInfo confCallInfo;
1808 bool isConferenceCallChanged = false;
1809 for (int index = 0; index < pActiveCallList->GetCount(); index++)
1811 //fetch conference call
1812 result r = pActiveCallList->GetAt(index, confCallInfo);
1813 if (r == E_SUCCESS && confCallInfo.IsConferenceCall() == true)
1815 //Conference call found - check if ended call is a participant
1816 isConferenceCallChanged = HandleParticipantEndedFromConference(endCallHandle, confCallInfo);
1820 delete pActiveCallList;
1821 pActiveCallList = null;
1822 if (isConferenceCallChanged == true)
1824 //end call event handled - conference call will now either remain as conf. call
1825 //or become single active call, if it has only 1 participant left.
1826 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1830 //check if ended call was among the active call list and not a conference call
1831 AppCallInfo endCallInfo;
1832 result r = __pActiveCallList->GetValue(endCallHandle, endCallInfo);
1835 bool isHandled = HandleEndNormalActiveCall(endCallInfo);
1836 if (isHandled == true)
1838 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1843 //Check if dialed call is rejected by other party
1844 bool isDialedCallEnded = ((__pDialedCall != null) && (((unsigned int)__pDialedCall->GetCallHandle()->ToLong()) == idleNotification.id));
1845 //Check if "missed" incoming call is ended
1846 bool isMissedIncomingCallEnded = (__pIncomingCall != null && ((unsigned int)__pIncomingCall->GetCallHandle()->ToLong() == idleNotification.id));
1847 if (isDialedCallEnded == true || isMissedIncomingCallEnded == true)
1849 //It comes here only if the ended call was either a "unconnected" dialed call or an "Missed" incoming call.
1850 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1852 ArrayListT<AppCallInfo>* pCallList = null;
1853 //Check if dialed call was ended
1854 if (isDialedCallEnded == true)
1856 AppLogDebug("Dialed Call Ended");
1857 //Call Ended is the dialed call
1858 endCallInfo = *(__pDialedCall);
1859 delete __pDialedCall;
1860 __pDialedCall = null;
1864 //Here, only "Missed" Incoming call ended by other caller is handled.
1865 AppLogDebug("Missed Call Ended");
1866 __pSoundManager->StopAlert();
1867 endCallInfo = *(__pIncomingCall);
1868 delete __pIncomingCall;
1869 __pIncomingCall = null;
1870 //update missed status
1871 endCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED_UNSEEN);
1873 //save ended call to call log db.
1874 SaveCallInfoToLogsDb(endCallInfo);
1876 //notify listener that call is disconnected.
1877 if (isLastCall == true)
1879 __pSoundManager->StopSession();
1880 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1881 pCallList->Construct(1);
1882 if (isMissedIncomingCallEnded == false)
1884 //save to list to show EndCallForm
1885 pCallList->Add(endCallInfo);
1887 __pSoundManager->GetTimer()->Cancel();
1892 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
1894 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1898 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
1899 AppLogDebug("EXIT");
1903 TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
1905 // This function gets called only from HandleIdleCallback(),
1906 // to handle disconnection of normal active calls.
1907 if (endCallInfo.IsConferenceCall() == false)
1909 //remove the call handle from active call list
1910 __pActiveCallList->Remove(endCallInfo.GetCallHandle()->ToLong());
1911 //check if the ended call was the last call and show notification to user
1912 bool isLastCall = (__pActiveCallList->GetCount() == 0);
1913 ArrayListT<AppCallInfo>* pCallList = null;
1916 //stop sound session
1917 __pSoundManager->StopSession();
1918 //save "End" CallInfo to list to show EndCallForm
1919 pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
1920 pCallList->Construct(1);
1921 pCallList->Add(endCallInfo);
1925 //fetch active calls to show appropriate scene
1926 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
1929 //Save "End" call info to call log database
1930 SaveCallInfoToLogsDb(endCallInfo);
1931 //notify listener that call is disconnected.
1932 __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
1941 TelephonyManager::HandleDialingCallBack(void* pData)
1943 unsigned int tempHandle = 0;
1944 TelCallStatusDialingNoti_t dialingNotification;
1945 memcpy(&tempHandle, pData, sizeof(TS_UINT));
1946 dialingNotification.id = tempHandle;
1947 //check if callback is for different dialed call
1948 //Dont check for call handle, since this is the first time, we get call handle for a dialed call.
1949 if (__pDialedCall == null)
1951 //construct new dialed call
1952 __pDialedCall = new (std::nothrow) AppCallInfo();
1954 TelCallStatus_t callStatus;
1955 int res = tel_get_call_status(__pTapiHandle, dialingNotification.id, &callStatus);
1956 if (res == TAPI_CAUSE_SUCCESS)
1959 String contactNumber(callStatus.pNumber);
1960 __pDialedCall->SetContactNumber(contactNumber);
1961 //set emergency state
1962 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
1964 __pDialedCall->SetEmergency(true);
1968 __pDialedCall->SetEmergency(false);
1971 FetchContactInfoForNumber(__pDialedCall->GetContactNumber());
1972 if (__pCachedContact != null)
1974 __pDialedCall->SetContactInfo(*(__pCachedContact));
1978 //set call handle for dialed call
1979 __pDialedCall->SetCallHandle(dialingNotification.id);
1980 __pDialedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
1982 //set call notification time.
1983 long long startTime = 0;
1984 SystemTime::GetTicks(startTime);
1985 __pDialedCall->SetCallNotificationTime(startTime);
1989 TelephonyManager::HandleActiveCallBack(void* pData)
1991 // This callback comes whenever any new call is connected
1992 // Or, any "Held" call is activated (we ignore activation of "Held" calls).
1993 unsigned int newCallHandle = 0;
1994 TelCallStatusActiveNoti_t activeNotification;
1995 memcpy(&newCallHandle, pData, sizeof(TS_UINT));
1996 activeNotification.id = newCallHandle;
1997 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
1999 //Check if the "Held" call was activated, i.e it is already present in already activated calls list.
2000 bool toHandleEvent = true;
2001 for (int callIndex = 0; (callIndex < pCallList->GetCount() && toHandleEvent == true); callIndex++ )
2003 AppCallInfo tempCallInfo;
2004 pCallList->GetAt(callIndex, tempCallInfo);
2005 unsigned int tempCallHandle = tempCallInfo.GetCallHandle()->ToLong();
2006 //Check if active callback came for "HandleJoinCallbackResponse"
2007 //or for "UnHold Conference Call or normal call".
2008 if(tempCallInfo.IsConferenceCall() == true)
2010 if (tempCallHandle == activeNotification.id)
2012 toHandleEvent = false;
2016 //check individual participants of conf call
2017 IListT<AppCallInfo>* pConfCallList = tempCallInfo.GetCallerList();
2018 int confCallCount = pConfCallList->GetCount();
2019 for (int callIndex = 0; (callIndex < confCallCount && toHandleEvent == true); callIndex++)
2021 AppCallInfo confCallerInfo;
2022 pConfCallList->GetAt(callIndex, confCallerInfo);
2023 unsigned int confCallerHandle = confCallerInfo.GetCallHandle()->ToLong();
2024 if (confCallerHandle == activeNotification.id)
2026 toHandleEvent = false;
2031 else if(tempCallHandle == activeNotification.id)
2033 //If normal call is UnHold
2034 toHandleEvent = false;
2038 //check if we need to handle this event.
2039 if(toHandleEvent == true)
2041 //Here it comes, only if either new dialed or incoming call was connected.
2042 HandleCallConnected( activeNotification.id);
2049 TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
2051 //Here it comes, only if either new dialed or incoming call was connected.
2052 //This function should be called only from "HandleActiveCallback()".
2053 AppCallInfo* pConnectedCall = null;
2054 //to check if incoming call was connected
2055 bool isIncomingCallConnected = false;
2057 __pSoundManager->SetConnectTone();
2058 //Check if dialed call is connected.
2059 if ((__pDialedCall != null) && (connectedCallHandle == (unsigned int)__pDialedCall->GetCallHandle()->ToLong()))
2061 pConnectedCall = __pDialedCall;
2062 __pDialedCall = null;
2064 //Check if connected call is incoming call.
2065 else if (__pIncomingCall != null && (connectedCallHandle == (unsigned int)__pIncomingCall->GetCallHandle()->ToLong()))
2067 pConnectedCall = __pIncomingCall;
2068 __pIncomingCall = null;
2069 isIncomingCallConnected = true;
2073 // this is just for safety. This scenario should never come.
2074 // Otherwise Correct the code in some other function, if it comes here.
2075 AppLogDebug("Error - Connected call was neither one of active calls nor it was dialed or incoming call");
2076 //Construct a new CallInfo object for call
2077 pConnectedCall = new (std::nothrow) AppCallInfo();
2078 pConnectedCall->SetCallHandle(connectedCallHandle);
2080 TelCallStatus_t callStatus;
2081 int res = tel_get_call_status(__pTapiHandle, connectedCallHandle, &callStatus);
2082 if (res == TAPI_CAUSE_SUCCESS)
2084 String contactNumber(callStatus.pNumber);
2085 pConnectedCall->SetContactNumber(contactNumber);
2086 //set emergency state
2087 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2089 pConnectedCall->SetEmergency(true);
2093 pConnectedCall->SetEmergency(false);
2095 //set call notification time
2096 long long startTime = 0;
2097 SystemTime::GetTicks(startTime);
2098 pConnectedCall->SetCallNotificationTime(startTime);
2099 if (callStatus.bMoCall == true)
2101 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_OUTGOING);
2105 pConnectedCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2106 isIncomingCallConnected = true;
2109 //delete any dialed or incoming call objects
2110 delete __pDialedCall;
2111 __pDialedCall = null;
2112 delete __pIncomingCall;
2113 __pIncomingCall = null;
2116 //fetch contact info for connected call & it is not a hidden call
2117 if (pConnectedCall->GetContactInfo() == null && pConnectedCall->GetContactNumber().IsEmpty() == false)
2119 FetchContactInfoForNumber(pConnectedCall->GetContactNumber());
2120 if (__pCachedContact != null)
2122 pConnectedCall->SetContactInfo(*(__pCachedContact));
2125 //set Call connect time for newly connected call
2126 long long startTime = 0;
2127 SystemTime::GetTicks(startTime);
2128 pConnectedCall->SetCallConnectTime(startTime);
2129 if(GetCurrentCallCount() == 0)
2131 __pSoundManager->SetMinuteReminderTone();
2135 //transfer ownership to Active calls list
2136 __pActiveCallList->Add(connectedCallHandle, *(pConnectedCall));
2137 pConnectedCall = null;
2139 //notify listener that call is connected.
2140 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2141 __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
2142 __pEventListener->HandleCallConnected(*pCallList);
2143 if (isIncomingCallConnected == true)
2145 __pSoundManager->StopAlert();
2152 TelephonyManager::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
2154 int callHandle = pIncomingCallInfo->GetCallHandle()->ToLong();
2155 String contactNumber(L"");
2156 contactNumber.Append(pIncomingCallInfo->GetContactNumber());
2157 //Check if "reject unknown calls" is set and contact number is not present in AddressBook
2158 //or if contact number is blacklisted
2159 if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pIncomingCallInfo->GetContactInfo() == null))
2160 || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
2162 AnswerCall(callHandle,false);
2169 TelephonyManager::HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
2171 unsigned int tempHandle = 0;
2172 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2173 if (pTelManager->__pSoundManager == null)
2175 AppLog("Creating Sound Manager");
2176 pTelManager->__pSoundManager = new (std::nothrow) SoundManager();
2178 //Handle telephony events
2179 if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) == 0)
2181 pTelManager->HandleIdleCallBack(pData);
2183 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) == 0)
2185 pTelManager->__pSoundManager->StartSession();
2186 pTelManager->HandleActiveCallBack(pData);
2188 else if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) == 0)
2190 pTelManager->HandleDialingCallBack(pData);
2194 memcpy(&tempHandle, pData, sizeof(TS_UINT));
2199 TelephonyManager::GetConferenceCallInfoN(void)
2201 AppCallInfo* pConfCallInfo = null;
2203 IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
2204 int callCount = pCallList->GetCount();
2205 for (int index = 0; index < callCount; index++)
2207 AppCallInfo callInfo;
2208 pCallList->GetAt(index, callInfo);
2209 if (callInfo.IsConferenceCall() == true)
2211 pConfCallInfo = new (std::nothrow) AppCallInfo();
2212 *pConfCallInfo = callInfo;
2213 //Found the Conference call
2220 return pConfCallInfo;
2223 IListT<AppCallInfo>*
2224 TelephonyManager::GetCallListN(void)
2226 ArrayListT<AppCallInfo>* pCallList = null;
2227 if (__pActiveCallList != null)
2229 pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
2235 TelephonyManager::GetCurrentCallCount(void)
2237 if (__pActiveCallList != null)
2239 return __pActiveCallList->GetCount();
2245 TelephonyManager::StartAlert(AppCallInfo& incomingCallInfo)
2247 String contactRingTone(L"");
2248 String contactNumber = incomingCallInfo.GetContactNumber();
2249 //check if not hidden call
2250 if(contactNumber.IsEmpty() == false)
2252 //fetch contact info from Db
2253 Contact* foundContact = GetContactN(contactNumber);
2254 if(foundContact != null)
2256 //fetch custom ringtone for contact
2257 result r = foundContact->GetValue(CONTACT_PROPERTY_ID_RINGTONE, contactRingTone);
2258 AppLog("ringtone fetched - r = %d", r);
2259 delete foundContact;
2260 foundContact = null;
2263 __pSoundManager->StartAlert(contactRingTone);
2267 TelephonyManager::StopAlert(void)
2269 __pSoundManager->StopAlert();
2273 TelephonyManager::CheckValidTelePhoneNumber(const String& contactNumber)
2275 result r = E_SUCCESS;
2276 if (contactNumber.GetLength() > TAPI_CALL_DIALDIGIT_LEN_MAX)
2280 //TODO: check if valid phone number else return error message
2285 TelephonyManager::CheckIfMOCallIsPossible()
2287 result r = E_SUCCESS;
2289 //Check modem power status
2290 int modemStatus = 0;
2291 int errorCode = tel_check_modem_power_status(__pTapiHandle, &modemStatus);
2292 if (errorCode != TAPI_API_SUCCESS || modemStatus == TAPI_PHONE_POWER_STATUS_OFF
2293 || modemStatus == TAPI_PHONE_POWER_STATUS_ERROR)
2299 TelSimCardStatus_t simStatus;
2300 int simChangedStatus;
2301 //fetch sim initialization status
2302 int errorCode = tel_get_sim_init_info(__pTapiHandle, &simStatus, &simChangedStatus);
2303 if (errorCode != TAPI_API_SUCCESS)
2311 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: // Sim Initialization ok
2315 case TAPI_SIM_STATUS_UNKNOWN: //initial state
2316 case TAPI_SIM_STATUS_CARD_NOT_PRESENT: //Card not present
2317 case TAPI_SIM_STATUS_CARD_REMOVED: //Card removed
2318 case TAPI_SIM_STATUS_CARD_ERROR: // Bad card / On the fly, SIM gone bad
2319 //TODO: might want to set different error code, to give proper message to user
2332 TelephonyManager::CheckIfMOCallIsEmergency(const String& contactNumber, bool isSimInitialized)
2334 //TODO: extract actual telephone number from contactNumber
2335 //by deleting prefix,'P','W', etx.
2337 bool isEmergency = false;
2338 //conversion "contactNumber" to char*
2339 const wchar_t* pContact = contactNumber.GetPointer();
2340 int len = contactNumber.GetLength() + 1;
2341 char* pNumber = new (std::nothrow) char[len];
2342 wcstombs(pNumber, pContact, len);
2344 if(isSimInitialized)
2346 //used to get Ecc information for 2G and 3G.
2347 TelSimEccList_t simEccList;
2348 memset(&simEccList, 0x00, sizeof(TelSimEccList_t));
2349 //Check if given number matches the sim card's emergency numbers
2350 int errorCode = tel_get_sim_ecc(__pTapiHandle, &simEccList);
2351 if (errorCode == TAPI_API_SUCCESS && simEccList.ecc_count > 0)
2353 for (int index = 0; index < simEccList.ecc_count; index++)
2355 if ((strcmp(pNumber, simEccList.list[index].number) == 0))
2364 //TODO: check if we need to also check SOS call numbers, if sim not present.
2373 TelephonyManager::FetchContactInfoForNumber(const String& phoneNumberStr)
2375 result r = E_FAILURE;
2377 //delete previously cached data
2378 if (__pCachedContact != null)
2380 delete __pCachedContact;
2381 __pCachedContact = null;
2384 //Searches contacts by phone number.
2385 IList* pContactList = __pAddressBook->SearchContactsByPhoneNumberN(phoneNumberStr);
2386 if (pContactList == null || IsFailed(GetLastResult()))
2391 //Fetch the contact's info to be displayed
2392 IEnumerator* pContactEnum = pContactList->GetEnumeratorN();
2393 while ((E_SUCCESS == pContactEnum->MoveNext()) && (__pCachedContact == null))
2395 Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
2397 IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
2398 if (pPhoneNumberList != null)
2400 IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
2401 while (E_SUCCESS == pPhoneEnum->MoveNext())
2403 PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
2404 //Check if this is the correct contact
2405 if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumberStr))
2407 //save newly fetched contact info.
2408 __pCachedContact = new (std::nothrow) Contact(*pContact);
2414 pPhoneNumberList->RemoveAll(true);
2415 delete pPhoneNumberList;
2418 delete pContactEnum;
2419 pContactList->RemoveAll(true);
2420 delete pContactList;
2426 TelephonyManager::GetContactN(const String& phoneNumber)
2428 result r = FetchContactInfoForNumber(phoneNumber);
2431 return new (std::nothrow) Contact(*__pCachedContact);
2437 TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const String& contactNumber)
2439 if(__pIncomingCall != null)
2441 delete __pIncomingCall;
2442 __pIncomingCall = null;
2445 if(callHandle.IsEmpty() == false)
2448 Integer::Parse(callHandle,incomingHandle);
2449 //This API call is synchronous
2450 TelCallStatus_t callStatus;
2451 int errCode = tel_get_call_status(__pTapiHandle, incomingHandle, &callStatus);
2452 if (errCode != TAPI_API_SUCCESS)
2454 AppLogDebug("tel_get_call_status failed");
2457 //construct incoming call info object
2458 __pIncomingCall = new (std::nothrow) AppCallInfo();
2459 __pIncomingCall->SetCallHandle(incomingHandle);
2462 String phoneNumber(contactNumber);
2463 if(phoneNumber.IsEmpty() == true)
2465 phoneNumber.Append(callStatus.pNumber);
2467 __pIncomingCall->SetContactNumber(phoneNumber);
2468 //set emergency state
2469 if(callStatus.CallType == TAPI_CALL_TYPE_E911)
2471 __pIncomingCall->SetEmergency(true);
2475 __pIncomingCall->SetEmergency(false);
2477 //set start time, when call is connected
2478 long long startTime = 0;
2479 SystemTime::GetTicks(startTime);
2480 __pIncomingCall->SetCallNotificationTime(startTime);
2481 __pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2485 //TODO: This 'else' block can be removed once AppControl request API is stabilized.
2486 //This API call is synchronous and 'HandleIncomingCallStatusCallBack' is called for each active call.
2487 int errCode = tel_get_call_status_all(__pTapiHandle, &HandleIncomingCallStatusCallBack, this);
2488 if (errCode != TAPI_API_SUCCESS)
2494 if(__pIncomingCall != null)
2496 //set call notification time
2497 long long startTime = 0;
2498 SystemTime::GetTicks(startTime);
2499 __pIncomingCall->SetCallNotificationTime(startTime);
2501 if(__pIncomingCall->GetContactNumber().IsEmpty() == false)
2503 //fetch contact info
2504 FetchContactInfoForNumber(__pIncomingCall->GetContactNumber());
2505 if (__pCachedContact != null)
2507 __pIncomingCall->SetContactInfo(*__pCachedContact);
2511 //construct a new callinfo object to pass its ownership to caller.
2512 AppCallInfo* pNewIncomingCall = new (std::nothrow) AppCallInfo();
2513 *pNewIncomingCall = *__pIncomingCall;
2514 return pNewIncomingCall;
2516 //return null, if no incoming call found
2521 TelephonyManager::HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus, void* pUserData)
2523 TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
2524 if (pCallStatus != null && pCallStatus->bMoCall == false
2525 && ((pCallStatus->CallState == TAPI_CALL_STATE_INCOMING)
2526 || (pCallStatus->CallState == TAPI_CALL_STATE_WAITING)))
2528 //construct incoming call details
2529 pTelManager->__pIncomingCall = new (std::nothrow) AppCallInfo();
2530 pTelManager->__pIncomingCall->SetCallHandle(pCallStatus->CallHandle);
2532 String contactNumber(pCallStatus->pNumber);
2533 pTelManager->__pIncomingCall->SetContactNumber(contactNumber);
2534 //set emergency state
2535 if(pCallStatus->CallType == TAPI_CALL_TYPE_E911)
2537 pTelManager->__pIncomingCall->SetEmergency(true);
2541 pTelManager->__pIncomingCall->SetEmergency(false);
2544 pTelManager->__pIncomingCall->SetCalllogType(CALL_LOG_TYPE_VOICE_INCOMING);
2549 TelephonyManager::SaveCallInfoToLogsDb(AppCallInfo& endCallInfo)
2551 if (endCallInfo.IsConferenceCall() == false)
2553 //single active call - Add call ended to call log database
2554 __pCalllogMgr->AddCallogInfoToDatabase(&endCallInfo);
2559 int confCallCount = endCallInfo.GetCallerListCount();
2560 IListT<AppCallInfo>* pParticipantList = endCallInfo.GetCallerList();
2561 for (int index = 0; index < confCallCount; index++)
2563 AppCallInfo participantInfo;
2564 if (pParticipantList->GetAt(index, participantInfo) == E_SUCCESS)
2566 //Add call ended to call log database
2567 __pCalllogMgr->AddCallogInfoToDatabase(&participantInfo);
2574 TelephonyManager::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
2577 if(networkStatus.IsCallServiceAvailable() == false)