Fix for 42792
[apps/osp/Call.git] / src / CallTelephonyManager.cpp
index d420746..b057fbe 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
 //
@@ -337,7 +337,6 @@ result
 TelephonyManager::EndActiveCall(Long callHandle)
 {
        result r = E_FAILURE;
-
        //fetch ended callInfo from active call list
        AppCallInfo endCall;
        r = __pActiveCallList->GetValue(callHandle.ToLong(), endCall);
@@ -345,6 +344,7 @@ TelephonyManager::EndActiveCall(Long callHandle)
        {
                r = EndCall(endCall);
        }
+
        return r;
 }
 
@@ -390,19 +390,21 @@ TelephonyManager::EndCall(AppCallInfo& 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_ACCEPT;
+       TelCallAnswerType_t answerType = TAPI_CALL_ANSWER_REJECT;
        int res = -1;
 
        AppLogDebug("tel_answer_call");
-       answerType = TAPI_CALL_ANSWER_REJECT;
+       //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);
 
@@ -1279,6 +1281,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);
        }
 }
@@ -1287,8 +1304,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)
        {
@@ -1298,65 +1314,48 @@ TelephonyManager::HandleRejectCallbackResponse(TapiHandle* pHandle, int callBack
                //Check if incoming call is rejected
                if (pTelManager->__pIncomingCall != null && (rejectedCallHandle == (unsigned int) pTelManager->__pIncomingCall->GetCallHandle()->ToLong()))
                {
+                       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->StopSession();
-                                       }
-                               }
-                               //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
+                               pTelManager->__pSoundManager->StopAlert();
+                               //Do not call stop session if there is already a call going on
+                               if(isLastCall == true)
                                {
-                                       //fetch active calls to show appropriate scene
-                                       pCallList = static_cast<ArrayListT<AppCallInfo>*>(pTelManager->__pActiveCallList->GetValuesN());
+                                       pTelManager->__pSoundManager->StopSession();
                                }
-                               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
@@ -1529,6 +1528,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)
@@ -1586,6 +1589,7 @@ 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<AppCallInfo>* pActiveCallList = __pActiveCallList->GetValuesN();
@@ -1735,6 +1739,7 @@ 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
@@ -1780,12 +1785,32 @@ TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int c
                        //stop sound session
                        pTelManager->__pSoundManager->StopSession();
                        //send empty call list to show dialer or call log screen
-                       pCallList = new (std::nothrow) ArrayListT<AppCallInfo>();
+                       pCallList =new (std::nothrow) ArrayListT<AppCallInfo>();
+                       pCallList->Construct(1);
+                       pCallList->Add(endConfCallInfo);
                }
                else
                {
                        //fetch active calls to show appropriate scene
                        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);
@@ -1806,7 +1831,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()".
@@ -1815,10 +1840,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));
@@ -1833,7 +1855,10 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                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()"
        AppCallInfo confCallInfo;
@@ -1856,6 +1881,7 @@ 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;
        }
 
@@ -1873,7 +1899,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)
@@ -1901,6 +1927,8 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                        __pIncomingCall = null;
                        //update missed status
                        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);
@@ -1911,7 +1939,12 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                        __pSoundManager->StopSession();
                        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);
@@ -1934,6 +1967,9 @@ TelephonyManager::HandleIdleCallBack(void* pData)
 bool
 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)
@@ -1954,8 +1990,19 @@ TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
                }
                else
                {
-                       //fetch active calls to show appropriate scene
-                       pCallList = static_cast<ArrayListT<AppCallInfo>*>(__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
@@ -1972,6 +2019,7 @@ TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
 void
 TelephonyManager::HandleDialingCallBack(void* pData)
 {
+       AppLogDebug("Enter");
        unsigned int tempHandle = 0;
        TelCallStatusDialingNoti_t dialingNotification;
        memcpy(&tempHandle, pData, sizeof(TS_UINT));
@@ -1980,6 +2028,7 @@ 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) AppCallInfo();
 
@@ -2015,6 +2064,7 @@ TelephonyManager::HandleDialingCallBack(void* pData)
        long long startTime = 0;
        SystemTime::GetTicks(startTime);
        __pDialedCall->SetCallNotificationTime(startTime);
+       //SaveCallInfoToLogsDb(*__pDialedCall);
 }
 
 void
@@ -2166,6 +2216,10 @@ 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.
@@ -2189,11 +2243,14 @@ TelephonyManager::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
        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)
        {
-               AnswerAutoRejectCall(callHandle);
-               return true;
+               if (((__pSettingsManager->GetUnknownRejectStatus() == true) && (pIncomingCallInfo->GetContactInfo() == null))
+                               || (__pSettingsManager->IsCallToBeRejected(contactNumber) == true))
+               {
+                       AnswerAutoRejectCall(callHandle);
+                       return true;
+               }
        }
        return false;
 }
@@ -2201,6 +2258,7 @@ TelephonyManager::CheckIncomingCallToBeRejected(AppCallInfo* 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)
@@ -2288,6 +2346,16 @@ TelephonyManager::StartAlert(AppCallInfo& 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;
@@ -2606,9 +2674,15 @@ TelephonyManager::SaveCallInfoToLogsDb(AppCallInfo& 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));
+}