Fix for 44593 42495
[apps/osp/Call.git] / src / CallTelephonyManager.cpp
index f3d821b..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
 //
@@ -35,6 +35,7 @@ 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,
@@ -337,7 +338,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 +345,7 @@ TelephonyManager::EndActiveCall(Long callHandle)
        {
                r = EndCall(endCall);
        }
+
        return r;
 }
 
@@ -1281,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);
        }
 }
@@ -1724,6 +1740,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
@@ -1769,12 +1786,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);
@@ -1804,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));
@@ -1822,7 +1856,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;
@@ -1891,6 +1928,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);
@@ -1901,7 +1940,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);
@@ -1925,6 +1969,8 @@ 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)
@@ -1945,8 +1991,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
@@ -2008,6 +2065,7 @@ TelephonyManager::HandleDialingCallBack(void* pData)
        long long startTime = 0;
        SystemTime::GetTicks(startTime);
        __pDialedCall->SetCallNotificationTime(startTime);
+       //SaveCallInfoToLogsDb(*__pDialedCall);
 }
 
 void
@@ -2159,6 +2217,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.
@@ -2182,11 +2244,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;
 }
@@ -2314,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;
 }