2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include "MsgIpcSocket.h"
24 #include "MsgUtilStorage.h"
25 #include "MsgGconfWrapper.h"
26 #include "MsgContact.h"
29 /*==================================================================================================
31 ==================================================================================================*/
32 __thread bool isContactSvcConnected = false;
34 MsgDbHandler ContactDbHandle;
36 MsgContactChangeCB cbFunction = NULL;
37 /*==================================================================================================
38 FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
40 static void MsgContactSvcCallback(const char *view_uri, void *user_data)
42 MSG_DEBUG("Contact Data is Changed!!!");
44 // establish connection to msgfw daemon
45 MsgIpcClientSocket client;
46 client.connect(MSG_SOCKET_PATH);
49 int cmdSize = sizeof(MSG_CMD_S); // cmd type
52 bzero(cmdBuf, cmdSize);
54 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
56 // Set Command Parameters
57 pCmd->cmdType = MSG_CMD_CONTACT_SYNC;
59 memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
61 // Send Command to Transaction Manager
62 client.write(cmdBuf, cmdSize);
64 // Receive result from Transaction Manager
66 AutoPtr<char> wrap(&temp);
68 client.read(&temp, &len);
70 // close connection to msgfw daemon
75 msg_error_t MsgOpenContactSvc()
77 int errCode = CONTACTS_ERROR_NONE;
79 if (!isContactSvcConnected) {
80 errCode = contacts_connect2();
82 if (errCode == CONTACTS_ERROR_NONE) {
83 MSG_DEBUG("Connect to Contact Service Success");
84 isContactSvcConnected = true;
86 MSG_DEBUG("Connect to Contact Service Fail [%d]", errCode);
87 isContactSvcConnected = false;
88 return MSG_ERR_DB_CONNECT;
91 MSG_DEBUG("Already connected to Contact Service.");
98 msg_error_t MsgCloseContactSvc()
100 int errCode = CONTACTS_ERROR_NONE;
102 if (isContactSvcConnected) {
103 errCode = contacts_disconnect2();
105 if (errCode == CONTACTS_ERROR_NONE) {
106 MSG_DEBUG("Disconnect to Contact Service Success");
108 MSG_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
109 return MSG_ERR_DB_DISCONNECT;
117 msg_error_t MsgInitContactSvc(MsgContactChangeCB cb)
119 msg_error_t err = MSG_SUCCESS;
121 unsigned int retryCnt = 100;
124 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
126 MSG_DEBUG("MsgOpenContactSvc fail. Retry count left [%d]", retryCnt);
129 } while (err != MSG_SUCCESS && retryCnt > 0);
131 if (!isContactSvcConnected) {
132 MSG_DEBUG("Contact Service Not Opened.");
133 return MSG_ERR_UNKNOWN;
136 int errCode = CONTACTS_ERROR_NONE;
141 // Register callback function
142 errCode = contacts_db_add_changed_cb(_contacts_contact._uri, MsgContactSvcCallback, NULL);
144 if (errCode == CONTACTS_ERROR_NONE)
145 MSG_DEBUG("Register Contact Service Callback");
147 MSG_DEBUG("Fail to Register Contact Service Callback [%d]", errCode);
153 msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_INFO_S *pContactInfo)
157 msg_error_t err = MSG_SUCCESS;
159 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
160 MSG_DEBUG("MsgOpenContactSvc fail.");
164 if (!isContactSvcConnected) {
165 MSG_DEBUG("Contact Service Not Opened.");
166 return MSG_ERR_UNKNOWN;
169 MSG_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
171 memset(pContactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
173 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN && strlen(pAddrInfo->addressVal) > (MAX_PHONE_NUMBER_LEN+1)) {
174 MSG_DEBUG("Phone Number is too long [%s]", pAddrInfo->addressVal);
180 unsigned int count = 0;
181 contacts_query_h query = NULL;
182 contacts_filter_h filter = NULL;
183 contacts_list_h contacts = NULL;
185 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
186 ret = contacts_query_create(_contacts_contact_number._uri, &query);
187 ret = contacts_filter_create(_contacts_contact_number._uri, &filter);
189 ret = contacts_filter_add_str(filter, _contacts_contact_number.number, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
191 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
192 ret = contacts_query_create(_contacts_contact_email._uri, &query);
193 ret = contacts_filter_create(_contacts_contact_email._uri, &filter);
195 ret = contacts_filter_add_str(filter, _contacts_contact_email.email, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
198 MSG_DEBUG("Invalid pAddrInfo->addressType.");
202 ret = contacts_query_set_filter(query, filter);
203 ret = contacts_db_get_records_with_query(query, 0, 1, &contacts);
204 if (ret != CONTACTS_ERROR_NONE) {
205 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
206 contacts_query_destroy(query);
207 contacts_filter_destroy(filter);
208 contacts_list_destroy(contacts, true);
212 ret = contacts_list_get_count(contacts, &count);
214 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
215 MSG_DEBUG("No Serach Data from Contact Service.");
216 contacts_query_destroy(query);
217 contacts_filter_destroy(filter);
218 contacts_list_destroy(contacts, true);
222 contacts_query_destroy(query);
223 contacts_filter_destroy(filter);
225 contacts_record_h contact = NULL;
227 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
228 contacts_record_h number = NULL;
230 ret = contacts_list_get_current_record_p(contacts, &number);
231 if (ret != CONTACTS_ERROR_NONE) {
232 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
233 contacts_list_destroy(contacts, true);
237 ret = contacts_record_get_int(number, _contacts_contact_number.contact_id, &index);
238 if (ret != CONTACTS_ERROR_NONE) {
239 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
240 contacts_list_destroy(contacts, true);
244 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
245 if (ret != CONTACTS_ERROR_NONE) {
246 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
247 contacts_list_destroy(contacts, true);
248 contacts_record_destroy(contact, true);
251 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
252 contacts_record_h email = NULL;
254 ret = contacts_list_get_current_record_p(contacts, &email);
255 if (ret != CONTACTS_ERROR_NONE) {
256 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
257 contacts_list_destroy(contacts, true);
261 ret = contacts_record_get_int(email, _contacts_contact_email.contact_id, &index);
262 if (ret != CONTACTS_ERROR_NONE) {
263 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
264 contacts_list_destroy(contacts, true);
268 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
269 if (ret != CONTACTS_ERROR_NONE) {
270 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
271 contacts_list_destroy(contacts, true);
272 contacts_record_destroy(contact, true);
277 contacts_list_destroy(contacts, true);
280 contacts_record_h name = NULL;
282 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
283 if (ret != CONTACTS_ERROR_NONE) {
284 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
286 char* strFirstName = NULL;
287 ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
288 if (ret != CONTACTS_ERROR_NONE) {
289 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
292 char* strLastName = NULL;
293 ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
294 if (ret != CONTACTS_ERROR_NONE) {
295 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
298 char* strDisplayName = NULL;
299 ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &strDisplayName);
300 if (ret != CONTACTS_ERROR_NONE) {
301 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
304 if (strFirstName != NULL)
305 strncpy(pContactInfo->firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
307 if (strLastName != NULL)
308 strncpy(pContactInfo->lastName, strLastName, MAX_DISPLAY_NAME_LEN);
310 if (strDisplayName != NULL)
311 strncpy(pContactInfo->displayName, strDisplayName, MAX_DISPLAY_NAME_LEN);
314 MSG_DEBUG("pContactInfo->firstName : [%s], pContactInfo->lastName : [%s]", pContactInfo->firstName, pContactInfo->lastName);
315 MSG_DEBUG("pContactInfo->displayName : [%s]", pContactInfo->displayName);
317 ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
318 if (ret != CONTACTS_ERROR_NONE) {
319 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
320 contacts_record_destroy(contact, true);
324 MSG_DEBUG("Contact ID [%d]", pContactInfo->contactId);
326 char* strImagePath = NULL;
327 ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
328 if (ret != CONTACTS_ERROR_NONE) {
329 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
330 contacts_record_destroy(contact, true);
334 if (strImagePath != NULL)
335 strncpy(pContactInfo->imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
337 MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
339 contacts_record_destroy(contact, true);
347 void MsgSyncContact()
350 unsigned int changed_count = 0;
351 int lastSyncTime = 0;
352 int finalSyncTime = 0;
354 /* get contact sync time */
355 lastSyncTime = MsgSettingGetInt(CONTACT_SYNC_TIME);
357 if (lastSyncTime < 0) {
358 MSG_DEBUG("Fail to get CONTACT_SYNC_TIME.");
362 contacts_list_h contactsList = NULL;
364 ret = contacts_db_get_changes_by_version(_contacts_contact_updated_info._uri, -1, lastSyncTime, &contactsList, &finalSyncTime);
366 if (ret != CONTACTS_ERROR_NONE) {
367 MSG_DEBUG("contacts_db_get_changes_by_version() Error [%d]", ret);
368 contacts_list_destroy(contactsList, true);
372 ret = contacts_list_get_count(contactsList, &changed_count);
374 if (ret != CONTACTS_ERROR_NONE) {
375 MSG_DEBUG("contacts_list_get_count() Error [%d]", ret);
376 contacts_list_destroy(contactsList, true);
380 for (unsigned int i = 0; i < changed_count; i++)
384 contacts_record_h event = NULL;
386 ret = contacts_list_get_current_record_p(contactsList, &event);
387 if (ret != CONTACTS_ERROR_NONE) {
388 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
389 contacts_list_destroy(contactsList, true);
393 ret = contacts_record_get_int(event, _contacts_contact_updated_info.contact_id, &index_num);
394 if (ret != CONTACTS_ERROR_NONE) {
395 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
396 contacts_list_destroy(contactsList, true);
400 MSG_DEBUG("index (%d)", index_num);
402 ret = contacts_record_get_int(event, _contacts_contact_updated_info.type, &type);
403 if (ret != CONTACTS_ERROR_NONE) {
404 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
405 contacts_list_destroy(contactsList, true);
409 if (type == CONTACTS_CHANGE_UPDATED || type == CONTACTS_CHANGE_INSERTED) {
410 MsgUpdateContact(index_num, type);
412 MSG_DEBUG("Delete Contact");
413 MsgDeleteContact(index_num);
416 ret = contacts_list_next(contactsList);
417 if (ret != CONTACTS_ERROR_NONE) {
418 MSG_DEBUG("contacts_list_next() Error [%d]", ret);
422 if(MsgSettingSetInt(CONTACT_SYNC_TIME, finalSyncTime) != MSG_SUCCESS)
423 MSG_DEBUG("MsgSettingSetInt fail : CONTACT_SYNC_TIME");
424 MSG_DEBUG("lastSyncTime : %d", finalSyncTime);
426 contacts_list_destroy(contactsList, true);
428 if(changed_count > 0)
433 bool MsgInsertContact(MSG_CONTACT_INFO_S *pContactInfo, const char *pNumber)
435 if (!pNumber || strlen(pNumber) <= 0)
438 if (MsgStoAddContactInfo(&ContactDbHandle, pContactInfo, pNumber) != MSG_SUCCESS) {
439 MSG_DEBUG("Fail to add contact info.");
447 bool MsgUpdateContact(int index, int type)
449 int ret = CONTACTS_ERROR_NONE;
451 contacts_record_h contact = NULL;
453 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
454 if (ret != CONTACTS_ERROR_NONE) {
455 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
456 contacts_record_destroy(contact, true);
460 MSG_CONTACT_INFO_S contactInfo;
461 memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
463 ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&contactInfo.contactId);
464 if (ret != CONTACTS_ERROR_NONE) {
465 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
466 contacts_record_destroy(contact, true);
470 MSG_DEBUG("Contact ID [%d]", contactInfo.contactId);
472 char* strImagePath = NULL;
473 ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
474 if (ret != CONTACTS_ERROR_NONE) {
475 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
476 contacts_record_destroy(contact, true);
480 if (strImagePath != NULL)
481 strncpy(contactInfo.imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
483 MSG_DEBUG("Image Path [%s]", contactInfo.imagePath);
486 contacts_record_h name = NULL;
488 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
489 if (ret != CONTACTS_ERROR_NONE) {
490 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
492 char* strFirstName = NULL;
493 ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
494 if (ret != CONTACTS_ERROR_NONE) {
495 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
498 char* strLastName = NULL;
499 ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
500 if (ret != CONTACTS_ERROR_NONE) {
501 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
504 char* strDisplayName = NULL;
505 ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &strDisplayName);
506 if (ret != CONTACTS_ERROR_NONE) {
507 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
510 if (strFirstName != NULL)
511 strncpy(contactInfo.firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
513 if (strLastName != NULL)
514 strncpy(contactInfo.lastName, strLastName, MAX_DISPLAY_NAME_LEN);
516 if (strDisplayName != NULL)
517 strncpy(contactInfo.displayName, strDisplayName, MAX_DISPLAY_NAME_LEN);
519 MSG_DEBUG("First Name : [%s], Last Name : [%s]", contactInfo.firstName, contactInfo.lastName);
520 MSG_DEBUG("displayName : [%s]", contactInfo.displayName);
523 MsgStoResetContactInfo(&ContactDbHandle, index);
525 unsigned int count = 0;
526 ret = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);
527 if (ret != CONTACTS_ERROR_NONE) {
528 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
529 contacts_record_destroy(contact, true);
533 MSG_DEBUG("_contacts_contact.number count [%d]", count);
536 for(unsigned int i=0; i < count; i++)
538 MSG_DEBUG("Add Number Contact Data");
540 contacts_record_h number = NULL;
542 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.number, i, &number);
543 if (ret != CONTACTS_ERROR_NONE) {
544 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
545 contacts_record_destroy(contact, true);
549 char* strNumber = NULL;
550 ret = contacts_record_get_str_p(number, _contacts_number.number, &strNumber);
551 if (ret != CONTACTS_ERROR_NONE) {
552 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
553 contacts_record_destroy(contact, true);
557 if (strNumber != NULL) {
558 MSG_DEBUG("Number = %s", strNumber);
559 if (!MsgInsertContact(&contactInfo, strNumber)) {
560 MSG_DEBUG("MsgInsertContact fail.");
567 ret = contacts_record_get_child_record_count(contact, _contacts_contact.email, &count);
568 if (ret != CONTACTS_ERROR_NONE) {
569 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
570 contacts_record_destroy(contact, true);
574 MSG_DEBUG("_contacts_contact.email count [%d]", count);
577 for(unsigned int i=0; i < count; i++)
579 MSG_DEBUG("Add Email Contact Data");
581 contacts_record_h email = NULL;
583 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.email, i, &email);
584 if (ret != CONTACTS_ERROR_NONE) {
585 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
586 contacts_record_destroy(contact, true);
590 char* strNumber = NULL;
591 ret = contacts_record_get_str_p(email, _contacts_email.email, &strNumber);
592 if (ret != CONTACTS_ERROR_NONE) {
593 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
594 contacts_record_destroy(contact, true);
598 if (strNumber != NULL) {
599 MSG_DEBUG("email = %s", strNumber);
600 if (!MsgInsertContact(&contactInfo, strNumber)) {
601 MSG_DEBUG("MsgInsertContact fail.");
607 MsgStoSetConversationDisplayName(&ContactDbHandle, index);
609 contacts_record_destroy(contact, true);
611 if (type == -1 && cbFunction != NULL)
618 bool MsgDeleteContact(int index)
620 if (MsgStoResetContactInfo(&ContactDbHandle, index) != MSG_SUCCESS)
627 int MsgGetContactNameOrder()
629 msg_error_t err = MSG_SUCCESS;
631 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
632 MSG_DEBUG("MsgOpenContactSvc fail.");
636 if (!isContactSvcConnected) {
637 MSG_DEBUG("Contact Service Not Opened.");
638 return 0; // return default value : FIRSTLAST
641 int ret = CONTACTS_ERROR_NONE;
643 contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
645 ret = contacts_setting_get_name_display_order(&order);
646 if (ret != CONTACTS_ERROR_NONE) {
647 MSG_DEBUG("contacts_setting_get_name_display_order() Error [%d]", ret);
651 if (order == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST)
658 void MsgAddPhoneLog(const MSG_MESSAGE_INFO_S *pMsgInfo)
660 msg_error_t err = MSG_SUCCESS;
662 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
663 MSG_DEBUG("MsgOpenContactSvc fail.");
667 if (!isContactSvcConnected) {
668 MSG_DEBUG("Contact Service Not Opened.");
672 if(pMsgInfo->nAddressCnt < 1) {
673 MSG_DEBUG("address count is [%d]", pMsgInfo->nAddressCnt);
677 for (int i = 0; pMsgInfo->nAddressCnt > i; i++) {
679 contacts_record_h plog = NULL;
681 ret = contacts_record_create(_contacts_phone_log._uri, &plog);
682 if (ret != CONTACTS_ERROR_NONE) {
683 MSG_DEBUG("contacts_record_create() Error [%d]", ret);
684 contacts_record_destroy(plog, true);
688 contacts_record_set_str(plog, _contacts_phone_log.address, (char*)pMsgInfo->addressList[i].addressVal);
689 contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
692 memset(strText, 0x00, sizeof(strText));
694 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
695 strncpy(strText, pMsgInfo->msgText, 100);
696 MSG_DEBUG("msgText : %s", strText);
697 } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
698 if (strlen(pMsgInfo->subject) > 0 || pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
699 strncpy(strText, pMsgInfo->subject, 100);
700 MSG_DEBUG("subject : %s", strText);
702 strncpy(strText, pMsgInfo->msgText, 100);
703 MSG_DEBUG("msgText : %s", strText);
707 contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
708 contacts_record_set_int(plog, _contacts_phone_log.extra_data1, (int)pMsgInfo->msgId);
710 if (pMsgInfo->folderId == MSG_INBOX_ID) {
711 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
712 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMMING);
713 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
714 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMMING);
715 } else if (pMsgInfo->folderId == MSG_OUTBOX_ID) {
716 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
717 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
718 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
719 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
720 } else if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
721 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
722 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
723 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
724 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
727 ret = contacts_db_insert_record(plog, NULL);
728 if (ret != CONTACTS_ERROR_NONE) {
729 MSG_DEBUG("contacts_db_insert_record() Error [%d]", ret);
732 contacts_record_destroy(plog, true);
737 void MsgDeletePhoneLog(msg_message_id_t msgId)
739 msg_error_t err = MSG_SUCCESS;
741 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
742 MSG_DEBUG("MsgOpenContactSvc fail.");
746 MSG_DEBUG("MsgDeletePhoneLog [%d]", msgId);
748 if (!isContactSvcConnected) {
749 MSG_DEBUG("Contact Service Not Opened.");
753 int ret = CONTACTS_ERROR_NONE;
755 unsigned int count = 0;
756 contacts_query_h query;
757 contacts_filter_h filter;
758 contacts_list_h plogs = NULL;
760 ret = contacts_query_create(_contacts_phone_log._uri, &query);
761 ret = contacts_filter_create(_contacts_phone_log._uri, &filter);
763 ret = contacts_filter_add_int(filter, _contacts_phone_log.extra_data1, CONTACTS_MATCH_EQUAL, (int)msgId);
766 ret = contacts_query_set_filter(query, filter);
767 ret = contacts_db_get_records_with_query(query, 0, 1, &plogs);
769 ret = contacts_list_get_count(plogs, &count);
772 MSG_DEBUG("No Serach Data from Contact Service.");
774 contacts_record_h plog = NULL;
776 ret = contacts_list_get_current_record_p(plogs, &plog);
777 if (ret != CONTACTS_ERROR_NONE) {
778 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
781 ret = contacts_record_get_int(plog, _contacts_phone_log.id, &index);
782 if (ret != CONTACTS_ERROR_NONE) {
783 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
786 ret = contacts_db_delete_record(_contacts_phone_log._uri, index);
787 if (ret != CONTACTS_ERROR_NONE) {
788 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
790 MSG_DEBUG("contacts_db_delete_record() Success.");
794 contacts_query_destroy(query);
795 contacts_filter_destroy(filter);
796 contacts_list_destroy(plogs, true);
801 int MsgContactSVCBeginTrans()
803 //return contacts_svc_begin_trans();
808 int MsgContactSVCEndTrans(bool bSuccess)
810 //return contacts_svc_end_trans(bSuccess);