Add new DA model names
[platform/core/connectivity/bluetooth-agent.git] / pb-agent / bluetooth_pb_vcard.c
index c17dc44..1b0cc34 100644 (file)
@@ -1,13 +1,18 @@
 /*
- * bluetooth-agent
+ * Bluetooth-agent
  *
- * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
+ *              Girishashok Joshi <girish.joshi@samsung.com>
+ *              Chanyeol Park <chanyeol.park@samsung.com>
+ *              Jaekyun Lee <jkyun.lee@samsung.com>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *              http://www.apache.org/licenses/LICENSE-2.0
+ *             http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * limitations under the License.
  *
  */
-
 #include <time.h>
 #include <string.h>
 #include <stdarg.h>
-
-
+#include <stdlib.h>
+#include <stdio.h>
 #include <glib.h>
-#include <dbus/dbus-glib.h>
-
 #include <vconf.h>
 #include <dlog.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/stat.h>
 #include <contacts.h>
+#include <image_util.h>
+#include <libexif/exif-data.h>
+#include <unistd.h>
 
 #include "bluetooth_pb_vcard.h"
-
-#define BT_PB_AGENT    "BT_PB_AGENT"
-#define DBG(fmt, args...) SLOG(LOG_DEBUG, BT_PB_AGENT, "%s():%d "fmt, __func__, __LINE__, ##args)
-#define ERR(fmt, args...) SLOG(LOG_ERROR, BT_PB_AGENT, "%s():%d "fmt, __func__, __LINE__, ##args)
-
-#define VCARD_FORMAT_2_1 0x0
-#define VCARD_FORMAT_3_0 0x1
-
-#define VCARD_VERSION  (0x1)
-#define VCARD_FN       (0x1 << 1)
-#define VCARD_N                (0x1 << 2)
-#define VCARD_PHOTO    (0x1 << 3)
-#define VCARD_BDAY     (0x1 << 4)
-#define VCARD_ADR      (0x1 << 5)
-#define VCARD_LABEL    (0x1 << 6)      /* not supported */
-#define VCARD_TEL      (0x1 << 7)
-#define VCARD_EMAIL    (0x1 << 8)
-#define VCARD_MAILER   (0x1 << 9)      /* not supported */
-#define VCARD_TZ       (0x1 << 10)     /* not supported */
-#define VCARD_GEO      (0x1 << 11)     /* not supported */
-#define VCARD_TITLE    (0x1 << 12)
-#define VCARD_ROLE     (0x1 << 13)
-#define VCARD_LOGO     (0x1 << 14)     /* not supported */
-#define VCARD_AGENT    (0x1 << 15)     /* not supported */
-#define VCARD_ORG      (0x1 << 16)
-#define VCARD_NOTE     (0x1 << 17)
-#define VCARD_REV      (0x1 << 18)
-#define VCARD_SOUND    (0x1 << 19)     /* not supported */
-#define VCARD_URL      (0x1 << 20)
-#define VCARD_UID      (0x1 << 21)
-#define VCARD_KEY      (0x1 << 22)     /* not supported */
-#define VCARD_NICKNAME (0x1 << 23)
-#define VCARD_CATEGORIES       (0x1 << 24)     /* not supported */
-#define VCARD_PROID    (0x1 << 25)     /* not supported */
-#define VCARD_CLASS    (0x1 << 26)     /* not supported */
-#define VCARD_SORT_STRING      (0x1 << 27)     /* not supported */
-
-#define VCARD_X_IRMC_CALL_DATETIME     (0x1 << 28)
+#include "bluetooth_pb_agent.h"
 
 #define QP_ENC_LEN     3
 #define LINEBREAK_LEN  75
 
+typedef struct {
+       const char *src;
+       const char *dest;
+       int ret;
+       contacts_record_h person;
+       GString *string;
+} bt_image_info_t;
+
+gchar dest_thumb_path[255];
+#define PBAP_IMAGE_THUMB_SIZE 48
+#define PBAP_THMB_PATH "_thumb"
+#define PBAP_THUMB_FILE_SIZE 4096
+#define PBAP_IMAGE_ENCODE_QUALITY      90
+#define PBAP_SECURITY_FILE_GROUP 6005
+#define PBAP_SECURITY_DEFAULT_PERMISSION 0660
+#define PBAP_SECURITY_DIR_DEFAULT_PERMISSION 0770
+#define PBAP_SECURITY_IMAGE_PERMISSION 0440
+
 static gchar *__bluetooth_pb_vcard_escape(const gchar *str);
 
 static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
@@ -116,6 +105,9 @@ static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
 static void __bluetooth_pb_vcard_append_n_v21(GString *string,
                                        contacts_record_h contact);
 
+static void __bluetooth_pb_vcard_append_phonetic_first_v21(GString *string,
+                                       contacts_record_h contact);
+
 static void __bluetooth_pb_vcard_append_tel_v21(GString *string,
                                                contacts_record_h conatct);
 
@@ -179,11 +171,11 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                                                        va_list args);
 
 static gchar *__bluetooth_pb_vcard_real_contact_with_properties(gint person_id,
-                                                               gint phonelog_id,
-                                                               guint64 filter,
-                                                               guint8 format,
-                                                               const gchar *first_name,
-                                                               ...);
+                                                       gint phonelog_id,
+                                                       guint64 filter,
+                                                       guint8 format,
+                                                       const gchar *first_name,
+                                                       ...);
 
 static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
                                                guint filter,
@@ -214,13 +206,16 @@ static gchar *__bluetooth_pb_phonelog_datetime(gint phonelog_id);
 
 static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact);
 
+static gchar *__bluetooth_pb_phonetic_name_from_contact(contacts_record_h contact);
+
 static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact);
 
 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id);
 
-
+/* LCOV_EXCL_START */
 static gchar *__bluetooth_pb_vcard_escape(const gchar *str)
 {
+       FN_START;
        GString *escaped;
 
        gchar *st = NULL;
@@ -241,19 +236,20 @@ static gchar *__bluetooth_pb_vcard_escape(const gchar *str)
 
                        pos++;
                        st = pos;
-               }
-               else {
+               } else {
                        pos++;
                }
        }
 
        g_string_append_len(escaped, st, (pos - st));
+       FN_END;
        return g_string_free(escaped, FALSE);
 }
 
 static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
                                        const gchar *separator)
 {
+       FN_START;
        GString *string = g_string_new(NULL);
        gint i;
 
@@ -264,11 +260,14 @@ static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
                g_string_append(string, strv[i]);
        }
 
+       FN_END;
        return g_string_free(string, FALSE);
 }
+/* LCOV_EXCL_STOP */
 
 static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str)
 {
+       FN_START;
        gchar *pos = NULL;
 
        if (str == NULL)
@@ -282,13 +281,16 @@ static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str)
 
                pos++;
        }
+       FN_END;
        return FALSE;
 }
 
+/* LCOV_EXCL_START */
 /* get string length, which convert to quoted-printable encoding */
 static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
                                                gint len)
 {
+       FN_START;
        gchar *pos;
 
        gint count = 0;
@@ -297,7 +299,7 @@ static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
        if (str == NULL)
                return 0;
 
-       if (strlen(str) < len )
+       if (strlen(str) < len)
                length = -1;
 
        pos = (gchar *)str;
@@ -331,6 +333,7 @@ static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
                count++;
        }
 
+       FN_END;
        return count;
 }
 
@@ -340,6 +343,7 @@ static void __bluetooth_pb_vcard_qp_encode_append_to_hex(GString *string,
                                                        gint len,
                                                        gint *line_pos)
 {
+       FN_START;
        int i;
 
        if (str == NULL || len == 0)
@@ -355,6 +359,7 @@ static void __bluetooth_pb_vcard_qp_encode_append_to_hex(GString *string,
                g_string_append_printf(string, "=%02X", (guchar)*(str+i));
                *line_pos += QP_ENC_LEN;
        }
+       FN_END;
 }
 
 /* append plain visiable ascii character */
@@ -362,6 +367,7 @@ static void __bluetooth_pb_vcard_qp_encode_append_printable_c(GString *string,
                                                        gchar ch,
                                                        gint *line_pos)
 {
+       FN_START;
        /* add soft linebreak when it exceed */
        if (*line_pos + 1 > LINEBREAK_LEN) {
                g_string_append(string, "=\r\n");
@@ -369,6 +375,7 @@ static void __bluetooth_pb_vcard_qp_encode_append_printable_c(GString *string,
        }
        g_string_append_c(string, ch);
        (*line_pos)++;
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
@@ -376,7 +383,7 @@ static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
                                                gint len,
                                                gint *line_pos)
 {
-       gint length;
+       FN_START;
        gint encode_len;
 
        gint i = 0;
@@ -392,20 +399,17 @@ static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
                *line_pos = 0;
        }
 
-       length = strlen(str);
-       if (length > len)
-               length = len;
-
        while (i < len) {
                gchar *pos;
 
                pos = ((gchar *)str) + i;
 
-               /* converts invisiable character and escape character '=' to quoted-printable */
+               /* converts invisiable character and escape character '='
+                       to quoted-printable */
                if ((guchar)*pos != '\t' &&
                                ((guchar)*pos < ' ' || (guchar)*pos == '=')) {
-                       __bluetooth_pb_vcard_qp_encode_append_to_hex(string, pos,
-                                       1, line_pos);
+                       __bluetooth_pb_vcard_qp_encode_append_to_hex(string,
+                                                       pos, 1, line_pos);
                        i++;
 
                        continue;
@@ -419,20 +423,23 @@ static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
                        next = g_utf8_next_char(pos);
 
                        ch_len = next - pos;
-                       __bluetooth_pb_vcard_qp_encode_append_to_hex(string, pos,
-                                       ch_len, line_pos);
+                       __bluetooth_pb_vcard_qp_encode_append_to_hex(string,
+                                                       pos, ch_len, line_pos);
                        i += ch_len;
 
                        continue;
                }
 
-               __bluetooth_pb_vcard_qp_encode_append_printable_c(string, *pos, line_pos);
+               __bluetooth_pb_vcard_qp_encode_append_printable_c(string, *pos,
+                                                               line_pos);
                i++;
        }
+       FN_END;
 }
 
-static gchar__bluetooth_pb_vcard_qp_encode(const gchar *str)
+static gchar *__bluetooth_pb_vcard_qp_encode(const gchar *str)
 {
+       FN_START;
        GString *enc;
 
        gchar *st_pos;
@@ -460,15 +467,16 @@ static gchar* __bluetooth_pb_vcard_qp_encode(const gchar *str)
                        continue;
                }
 
-               /* split string with given delimeter '\r', '\n' or '\r\n' - newline */
-               if (*pos == '\r' || *pos == '\n' ) {
+               /* split string with given delimeter '\r', '\n' or
+                       '\r\n' - newline */
+               if (*pos == '\r' || *pos == '\n') {
                        __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
                                        (pos - st_pos), &line_pos);
 
                        /* converts newline to qp_encode with soft linebreak
                         for example, converts \r\n to =0D=0A=\r\n */
-                       __bluetooth_pb_vcard_qp_encode_append_to_hex(enc, "\r\n",
-                                       2, &line_pos);
+                       __bluetooth_pb_vcard_qp_encode_append_to_hex(enc,
+                                                       "\r\n", 2, &line_pos);
                        g_string_append(enc, "=\r\n ");
 
                        line_pos = 1;
@@ -489,12 +497,15 @@ static gchar* __bluetooth_pb_vcard_qp_encode(const gchar *str)
        __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
                        (pos - st_pos), &line_pos);
 
+       FN_END;
        return g_string_free(enc, FALSE);
 }
+/* LCOV_EXCL_STOP */
 
 static void __bluetooth_pb_vcard_append_param_v21(GString *string,
                                                 const gchar *param)
 {
+       FN_START;
        gchar *pos = NULL;
 
        if (param == NULL)
@@ -512,6 +523,7 @@ static void __bluetooth_pb_vcard_append_param_v21(GString *string,
 
        if (*pos != '\0')
                g_string_append_printf(string, ";%s", pos);
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
@@ -519,6 +531,7 @@ static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
                                                const gchar *param,
                                                const gchar *value)
 {
+       FN_START;
        GString *property = NULL;
 
        if (name == NULL)
@@ -528,6 +541,7 @@ static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
        __bluetooth_pb_vcard_append_param_v21(property, param);
 
        if (__bluetooth_pb_vcard_qp_encode_check(value)) {
+               /* LCOV_EXCL_START */
                gchar *enc = NULL;
 
                __bluetooth_pb_vcard_append_param_v21(property,
@@ -542,6 +556,7 @@ static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
                        g_string_append(property, enc);
                        g_free(enc);
                }
+               /* LCOV_EXCL_STOP */
        } else {
                g_string_append(property, ":");
                if (value)
@@ -551,9 +566,10 @@ static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
        g_string_append_printf(string, "%s\r\n", property->str);
 
        g_string_free(property, TRUE);
+       FN_END;
 }
 
-
+/* LCOV_EXCL_START */
 static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
                                                        const gchar *name,
                                                        const gchar *param,
@@ -561,10 +577,12 @@ static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
                                                        gsize len,
                                                        gboolean folding)
 {
+       FN_START;
        gchar *enc = NULL;
 
        if (name == NULL)
                return;
+       DBG("base 64 encoding\n");
 
        g_string_append(string, name);
 
@@ -578,7 +596,6 @@ static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
 
        enc = g_base64_encode((const guchar *)value, len);
 
-
        if (folding == FALSE) {
                g_string_append(string, enc);
        } else {
@@ -586,39 +603,60 @@ static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
                gint i = 0;
 
                /* count ' ' size for folding */
-               gint fline_len = LINEBREAK_LEN -1;
+               gint fline_len = LINEBREAK_LEN - 1;
 
                for (i = 0; (i * fline_len) < enc_len; i++) {
                        g_string_append(string, "\r\n ");
                        if ((i * fline_len) + fline_len > enc_len)
                                g_string_append(string, enc + (i * fline_len));
                        else
-                               g_string_append_len(string, enc + (i * fline_len), fline_len);
+                               g_string_append_len(string, enc +
+                                               (i * fline_len), fline_len);
                }
 
                /* some application requires more \r\n */
                g_string_append(string, "\r\n");
        }
        g_string_append(string, "\r\n");
+       DBG("base 64 encoding\n");
 
        g_free(enc);
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_n_v21(GString *string,
                                        contacts_record_h contact)
 {
+       FN_START;
        gchar *str;
 
        str = __bluetooth_pb_name_from_contact(contact);
        __bluetooth_pb_vcard_append_qp_encode_v21(string, "N", NULL, str);
 
        g_free(str);
+       FN_END;
+}
+
+static void __bluetooth_pb_vcard_append_phonetic_first_v21(GString *string,
+                                       contacts_record_h contact)
+{
+       FN_START;
+       gchar *str;
+
+       str = __bluetooth_pb_phonetic_name_from_contact(contact);
+
+       if (str != NULL) {
+               __bluetooth_pb_vcard_append_qp_encode_v21(string, "SOUND", "X-IRMC-N", str);
+               g_free(str);
+       }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_tel_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint i;
        gint status;
@@ -655,20 +693,23 @@ static void __bluetooth_pb_vcard_append_tel_v21(GString *string,
                escaped = __bluetooth_pb_vcard_escape(tel);
 
                paramv = __bluetooth_pb_contact_tel_param(number);
-               param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
-
-               g_strfreev(paramv);
-
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "TEL", param, escaped);
+               if (paramv) {
+                       param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
+                       g_strfreev(paramv);
+                       __bluetooth_pb_vcard_append_qp_encode_v21(string, "TEL", param,
+                                                               escaped);
+                       g_free(param);
+               }
 
                g_free(escaped);
-               g_free(param);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_fn_v21(GString *string,
                                        contacts_record_h person)
 {
+       FN_START;
        gint status;
 
        gchar *fn = NULL;
@@ -687,51 +728,318 @@ static void __bluetooth_pb_vcard_append_fn_v21(GString *string,
 
        g_free(fn);
 }
-
-static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
-                                               contacts_record_h person)
+/* LCOV_EXCL_STOP */
+
+/* image util APIs will be deprecated in Tizen 5.0. So we should replace it to new API
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#decode
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#encode
+*/
+#if 0
+static image_util_rotation_e __bt_pbap_get_rotation_info(const char *path)
 {
-       gint status;
+       FN_START;
+       ExifData *ed = NULL;
+       ExifEntry *entry;
+       image_util_rotation_e rotation = IMAGE_UTIL_ROTATION_NONE;
+       int orientation = 0;
 
-       gsize len = 0;
+       ed = exif_data_new_from_file(path);
+       if (ed == NULL) {
+               ERR("exif_data_new_from_file : ExifData is NULL");
+               return IMAGE_UTIL_ROTATION_NONE;
+       }
+
+       entry = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION);
+       if (entry) {
+               ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
+               orientation = (int)exif_get_short(entry->data, mByteOrder);
+               if (orientation < 0 || orientation > 8)
+                       orientation = 0;
+       }
+
+       exif_data_unref(ed);
+
+       switch (orientation) {
+       case 1: /* Top-left */
+               rotation = IMAGE_UTIL_ROTATION_NONE;
+               break;
+       case 2: /* Top-right */
+               rotation = IMAGE_UTIL_ROTATION_FLIP_HORZ;
+               break;
+       case 3: /* Bottom-right */
+               rotation = IMAGE_UTIL_ROTATION_180;
+               break;
+       case 4: /* Bottom-left */
+               rotation = IMAGE_UTIL_ROTATION_FLIP_VERT;
+               break;
+       case 6: /* Right-top */
+               rotation = IMAGE_UTIL_ROTATION_90;
+               break;
+       case 8: /* Left-bottom */
+               rotation = IMAGE_UTIL_ROTATION_270;
+               break;
+       case 5: /* Left-top */
+       case 7: /* Right-bottom */
+       case 0:
+       default:
+               break;
+       };
+
+       FN_END;
+       return rotation;
+}
 
-       gchar *filename = NULL;
 
+static bool __bt_pbap_image_util_supported_jpeg_colorspace_cb(
+                       image_util_colorspace_e colorspace, void *user_data)
+{
+       FN_START;
+       unsigned char *img_target = 0;
+       unsigned char *img_source = 0;
        gchar *type = NULL;
        gchar *param = NULL;
        gchar *contents = NULL;
+       int width = 0;
+       int height = 0;
+       int resized_width = 0;
+       int resized_height = 0;
+       int dest_fd = 0;
+       unsigned int size_decode = 0;
+       image_util_rotation_e rotation;
+       image_util_error_e ret = 0;
+       gsize len = 0;
 
+       bt_image_info_t *info = (bt_image_info_t *)user_data;
+       rotation = __bt_pbap_get_rotation_info(info->src);
+       ret = image_util_decode_jpeg(info->src, colorspace, &img_source, &width,
+                                                       &height, &size_decode);
+       if (ret != IMAGE_UTIL_ERROR_NONE) {
+               ERR("Can not decode");
+               memset(info, 0x00, sizeof(bt_image_info_t));
+               return true;
+       }
+
+       DBG("decoding completed width = %d, height = %d, size = %d\n", width,
+                                                       height, size_decode);
+       if (width > PBAP_IMAGE_THUMB_SIZE  || height > PBAP_IMAGE_THUMB_SIZE) {
+               if (width <= 0 || height <= 0) {
+                       free(img_source);
+                       ERR("image size error(%d)", PBAP_IMAGE_THUMB_SIZE);
+                       memset(info, 0x00, sizeof(bt_image_info_t));
+                       return false;
+               }
 
-       status = contacts_record_get_str_p(person,
-                       _contacts_person.image_thumbnail_path,
-                       &filename);
-
-       if (status != CONTACTS_ERROR_NONE)
-               return;
+               if (width > height) {
+                       resized_width = PBAP_IMAGE_THUMB_SIZE ;
+                       resized_height = height * PBAP_IMAGE_THUMB_SIZE / width;
+               } else {
+                       resized_height = PBAP_IMAGE_THUMB_SIZE;
+                       resized_width = width * PBAP_IMAGE_THUMB_SIZE / height;
+               }
 
-       type = __bluetooth_pb_contact_photo_type(filename);
+               if (resized_height % 8)
+                       resized_height += 8 - (resized_height % 8);
+               if (resized_width % 8)
+                       resized_width += 8 - (resized_width % 8);
+
+               DBG("original size[%d, %d] changed to resize[%d,%d]", width,
+                                       height, resized_width, resized_height);
+
+               ret = image_util_calculate_buffer_size(resized_width,
+                                                       resized_height,
+                                                       colorspace ,
+                                                       &size_decode);
+
+               img_target = g_malloc0(size_decode);
+
+               /* do resize */
+               ret = image_util_resize(img_target, &resized_width,
+                                       &resized_height, img_source, width,
+                                       height, colorspace);
+               if (ret != IMAGE_UTIL_ERROR_NONE) {
+                       ERR("image_util_resize failed(%d)", ret);
+                       g_free(img_target);
+                       free(img_source);
+                       memset(info, 0x00, sizeof(bt_image_info_t));
+                       return false;
+               }
+               free(img_source);
+       } else {
+               resized_width = width;
+               resized_height = height;
+               img_target = img_source;
+       }
+       DBG("Resized w = %d, ht = %d, size = %d\n", width, height, size_decode);
+
+       if (IMAGE_UTIL_ROTATION_NONE != rotation) {
+               int rotated_width, rotated_height;
+               unsigned char *img_rotate = 0;
+               img_rotate = g_malloc0(size_decode);
+               ret = image_util_rotate(img_rotate, &rotated_width, &rotated_height,
+                                       rotation, img_target, resized_width,
+                                       resized_height, colorspace);
+               if (ret != 0)
+                       ERR("image_util_rotate failed");
+               resized_width = rotated_width;
+               resized_height = rotated_height;
+               g_free(img_target);
+               img_target = img_rotate;
+       }
+
+       /* image encode */
+       ret = image_util_encode_jpeg(img_target, resized_width, resized_height,
+                                       colorspace, PBAP_IMAGE_ENCODE_QUALITY,
+                                       info->dest);
+       g_free(img_target);
+       if (ret != IMAGE_UTIL_ERROR_NONE) {
+               ERR("image_util_encode_jpeg failed(%d)", ret);
+               info->ret = CONTACTS_ERROR_INTERNAL;
+               goto done;
+       }
+       DBG("Encoding done\n");
+
+       dest_fd = open(info->dest, O_RDONLY);
+       if (dest_fd < 0) {
+               ERR("System : Open Failed(%d)", errno);
+               ERR_SECURE("Open : dest path(%s)", info->dest);
+               goto done;
+       }
+
+       ret = fchown(dest_fd, getuid(), PBAP_SECURITY_FILE_GROUP);
+       if (0 != ret) {
+               ERR("fchown Failed(%d)", errno);
+               DBG_SECURE("fchown : dest path(%s)", info->dest);
+               close(dest_fd);
+               goto done;
+       }
+
+       ret = fchmod(dest_fd, PBAP_SECURITY_IMAGE_PERMISSION);
+       if (0 != ret) {
+               ERR("fchmod Failed(%d)", errno);
+               ERR_SECURE("fchmod : dest path(%s)", info->dest);
+               close(dest_fd);
+               goto done;
+       }
+       close(dest_fd);
+
+       info->ret = CONTACTS_ERROR_NONE;
+       type = __bluetooth_pb_contact_photo_type(info->dest);
+       DBG("Cintact image thumb type is = %s\n", type);
 
        if (type) {
                param = g_strdup_printf("TYPE=%s", type);
                g_free(type);
        }
 
-       if (g_file_get_contents(filename, &contents, &len, NULL) == FALSE) {
-               ERR("can not read file contents:%s\n", filename);
-               return;
+       if (g_file_get_contents(info->dest, &contents, &len, NULL) == FALSE) {
+               ERR("can not read file contents:%s\n", info->dest);
+               goto done;
        }
 
-       __bluetooth_pb_vcard_append_base64_encode_v21(string,
+       __bluetooth_pb_vcard_append_base64_encode_v21(info->string,
                        "PHOTO", param, contents, len, TRUE);
 
+done:
        g_free(param);
        g_free(contents);
+       remove(info->dest);
+       memset(info, 0x00, sizeof(bt_image_info_t));
+       DBG("Cintact image thumb created successfuly\n");
+       FN_END;
+       return false;
+}
+#endif
+
+/* LCOV_EXCL_START */
+static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
+                                               contacts_record_h person)
+{
+       FN_START;
+       gint status;
+       gchar *filename = NULL;
+       struct stat stat_info;
+       gchar *type = NULL;
+       gchar *param = NULL;
+       gchar *contents = NULL;
+       gsize len = 0;
+       char *ptr = NULL;
+
+       status = contacts_record_get_str_p(person,
+                       _contacts_person.image_thumbnail_path,
+                       &filename);
+
+       if (status != CONTACTS_ERROR_NONE || NULL == filename)
+               return;
+
+       stat_info.st_size = 0;
+
+       if (0 > stat(filename, &stat_info))
+               ERR("fstat failed, file does not exist %s", filename);
+
+       if (PBAP_THUMB_FILE_SIZE > stat_info.st_size) {
+               DBG_SECURE("File size small, so use thubnail %s\n", filename);
+
+               type = __bluetooth_pb_contact_photo_type(filename);
+               if (type) {
+                       param = g_strdup_printf("TYPE=%s", type);
+                       g_free(type);
+               }
+
+               if (g_file_get_contents(filename, &contents, &len, NULL) ==
+                                                                       FALSE) {
+                       ERR("can not read file contents:%s\n", filename);
+                       g_free(param);
+                       return;
+               }
+               DBG("Retrieved the contents of the file \n");
+               __bluetooth_pb_vcard_append_base64_encode_v21(string,
+                               "PHOTO", param, contents, len, TRUE);
+
+               g_free(param);
+               g_free(contents);
+               return;
+       }
+
+       ptr = strrchr(filename, '.');
+       if (NULL != ptr) {
+               memset(dest_thumb_path, 0x00, sizeof(dest_thumb_path));
+               g_strlcpy(dest_thumb_path, filename, ptr - filename);
+               g_strlcat(dest_thumb_path, PBAP_THMB_PATH,
+                                               sizeof(dest_thumb_path));
+               g_strlcat(dest_thumb_path, ptr, sizeof(dest_thumb_path));
+               DBG("Thumbnail path is = %s", dest_thumb_path);
+       }
+       DBG_SECURE("filename = %s Thumbnail path is = %s", filename, dest_thumb_path);
+
+/* image_util_foreach_supported_jpeg_colorspace API will be deprecated in Tizen 5.0. So we should replace it to new API
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#decode
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#encode
+*/
+#if 0
+       bt_image_info_t img_info;
+       int res = 0;
+
+       img_info.src = filename;
+       img_info.dest = dest_thumb_path;
+       img_info.ret = CONTACTS_ERROR_INTERNAL;
+       img_info.person = person;
+       img_info.string = string;
+
+       res = image_util_foreach_supported_jpeg_colorspace(
+               __bt_pbap_image_util_supported_jpeg_colorspace_cb, &img_info);
+
+       if (res != IMAGE_UTIL_ERROR_NONE)
+               ERR("Image resizing is failed");
+#endif
+
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_bday_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -783,12 +1091,14 @@ static void __bluetooth_pb_vcard_append_bday_v21(GString *string,
                                NULL, bday);
                g_free(bday);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_adr_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -824,21 +1134,25 @@ static void __bluetooth_pb_vcard_append_adr_v21(GString *string,
                g_strfreev(addrv);
 
                paramv = __bluetooth_pb_contact_addr_param(address);
-               param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
-               g_strfreev(paramv);
+               if (paramv) {
+                       param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
+                       g_strfreev(paramv);
 
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "ADR",
-                               param, addr);
+                       __bluetooth_pb_vcard_append_qp_encode_v21(string, "ADR",
+                                       param, addr);
+                       g_free(param);
+               }
 
-               g_free(param);
                g_free(addr);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_email_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -870,16 +1184,19 @@ static void __bluetooth_pb_vcard_append_email_v21(GString *string,
                        continue;
 
                escaped = __bluetooth_pb_vcard_escape(tmp);
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "EMAIL", NULL, escaped);
+               __bluetooth_pb_vcard_append_qp_encode_v21(string, "EMAIL", NULL,
+                                                               escaped);
 
                g_free(escaped);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_title_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -898,7 +1215,7 @@ static void __bluetooth_pb_vcard_append_title_v21(GString *string,
                gchar *escaped;
 
                status = contacts_record_get_child_record_at_p(contact,
-                               _contacts_contact.company,i, &company);
+                                       _contacts_contact.company, i, &company);
 
                if (status != CONTACTS_ERROR_NONE)
                        continue;
@@ -911,16 +1228,19 @@ static void __bluetooth_pb_vcard_append_title_v21(GString *string,
                        continue;
 
                escaped = __bluetooth_pb_vcard_escape(title);
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "TITLE", NULL, escaped);
+               __bluetooth_pb_vcard_append_qp_encode_v21(string, "TITLE", NULL,
+                                                               escaped);
 
                g_free(escaped);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_role_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -952,16 +1272,19 @@ static void __bluetooth_pb_vcard_append_role_v21(GString *string,
                        continue;
 
                escaped = __bluetooth_pb_vcard_escape(role);
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "ROLE", NULL, escaped);
+               __bluetooth_pb_vcard_append_qp_encode_v21(string, "ROLE", NULL,
+                                                               escaped);
 
                g_free(escaped);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_org_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -1023,17 +1346,20 @@ static void __bluetooth_pb_vcard_append_org_v21(GString *string,
                        g_free(escaped);
                }
 
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "ORG", NULL, str->str);
+               __bluetooth_pb_vcard_append_qp_encode_v21(string, "ORG", NULL,
+                                                               str->str);
 
                g_string_free(str, TRUE);
 
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_note_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -1065,15 +1391,18 @@ static void __bluetooth_pb_vcard_append_note_v21(GString *string,
                        continue;
 
                escaped = __bluetooth_pb_vcard_escape(tmp);
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "NOTE", NULL, escaped);
+               __bluetooth_pb_vcard_append_qp_encode_v21(string, "NOTE", NULL,
+                                                               escaped);
 
                g_free(escaped);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_rev_v21(GString *string,
                                                contacts_record_h contact)
 {
+       FN_START;
        gint time = 0;
        gint status;
 
@@ -1090,21 +1419,24 @@ static void __bluetooth_pb_vcard_append_rev_v21(GString *string,
        if (time <= 0)
                return;
 
-       gmtime_r((const time_t*)(&time), &result);
+       gmtime_r((const time_t *)(&time), &result);
 
        rev = g_strdup_printf("%04d-%02d-%02dT%02d:%02d:%02dZ",
-                       (1900 + result.tm_year), (1 + result.tm_mon), result.tm_mday,
-                       result.tm_hour, result.tm_min, result.tm_sec);
+                       (1900 + result.tm_year), (1 + result.tm_mon),
+                       result.tm_mday, result.tm_hour, result.tm_min,
+                       result.tm_sec);
 
        __bluetooth_pb_vcard_append_qp_encode_v21(string, "REV", NULL, rev);
 
        g_free(rev);
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_url_v21(GString *string,
                                                contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint i;
        gint status;
@@ -1139,15 +1471,18 @@ static void __bluetooth_pb_vcard_append_url_v21(GString *string,
                        continue;
 
                escaped = __bluetooth_pb_vcard_escape(tmp);
-               __bluetooth_pb_vcard_append_qp_encode_v21(string, "URL", NULL, escaped);
+               __bluetooth_pb_vcard_append_qp_encode_v21(string, "URL", NULL,
+                                                               escaped);
 
                g_free(escaped);
        }
+       FN_END;
 }
 
 static void __bluetooth_pb_vcard_append_uid_v21(GString *string,
                                                contacts_record_h contact)
 {
+       FN_START;
        int status;
 
        gchar *uid = NULL;
@@ -1164,13 +1499,16 @@ static void __bluetooth_pb_vcard_append_uid_v21(GString *string,
        __bluetooth_pb_vcard_append_qp_encode_v21(string, "UID", NULL, escaped);
 
        g_free(escaped);
+       FN_END;
 }
+/* LCOV_EXCL_STOP */
 
 static void __bluetooth_pb_vcard_append_v30(GString *string,
                                        const gchar *name,
                                        const gchar *param,
                                        const gchar *value)
 {
+       FN_START;
        if (string == NULL)
                return;
        if (name == NULL)
@@ -1187,22 +1525,25 @@ static void __bluetooth_pb_vcard_append_v30(GString *string,
                g_string_append(string, value);
 
        g_string_append(string, "\r\n");
+       FN_END;
 }
 
+/* LCOV_EXCL_START */
 static void __bluetooth_pb_vcard_remove_v30(GString *string,
                                        const gchar *property_name)
 {
+       FN_START;
        gchar *pos = NULL;
        gchar *st_pos = NULL;
 
        gboolean matched = FALSE;
 
-       if(string == NULL || property_name == NULL)
+       if (string == NULL || property_name == NULL)
                return;
 
        pos = string->str;
 
-       while(*pos != '\0') {
+       while (*pos != '\0') {
                if (matched == FALSE) {
                        if (g_ascii_strncasecmp(pos, "\r\n", 2) == 0) {
                                gint attrlen = 0;
@@ -1211,7 +1552,8 @@ static void __bluetooth_pb_vcard_remove_v30(GString *string,
                                pos += 2;
 
                                attrlen = strlen(property_name);
-                               if (g_ascii_strncasecmp(pos, property_name, attrlen) == 0) {
+                               if (g_ascii_strncasecmp(pos, property_name,
+                                                               attrlen) == 0) {
                                        pos += attrlen;
 
                                        if (*pos == ':' || *pos == ';') {
@@ -1221,14 +1563,16 @@ static void __bluetooth_pb_vcard_remove_v30(GString *string,
                                }
                                continue;
                        }
-               }
-               else {
+               } else {
                        if (g_ascii_strncasecmp(pos, "\r\n", 2) == 0) {
                                pos += 2;
 
                                if (*pos != ' ' && *pos != '\t') {
                                        /* +2 means move over \r\n */
-                                       g_string_erase(string, (st_pos+2)-(string->str), pos-(st_pos +2));
+                                       g_string_erase(string,
+                                               (st_pos+2)-(string->str),
+                                               pos-(st_pos+2));
+
                                        pos = st_pos;
                                        matched = FALSE;
                                }
@@ -1238,11 +1582,13 @@ static void __bluetooth_pb_vcard_remove_v30(GString *string,
 
                pos++;
        }
+       FN_END;
 }
 
 static gchar *__bluetooth_pb_vcard_filter_v30(const gchar *vcard,
                                        guint64 filter)
 {
+       FN_START;
        GString *string = NULL;
 
        if (vcard == NULL)
@@ -1250,42 +1596,40 @@ static gchar *__bluetooth_pb_vcard_filter_v30(const gchar *vcard,
 
        string = g_string_new(vcard);
 
-       if ((filter & VCARD_PHOTO) == 0)
-               __bluetooth_pb_vcard_remove_v30(string, "PHOTO");
-
        if ((filter & VCARD_BDAY) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "BDAY");
 
-       if ((filter & VCARD_ADR) == 0 )
+       if ((filter & VCARD_ADR) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "ADR");
 
-       if ((filter & VCARD_EMAIL) == 0 )
+       if ((filter & VCARD_EMAIL) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "EMAIL");
 
-       if ((filter & VCARD_TITLE) == 0 )
+       if ((filter & VCARD_TITLE) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "TITLE");
 
-       if ((filter & VCARD_ROLE) == 0 )
+       if ((filter & VCARD_ROLE) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "ROLE");
 
-       if ((filter & VCARD_ORG) == 0 )
+       if ((filter & VCARD_ORG) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "ORG");
 
-       if ((filter & VCARD_NOTE) == 0 )
+       if ((filter & VCARD_NOTE) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "NOTE");
 
-       if ((filter & VCARD_REV) == 0 )
+       if ((filter & VCARD_REV) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "REV");
 
-       if ((filter & VCARD_URL) == 0 )
+       if ((filter & VCARD_URL) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "URL");
 
-       if ((filter & VCARD_UID) == 0 )
+       if ((filter & VCARD_UID) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "UID");
 
-       if ((filter & VCARD_NICKNAME) == 0 )
+       if ((filter & VCARD_NICKNAME) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "NICKNAME");
 
+       FN_END;
        return g_string_free(string, FALSE);
 }
 
@@ -1295,6 +1639,7 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
                                                        const gchar *first_name,
                                                        va_list args)
 {
+       FN_START;
        contacts_record_h person = NULL;
        contacts_record_h contact = NULL;
 
@@ -1333,6 +1678,8 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
        if (f == 0)
                f = ~f;
 
+       DBG("filter[%llu]\n", (unsigned long long int)filter);
+
        str = g_string_new("BEGIN:VCARD\r\nVERSION:2.1\r\n");
 
        /* N, TEL is default */
@@ -1342,7 +1689,8 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
                gchar *number;
 
                number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
-               __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0", number);
+               __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0",
+                                                                       number);
                g_free(number);
 
 
@@ -1352,6 +1700,9 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
 
        if (f & VCARD_FN)
                __bluetooth_pb_vcard_append_fn_v21(str, person);
+/*     Need to check filter
+       if (f & VCARD_SOUND)*/
+               __bluetooth_pb_vcard_append_phonetic_first_v21(str, contact);
        if (f & VCARD_PHOTO)
                __bluetooth_pb_vcard_append_photo_v21(str, person);
        if (f & VCARD_BDAY)
@@ -1383,7 +1734,8 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
                        gchar *escaped = NULL;
 
                        escaped = __bluetooth_pb_vcard_escape(value);
-                       __bluetooth_pb_vcard_append_qp_encode_v21(str, name, param, escaped);
+                       __bluetooth_pb_vcard_append_qp_encode_v21(str, name,
+                                                               param, escaped);
 
                        g_free(escaped);
                }
@@ -1396,9 +1748,10 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
        contacts_record_destroy(contact, TRUE);
        contacts_record_destroy(person, TRUE);
 
+       FN_END;
        return g_string_free(str, FALSE);
 }
-
+/* LCOV_EXCL_STOP */
 
 static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                                                        gint phonelog_id,
@@ -1406,6 +1759,7 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                                                        const gchar *first_name,
                                                        va_list args)
 {
+       FN_START;
        contacts_record_h person = NULL;
 
        GString *str = NULL;
@@ -1422,17 +1776,14 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* LCOV_EXCL_START */
        status = contacts_vcard_make_from_person(person, &vcard);
 
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
-       status = contacts_record_destroy(person, TRUE);
-
-       if (status != CONTACTS_ERROR_NONE)
-               return NULL;
-
-       str = g_string_new(vcard);
+       /* removing the END:VCARD\r\n" to append extra data */
+       str = g_string_new_len(vcard, (strlen(vcard)-11));
        g_free(vcard);
 
        /* append contents on vcard */
@@ -1445,8 +1796,8 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                name = va_arg(args, const gchar *);
        }
 
-       /* if phonelog_id exist,
-          we shall show only the phone number, which was used for that phone log */
+       /* if phonelog_id exist, we shall show only the phone number, which was
+          used for that phone log */
        if (phonelog_id > 0) {
                gchar *number;
 
@@ -1457,6 +1808,18 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                g_free(number);
        }
 
+       /* Remove Full contact image and add thumbnail image */
+       __bluetooth_pb_vcard_remove_v30(str, "PHOTO");
+       if (filter & VCARD_PHOTO)
+               __bluetooth_pb_vcard_append_photo_v21(str, person); /* Photo is same as vCard 2.1 */
+
+       /* Destroy contact record */
+       status = contacts_record_destroy(person, TRUE);
+       if (status != CONTACTS_ERROR_NONE)
+               ERR("Failed to destroy person");
+
+       g_string_append(str, "END:VCARD\r\n");
+
        vcard = g_string_free(str, FALSE);
 
        /* temporary fixed for some application crash */
@@ -1474,24 +1837,27 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                }
        }
 
+       FN_END;
        return vcard;
+       /* LCOV_EXCL_STOP */
 }
 
 
 static gchar *__bluetooth_pb_vcard_real_contact_with_properties(gint person_id,
-                                                               gint phonelog_id,
-                                                               guint64 filter,
-                                                               guint8 format,
-                                                               const gchar *first_name,
-                                                               ...)
+                                                       gint phonelog_id,
+                                                       guint64 filter,
+                                                       guint8 format,
+                                                       const gchar *first_name,
+                                                       ...)
 {
-       DBG("\n");
+       FN_START;
+       DBG(" format [%d]\n", format);
        gchar *vcard = NULL;
        va_list args;
 
        va_start(args, first_name);
 
-       switch(format) {
+       switch (format) {
        case VCARD_FORMAT_3_0:
                vcard = __bluetooth_pb_vcard_real_contact_valist_v30(person_id,
                                phonelog_id, filter,
@@ -1507,6 +1873,7 @@ static gchar *__bluetooth_pb_vcard_real_contact_with_properties(gint person_id,
 
        va_end(args);
 
+       FN_END;
        return vcard;
 }
 
@@ -1514,6 +1881,7 @@ static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
                                                guint filter,
                                                const char *attr)
 {
+       FN_START;
        GString *str;
        gchar *number;
 
@@ -1525,25 +1893,31 @@ static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
        __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0", number);
        g_free(number);
 
+       /* LCOV_EXCL_START */
        if (((filter == 0) || (filter & VCARD_X_IRMC_CALL_DATETIME))
                        && attr) {
                gchar *datetime = NULL;
 
                datetime = __bluetooth_pb_phonelog_datetime(phonelog_id);
-               __bluetooth_pb_vcard_append_qp_encode_v21(str, "X-IRMC-CALL-DATETIME",
-                               attr, datetime);
+               __bluetooth_pb_vcard_append_qp_encode_v21(str,
+                                                       "X-IRMC-CALL-DATETIME",
+                                                       attr, datetime);
                g_free(datetime);
        }
+       /* LCOV_EXCL_STOP */
 
        g_string_append(str, "END:VCARD\r\n");
 
+       FN_END;
        return g_string_free(str, FALSE);
 }
 
+/* LCOV_EXCL_START */
 static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
                                                guint filter,
                                                const gchar *attr)
 {
+       FN_START;
        GString *str;
        gchar *number;
 
@@ -1568,18 +1942,20 @@ static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
 
        g_string_append(str, "END:VCARD\r\n");
 
+       FN_END;
        return g_string_free(str, FALSE);
 }
+/* LCOV_EXCL_STOP */
 
 static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
                                        guint filter,
                                        guint8 format,
                                        const gchar *attr)
 {
-       DBG("\n");
+       FN_START;
        gchar *vcard = NULL;
 
-       switch(format) {
+       switch (format) {
        case VCARD_FORMAT_3_0:
                vcard = __bluetooth_pb_vcard_real_call_v30(phonelog_id,
                                filter, attr);
@@ -1591,13 +1967,16 @@ static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
                break;
        }
 
+       FN_END;
        return vcard;
 }
 
+/* LCOV_EXCL_START */
 static gchar **__bluetooth_pb_contact_add_field_str(contacts_record_h record,
                                                int *field,
                                                gint field_size)
 {
+       FN_START;
        gchar **strv;
 
        gint status;
@@ -1639,11 +2018,13 @@ static gchar **__bluetooth_pb_contact_add_field_str(contacts_record_h record,
                        strv[i] = __bluetooth_pb_vcard_escape(tmp);
        }
 
+       FN_END;
        return strv;
 }
 
 static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
 {
+       FN_START;
        gchar **strv = NULL;
 
        const gint TEL_PARAM_LEN = 13;
@@ -1655,19 +2036,12 @@ static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
 
        bool is_default = false;
 
-       strv = g_new0(char *, TEL_PARAM_LEN + 1);       /* tel param max size is 13 */
-
        status = contacts_record_get_bool(number, _contacts_number.is_default,
                        &is_default);
 
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
-       if (is_default) {
-               strv[i] = g_strdup("PREF");
-               i++;
-       }
-
        status = contacts_record_get_int(number,
                        _contacts_number.type,
                        (gint *)&type);
@@ -1675,6 +2049,13 @@ static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       strv = g_new0(char *, TEL_PARAM_LEN + 1);/* tel param max size is 13 */
+
+       if (is_default) {
+               strv[i] = g_strdup("PREF");
+               i++;
+       }
+
        if (type & CONTACTS_NUMBER_TYPE_HOME) {
                strv[i] = g_strdup("HOME");
                i++;
@@ -1736,17 +2117,19 @@ static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
        }
 
        /* CTS_NUM_TYPE_PCS is not part of vcard2.1 */
+       FN_END;
        return strv;
 }
 
 
 static gchar *__bluetooth_pb_contact_photo_type(const gchar *filename)
 {
+       FN_START;
        gchar *filetype = NULL;
        gchar *ext = NULL;
 
        if (g_file_test(filename, G_FILE_TEST_IS_REGULAR) == FALSE) {
-               ERR("file does not regular:%s\n", filename);
+               ERR_SECURE("file does not regular:%s\n", filename);
                return NULL;
        }
 
@@ -1770,19 +2153,23 @@ static gchar *__bluetooth_pb_contact_photo_type(const gchar *filename)
                filetype = "MET";
        else if (g_ascii_strcasecmp(ext, "dib") == 0)
                filetype = "DIB";
-       else if (g_ascii_strcasecmp(ext, "pict") == 0 || g_ascii_strcasecmp(ext, "pct") == 0 ||
+       else if (g_ascii_strcasecmp(ext, "pict") == 0 ||
+                       g_ascii_strcasecmp(ext, "pct") == 0 ||
                        g_ascii_strcasecmp(ext, "pic") == 0)
                filetype = "PICT";
-       else if (g_ascii_strcasecmp(ext, "tiff") == 0 || g_ascii_strcasecmp(ext, "tif") == 0)
+       else if (g_ascii_strcasecmp(ext, "tiff") == 0 ||
+                       g_ascii_strcasecmp(ext, "tif") == 0)
                filetype = "TIFF";
        else if (g_ascii_strcasecmp(ext, "ps") == 0)
                filetype = "PS";
        else if (g_ascii_strcasecmp(ext, "pdf") == 0)
                filetype = "PDF";
-       else if (g_ascii_strcasecmp(ext, "jpeg") == 0 || g_ascii_strcasecmp(ext, "jpg") == 0 ||
+       else if (g_ascii_strcasecmp(ext, "jpeg") == 0 ||
+                       g_ascii_strcasecmp(ext, "jpg") == 0 ||
                        g_ascii_strcasecmp(ext, "jpe") == 0)
                filetype = "JPEG";
-       else if (g_ascii_strcasecmp(ext, "mpeg") == 0 || g_ascii_strcasecmp(ext, "mpg") == 0)
+       else if (g_ascii_strcasecmp(ext, "mpeg") == 0 ||
+                       g_ascii_strcasecmp(ext, "mpg") == 0)
                filetype = "MPEG";
        else if (g_ascii_strcasecmp(ext, "m2v") == 0)
                filetype = "MPEG2";
@@ -1793,11 +2180,13 @@ static gchar *__bluetooth_pb_contact_photo_type(const gchar *filename)
        else if (g_ascii_strcasecmp(ext, "png") == 0)
                filetype = "PNG";
 
+       FN_END;
        return g_strdup(filetype);
 }
 
 static gchar **__bluetooth_pb_contact_addr(contacts_record_h address)
 {
+       FN_START;
        const gint ADDR_LEN = 7;
 
        gchar **strv = NULL;
@@ -1812,12 +2201,13 @@ static gchar **__bluetooth_pb_contact_addr(contacts_record_h address)
 
        strv = __bluetooth_pb_contact_add_field_str(address,
                        addr, ADDR_LEN);
+       FN_END;
        return strv;
 }
 
 static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address)
 {
-
+       FN_START;
        contacts_address_type_e type;
 
        gint status;
@@ -1825,8 +2215,6 @@ static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address)
 
        gchar **strv = NULL;
 
-       strv = g_new0(gchar *, 7);      /* ADDR param max size is 6 */
-
        status = contacts_record_get_int(address,
                        _contacts_address.type,
                        (gint *)&type);
@@ -1834,6 +2222,8 @@ static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       strv = g_new0(gchar *, 7);      /* ADDR param max size is 6 */
+
        if (type & CONTACTS_ADDRESS_TYPE_HOME) {
                strv[i] = g_strdup("HOME");
                i++;
@@ -1858,11 +2248,13 @@ static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address)
                strv[i] = g_strdup("PARCEL");
                i++;
        }
+       FN_END;
        return strv;
 }
 
 static gchar *__bluetooth_pb_phonelog_datetime(gint phonelog_id)
 {
+       FN_START;
        contacts_record_h phone_log;
 
        char time_str[32] = {0,};
@@ -1896,15 +2288,16 @@ static gchar *__bluetooth_pb_phonelog_datetime(gint phonelog_id)
 
        contacts_record_destroy(phone_log, TRUE);
 
+       FN_END;
        return g_strdup(time_str);
 }
 
 static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact)
 {
+       FN_START;
        contacts_record_h name = NULL;
 
-       GString *str = g_string_new(NULL);
-
+       GString *str;
        gint status;
        gint i;
 
@@ -1922,6 +2315,8 @@ static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       str = g_string_new(NULL);
+
        for (i = 0; i < name_size; i++) {
                gchar *tmp = NULL;
                gchar *escape = NULL;
@@ -1940,12 +2335,66 @@ static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact)
                g_free(escape);
        }
 
+       FN_END;
+       return g_string_free(str, FALSE);
+}
+
+static gchar *__bluetooth_pb_phonetic_name_from_contact(contacts_record_h contact)
+{
+       FN_START;
+       contacts_record_h name = NULL;
+
+       GString *str;
+
+       gint status;
+
+       gchar *phonetic_first = NULL;
+       gchar *phonetic_last = NULL;
+       gchar *escape = NULL;
+
+       status = contacts_record_get_child_record_at_p(contact,
+                       _contacts_contact.name, 0, &name);
+
+       if (status != CONTACTS_ERROR_NONE)
+               return NULL;
+
+       status = contacts_record_get_str_p(name, _contacts_name.phonetic_first, &phonetic_first);
+
+       if (status != CONTACTS_ERROR_NONE)
+               return NULL;
+
+       if (phonetic_first == NULL)
+               return NULL;
+
+       str = g_string_new(NULL);
+
+       status = contacts_record_get_str_p(name, _contacts_name.phonetic_last, &phonetic_last);
+
+       if ((status == CONTACTS_ERROR_NONE) && (phonetic_last != NULL)) {
+               escape = __bluetooth_pb_vcard_escape(phonetic_last);
+               g_string_append(str, escape);
+               g_free(escape);
+               g_string_append_c(str, ' ');
+       }
+
+       escape = __bluetooth_pb_vcard_escape(phonetic_first);
+       g_string_append(str, escape);
+
+       g_free(escape);
+       g_string_append_c(str, ';');
+       g_string_append_c(str, ';');
+       g_string_append_c(str, ';');
+       g_string_append_c(str, ';');
+
+       FN_END;
        return g_string_free(str, FALSE);
 }
 
+
 static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact)
 {
-       guint count = 0;
+       FN_START;
+       gint count = 0;
 
        gint status;
        gint i;
@@ -2017,11 +2466,14 @@ static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact)
                str = g_strdup(tmp);
        }
 
+       FN_END;
        return str;
 }
+/* LCOV_EXCL_STOP */
 
 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id)
 {
+       FN_START;
        contacts_query_h query = NULL;
        contacts_filter_h filter = NULL;
        contacts_list_h record_list = NULL;
@@ -2039,6 +2491,7 @@ static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id)
        if (status != CONTACTS_ERROR_NONE)
                return 0;
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_int(phone_log,
                        _contacts_phone_log.person_id,
                        &person_id);
@@ -2065,79 +2518,121 @@ static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id)
                        CONTACTS_MATCH_EQUAL,
                        phonelog_id);
 
-       if (status != CONTACTS_ERROR_NONE) {
-               contacts_filter_destroy(filter);
-               return 0;
-       }
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
 
        status = contacts_query_create(_contacts_person_phone_log._uri, &query);
 
-       if (status != CONTACTS_ERROR_NONE) {
-               contacts_filter_destroy(filter);
-               return 0;
-       }
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
 
        status = contacts_query_set_filter(query, filter);
 
-       if (status != CONTACTS_ERROR_NONE) {
-               contacts_filter_destroy(filter);
-               contacts_query_destroy(query);
-               return 0;
-       }
-
-       status = contacts_db_get_records_with_query(query, -1, -1, &record_list);
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
 
-       if (status != CONTACTS_ERROR_NONE) {
-               contacts_filter_destroy(filter);
-               contacts_query_destroy(query);
+       status = contacts_db_get_records_with_query(query, -1, -1,
+                                                               &record_list);
 
-               return 0;
-       }
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
 
        status = contacts_list_first(record_list);
 
-       if (status != CONTACTS_ERROR_NONE) {
-               contacts_list_destroy(record_list, TRUE);
-               contacts_filter_destroy(filter);
-               contacts_query_destroy(query);
-
-               return 0;
-       }
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
 
        status = contacts_list_get_current_record_p(record_list, &record);
 
-       if (status != CONTACTS_ERROR_NONE) {
-               contacts_list_destroy(record_list, TRUE);
-               contacts_filter_destroy(filter);
-               contacts_query_destroy(query);
-
-               return 0;
-       }
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
 
        status = contacts_record_get_int(record,
                        _contacts_person_phone_log.person_id,
                        &person_id);
 
-       if (status != CONTACTS_ERROR_NONE) {
-               contacts_list_destroy(record_list, TRUE);
-               contacts_filter_destroy(filter);
-               contacts_query_destroy(query);
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
 
-               return 0;
-       }
+done:
+       if (record_list != NULL)
+               contacts_list_destroy(record_list, TRUE);
 
-       contacts_list_destroy(record_list, TRUE);
        contacts_filter_destroy(filter);
-       contacts_query_destroy(query);
 
+       if (query != NULL)
+               contacts_query_destroy(query);
+
+       FN_END;
        return person_id;
+       /* LCOV_EXCL_STOP */
 }
 
+int _bluetooth_get_contact_addressbook(gint person_id)
+{
+       contacts_record_h person = NULL;
+       contacts_record_h contact = NULL;
+       contacts_record_h addressbook = NULL;
+
+       char* addressbook_name = NULL;
+       gint contact_id = 0;
+       gint address_book_id = 0;
+       gint status;
+
+       status = contacts_db_get_record(_contacts_person._uri,
+                       person_id,
+                       &person);
+       if (status != CONTACTS_ERROR_NONE)
+               return PBAP_ADDRESSBOOK_PHONE; /* Default*/
+
+       /* LCOV_EXCL_START */
+       status = contacts_record_get_int(person,
+                       _contacts_person.display_contact_id,
+                       &contact_id);
+       contacts_record_destroy(person, TRUE);
+
+       if (status != CONTACTS_ERROR_NONE)
+               return PBAP_ADDRESSBOOK_PHONE; /* Default*/
+
+       status = contacts_db_get_record(_contacts_contact._uri,
+                       contact_id,
+                       &contact);
+       if (status != CONTACTS_ERROR_NONE)
+               return PBAP_ADDRESSBOOK_PHONE; /* Default*/
+
+       status = contacts_record_get_int(contact,
+                       _contacts_contact.address_book_id,
+                       &address_book_id);
+       contacts_record_destroy(contact, TRUE);
+
+       if (status != CONTACTS_ERROR_NONE)
+               return PBAP_ADDRESSBOOK_PHONE; /* Default*/
+
+       status = contacts_db_get_record(_contacts_address_book._uri,
+                       address_book_id,
+                       &addressbook);
+       if (status != CONTACTS_ERROR_NONE)
+               return PBAP_ADDRESSBOOK_PHONE; /* Default*/
+
+       status = contacts_record_get_str_p(addressbook, _contacts_address_book.name,
+                                               &addressbook_name);
+       contacts_record_destroy(addressbook, TRUE);
+
+       if (status != CONTACTS_ERROR_NONE)
+               return PBAP_ADDRESSBOOK_PHONE; /* Default*/
+
+       if (address_book_id == 0 || _bt_is_sim_addressbook(addressbook_name) == false)
+               return PBAP_ADDRESSBOOK_PHONE;
+
+       return PBAP_ADDRESSBOOK_SIM;
+       /* LCOV_EXCL_STOP */
+}
 /* API for vcard */
 gchar *_bluetooth_pb_vcard_contact(gint person_id,
                                guint64 filter,
                                guint8 format)
 {
+       FN_START;
        gchar *str = NULL;
 
        if (person_id <= 0)
@@ -2146,6 +2641,7 @@ gchar *_bluetooth_pb_vcard_contact(gint person_id,
        str = __bluetooth_pb_vcard_real_contact_with_properties(person_id, 0,
                        filter, format,
                        NULL);
+       FN_END;
        return str;
 }
 
@@ -2153,6 +2649,7 @@ gchar *_bluetooth_pb_vcard_contact_owner(const gchar *number,
                                        guint64 filter,
                                        guint8 format)
 {
+       FN_START;
        GString *str = g_string_new("BEGIN:VCARD\r\n");
        gchar *fn;
        gchar *name;
@@ -2166,18 +2663,21 @@ gchar *_bluetooth_pb_vcard_contact_owner(const gchar *number,
 
                __bluetooth_pb_vcard_append_v30(str, "N", NULL, name);
                __bluetooth_pb_vcard_append_v30(str, "FN", NULL, fn);
-               __bluetooth_pb_vcard_append_v30(str, "TEL", "TYPE=CELL", number);
+               __bluetooth_pb_vcard_append_v30(str, "TEL", "TYPE=CELL",
+                                                                       number);
                break;
        case VCARD_FORMAT_2_1:
-       default :
+       default:
                g_string_append(str, "VERSION:2.1\r\n");
 
                __bluetooth_pb_vcard_append_qp_encode_v21(str, "N", NULL, name);
 
                if (filter == 0 || (filter & VCARD_FN))
-                       __bluetooth_pb_vcard_append_qp_encode_v21(str, "FN", NULL, fn);
+                       __bluetooth_pb_vcard_append_qp_encode_v21(str, "FN",
+                                                               NULL, fn);
 
-               __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "CELL", number);
+               __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "CELL",
+                                                                       number);
                break;
 
        }
@@ -2187,6 +2687,7 @@ gchar *_bluetooth_pb_vcard_contact_owner(const gchar *number,
        g_free(fn);
        g_free(name);
 
+       FN_END;
        return g_string_free(str, FALSE);
 }
 
@@ -2195,12 +2696,13 @@ gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
                                guint8 format,
                                const gchar *attr)
 {
+       FN_START;
        gint person_id = 0;
 
        gchar *str = NULL;
 
        if (attr == NULL) {
-               DBG("Unknown attribute type ignored\n");
+               ERR("Unknown attribute type ignored\n");
                return NULL;
        }
 
@@ -2209,35 +2711,41 @@ gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
        DBG("person_id %d\n", person_id);
 
        if (person_id) {
+               /* LCOV_EXCL_START */
                if (filter == 0 || (filter & VCARD_X_IRMC_CALL_DATETIME)) {
                        gchar *datetime = NULL;
 
-                       datetime = __bluetooth_pb_phonelog_datetime(phonelog_id);
+                       datetime = __bluetooth_pb_phonelog_datetime(
+                                                               phonelog_id);
 
-                       str = __bluetooth_pb_vcard_real_contact_with_properties(person_id,
+                       str = __bluetooth_pb_vcard_real_contact_with_properties(
+                                       person_id,
                                        phonelog_id,
                                        filter, format,
                                        "X-IRMC-CALL-DATETIME", attr, datetime,
                                        NULL);
 
-                       if(datetime)
+                       if (datetime)
                                g_free(datetime);
-               }
-               else {
-                       str = __bluetooth_pb_vcard_real_contact_with_properties(person_id,
+               } else {
+                       str = __bluetooth_pb_vcard_real_contact_with_properties(
+                                       person_id,
                                        phonelog_id,
                                        filter, format,
                                        NULL);
                }
-       }
-       else
-               str = __bluetooth_pb_vcard_real_call(phonelog_id, filter, format, attr);
+               /* LCOV_EXCL_STOP */
+       } else
+               str = __bluetooth_pb_vcard_real_call(phonelog_id, filter,
+                                                               format, attr);
 
+       FN_END;
        return str;
 }
 
 gchar *_bluetooth_pb_fn_from_person_id(gint person_id)
 {
+       FN_START;
        contacts_record_h person = NULL;
 
        gint status;
@@ -2251,6 +2759,7 @@ gchar *_bluetooth_pb_fn_from_person_id(gint person_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_str(person,
                        _contacts_person.display_name,
                        &str);
@@ -2260,11 +2769,14 @@ gchar *_bluetooth_pb_fn_from_person_id(gint person_id)
 
        contacts_record_destroy(person, TRUE);
 
+       FN_END;
        return str;
+       /* LCOV_EXCL_STOP */
 }
 
 gchar *_bluetooth_pb_name_from_person_id(gint person_id)
 {
+       FN_START;
        contacts_record_h person = NULL;
        contacts_record_h contact = NULL;
 
@@ -2280,6 +2792,7 @@ gchar *_bluetooth_pb_name_from_person_id(gint person_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_int(person,
                        _contacts_person.display_contact_id,
                        &contact_id);
@@ -2289,7 +2802,7 @@ gchar *_bluetooth_pb_name_from_person_id(gint person_id)
                return NULL;
        }
 
-       contacts_db_get_record(_contacts_contact._uri,
+       status = contacts_db_get_record(_contacts_contact._uri,
                        contact_id,
                        &contact);
 
@@ -2302,12 +2815,15 @@ gchar *_bluetooth_pb_name_from_person_id(gint person_id)
 
        contacts_record_destroy(contact, TRUE);
        contacts_record_destroy(person, TRUE);
+       /* LCOV_EXCL_STOP */
 
+       FN_END;
        return str;
 }
 
 gchar *_bluetooth_pb_number_from_person_id(gint person_id)
 {
+       FN_START;
        contacts_record_h person = NULL;
        contacts_record_h contact = NULL;
 
@@ -2323,7 +2839,7 @@ gchar *_bluetooth_pb_number_from_person_id(gint person_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
-
+       /* LCOV_EXCL_START */
        status = contacts_record_get_int(person,
                        _contacts_person.display_contact_id,
                        &contact_id);
@@ -2346,12 +2862,15 @@ gchar *_bluetooth_pb_number_from_person_id(gint person_id)
 
        contacts_record_destroy(contact, TRUE);
        contacts_record_destroy(person, TRUE);
+       /* LCOV_EXCL_STOP */
 
+       FN_END;
        return str;
 }
 
 gchar *_bluetooth_pb_fn_from_phonelog_id(gint phonelog_id)
 {
+       FN_START;
        gint person_id = 0;
        gchar *str = NULL;
 
@@ -2360,13 +2879,15 @@ gchar *_bluetooth_pb_fn_from_phonelog_id(gint phonelog_id)
        if (person_id > 0)
                str = _bluetooth_pb_fn_from_person_id(person_id);
        else
-               str = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
+               str = g_strdup("");
 
+       FN_END;
        return str;
 }
 
 gchar *_bluetooth_pb_name_from_phonelog_id(gint phonelog_id)
 {
+       FN_START;
        gint person_id = 0;
        gchar *str = NULL;
 
@@ -2383,11 +2904,13 @@ gchar *_bluetooth_pb_name_from_phonelog_id(gint phonelog_id)
                g_free(tmp);
        }
 
+       FN_END;
        return str;
 }
 
 gchar *_bluetooth_pb_number_from_phonelog_id(gint phonelog_id)
 {
+       FN_START;
        contacts_record_h phone_log;
 
        gint status;
@@ -2401,7 +2924,8 @@ gchar *_bluetooth_pb_number_from_phonelog_id(gint phonelog_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
-       contacts_record_get_str_p(phone_log,
+       /* LCOV_EXCL_START */
+       status = contacts_record_get_str_p(phone_log,
                        _contacts_phone_log.address,
                        &tmp);
 
@@ -2413,18 +2937,27 @@ gchar *_bluetooth_pb_number_from_phonelog_id(gint phonelog_id)
        str = g_strdup(tmp);
 
        contacts_record_destroy(phone_log, TRUE);
+       /* LCOV_EXCL_STOP */
 
+       FN_END;
        return str;
 }
 
 gchar *_bluetooth_pb_owner_name(void)
 {
+       FN_START;
        gchar *name;
 
        name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
 
        if (name == NULL)
-               name = g_strdup("My Name");
+               name = g_strdup("My Name"); /* LCOV_EXCL_LINE */
 
+       FN_END;
        return name;
 }
+
+bool _bt_is_sim_addressbook(const char *addressbook)
+{
+       return g_str_has_prefix(addressbook, SIM_ADDRESSBOOK_PREFIX);
+}