Fix for 44593 42495
[apps/osp/Call.git] / src / CallTelephonyManager.cpp
index 9059e43..f1dacba 100644 (file)
@@ -1,7 +1,7 @@
 //
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
-// Licensed under the Flora License, Version 1.0 (the License);
+// Licensed under the Flora License, Version 1.1 (the License);
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <FBaseSys.h>
 #include <FSystem.h>
+#include <FTelephony.h>
 #include "ITapiModem.h"
 #include "ITapiSim.h"
 #include "CallInfo.h"
@@ -33,6 +34,8 @@ using namespace Tizen::Graphics;
 using namespace Tizen::Social;
 using namespace Tizen::System;
 using namespace Tizen::Base::Collection;
+using namespace Tizen::Telephony;
+using namespace Tizen::Base::Utility;
 
 const char* callEventList[] = {
                TAPI_NOTI_VOICE_CALL_STATUS_IDLE,
@@ -82,6 +85,7 @@ TelephonyManager::TelephonyManager(ITelephonyEventListener* pEventListener)
        __isSpeakerOn = false;
        __pSoundManager = null;
        __pCalllogMgr = null;
+       __pNetworkManager = null;
 }
 
 TelephonyManager::~TelephonyManager(void)
@@ -177,7 +181,7 @@ TelephonyManager::Initialize(void)
        {
                return r;
        }
-       __pActiveCallList = new (std::nothrow) HashMapT<long, CallInfo>();
+       __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
        __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
 
        //Initialize the Settings Manager to fetch call settings
@@ -192,6 +196,11 @@ TelephonyManager::Initialize(void)
        {
                return E_FAILURE;
        }
+       __pNetworkManager = new NetworkManager();
+       if(__pNetworkManager != null)
+       {
+               __pNetworkManager->Construct(this);
+       }
        return r;
 }
 
@@ -256,8 +265,8 @@ TelephonyManager::SetupMoCall(String& contactNumber, bool isEmergency)
        if (isEmergency && __pActiveCallList->GetCount() > 0)
        {
                //Get first call handle
-               CallInfo endCallInfo;
-               IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+               AppCallInfo endCallInfo;
+               IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
                pCallList->GetAt(0, endCallInfo);
                int callHandle = endCallInfo.GetCallHandle()->ToLong();
                delete pCallList;
@@ -279,8 +288,8 @@ TelephonyManager::SetupMoCall(String& contactNumber, bool isEmergency)
        {
                //Check if there is already an active call,
                //Put the already active call on hold.
-               CallInfo holdCallInfo;
-               IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+               AppCallInfo holdCallInfo;
+               IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
 
                pCallList->GetAt(0, holdCallInfo);
                //Check if call is active, then put on hold
@@ -329,14 +338,14 @@ result
 TelephonyManager::EndActiveCall(Long callHandle)
 {
        result r = E_FAILURE;
-
        //fetch ended callInfo from active call list
-       CallInfo endCall;
+       AppCallInfo endCall;
        r = __pActiveCallList->GetValue(callHandle.ToLong(), endCall);
        if (r == E_SUCCESS)
        {
                r = EndCall(endCall);
        }
+
        return r;
 }
 
@@ -352,7 +361,7 @@ TelephonyManager::EndDialingCall(String& contactNumber)
        }
 
        //Check If Ended call matches Dialed Call.
-       CallInfo endCall;
+       AppCallInfo endCall;
        if (__pDialedCall != null && __pDialedCall->GetContactNumber().Equals(contactNumber))
        {
                endCall = *__pDialedCall;
@@ -362,7 +371,7 @@ TelephonyManager::EndDialingCall(String& contactNumber)
 }
 
 result
-TelephonyManager::EndCall(CallInfo& endCallInfo)
+TelephonyManager::EndCall(AppCallInfo& endCallInfo)
 {
        result r = E_FAILURE;
 
@@ -380,8 +389,41 @@ TelephonyManager::EndCall(CallInfo& endCallInfo)
 }
 
 result
+TelephonyManager::AnswerAutoRejectCall(int callHandle)
+{
+       //Incoming call automatically blocked is handled here.
+       AppLogDebug("Enter ");
+       result r = E_FAILURE;
+       TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_REJECT;
+       int res = -1;
+
+       AppLogDebug("tel_answer_call");
+       //save to logs db.
+       AppCallInfo rejectedCallInfo;
+       rejectedCallInfo = *(__pIncomingCall);
+       rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
+       SaveCallInfoToLogsDb(rejectedCallInfo);
+       delete __pIncomingCall;
+       __pIncomingCall = null;
+
+       // redirect to reject call back handler as the flow has to be handled
+       res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleCallbackResponse, this);
+
+       if (res == TAPI_CAUSE_SUCCESS)
+       {
+               r = E_SUCCESS;
+       }
+       else
+       {
+               r = E_FAILURE;
+       }
+       return r;
+}
+
+result
 TelephonyManager::AnswerCall(int callHandle, bool acceptCall)
 {
+       AppLogDebug("Enter %d",acceptCall);
        result r = E_FAILURE;
        __pSoundManager->StopAlert();
        TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_ACCEPT;
@@ -394,6 +436,7 @@ TelephonyManager::AnswerCall(int callHandle, bool acceptCall)
        }
        else
        {
+               AppLogDebug("tel_answer_call");
                answerType = TAPI_CALL_ANSWER_REJECT;
                // redirect to reject call back handler as the flow has to be handled
                res = tel_answer_call(__pTapiHandle, callHandle, answerType, &HandleRejectCallbackResponse, this);
@@ -423,7 +466,7 @@ TelephonyManager::AcceptCall(CallAnsweringOptions answerOptions,int callHandle)
                //construct and fetch new Incoming call Info
                String incomingHandle;
                incomingHandle.Append(callHandle);
-               CallInfo* pDuplicateCallInfo = FetchIncomingCallHandleN(incomingHandle, String(L""));
+               AppCallInfo* pDuplicateCallInfo = FetchIncomingCallHandleN(incomingHandle, String(L""));
                if(pDuplicateCallInfo == null)
                {
                        r = E_FAILURE;
@@ -476,11 +519,11 @@ TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int
                //Call connected successfully
                r = E_SUCCESS;
                //update status of first call to "OnHold"
-               IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
-               CallInfo firstCallInfo;
+               IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
+               AppCallInfo firstCallInfo;
                pCallList->GetAt(0, firstCallInfo);
-               //replace old object with update CallInfo
-               CallInfo* pHeldCallInfo = new (std::nothrow) CallInfo();
+               //replace old object with update AppCallInfo
+               AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
                *pHeldCallInfo = firstCallInfo;
                pHeldCallInfo->SetOnHold(true);
                __pActiveCallList->Remove(firstCallInfo.GetCallHandle()->ToLong());
@@ -493,9 +536,9 @@ TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int
        case ANSERWING_OPTION_END_SINGLE_CALL:
        {
                //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
-               HashMapT<long, CallInfo>*  pEndCallsList = __pActiveCallList;
+               HashMapT<long, AppCallInfo>*  pEndCallsList = __pActiveCallList;
                //create a new ActiveCallList
-               __pActiveCallList = new (std::nothrow) HashMapT<long, CallInfo>();
+               __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
                __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
 
                //accept call and reject all active calls with 'TAPI_CALL_ANSWER_REPLACE'
@@ -512,10 +555,10 @@ TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int
                //Call connected successfully
                r = E_SUCCESS;
                //Add calls information to call log before deleting from active call list.
-               IListT<CallInfo>* pCallList = pEndCallsList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
                if(pCallList != null)
                {
-                       CallInfo endCallInfo;
+                       AppCallInfo endCallInfo;
                        if (pCallList->GetAt(0, endCallInfo) == E_SUCCESS)
                        {
                                SaveCallInfoToLogsDb(endCallInfo);
@@ -543,8 +586,8 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
        case ANSERWING_OPTION_REPLACE_ACTIVE_CALL:
        {
                //Replace "Active" call by incoming call and save ended call to call logs db.
-               IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
-               CallInfo callToBeEnded;
+               IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
+               AppCallInfo callToBeEnded;
                pCallList->GetAt(0, callToBeEnded);
                //Check if the call is on "Hold", then fetch 2nd callInfo
                if (callToBeEnded.IsOnHold() == true)
@@ -577,11 +620,11 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
        case ANSERWING_OPTION_REPLACE_HELD_CALL:
        {
                //Replace "Held" call by incoming call and save ended call to call logs db.
-               IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
                //"Held" call is to be ended
-               CallInfo callToBeEnded;
+               AppCallInfo callToBeEnded;
                //"Active" call will be put on Hold
-               CallInfo callToPutOnHold;
+               AppCallInfo callToPutOnHold;
                pCallList->GetAt(0, callToBeEnded);
                //Check if the call is NOT "Held", then fetch 2nd callInfo
                if (callToBeEnded.IsOnHold() == false)
@@ -607,11 +650,11 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                }
                else
                {
-                       IListT<CallInfo>* pParticipantsInfo = callToBeEnded.GetCallerList();
+                       IListT<AppCallInfo>* pParticipantsInfo = callToBeEnded.GetCallerList();
                        //need to end every participant individually for conference call
                        for (int index = 0; index < pParticipantsInfo->GetCount(); index++)
                        {
-                               CallInfo memberCallInfo;
+                               AppCallInfo memberCallInfo;
                                pParticipantsInfo->GetAt(index, memberCallInfo);
                                res = tel_end_call(__pTapiHandle, memberCallInfo.GetCallHandle()->ToLong(), TAPI_CALL_END, &HandleCallbackResponse, this);
                        }
@@ -638,7 +681,7 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                //Call connected successfully and active call is "Onhold"
                r = E_SUCCESS;
                //replace old object with update CallInfo
-               CallInfo* pHeldCallInfo = new (std::nothrow) CallInfo();
+               AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
                *pHeldCallInfo = callToPutOnHold;
                pHeldCallInfo->SetOnHold(true);
                __pActiveCallList->Remove(callToPutOnHold.GetCallHandle()->ToLong());
@@ -652,9 +695,9 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                // and processing of Incoming call is handled in HandleActiveCallback().
 
                //Transfer Old active calls to a separate list to avoid any processing in HandleIdleCallback().
-               HashMapT<long, CallInfo>*  pEndCallsList = __pActiveCallList;
+               HashMapT<long, AppCallInfo>*  pEndCallsList = __pActiveCallList;
                //create a new ActiveCallList
-               __pActiveCallList = new (std::nothrow) HashMapT<long, CallInfo>();
+               __pActiveCallList = new (std::nothrow) HashMapT<long, AppCallInfo>();
                __pActiveCallList->Construct(IDI_MAX_ACTIVE_CALLS);
 
                //End all active calls and all hold calls
@@ -677,13 +720,13 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                r = E_SUCCESS;
 
                //Add calls information to call log before deleting from active call list.
-               IListT<CallInfo>* pCallList = pEndCallsList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
                if(pCallList != null)
                {
                        int callCount = pCallList->GetCount();
                        for (int index = 0; index < callCount; index++)
                        {
-                               CallInfo endCallInfo;
+                               AppCallInfo endCallInfo;
                                if (pCallList->GetAt(index, endCallInfo) == E_SUCCESS)
                                {
                                        SaveCallInfoToLogsDb(endCallInfo);
@@ -711,11 +754,11 @@ TelephonyManager::HoldCall(Tizen::Base::Long callHandle, bool holdCall)
        //Check if there are any existing active calls
        if (__pActiveCallList->GetCount())
        {
-               IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
                int callCount = pCallList->GetCount();
                for (int index = 0; index < callCount; index++)
                {
-                       CallInfo holdCallInfo;
+                       AppCallInfo holdCallInfo;
 
                        r = pCallList->GetAt(index, holdCallInfo);
                        //check if an active call is found with matching contact no.
@@ -737,10 +780,10 @@ TelephonyManager::EndConferenceCall(void)
 {
        result r = E_FAILURE;
        //fetch conference callInfo to end
-       CallInfo confCallToEnd;
+       AppCallInfo confCallToEnd;
        bool isConferenceCallFound = false;
 
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
        int callCount = pCallList->GetCount();
        for (int index = 0; index < callCount; index++)
        {
@@ -776,10 +819,10 @@ TelephonyManager::HoldConferenceCall(bool holdCall)
 {
        result r = E_FAILURE;
        int confCallIndex = -1;
-       CallInfo confCallToHold;
+       AppCallInfo confCallToHold;
        bool isConferenceCallFound = false;
 
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
        int confCallCount = pCallList->GetCount();
 
        for (int index = 0; index < confCallCount; index++)
@@ -822,7 +865,7 @@ TelephonyManager::HoldConferenceCall(bool holdCall)
                {
                        confCallToHold.SetOnHold(false);
                }
-               CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+               AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
                *pConfCallInfo = confCallToHold;
                __pActiveCallList->Remove(callHandle);
                __pActiveCallList->Add(callHandle, *pConfCallInfo);
@@ -842,10 +885,10 @@ TelephonyManager::JoinCall(void)
 {
        result r = E_FAILURE;
        int res = -1;
-       CallInfo activeCall;
-       CallInfo heldCall;
+       AppCallInfo activeCall;
+       AppCallInfo heldCall;
        // Use enumerator to access elements in the map
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
        r = pCallList->GetAt(0, activeCall);
 
        if (r == E_SUCCESS)
@@ -881,7 +924,7 @@ TelephonyManager::JoinCall(void)
 }
 
 result
-TelephonyManager::HoldActiveCall(CallInfo* pActiveCallInfo, bool holdCall)
+TelephonyManager::HoldActiveCall(AppCallInfo* pActiveCallInfo, bool holdCall)
 {
        unsigned int callHandle = pActiveCallInfo->GetCallHandle()->ToLong();
        int retStatus = -1;
@@ -896,7 +939,7 @@ TelephonyManager::HoldActiveCall(CallInfo* pActiveCallInfo, bool holdCall)
 
        if (retStatus == TAPI_CAUSE_SUCCESS)
        {
-               CallInfo* pHeldCallInfo = new (std::nothrow) CallInfo();
+               AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
                //copy state into new callinfo object
                *pHeldCallInfo = *pActiveCallInfo;
 
@@ -919,10 +962,15 @@ TelephonyManager::DialOutgoingCall(String& contactNumber, bool isEmergency)
 {
        TelCallDial_t structDialCall;
 
-       AppLogDebug("Enter");
+       AppLogDebug("Enter %ls",contactNumber.GetPointer());
+       //Temp String to replace , with P and ; with W
+       String TempContactNum;
+       TempContactNum.Append(contactNumber);
+       TempContactNum.Replace(L",",L"W");
+       TempContactNum.Replace(L";",L",");
        //conversion "contactNumber" to char*
-       const wchar_t* pContact = contactNumber.GetPointer();
-       int len = contactNumber.GetLength()+1;
+       const wchar_t* pContact = TempContactNum.GetPointer();
+       int len = TempContactNum.GetLength()+1;
        char* pNumber = new (std::nothrow) char[len];
        wcstombs(pNumber, pContact, len);
 
@@ -956,7 +1004,7 @@ TelephonyManager::DialOutgoingCall(String& contactNumber, bool isEmergency)
                        delete __pDialedCall;
                        __pDialedCall = null;
                }
-               __pDialedCall = new (std::nothrow) CallInfo();
+               __pDialedCall = new (std::nothrow) AppCallInfo();
                __pDialedCall->SetContactNumber(contactNumber);
                __pDialedCall->SetEmergency(isEmergency);
                result r = FetchContactInfoForNumber(contactNumber);
@@ -1030,10 +1078,10 @@ TelephonyManager::EndFromConference(int callHandle)
 {
        result r = E_FAILURE;
        int confCallIndex = -1;
-       CallInfo endConfCall;
+       AppCallInfo endConfCall;
        bool isConferenceCallFound = false;
 
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
        int callCount = pCallList->GetCount();
        for (int index = 0; index < callCount; index++)
        {
@@ -1057,8 +1105,8 @@ TelephonyManager::EndFromConference(int callHandle)
        }
 
        //Identify the call to be ended and remove from list on API success
-       CallInfo callToBeEnded;
-       IListT<CallInfo>* pParticipantList = endConfCall.GetCallerList();
+       AppCallInfo callToBeEnded;
+       IListT<AppCallInfo>* pParticipantList = endConfCall.GetCallerList();
        int participantCount = pParticipantList->GetCount();
        for (int index = 0; index < participantCount; index++)
        {
@@ -1089,10 +1137,10 @@ TelephonyManager::SplitFromConference(int callHandle)
 {
        result r = E_FAILURE;
        int confCallIndex = -1;
-       CallInfo endConfCall;
+       AppCallInfo endConfCall;
        bool isConferenceCallFound = false;
 
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
        int callCount = pCallList->GetCount();
        for (int index = 0; index < callCount; index++)
        {
@@ -1114,7 +1162,7 @@ TelephonyManager::SplitFromConference(int callHandle)
        }
 
        //Identify the call to be ended and remove from list on API success
-       CallInfo callToBeEnded;
+       AppCallInfo callToBeEnded;
        pCallList = endConfCall.GetCallerList();
        callCount = pCallList->GetCount();
        for (int index = 0; index < callCount; index++)
@@ -1234,6 +1282,21 @@ TelephonyManager::HandleDialCallbackResponse(TapiHandle* pHandle, int callBackRe
                        delete pTelManager->__pDialedCall;
                        pTelManager->__pDialedCall = null;
                }
+
+               //Check if there are no active connected calls and no incoming call.
+               if (pTelManager->__pIncomingCall != null)
+               {
+                       pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
+               }
+               else if (pTelManager->GetCurrentCallCount() >= 1)
+               {
+                       pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
+               }
+               else
+               {
+                       pTelManager->__pSettingsManager->SetCallState(CALL_STATE_CALL_OFF);
+               }
+
                pTelManager->__pEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
        }
 }
@@ -1242,8 +1305,7 @@ void
 TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData)
 {
        AppLogDebug("ENTER");
-       // This callback comes only if user has either rejected an incoming call from IncomingCallForm.
-       // or the incoming call was automatically blocked.
+       // This callback comes only if user has rejected an incoming call from IncomingCallForm.
        TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
        if (pData != null && callBackResult == TAPI_API_SUCCESS)
        {
@@ -1253,65 +1315,48 @@ TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBack
                //Check if incoming call is rejected
                if (pTelManager->__pIncomingCall != null && (rejectedCallHandle == (unsigned int) pTelManager->__pIncomingCall->GetCallHandle()->ToLong()))
                {
-                       CallInfo rejectedCallInfo;
+                       AppLogDebug("Call rejected by user");
+                       AppCallInfo rejectedCallInfo;
                        rejectedCallInfo = *(pTelManager->__pIncomingCall);
                        delete pTelManager->__pIncomingCall;
                        pTelManager->__pIncomingCall = null;
 
-                       //Check if number was automatically rejected using settings, then don't give any notification to user.
-                       bool showIncomingCallRejectedNotification = true;
-                       if (((pTelManager->__pSettingsManager->GetUnknownRejectStatus() == true) && (rejectedCallInfo.GetContactInfo() == null))
-                                               || (pTelManager->__pSettingsManager->IsCallToBeRejected(rejectedCallInfo.GetContactNumber()) == true))
-                       {
-                               //blocked
-                               AppLogDebug("Call blocked");
-                               showIncomingCallRejectedNotification = false;
-                               rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_BLOCKED);
-                       }
-                       else
-                       {
-                               AppLogDebug("Call rejected");
-                               //rejected by user from incoming call form
-                               showIncomingCallRejectedNotification = true;
-                               rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_REJECTED);
-                       }
+                       //rejected by user from incoming call form
+                       rejectedCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_REJECTED);
                        //Save rejected incoming call to call log db.
                        pTelManager->SaveCallInfoToLogsDb(rejectedCallInfo);
 
-                       if (showIncomingCallRejectedNotification == true)
+                       //check if the ended call was the last call
+                       bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
+                       //Stop alert - started only for incoming calls which are not blocked.
+                       if(pTelManager->__pSoundManager != null)
                        {
-                               //check if the ended call was the last call
-                               bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
-                               //Stop alert - started only for incoming calls which are not blocked.
-                               if(pTelManager->__pSoundManager != null)
+                               pTelManager->__pSoundManager->StopAlert();
+                               //Do not call stop session if there is already a call going on
+                               if(isLastCall == true)
                                {
-                                       pTelManager->__pSoundManager->StopAlert();
-                                       //Do not call stop session if there is already a call going on
-                                       if(isLastCall == true)
-                                       {
-                                               pTelManager->__pSoundManager->StopSession();
-                                       }
-                               }
-                               //Send notification to user
-                               ArrayListT<CallInfo>* pCallList = null;
-                               if (isLastCall)
-                               {
-                                       //save 'RejectedCall' to list to show on EndCallForm
-                                       pCallList = new (std::nothrow) ArrayListT<CallInfo>();
-                                       pCallList->Construct(1);
-                                       CallInfo* pRejectedCall = new (std::nothrow) CallInfo();
-                                       *pRejectedCall = rejectedCallInfo;
-                                       pCallList->Add(*pRejectedCall);
+                                       pTelManager->__pSoundManager->StopSession();
                                }
-                               else
-                               {
-                                       //fetch active calls to show appropriate scene
-                                       pCallList = static_cast<ArrayListT<CallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
-                               }
-                               pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
-                               delete pCallList;
-                               pCallList = null;
                        }
+                       //Send notification to user
+                       ArrayListT<AppCallInfo>* pCallList = null;
+                       if (isLastCall)
+                       {
+                               //save 'RejectedCall' to list to show on EndCallForm
+                               pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
+                               pCallList->Construct(1);
+                               AppCallInfo* pRejectedCall = new (std::nothrow) AppCallInfo();
+                               *pRejectedCall = rejectedCallInfo;
+                               pCallList->Add(*pRejectedCall);
+                       }
+                       else
+                       {
+                               //fetch active calls to show appropriate scene
+                               pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+                       }
+                       pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
+                       delete pCallList;
+                       pCallList = null;
                }
        }
        else
@@ -1329,14 +1374,14 @@ TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackRe
        {
                unsigned int tempHandle = 0;
                TelCallInfoJoinedNoti_t joinedInfoNotification;
-               CallInfo confCallInfo;
+               AppCallInfo confCallInfo;
 
                memcpy(&tempHandle, pData, sizeof(TS_UINT));
                joinedInfoNotification.id = tempHandle;
-               CallInfo activeCall;
-               CallInfo heldCall;
+               AppCallInfo activeCall;
+               AppCallInfo heldCall;
                // Use enumerator to access elements in the map
-               IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
                result r = pCallList->GetAt(0, activeCall);
 
                if (r == E_SUCCESS)
@@ -1344,7 +1389,7 @@ TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackRe
                        r = pCallList->GetAt(1, heldCall);
                        if (r == E_SUCCESS)
                        {
-                               CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+                               AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
                                unsigned int activeCallHandle = activeCall.GetCallHandle()->ToLong();
                                unsigned int heldCallHandle = heldCall.GetCallHandle()->ToLong();
                                if (activeCall.IsConferenceCall() == true)
@@ -1422,12 +1467,12 @@ TelephonyManager::HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackRe
        TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
        if (callBackResult == TAPI_CAUSE_SUCCESS)
        {
-               IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
                IListT<long>* pKeyList = pTelManager->__pActiveCallList->GetKeysN();
                int callCount = pTelManager->__pActiveCallList->GetCount();
                for (int index = 0; index < callCount; index++)
                {
-                       CallInfo* pTempCallInfo = new (std::nothrow) CallInfo();
+                       AppCallInfo* pTempCallInfo = new (std::nothrow) AppCallInfo();
                        pCallList->GetAt(index, *pTempCallInfo);
                        (pTempCallInfo->IsOnHold() == false) ? pTempCallInfo->SetOnHold(true) : pTempCallInfo->SetOnHold(false);
                        long callHandle;
@@ -1461,9 +1506,9 @@ TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, i
                TelCallEndCnf_t callEndNotification;
                memcpy(&callEndNotification, pData, sizeof(TelCallEndCnf_t));
                //Fetch conference call
-               CallInfo endConfCall;
+               AppCallInfo endConfCall;
                bool isConferenceCallFound = false;
-               IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
                int callCount = pCallList->GetCount();
                for (int index = 0; index < callCount; index++)
                {
@@ -1484,6 +1529,10 @@ TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, i
                        isParticipantCallEnded = pTelManager->HandleParticipantEndedFromConference(callEndNotification.id, endConfCall);
                }
        }
+       else
+       {
+               AppLog("TAPI Failed - %d", callBackResult);
+       }
 
        //Check if participant call or Conference call was not found, then show error
        if (isParticipantCallEnded == false)
@@ -1494,14 +1543,14 @@ TelephonyManager::HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, i
 }
 
 bool
-TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantCallHandle, CallInfo& conferenceCall)
+TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantCallHandle, AppCallInfo& conferenceCall)
 {
        AppLogDebug("ENTER");
        //to check if participant call was found and ended.
        bool isParticipantCallEnded = false;
        //Identify the call to be ended and remove from list.
-       CallInfo callToBeEnded;
-       IListT<CallInfo>* pCallerList = conferenceCall.GetCallerList();
+       AppCallInfo callToBeEnded;
+       IListT<AppCallInfo>* pCallerList = conferenceCall.GetCallerList();
        int callerCount = pCallerList->GetCount();
        for (int index = 0; index < callerCount; index++)
        {
@@ -1528,11 +1577,11 @@ TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantC
        //Check if last participant removed. If yes, switch to single active view
        if (conferenceCall.GetCallerListCount() == 1)
        {
-               CallInfo callFromList;
+               AppCallInfo callFromList;
                pCallerList = conferenceCall.GetCallerList();
                pCallerList->GetAt(0, callFromList);
                //construct a new single active call
-               CallInfo* pActiveCall = new (std::nothrow) CallInfo();
+               AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
                *pActiveCall = callFromList;
                //update conference status and Hold status
                pActiveCall->SetConference(false);
@@ -1541,20 +1590,21 @@ TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantC
                __pActiveCallList->Remove(confCallHandle);
                __pActiveCallList->Add(pActiveCall->GetCallHandle()->ToLong(), *pActiveCall);
                pActiveCall = null;
+
                //using the callConnected to switch to single active screen
                //or update multiple active call screen
-               IListT<CallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
+               IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
                __pEventListener->HandleCallConnected(*pActiveCallList);
                delete pActiveCallList;
                pActiveCallList = null;
        }
        else
        {
-               CallInfo callFromList;
+               AppCallInfo callFromList;
                pCallerList = conferenceCall.GetCallerList();
                pCallerList->GetAt(0, callFromList);
                //construct a new conference call
-               CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+               AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
                *pConfCallInfo = conferenceCall;
                if (confCallHandle == participantCallHandle)
                {
@@ -1583,10 +1633,10 @@ TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle,
                TelCallSplitCnf_t callSplitNotification;
                memcpy(&callSplitNotification, pData, sizeof(TelCallSplitCnf_t));
                int confCallIndex = -1;
-               CallInfo endConfCall;
+               AppCallInfo endConfCall;
                bool isConferenceCallFound = false;
 
-               IListT<CallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = pTelManager->__pActiveCallList->GetValuesN();
                int callCount = pCallList->GetCount();
                for (int index = 0; index < callCount; index++)
                {
@@ -1609,7 +1659,7 @@ TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle,
                delete pCallList;
                pCallList = null;
                //Identify the call to be ended and remove from list on API success
-               CallInfo callToBeEnded;
+               AppCallInfo callToBeEnded;
                pCallList = endConfCall.GetCallerList();
                callCount = pCallList->GetCount();
                for (int index = 0; index < callCount; index++)
@@ -1629,10 +1679,10 @@ TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle,
                {
                        //Set hold for the other single call
                        // and add to the list
-                       CallInfo callFromList;
+                       AppCallInfo callFromList;
                        pCallList = endConfCall.GetCallerList();
                        pCallList->GetAt(0, callFromList);
-                       CallInfo* pHeldCall = new (std::nothrow) CallInfo();
+                       AppCallInfo* pHeldCall = new (std::nothrow) AppCallInfo();
                        *pHeldCall = callFromList;
                        pHeldCall->SetConference(false);
                        pHeldCall->SetOnHold(true);
@@ -1644,11 +1694,11 @@ TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle,
                {
                        //Set hold flag for conference call
                        endConfCall.SetOnHold(true);
-                       CallInfo callFromList;
+                       AppCallInfo callFromList;
                        pCallList = endConfCall.GetCallerList();
                        pCallList->GetAt(0, callFromList);
 
-                       CallInfo* pConfCallInfo = new (std::nothrow) CallInfo();
+                       AppCallInfo* pConfCallInfo = new (std::nothrow) AppCallInfo();
                        *pConfCallInfo = endConfCall;
                        if (confCallHandle == callSplitNotification.id)
                        {
@@ -1666,7 +1716,7 @@ TelephonyManager::HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle,
                        }
                }
                //Add the new active call to active call list
-               CallInfo* pActiveCall = new (std::nothrow) CallInfo();
+               AppCallInfo* pActiveCall = new (std::nothrow) AppCallInfo();
                *pActiveCall = callToBeEnded;
                pActiveCall->SetConference(false);
                pActiveCall->SetOnHold(false);
@@ -1690,12 +1740,13 @@ TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int c
        AppLog("ENTER");
        //This callback comes only if a conference call is ended by user.
        TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
+       AppCallInfo heldCall;
        if (callBackResult == TAPI_CAUSE_SUCCESS && pData != null)
        {
                //fetch ended confCall details
                result r = E_FAILURE;
-               CallInfo endConfCallInfo;
-               IListT<CallInfo>* pActiveCallList = pTelManager->__pActiveCallList->GetValuesN();
+               AppCallInfo endConfCallInfo;
+               IListT<AppCallInfo>* pActiveCallList = pTelManager->__pActiveCallList->GetValuesN();
                if(pActiveCallList != null && pActiveCallList->GetCount() > 0)
                {
                        for (int index = 0; index < pActiveCallList->GetCount(); index++)
@@ -1728,19 +1779,39 @@ TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int c
 
                //check if the ended call was the last call and show notification to user
                bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
-               ArrayListT<CallInfo>* pCallList = null;
+               ArrayListT<AppCallInfo>* pCallList = null;
                if (isLastCall)
                {
                        pTelManager->__pSoundManager->SetlastEndedConferenceCall();
                        //stop sound session
                        pTelManager->__pSoundManager->StopSession();
                        //send empty call list to show dialer or call log screen
-                       pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+                       pCallList =new (std::nothrow) ArrayListT<AppCallInfo>();
+                       pCallList->Construct(1);
+                       pCallList->Add(endConfCallInfo);
                }
                else
                {
                        //fetch active calls to show appropriate scene
-                       pCallList = static_cast<ArrayListT<CallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+                       pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+                       r = pCallList->GetAt(0, heldCall);
+                       if (r == E_SUCCESS)
+                       {
+                               //pTelManager->HoldActiveCall(&heldCall, false);
+                               AppCallInfo* pHeldCallInfo = new (std::nothrow) AppCallInfo();
+                               unsigned int callHandle = heldCall.GetCallHandle()->ToLong();
+                               //copy state into new callinfo object
+                               *pHeldCallInfo = heldCall;
+
+                               //set call to hold state
+                               pHeldCallInfo->SetOnHold(false);
+
+                               pTelManager->__pActiveCallList->Remove(callHandle);
+                               //replace old object with new
+                               pTelManager->__pActiveCallList->Add(callHandle, *pHeldCallInfo);
+                               delete pCallList;
+                               pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+                       }
                }
                //notify listener that call is disconnected.
                pTelManager->__pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
@@ -1761,7 +1832,7 @@ TelephonyManager::HandleIdleCallBack(void* pData)
        //This callback comes when any type of calls are ended
        //We do NOT handle below scenarios here -
        //1) In incoming call scenarios, if we end any active calls - handled in "AcceptCall()".
-       //2) Incoming call automatically blocked and rejection by user scenarios are handled in "HandleRejectCallbackResponse()".
+       //2) Incoming call automatically blocked is handled in "AnswerAutoRejectCall()" and rejection by user scenarios are handled in "HandleRejectCallbackResponse()".
        //3) End conference call is handled in "HandleEndConferenceCallbackResponse()".
        //4) End Single Call from Conference call by user is handled in "HandleEndFromConferenceCallbackResponse()".
        //5) End Single Call from Conference call using eventInjector is diverted to "HandleParticipantEndedFromConference()".
@@ -1770,10 +1841,7 @@ TelephonyManager::HandleIdleCallBack(void* pData)
        //2) an "unconnected" dialed call is ended by caller or other party.
        //3) Any normal active calls(NOT conference calls) ended by user or by other party.
 
-       if(__pSoundManager->GetLastConferenceCall() == false)
-       {
-               __pSoundManager->SetDisconnectTone();
-       }
+
 
        TelCallStatusIdleNoti_t idleNotification;
        memcpy(&idleNotification, pData, sizeof(TelCallStatusIdleNoti_t));
@@ -1781,19 +1849,22 @@ TelephonyManager::HandleIdleCallBack(void* pData)
        unsigned int endCallHandle = idleNotification.id;
 
        //empty active call list or no dialed or incoming calls - ignore this event
-       IListT<CallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
        if((pActiveCallList == null || pActiveCallList->GetCount() <= 0) && __pDialedCall == null && __pIncomingCall == null)
        {
                delete pActiveCallList;
                AppLogDebug("EXIT - no calls exist");
                return;
        }
-
+       if(__pSoundManager->GetLastConferenceCall() == false)
+       {
+               __pSoundManager->SetDisconnectTone();
+       }
        //Check if ended call was among conference caller list,
        //then divert event to "HandleParticipantEndedFromConference()"
-       CallInfo confCallInfo;
+       AppCallInfo confCallInfo;
        bool isConferenceCallChanged = false;
-       for (int index = 0; index < pActiveCallList->GetCount(); index++)
+       for (int index = 0; (pActiveCallList != null && index < pActiveCallList->GetCount()); index++)
        {
                //fetch conference call
                result r = pActiveCallList->GetAt(index, confCallInfo);
@@ -1811,11 +1882,12 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                //end call event handled - conference call will now either remain as conf. call
                //or become single active call, if it has only 1 participant left.
                __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
+               AppLogDebug("isConferenceCallChanged == true");
                return;
        }
 
        //check if ended call was among the active call list and not a conference call
-       CallInfo endCallInfo;
+       AppCallInfo endCallInfo;
        result r = __pActiveCallList->GetValue(endCallHandle, endCallInfo);
        if (r == E_SUCCESS)
        {
@@ -1828,7 +1900,7 @@ TelephonyManager::HandleIdleCallBack(void* pData)
        }
 
        //Check if dialed call is rejected by other party
-       bool isDialedCallEnded = ((__pDialedCall != null)  && (((unsigned int)__pDialedCall->GetCallHandle()->ToLong()) == idleNotification.id));
+       bool isDialedCallEnded = ((__pDialedCall != null)  && (__pDialedCall->GetCallHandle() != null) &&(((unsigned int)__pDialedCall->GetCallHandle()->ToLong()) == idleNotification.id));
        //Check if "missed" incoming call is ended
        bool isMissedIncomingCallEnded = (__pIncomingCall != null && ((unsigned int)__pIncomingCall->GetCallHandle()->ToLong() == idleNotification.id));
        if (isDialedCallEnded == true || isMissedIncomingCallEnded == true)
@@ -1836,7 +1908,7 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                //It comes here only if the ended call was either a "unconnected" dialed call or an "Missed" incoming call.
                bool isLastCall = (__pActiveCallList->GetCount() == 0);
 
-               ArrayListT<CallInfo>* pCallList = null;
+               ArrayListT<AppCallInfo>* pCallList = null;
                //Check if dialed call was ended
                if (isDialedCallEnded == true)
                {
@@ -1855,7 +1927,9 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                        delete __pIncomingCall;
                        __pIncomingCall = null;
                        //update missed status
-                       endCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED);
+                       endCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED_UNSEEN);
+                       //save ended call to call log db.
+                       //SaveCallInfoToLogsDb(endCallInfo);
                }
                //save ended call to call log db.
                SaveCallInfoToLogsDb(endCallInfo);
@@ -1864,9 +1938,14 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                if (isLastCall == true)
                {
                        __pSoundManager->StopSession();
-                       pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+                       pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
                        pCallList->Construct(1);
-                       if (isMissedIncomingCallEnded == false)
+               //This is done to show end call form in missed call case also
+               //this was done on request received from HQ to solve a bug in
+               //camera application. In which if a call comes when camera is
+               //running and user disconnects before the ui is shown the camera
+               //application hangs
+                       //if (isMissedIncomingCallEnded == false)
                        {
                                //save to list to show EndCallForm
                                pCallList->Add(endCallInfo);
@@ -1876,7 +1955,7 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                }
                else
                {
-                       pCallList = static_cast<ArrayListT<CallInfo>*>(__pActiveCallList->GetValuesN());
+                       pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
                }
                __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
                delete pCallList;
@@ -1887,8 +1966,11 @@ TelephonyManager::HandleIdleCallBack(void* pData)
 }
 
 bool
-TelephonyManager::HandleEndNormalActiveCall(CallInfo& endCallInfo)
+TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
 {
+       AppLogDebug("Enter");
+       result r = E_FAILURE;
+       AppCallInfo heldCall;
        // This function gets called only from HandleIdleCallback(),
        // to handle disconnection of normal active calls.
        if (endCallInfo.IsConferenceCall() == false)
@@ -1897,20 +1979,31 @@ TelephonyManager::HandleEndNormalActiveCall(CallInfo& endCallInfo)
                __pActiveCallList->Remove(endCallInfo.GetCallHandle()->ToLong());
                //check if the ended call was the last call and show notification to user
                bool isLastCall = (__pActiveCallList->GetCount() == 0);
-               ArrayListT<CallInfo>* pCallList = null;
+               ArrayListT<AppCallInfo>* pCallList = null;
                if (isLastCall)
                {
                        //stop sound session
                        __pSoundManager->StopSession();
                        //save "End" CallInfo to list to show EndCallForm
-                       pCallList = new (std::nothrow) ArrayListT<CallInfo>();
+                       pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
                        pCallList->Construct(1);
                        pCallList->Add(endCallInfo);
                }
                else
                {
-                       //fetch active calls to show appropriate scene
-                       pCallList = static_cast<ArrayListT<CallInfo>*>(__pActiveCallList->GetValuesN());
+                       if(__pIncomingCall == null)
+                       {
+                               //fetch active calls to show appropriate scene
+                               pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
+                               //fetch the held call on disconnecting the active call and activate it.
+                               r = pCallList->GetAt(0, heldCall);
+                               if (r == E_SUCCESS)
+                               {
+                                       HoldActiveCall(&heldCall, false);
+                                       delete pCallList;
+                                       pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
+                               }
+                       }
                }
 
                //Save "End" call info to call log database
@@ -1927,6 +2020,7 @@ TelephonyManager::HandleEndNormalActiveCall(CallInfo& endCallInfo)
 void
 TelephonyManager::HandleDialingCallBack(void* pData)
 {
+       AppLogDebug("Enter");
        unsigned int tempHandle = 0;
        TelCallStatusDialingNoti_t dialingNotification;
        memcpy(&tempHandle, pData, sizeof(TS_UINT));
@@ -1935,8 +2029,9 @@ TelephonyManager::HandleDialingCallBack(void* pData)
        //Dont check for call handle, since this is the first time, we get call handle for a dialed call.
        if (__pDialedCall == null)
        {
+               AppLogDebug("__pDialedCall == null");
                //construct new dialed call
-               __pDialedCall = new (std::nothrow) CallInfo();
+               __pDialedCall = new (std::nothrow) AppCallInfo();
 
                TelCallStatus_t callStatus;
                int res = tel_get_call_status(__pTapiHandle, dialingNotification.id, &callStatus);
@@ -1970,6 +2065,7 @@ TelephonyManager::HandleDialingCallBack(void* pData)
        long long startTime = 0;
        SystemTime::GetTicks(startTime);
        __pDialedCall->SetCallNotificationTime(startTime);
+       //SaveCallInfoToLogsDb(*__pDialedCall);
 }
 
 void
@@ -1981,13 +2077,13 @@ TelephonyManager::HandleActiveCallBack(void* pData)
        TelCallStatusActiveNoti_t activeNotification;
        memcpy(&newCallHandle, pData, sizeof(TS_UINT));
        activeNotification.id = newCallHandle;
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
 
        //Check if the "Held" call was activated, i.e it is already present in already activated calls list.
        bool toHandleEvent = true;
        for (int callIndex = 0; (callIndex < pCallList->GetCount() && toHandleEvent == true); callIndex++ )
        {
-               CallInfo tempCallInfo;
+               AppCallInfo tempCallInfo;
                pCallList->GetAt(callIndex, tempCallInfo);
                unsigned int tempCallHandle = tempCallInfo.GetCallHandle()->ToLong();
                //Check if active callback came for "HandleJoinCallbackResponse"
@@ -2001,11 +2097,11 @@ TelephonyManager::HandleActiveCallBack(void* pData)
                        else
                        {
                                //check individual participants of conf call
-                               IListT<CallInfo>* pConfCallList = tempCallInfo.GetCallerList();
+                               IListT<AppCallInfo>* pConfCallList = tempCallInfo.GetCallerList();
                                int confCallCount  = pConfCallList->GetCount();
                                for (int callIndex = 0; (callIndex < confCallCount && toHandleEvent == true); callIndex++)
                                {
-                                       CallInfo confCallerInfo;
+                                       AppCallInfo confCallerInfo;
                                        pConfCallList->GetAt(callIndex, confCallerInfo);
                                        unsigned int confCallerHandle = confCallerInfo.GetCallHandle()->ToLong();
                                        if (confCallerHandle == activeNotification.id)
@@ -2037,7 +2133,7 @@ TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
 {
        //Here it comes, only if either new dialed or incoming call was connected.
        //This function should be called only from "HandleActiveCallback()".
-       CallInfo* pConnectedCall = null;
+       AppCallInfo* pConnectedCall = null;
        //to check if incoming call was connected
        bool isIncomingCallConnected = false;
 
@@ -2061,7 +2157,7 @@ TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
                // Otherwise Correct the code in some other function, if it comes here.
                AppLogDebug("Error - Connected call was neither one of active calls nor it was dialed or incoming call");
                //Construct a new CallInfo object for call
-               pConnectedCall = new (std::nothrow) CallInfo();
+               pConnectedCall = new (std::nothrow) AppCallInfo();
                pConnectedCall->SetCallHandle(connectedCallHandle);
 
                TelCallStatus_t callStatus;
@@ -2121,10 +2217,14 @@ TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
 
        //transfer ownership to Active calls list
        __pActiveCallList->Add(connectedCallHandle, *(pConnectedCall));
+/*     if (pConnectedCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_INCOMING)
+       {
+               SaveCallInfoToLogsDb(*pConnectedCall);
+       }*/
        pConnectedCall = null;
 
        //notify listener that call is connected.
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
        __pSoundManager->SetSoundMode(SOUND_MODE_VOICE);
        __pEventListener->HandleCallConnected(*pCallList);
        if (isIncomingCallConnected == true)
@@ -2136,18 +2236,22 @@ TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
 }
 
 bool
-TelephonyManager::CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo)
+TelephonyManager::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
 {
+       AppLogDebug("Enter");
        int callHandle = pIncomingCallInfo->GetCallHandle()->ToLong();
        String contactNumber(L"");
        contactNumber.Append(pIncomingCallInfo->GetContactNumber());
        //Check if "reject unknown calls" is set and contact number is not present in AddressBook
        //or if contact number is blacklisted
-       if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pIncomingCallInfo->GetContactInfo() == null))
-                       || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
+       if(__pSettingsManager != null)
        {
-               AnswerCall(callHandle,false);
-               return true;
+               if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pIncomingCallInfo->GetContactInfo() == null))
+                               || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
+               {
+                       AnswerAutoRejectCall(callHandle);
+                       return true;
+               }
        }
        return false;
 }
@@ -2155,6 +2259,7 @@ TelephonyManager::CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo)
 void
 TelephonyManager::HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
 {
+       AppLogDebug("Enter");
        unsigned int tempHandle = 0;
        TelephonyManager* pTelManager = (TelephonyManager*) pUserData;
        if (pTelManager->__pSoundManager == null)
@@ -2182,20 +2287,20 @@ TelephonyManager::HandleCallback(TapiHandle* pHandle, const char* pNotiId, void*
        }
 }
 
-CallInfo*
+AppCallInfo*
 TelephonyManager::GetConferenceCallInfoN(void)
 {
-       CallInfo* pConfCallInfo = null;
+       AppCallInfo* pConfCallInfo = null;
 
-       IListT<CallInfo>* pCallList = __pActiveCallList->GetValuesN();
+       IListT<AppCallInfo>* pCallList = __pActiveCallList->GetValuesN();
        int callCount = pCallList->GetCount();
        for (int index = 0; index < callCount; index++)
        {
-               CallInfo callInfo;
+               AppCallInfo callInfo;
                pCallList->GetAt(index, callInfo);
                if (callInfo.IsConferenceCall() == true)
                {
-                       pConfCallInfo = new (std::nothrow) CallInfo();
+                       pConfCallInfo = new (std::nothrow) AppCallInfo();
                        *pConfCallInfo = callInfo;
                        //Found the Conference call
                        break;
@@ -2207,13 +2312,13 @@ TelephonyManager::GetConferenceCallInfoN(void)
        return pConfCallInfo;
 }
 
-IListT<CallInfo>*
+IListT<AppCallInfo>*
 TelephonyManager::GetCallListN(void)
 {
-       ArrayListT<CallInfo>* pCallList = null;
+       ArrayListT<AppCallInfo>* pCallList = null;
        if (__pActiveCallList != null)
        {
-               pCallList = static_cast<ArrayListT<CallInfo>*>(__pActiveCallList->GetValuesN());
+               pCallList = static_cast<ArrayListT<AppCallInfo>*>(__pActiveCallList->GetValuesN());
        }
        return pCallList;
 }
@@ -2229,7 +2334,7 @@ TelephonyManager::GetCurrentCallCount(void)
 }
 
 void
-TelephonyManager::StartAlert(CallInfo& incomingCallInfo)
+TelephonyManager::StartAlert(AppCallInfo& incomingCallInfo)
 {
        String contactRingTone(L"");
        String contactNumber = incomingCallInfo.GetContactNumber();
@@ -2242,6 +2347,16 @@ TelephonyManager::StartAlert(CallInfo& incomingCallInfo)
                {
                        //fetch custom ringtone for contact
                        result r = foundContact->GetValue(CONTACT_PROPERTY_ID_RINGTONE, contactRingTone);
+                       //Now check if there is a group ring tone
+                       if(contactRingTone.IsEmpty() == true)
+                       {
+                               IList* pCategoryList = __pAddressBook->GetCategoriesByContactN(foundContact->GetRecordId());
+                               if(pCategoryList != null && pCategoryList->GetCount() > 0)
+                               {
+                                       Category* pCategory = static_cast<Category*>(pCategoryList->GetAt(0));
+                                       contactRingTone = pCategory->GetRingtonePath();
+                               }
+                       }
                        AppLog("ringtone fetched - r = %d", r);
                        delete foundContact;
                        foundContact = null;
@@ -2264,6 +2379,19 @@ TelephonyManager::CheckValidTelePhoneNumber(const String& contactNumber)
        {
                r = E_FAILURE;
        }
+
+       //Pattern to compare all characters except 0-9 * # P ; , +
+       String phoneNumberPattern(L"[^0-9*#P,p+;]");
+       RegularExpression checkPhoneNumber;
+       checkPhoneNumber.Construct(phoneNumberPattern);
+       //If there is any character other than these listed above then display invalid number
+       bool resultMatch = checkPhoneNumber.Match(contactNumber,false);
+       //return false for patterns other than 0-9 * # P ; , +
+       if(resultMatch == true)
+       {
+               //return phone number is invalid
+               r = E_FAILURE;
+       }
        //TODO: check if valid phone number else return error message
        return r;
 }
@@ -2420,7 +2548,7 @@ TelephonyManager::GetContactN(const String& phoneNumber)
        return null;
 }
 
-CallInfo*
+AppCallInfo*
 TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const String& contactNumber)
 {
        if(__pIncomingCall != null)
@@ -2442,7 +2570,7 @@ TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const Strin
                        return null;
                }
                //construct incoming call info object
-               __pIncomingCall = new (std::nothrow) CallInfo();
+               __pIncomingCall = new (std::nothrow) AppCallInfo();
                __pIncomingCall->SetCallHandle(incomingHandle);
 
                //contact number
@@ -2496,7 +2624,7 @@ TelephonyManager::FetchIncomingCallHandleN(const String& callHandle, const Strin
                }
 
                //construct a new callinfo object to pass its ownership to caller.
-               CallInfo* pNewIncomingCall = new (std::nothrow) CallInfo();
+               AppCallInfo* pNewIncomingCall = new (std::nothrow) AppCallInfo();
                *pNewIncomingCall = *__pIncomingCall;
                return pNewIncomingCall;
        }
@@ -2513,7 +2641,7 @@ TelephonyManager::HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus,
                                        || (pCallStatus->CallState == TAPI_CALL_STATE_WAITING)))
        {
                //construct incoming call details
-               pTelManager->__pIncomingCall = new (std::nothrow) CallInfo();
+               pTelManager->__pIncomingCall = new (std::nothrow) AppCallInfo();
                pTelManager->__pIncomingCall->SetCallHandle(pCallStatus->CallHandle);
                //contact number
                String contactNumber(pCallStatus->pNumber);
@@ -2533,7 +2661,7 @@ TelephonyManager::HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus,
 }
 
 void
-TelephonyManager::SaveCallInfoToLogsDb(CallInfo& endCallInfo)
+TelephonyManager::SaveCallInfoToLogsDb(AppCallInfo& endCallInfo)
 {
        if (endCallInfo.IsConferenceCall() == false)
        {
@@ -2544,10 +2672,10 @@ TelephonyManager::SaveCallInfoToLogsDb(CallInfo& endCallInfo)
        {
                //Conference call
                int confCallCount = endCallInfo.GetCallerListCount();
-               IListT<CallInfo>* pParticipantList = endCallInfo.GetCallerList();
+               IListT<AppCallInfo>* pParticipantList = endCallInfo.GetCallerList();
                for (int index = 0; index < confCallCount; index++)
                {
-                       CallInfo participantInfo;
+                       AppCallInfo participantInfo;
                        if (pParticipantList->GetAt(index, participantInfo) == E_SUCCESS)
                        {
                                //Add call ended to call log database
@@ -2556,3 +2684,19 @@ TelephonyManager::SaveCallInfoToLogsDb(CallInfo& endCallInfo)
                }
        }
 }
+
+void
+TelephonyManager::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
+{
+       if(networkStatus.IsCallServiceAvailable() == false)
+       {
+               EndAllCalls();
+       }
+}
+
+bool
+TelephonyManager::IsIncomingorDialingCallPresent(void)
+{
+       //returns false, if incoming call or dialed call is present.
+       return ((__pIncomingCall != null) || (__pDialedCall != null));
+}