Fix for Call sate not set properly when there is 1 waiting and 1 active call and...
[apps/osp/Call.git] / src / CallTelephonyManager.cpp
index 65884c6..9c128e8 100644 (file)
@@ -24,6 +24,7 @@
 #include <FTelephony.h>
 #include "ITapiModem.h"
 #include "ITapiSim.h"
+#include "CallApp.h"
 #include "CallInfo.h"
 #include "CallTelephonyManager.h"
 #include "CallSettingsManager.h"
@@ -35,6 +36,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,
@@ -554,7 +556,7 @@ 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<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
+               IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
                if(pCallList != null)
                {
                        AppCallInfo endCallInfo;
@@ -563,7 +565,7 @@ TelephonyManager::AcceptSecondCall(CallAnsweringOptions answerOptions, const int
                                SaveCallInfoToLogsDb(endCallInfo);
                        }
                        delete pCallList;
-               }*/
+               }
                pEndCallsList->RemoveAll();
                delete pEndCallsList;
        }
@@ -612,7 +614,7 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                //Incoming Call connected successfully
                r = E_SUCCESS;
                //save to ended call to call logs db.
-               //SaveCallInfoToLogsDb(callToBeEnded);
+               SaveCallInfoToLogsDb(callToBeEnded);
        }
        break;
 
@@ -667,7 +669,7 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                        break;
                }
                //"Held" call successfully ended - Add call ended to call log database
-               //SaveCallInfoToLogsDb(callToBeEnded);
+               SaveCallInfoToLogsDb(callToBeEnded);
 
                //accept incoming call by Holding "Active" call using "TAPI_CALL_ANSWER_HOLD_AND_ACCEPT".
                res = tel_answer_call(__pTapiHandle, incomingCallHandle, TAPI_CALL_ANSWER_HOLD_AND_ACCEPT, &HandleCallbackResponse, this);
@@ -722,7 +724,7 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                IListT<AppCallInfo>* pCallList = pEndCallsList->GetValuesN();
                if(pCallList != null)
                {
-/*                     int callCount = pCallList->GetCount();
+                       int callCount = pCallList->GetCount();
                        for (int index = 0; index < callCount; index++)
                        {
                                AppCallInfo endCallInfo;
@@ -730,7 +732,7 @@ TelephonyManager::AcceptMultipleCall(CallAnsweringOptions answerOptions, const i
                                {
                                        SaveCallInfoToLogsDb(endCallInfo);
                                }
-                       }*/
+                       }
                        delete pCallList;
                        pCallList = null;
                }
@@ -1401,9 +1403,11 @@ TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackRe
                                        pConfCallInfo->AddCallToCallerList(heldCall);
                                        pConfCallInfo->SetCallHandle(activeCallHandle);
                                        //Set call start time
-                                       if (pConfCallInfo->GetCallConnectTime() > heldCall.GetCallConnectTime())
+                                       //if (pConfCallInfo->GetCallConnectTime() > heldCall.GetCallConnectTime())
+                                       if (pConfCallInfo->GetDurationTime() > heldCall.GetDurationTime())
                                        {
                                                pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
+                                               pConfCallInfo->SetDurationTime(heldCall.GetDurationTime());
                                                pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
                                        }
                                }
@@ -1416,9 +1420,11 @@ TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackRe
                                        pConfCallInfo->AddCallToCallerList(activeCall);
                                        pConfCallInfo->SetCallHandle(heldCallHandle);
                                        //Set call start time
-                                       if (pConfCallInfo->GetCallConnectTime() > activeCall.GetCallConnectTime())
+                                       //if (pConfCallInfo->GetCallConnectTime() > activeCall.GetCallConnectTime())
+                                       if (pConfCallInfo->GetDurationTime() > activeCall.GetDurationTime())
                                        {
                                                pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
+                                               pConfCallInfo->SetDurationTime(activeCall.GetDurationTime());
                                                pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
                                        }
                                }
@@ -1432,14 +1438,17 @@ TelephonyManager::HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackRe
                                        pConfCallInfo->AddCallToCallerList(heldCall);
                                        pConfCallInfo->SetCallHandle(activeCallHandle);
                                        //Set call start time
-                                       if (activeCall.GetCallConnectTime() > heldCall.GetCallConnectTime())
+                                       //if (activeCall.GetCallConnectTime() > heldCall.GetCallConnectTime())
+                                       if (activeCall.GetDurationTime() > heldCall.GetDurationTime())
                                        {
                                                pConfCallInfo->SetCallConnectTime(heldCall.GetCallConnectTime());
+                                               pConfCallInfo->SetDurationTime(heldCall.GetDurationTime());
                                                pConfCallInfo->SetCallNotificationTime(heldCall.GetCallNotificationTime());
                                        }
                                        else
                                        {
                                                pConfCallInfo->SetCallConnectTime(activeCall.GetCallConnectTime());
+                                               pConfCallInfo->SetDurationTime(activeCall.GetDurationTime());
                                                pConfCallInfo->SetCallNotificationTime(activeCall.GetCallNotificationTime());
                                        }
                                }
@@ -1560,7 +1569,7 @@ TelephonyManager::HandleParticipantEndedFromConference(unsigned int participantC
                        conferenceCall.RemoveCallFromCallerList(index);
                        //update its status to individual call before saving to database
                        callToBeEnded.SetConference(false);
-               //      SaveCallInfoToLogsDb(callToBeEnded);
+                       SaveCallInfoToLogsDb(callToBeEnded);
                        isParticipantCallEnded = true;
                        break;
                }
@@ -1774,7 +1783,7 @@ TelephonyManager::HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int c
                //remove the conference call handle from active call list to avoid any processing in HandleIdleCallback().
                pTelManager->__pActiveCallList->Remove(endConfCallInfo.GetCallHandle()->ToLong());
                //Save "End" Conf. call info to call log database
-       //      pTelManager->SaveCallInfoToLogsDb(endConfCallInfo);
+               pTelManager->SaveCallInfoToLogsDb(endConfCallInfo);
 
                //check if the ended call was the last call and show notification to user
                bool isLastCall = (pTelManager->__pActiveCallList->GetCount() == 0);
@@ -1928,10 +1937,10 @@ TelephonyManager::HandleIdleCallBack(void* pData)
                        //update missed status
                        endCallInfo.SetCalllogType(CALL_LOG_TYPE_VOICE_MISSED_UNSEEN);
                        //save ended call to call log db.
-                       SaveCallInfoToLogsDb(endCallInfo);
+                       //SaveCallInfoToLogsDb(endCallInfo);
                }
-               /*//save ended call to call log db.
-               SaveCallInfoToLogsDb(endCallInfo);*/
+               //save ended call to call log db.
+               SaveCallInfoToLogsDb(endCallInfo);
 
                //notify listener that call is disconnected.
                if (isLastCall == true)
@@ -1981,6 +1990,7 @@ TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
                ArrayListT<AppCallInfo>* pCallList = null;
                if (isLastCall)
                {
+                       __pSoundManager->GetTimer()->Cancel();
                        //stop sound session
                        __pSoundManager->StopSession();
                        //save "End" CallInfo to list to show EndCallForm
@@ -1990,20 +2000,23 @@ TelephonyManager::HandleEndNormalActiveCall(AppCallInfo& endCallInfo)
                }
                else
                {
-                       //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)
+                       if(__pIncomingCall == null)
                        {
-                               HoldActiveCall(&heldCall, false);
-                               delete pCallList;
+                               //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
-               //SaveCallInfoToLogsDb(endCallInfo);
+               SaveCallInfoToLogsDb(endCallInfo);
                //notify listener that call is disconnected.
                __pEventListener->HandleCallDisconnected(isLastCall, *pCallList);
                delete pCallList;
@@ -2061,7 +2074,7 @@ TelephonyManager::HandleDialingCallBack(void* pData)
        long long startTime = 0;
        SystemTime::GetTicks(startTime);
        __pDialedCall->SetCallNotificationTime(startTime);
-       SaveCallInfoToLogsDb(*__pDialedCall);
+       //SaveCallInfoToLogsDb(*__pDialedCall);
 }
 
 void
@@ -2205,6 +2218,8 @@ TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
        long long startTime = 0;
        SystemTime::GetTicks(startTime);
        pConnectedCall->SetCallConnectTime(startTime);
+       CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
+       pConnectedCall->SetDurationTime(pPhoneApp->GetCallAppTicks());
        if(GetCurrentCallCount() == 0)
        {
                __pSoundManager->SetMinuteReminderTone();
@@ -2213,10 +2228,10 @@ TelephonyManager::HandleCallConnected(unsigned int connectedCallHandle)
 
        //transfer ownership to Active calls list
        __pActiveCallList->Add(connectedCallHandle, *(pConnectedCall));
-       if (pConnectedCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_INCOMING)
+/*     if (pConnectedCall->GetCalllogType() == CALL_LOG_TYPE_VOICE_INCOMING)
        {
                SaveCallInfoToLogsDb(*pConnectedCall);
-       }
+       }*/
        pConnectedCall = null;
 
        //notify listener that call is connected.
@@ -2375,6 +2390,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;
 }