Fix for N_SE-48378 N_SE-48015
[apps/osp/Call.git] / src / CalllogManager.cpp
index 125a082..2814c23 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
 //
@@ -18,8 +18,9 @@
  * @file       CalllogManager.cpp
  * @brief      This class provides call log APIs
  */
-#include "CalllogManager.h"
 #include <FLocales.h>
+#include "CallApp.h"
+#include "CalllogManager.h"
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -84,7 +85,7 @@ CallLogManager::DestroyInstance(void)
 }
 
 result
-CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
+CallLogManager::AddCallogInfoToDatabase(AppCallInfo* calllogInfo)
 {
        AppLog(" AddVoiceCallInfo Entry");
        int duration = 0;
@@ -102,7 +103,7 @@ CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
                case CALL_LOG_TYPE_VOICE_OUTGOING:
                        logType = CONTACTS_PLOG_TYPE_VOICE_OUTGOING;
                        break;
-               case CALL_LOG_TYPE_VOICE_MISSED:
+               case CALL_LOG_TYPE_VOICE_MISSED_UNSEEN:
                        logType = CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN;
                        break;
                case CALL_LOG_TYPE_VOICE_REJECTED:
@@ -124,14 +125,17 @@ CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
                else
                {
                        //start time is in miliseconds . so convert to seconds and set it to time_t format.
-                       long long connectTime = calllogInfo->GetCallConnectTime();
+                       long long connectTime = calllogInfo->GetDurationTime();
                        if(connectTime == 0 || connectTime < 0)
                        {
-                               connectTime = time(null);
+                               //connectTime = time(null);
+                               CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
+                               connectTime = pPhoneApp->GetCallAppTicks();
+                               connectTime /=1000;
                        }
                        else
                        {
-                               connectTime = calllogInfo->GetCallConnectTime()/ 1000;
+                               connectTime = calllogInfo->GetDurationTime()/ 1000;
                        }
                        duration = (int)GetDuration(connectTime);
                }
@@ -196,9 +200,12 @@ CallLogManager::AddCallogInfoToDatabase(CallInfo* calllogInfo)
 unsigned long
 CallLogManager::GetDuration(long long start_time)
 {
-       time_t curr_time;
+       long long curr_time;
        unsigned long call_duration_in_sec = 50;
-       curr_time = time(0);
+//     curr_time = time(0);
+       CallApp* pPhoneApp = static_cast<CallApp*>(CallApp::GetInstance());
+       curr_time = pPhoneApp->GetCallAppTicks();
+       curr_time /=1000;
        /*if(start_time != 0)
        {
                start_time /= 1000;
@@ -209,18 +216,54 @@ CallLogManager::GetDuration(long long start_time)
 int
 CallLogManager::GetPersonId(Tizen::Base::String& phoneNumber)
 {
+       AppLogDebug("Enter");
        int personId = -1;
+       bool bContactFound = false;
        if (pAddressBook != null)
        {
                IList* pNumberContactsList = pAddressBook->SearchContactsByPhoneNumberN(phoneNumber);
+               if (pNumberContactsList == null || IsFailed(GetLastResult()))
+               {
+                       return -1;
+               }
+
+               //Fetch the contact's info to be displayed
+               IEnumerator* pContactEnum = pNumberContactsList->GetEnumeratorN();
                if(pNumberContactsList != null)
                {
-                       Contact* pContact = static_cast<Contact*>(pNumberContactsList->GetAt(0));
-                       if(pContact != null)
+                       while (E_SUCCESS == pContactEnum->MoveNext())
                        {
-                               personId = pContact->GetPersonId();
+                               Contact* pContact = static_cast<Contact*>(pContactEnum->GetCurrent());
+
+                               IList* pPhoneNumberList = pContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
+                               if (pPhoneNumberList != null)
+                               {
+                                       IEnumerator* pPhoneEnum = pPhoneNumberList->GetEnumeratorN();
+                                       while (E_SUCCESS == pPhoneEnum->MoveNext())
+                                       {
+                                               PhoneNumber* pPhoneNumber = (PhoneNumber*) pPhoneEnum->GetCurrent();
+                                               //Check if this is the correct contact
+                                               if (pPhoneNumber->GetPhoneNumber().Equals(phoneNumber))
+                                               {
+                                                       //save newly fetched contact info.
+                                                       bContactFound = true;
+                                                       personId = pContact->GetPersonId();
+                                                       break;
+                                               }
+                                       }
+                                       delete pPhoneEnum;
+                                       pPhoneNumberList->RemoveAll(true);
+                                       delete pPhoneNumberList;
+                               }
+                               if(bContactFound == true)
+                               {
+                                       break;
+                               }
                        }
                }
+               delete pContactEnum;
+               pNumberContactsList->RemoveAll(true);
+               delete pNumberContactsList;
        }
        return personId;
 }