Specify the sender to receive necessary PropertiesChanged signals.
[platform/core/connectivity/bluetooth-agent.git] / ag-agent / bluetooth-ag-agent.c
index 00cb6c2..893e824 100644 (file)
@@ -225,6 +225,7 @@ static void __bt_ag_name_owner_changed_cb(GDBusConnection *connection,
                                        GVariant *parameters,
                                        gpointer user_data);
 
+/* LCOV_EXCL_START */
 static void __bt_convert_addr_type_to_rev_string(char *address,
                                unsigned char *addr)
 {
@@ -322,6 +323,7 @@ static int __bt_ag_agent_gdbus_method_send(const char *service,
        }
        return BT_HFP_AGENT_ERROR_NONE;
 }
+/* LCOV_EXCL_STOP */
 
 gboolean _bt_ag_agent_emit_signal(
                                GDBusConnection *connection,
@@ -340,10 +342,12 @@ gboolean _bt_ag_agent_emit_signal(
                                &error);
        if (!ret) {
                if (error != NULL) {
+                       /* LCOV_EXCL_START */
                        /* dBUS gives error cause */
                        ERR("D-Bus API failure: errCode[%x], message[%s]",
                                error->code, error->message);
                        g_clear_error(&error);
+                       /* LCOV_EXCL_STOP */
                }
        }
        INFO_C("Emit Signal done = [%s]", name);
@@ -373,6 +377,7 @@ gboolean _bt_ag_agent_emit_property_changed(
        return ret;
 }
 
+/* LCOV_EXCL_START */
 static void __bt_ag_agent_start_watch(bt_ag_info_t *bt_ag_info)
 {
        bt_ag_info->watch_id = g_io_add_watch(bt_ag_info->io_chan,
@@ -403,9 +408,12 @@ gboolean __bt_ag_agent_is_companion_device(const char *addr)
 
        if (g_strcmp0(host_device_address, addr) == 0) {
                INFO("addr[%s] is companion device", addr);
+               free(host_device_address);
                return TRUE;
        }
 
+       free(host_device_address);
+
        return FALSE;
 #else
        /* TODO : Need to add companion device check condition for Phone models */
@@ -472,6 +480,7 @@ gboolean __bt_ag_agent_check_dual_hf_condition(const gchar *device_path)
        return TRUE;
 }
 #endif /* TIZEN_SUPPORT_DUAL_HF */
+/* LCOV_EXCL_STOP */
 
 static gboolean __bt_is_phone_locked(int *phone_lock_state)
 {
@@ -483,8 +492,10 @@ static gboolean __bt_is_phone_locked(int *phone_lock_state)
 
        ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, phone_lock_state);
        if (ret != 0) {
+               /* LCOV_EXCL_START */
                ERR("Failed to read  [%s]\n", VCONFKEY_IDLE_LOCK_STATE);
                return FALSE;
+               /* LCOV_EXCL_STOP */
        }
 
        FN_END;
@@ -554,6 +565,7 @@ static gboolean __bt_get_outgoing_call_condition(int *condition)
 #endif
 }
 
+/* LCOV_EXCL_START */
 static gboolean  __bt_ag_agent_launch_call_app(const char *number)
 {
        FN_START;
@@ -665,7 +677,7 @@ gboolean _bt_ag_agent_answer_call(unsigned int call_id,
        DBG("Sender = %s", sender);
 
        _bt_ag_agent_emit_signal(ag_dbus_conn, path,
-                                       BT_AG_SERVICE_NAME, "Answer",
+                                       BT_HEADSET_INTERFACE, "Answer",
                                        g_variant_new("(u)", call_id));
        FN_END;
        return TRUE;
@@ -686,7 +698,7 @@ gboolean _bt_ag_agent_reject_call(unsigned int call_id,
        DBG("Sender = %s", sender);
 
        _bt_ag_agent_emit_signal(ag_dbus_conn, path,
-                                       BT_AG_SERVICE_NAME, "Reject",
+                                       BT_HEADSET_INTERFACE, "Reject",
                                        g_variant_new("(u)", call_id));
        FN_END;
        return TRUE;
@@ -707,12 +719,13 @@ gboolean _bt_ag_agent_release_call(unsigned int call_id,
        DBG("Sender = %s", sender);
 
        _bt_ag_agent_emit_signal(ag_dbus_conn, path,
-                                       BT_AG_SERVICE_NAME, "Release",
+                                       BT_HEADSET_INTERFACE, "Release",
                                        g_variant_new("(u)", call_id));
 
        FN_END;
        return TRUE;
 }
+/* LCOV_EXCL_STOP */
 
 bt_hfp_agent_error_t _bt_ag_agent_dial_num(const gchar *number, guint flags)
 {
@@ -753,6 +766,7 @@ bt_hfp_agent_error_t _bt_ag_agent_dial_num(const gchar *number, guint flags)
                goto fail;
        }
 
+       /* LCOV_EXCL_START */
        if (callapp_type == BT_VIDEO_CALL) {
                if (!__bt_ag_agent_make_video_call(number)) {
                        ERR("Problem launching application");
@@ -766,6 +780,7 @@ bt_hfp_agent_error_t _bt_ag_agent_dial_num(const gchar *number, guint flags)
                        goto fail;
                }
        }
+       /* LCOV_EXCL_STOP */
 
 fail:
        FN_END;
@@ -794,6 +809,7 @@ bt_hfp_agent_error_t _bt_ag_agent_dial_memory(unsigned int location)
                return BT_HFP_AGENT_ERROR_INTERNAL;
        }
 
+       /* LCOV_EXCL_START */
        contacts_filter_create(_contacts_speeddial._uri, &filter);
 
        if (filter == NULL)
@@ -877,8 +893,10 @@ done:
        FN_END;
 
        return error_code;
+       /* LCOV_EXCL_STOP */
 }
 
+/* LCOV_EXCL_START */
 bt_hfp_agent_error_t _bt_ag_agent_send_dtmf(const gchar *dtmf,
                                const gchar *path, const gchar *sender)
 {
@@ -928,11 +946,12 @@ gboolean _bt_ag_agent_threeway_call(unsigned int chld_value,
                return FALSE;
 #endif
        _bt_ag_agent_emit_signal(ag_dbus_conn, path,
-                                       BT_AG_SERVICE_NAME, "Threeway",
+                                       BT_HEADSET_INTERFACE, "Threeway",
                                        g_variant_new("(u)", chld_value));
        FN_END;
        return TRUE;
 }
+/* LCOV_EXCL_STOP */
 
 bt_hfp_agent_error_t _bt_ag_agent_dial_last_num(void *device)
 {
@@ -959,6 +978,7 @@ bt_hfp_agent_error_t _bt_ag_agent_dial_last_num(void *device)
                return err_code;
        }
 
+       /* LCOV_EXCL_START */
        contacts_filter_create(_contacts_phone_log._uri, &filter);
 
        if (filter == NULL)
@@ -1126,8 +1146,10 @@ done:
        FN_END;
 
        return err_code;
+       /* LCOV_EXCL_STOP */
 }
 
+/* LCOV_EXCL_START */
 bt_hfp_agent_error_t _bt_ag_agent_vendor_cmd(const gchar *cmd,
                const gchar *path, const gchar *sender)
 {
@@ -1151,6 +1173,7 @@ bt_hfp_agent_error_t _bt_ag_agent_vendor_cmd(const gchar *cmd,
        FN_END;
        return ret;
 }
+/* LCOV_EXCL_STOP */
 
 gboolean _bt_ag_agent_get_signal_quality(void *device)
 {
@@ -1159,7 +1182,7 @@ gboolean _bt_ag_agent_get_signal_quality(void *device)
        FN_START;
 
        if (vconf_get_int(VCONFKEY_TELEPHONY_RSSI, &rssi)) {
-               DBG("VCONFKEY_TELEPHONY_RSSI failed\n");
+               DBG("VCONFKEY_TELEPHONY_RSSI failed\n"); /* LCOV_EXCL_LINE */
                goto fail;
        }
 
@@ -1171,9 +1194,11 @@ gboolean _bt_ag_agent_get_signal_quality(void *device)
        FN_END;
        return TRUE;
 fail:
+       /* LCOV_EXCL_START */
        FN_END;
        _bt_hfp_signal_quality_reply(-1, -1, device);
        return FALSE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean _bt_ag_agent_get_battery_status(void *device)
@@ -1185,7 +1210,7 @@ gboolean _bt_ag_agent_get_battery_status(void *device)
 
        if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW,
                                                &battery_chrg_status)) {
-               DBG("VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW failed\n");
+               DBG("VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW failed\n"); /* LCOV_EXCL_LINE */
                goto fail;
        }
 
@@ -1193,7 +1218,7 @@ gboolean _bt_ag_agent_get_battery_status(void *device)
 
        if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY,
                                                &battery_capacity)) {
-               DBG("VCONFKEY_SYSMAN_BATTERY_CAPACITY failed\n");
+               DBG("VCONFKEY_SYSMAN_BATTERY_CAPACITY failed\n"); /* LCOV_EXCL_LINE */
                goto fail;
        }
 
@@ -1205,9 +1230,11 @@ gboolean _bt_ag_agent_get_battery_status(void *device)
        return TRUE;
 
 fail:
+       /* LCOV_EXCL_START */
        _bt_hfp_battery_property_reply(device, -1, -1);
        FN_END;
        return FALSE;
+       /* LCOV_EXCL_STOP */
 }
 
 gboolean _bt_ag_agent_get_operator_name(void *device)
@@ -1217,9 +1244,11 @@ gboolean _bt_ag_agent_get_operator_name(void *device)
 
        operator_name = vconf_get_str(VCONFKEY_TELEPHONY_NWNAME);
        if (NULL == operator_name) {
+               /* LCOV_EXCL_START */
                DBG("vconf_get_str failed");
                _bt_hfp_operator_reply(NULL, device);
                return FALSE;
+               /* LCOV_EXCL_STOP */
        }
 
        DBG("operator_name  = [%s]", operator_name);
@@ -1244,8 +1273,9 @@ gboolean _bt_hfp_agent_nrec_status(gboolean status,
        else
                hs->nrec_status = TRUE;
 
-       _bt_ag_agent_emit_signal(ag_dbus_conn, hs->path,
-                                       BT_AG_SERVICE_NAME, "NrecStatusChanged",
+       if (ag_dbus_conn)
+               _bt_ag_agent_emit_signal(ag_dbus_conn, hs->path,
+                                       BT_HEADSET_INTERFACE, "NrecStatusChanged",
                                        g_variant_new("(b)", status));
        FN_END;
        return TRUE;
@@ -1262,6 +1292,7 @@ gboolean _bt_ag_agent_get_imei_number(void *device)
                goto fail;
        }
 
+       /* LCOV_EXCL_START */
        if (!g_utf8_validate(imei_number, -1, NULL)) {
                free(imei_number);
                ERR("get_imei_number : invalid UTF8");
@@ -1273,7 +1304,7 @@ gboolean _bt_ag_agent_get_imei_number(void *device)
        free(imei_number);
        FN_END;
        return TRUE;
-
+       /* LCOV_EXCL_STOP */
 fail:
        _bt_hfp_get_imei_number_reply(NULL, device);
        FN_END;
@@ -1289,15 +1320,19 @@ void _bt_ag_agent_get_manufacturer_name(void *device)
        ret = system_info_get_platform_string("http://tizen.org/system/manufacturer",
                                                &manufacturer_name);
        if (SYSTEM_INFO_ERROR_NONE != ret) {
+               /* LCOV_EXCL_START */
                ERR("Get manufacturer_name failed : %d", ret);
                if (NULL != manufacturer_name)
                        free(manufacturer_name);
 
                manufacturer_name = g_strdup("Unknown");
+               /* LCOV_EXCL_STOP */
        } else if (!g_utf8_validate(manufacturer_name, -1, NULL)) {
+               /* LCOV_EXCL_START */
                free(manufacturer_name);
                manufacturer_name = g_strdup("Unknown");
                ERR("get_manufacturer_name : invalid UTF8");
+               /* LCOV_EXCL_STOP */
        }
 
        DBG_SECURE("manufacturer_name  = [%s]", manufacturer_name);
@@ -1315,16 +1350,19 @@ void _bt_ag_agent_get_imsi(void *device)
                ERR("tel_get_sim_imsi failed");
                goto fail;
        }
+       /* LCOV_EXCL_START */
        DBG_SECURE("tapi values %s %s %s", imsi.szMcc, imsi.szMnc, imsi.szMsin);
 
        _bt_hfp_get_imsi_reply(imsi.szMcc, imsi.szMnc, imsi.szMsin, device);
        FN_END;
        return;
+       /* LCOV_EXCL_STOP */
 fail:
        _bt_hfp_get_imsi_reply(NULL, NULL, NULL, device);
        FN_END;
 }
 
+/* LCOV_EXCL_START */
 int _bt_ag_agent_registration_status_convert(int result)
 {
        switch (result) {
@@ -1341,6 +1379,7 @@ int _bt_ag_agent_registration_status_convert(int result)
        }
        return result;
 }
+/* LCOV_EXCL_STOP */
 
 void _bt_ag_agent_get_creg_status(void *device)
 {
@@ -1357,6 +1396,7 @@ void _bt_ag_agent_get_creg_status(void *device)
                ERR("tel_get_property_int failed");
                return;
        }
+       /* LCOV_EXCL_START */
        registration_status =
                        _bt_ag_agent_registration_status_convert(result);
 
@@ -1380,6 +1420,7 @@ void _bt_ag_agent_get_creg_status(void *device)
 
        FN_END;
        return;
+       /* LCOV_EXCL_STOP */
 }
 
 void _bt_ag_agent_get_model_name(void *device)
@@ -1504,6 +1545,7 @@ gboolean _bt_ag_agent_voice_dial(gboolean activate)
        return __bt_ag_agent_launch_voice_dial(activate);
 }
 
+/* LCOV_EXCL_START */
 static void __bt_ag_codec_negotiation_info_reset(bt_ag_info_t *hs,
                                        gboolean reset)
 {
@@ -1821,6 +1863,7 @@ static void __bt_ag_str2ba(const char *str, bt_addr *ba)
        for (i = 5; i >= 0; i--, str += 3)
                ba->b[i] = strtol(str, NULL, 16);
 }
+/* LCOV_EXCL_STOP */
 
 static const char *__bt_ag_state2str(hs_state_t state)
 {
@@ -1860,6 +1903,7 @@ void _bt_convert_addr_string_to_type_rev(unsigned char *addr,
        }
 }
 
+/* LCOV_EXCL_START */
 static gboolean __bt_ag_check_nval(GIOChannel *chan)
 {
        struct pollfd file_desc;
@@ -2078,6 +2122,7 @@ static gboolean __bt_ag_sco_server_cb(GIOChannel *chan,
 
        return TRUE;
 }
+/* LCOV_EXCL_STOP */
 
 static int __bt_ag_start_sco_server(bt_ag_info_t *hs)
 {
@@ -2136,6 +2181,7 @@ error:
        return BT_HFP_AGENT_ERROR_INTERNAL;
 }
 
+/* LCOV_EXCL_START */
 void __bt_ag_stop_sco_server(bt_ag_info_t *hs)
 {
        DBG("Stop SCO server");
@@ -2316,6 +2362,7 @@ void _bt_ag_set_headset_state(bt_ag_info_t *hs, hs_state_t state)
        INFO("STATE CHANGED from [%s(%d)] to [%s(%d)]",
                __bt_ag_state2str(org_state), org_state, __bt_ag_state2str(state), state);
 }
+/* LCOV_EXCL_STOP */
 
 static struct event at_event_callbacks[] = {
        { "AT+BRSF", _bt_hfp_supported_features },
@@ -2364,6 +2411,7 @@ static struct event at_event_callbacks[] = {
 int num_of_secure_command = 4;
 static const char* secure_command[] = {"CLCC", "CLIP", "CPBR", "CCWA"};
 
+/* LCOV_EXCL_START */
 static void __bt_ag_agent_print_at_buffer(char *message, const char *buf)
 {
 
@@ -2421,7 +2469,7 @@ static void __bt_ag_agent_print_at_buffer(char *message, const char *buf)
                i++;
        }
        if (message)
-               INFO("%s Buffer = [%s], Len(%d)", message, s, strlen(s));
+               INFO("%s Buffer = [%s], Len(%zd)", message, s, strlen(s));
        else
                INFO("[%s]", s);
 }
@@ -2439,6 +2487,7 @@ static int __bt_ag_at_handler(bt_ag_info_t *hs, const char *buf)
 
        return -EINVAL;
 }
+/* LCOV_EXCL_STOP */
 
 static int __bt_ag_send_at_valist(bt_ag_info_t *hdset, va_list list,
                        char *list_format)
@@ -2450,7 +2499,7 @@ static int __bt_ag_send_at_valist(bt_ag_info_t *hdset, va_list list,
 
        count = vsnprintf(rsp_buffer, sizeof(rsp_buffer), list_format, list);
        if (count < 0) {
-               ERR("count is %d", count);
+               ERR("count is %zd", count);
                return -EINVAL;
        }
 
@@ -2546,6 +2595,7 @@ int _bt_ag_send_response(bt_ag_info_t *hs, hfp_state_manager_err_t err)
        }
 }
 
+/* LCOV_EXCL_START */
 static gboolean __bt_ag_event_handler(GIOChannel *channel,
                                GIOCondition cond, void *user_data)
 {
@@ -2599,8 +2649,8 @@ static gboolean __bt_ag_event_handler(GIOChannel *channel,
                        break;
                }
 
-               cmd_len = 1 + (off_t) get_cr -
-                       (off_t) &slconn->buffer[slconn->start];
+               cmd_len = 1 + (off_t)(intptr_t)get_cr -
+                       (off_t)(intptr_t)&slconn->buffer[slconn->start];
                *get_cr = '\0';
 
                if (cmd_len > 1) {
@@ -2742,7 +2792,7 @@ static gboolean __bt_ag_agent_is_device_vr_blacklisted(const char *lap_addr)
 
        rewind(fp);
 
-       buffer = g_malloc0(sizeof(char) * size);
+       buffer = g_malloc0((sizeof(char) * size) + 1);
        if (buffer == NULL) {
                ERR("g_malloc0 is failed");
                fclose(fp);
@@ -2809,6 +2859,7 @@ static gboolean __bt_sco_open_delay_timeout_cb(gpointer user_data)
 
        return FALSE;
 }
+/* LCOV_EXCL_STOP */
 
 /*
 * Service level connection complete
@@ -2837,6 +2888,7 @@ void _bt_ag_slconn_complete(bt_ag_info_t *hs)
        _bt_ag_set_headset_state(hs, HEADSET_STATE_CONNECTED);
 }
 
+/* LCOV_EXCL_START */
 static gboolean __bt_ag_agent_connection_release(bt_ag_info_t *hs)
 {
 
@@ -4041,9 +4093,7 @@ static void __bt_ag_agent_filter_cb(GDBusConnection *connection,
        GVariant *optional_param = NULL;
 
        if (strcasecmp(signal_name, "InterfacesAdded") == 0) {
-
-               g_variant_get(parameters, "(&o@a{sa{sv}})",
-                                                       &path, &optional_param);
+               g_variant_get(parameters, "(&o@a{sa{sv}})", &path, &optional_param);
                if (!path) {
                        if (optional_param)
                                g_variant_unref(optional_param);
@@ -4053,12 +4103,12 @@ static void __bt_ag_agent_filter_cb(GDBusConnection *connection,
 
                INFO("Adapter Path = [%s]", path);
                if (strcasecmp(path, DEFAULT_ADAPTER_OBJECT_PATH) == 0) {
-                       gchar *path = g_strdup(BT_AG_AGENT_OBJECT_PATH);
-                       __bt_ag_agent_register(path, hfp_ver,
+                       gchar *obj_path = g_strdup(BT_AG_AGENT_OBJECT_PATH);
+                       __bt_ag_agent_register(obj_path, hfp_ver,
                                 HFP_AG_UUID, "Hands-Free Audio Gateway");
 
-                       path =  g_strdup(BT_HS_AG_AGENT_OBJECT_PATH);
-                       __bt_ag_agent_register(path, hsp_ver,
+                       obj_path =  g_strdup(BT_HS_AG_AGENT_OBJECT_PATH);
+                       __bt_ag_agent_register(obj_path, hsp_ver,
                                HSP_AG_UUID, "Headset Audio Gateway");
                }
        } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
@@ -4072,11 +4122,11 @@ static void __bt_ag_agent_filter_cb(GDBusConnection *connection,
 
                INFO("Adapter Path = [%s]", path);
                if (strcasecmp(path, DEFAULT_ADAPTER_OBJECT_PATH) == 0) {
-                       gchar *path = g_strdup(BT_AG_AGENT_OBJECT_PATH);
-                       __bt_ag_agent_unregister(path);
+                       gchar *obj_path = g_strdup(BT_AG_AGENT_OBJECT_PATH);
+                       __bt_ag_agent_unregister(obj_path);
 
-                       path =  g_strdup(BT_HS_AG_AGENT_OBJECT_PATH);
-                       __bt_ag_agent_unregister(path);
+                       obj_path =  g_strdup(BT_HS_AG_AGENT_OBJECT_PATH);
+                       __bt_ag_agent_unregister(obj_path);
                }
        }
 
@@ -4203,6 +4253,7 @@ fail:
        return BT_HFP_AGENT_ERROR_INTERNAL;
 
 }
+/* LCOV_EXCL_STOP */
 
 #ifdef TIZEN_FEATURE_BT_MEDIA_ENHANCE
 void _bt_ag_agent_check_transport_state(void)
@@ -4215,7 +4266,7 @@ void _bt_ag_agent_check_transport_state(void)
 
                proxy =  g_dbus_proxy_new_sync(ag_dbus_conn,
                                G_DBUS_PROXY_FLAGS_NONE, NULL,
-                               "org.PulseAudio2", A2DP_SOURCE_ENDPOINT,
+                               "org.pulseaudio.Server", A2DP_SOURCE_ENDPOINT,
                                BLUEZ_MEDIA_ENDPOINT_INTERFACE, NULL, &err);
 
                if (!proxy) {
@@ -4314,6 +4365,8 @@ static void __bt_ag_agent_media_filter_cb(GDBusConnection *connection,
        FN_END;
 }
 #endif
+
+/* LCOV_EXCL_START */
 static void __bt_ag_agent_dbus_init(void)
 {
        FN_START;
@@ -4350,7 +4403,7 @@ static void __bt_ag_agent_dbus_init(void)
 
 #ifdef TIZEN_FEATURE_BT_MEDIA_ENHANCE
        media_sig_id = g_dbus_connection_signal_subscribe(ag_dbus_conn,
-                               NULL, BT_PROPERTIES_INTERFACE, NULL, NULL,
+                               BLUEZ_SERVICE_NAME, BT_PROPERTIES_INTERFACE, NULL, NULL,
                                NULL, 0, __bt_ag_agent_media_filter_cb,
                                NULL, NULL);
 
@@ -4364,6 +4417,7 @@ static void __bt_ag_agent_dbus_init(void)
        FN_END;
        return;
 }
+/* LCOV_EXCL_STOP */
 
 static uint32_t __bt_ag_agent_get_ag_features(void)
 {
@@ -4401,6 +4455,7 @@ static uint32_t __bt_ag_agent_get_ag_features(void)
        return ag_features;
 }
 
+/* LCOV_EXCL_START */
 void *__bt_ag_agent_telephony_init(void *arg)
 {
 
@@ -4480,3 +4535,4 @@ int main(void)
        INFO_C("### Terminating Bluetooth AG agent");
        return 0;
 }
+/* LCOV_EXCL_STOP */