return 0;
}
+static int handle_bluez_headset_property_changed(DBusConnection *c, DBusMessage *s, pa_device_manager *dm) {
+ DBusMessageIter msg_iter, variant_iter;
+ char *property_name;
+ dbus_bool_t value;
+ char *name = NULL;
+
+ pa_assert(c);
+ pa_assert(s);
+ pa_assert(dm);
+
+ pa_log_debug("Got %s PropertyChanged signal", DBUS_INTERFACE_BLUEZ_HEADSET);
+ dbus_message_iter_init(s, &msg_iter);
+ if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_STRING) {
+ pa_log_error("Property name not string");
+ return -1;
+ }
+ dbus_message_iter_get_basic(&msg_iter, &property_name);
+ pa_log_info("Changed Property name : %s", property_name);
+
+ if (!dbus_message_iter_next(&msg_iter)) {
+ pa_log_debug("Property value missing");
+ return -1;
+ }
+
+ if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_VARIANT) {
+ pa_log_debug("Property value not a variant.");
+ return -1;
+ }
+
+ dbus_message_iter_recurse(&msg_iter, &variant_iter);
+
+ if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_BOOLEAN)
+ return 0; /* Returning 0 here to keep the same behavior comparing with the previous codes */
+
+ dbus_message_iter_get_basic(&variant_iter, &value);
+ if (pa_safe_streq(property_name, "Connected")) {
+ device_detected_type_t detected;
+ int status = 0;
+ pa_log_info("HFP Connection : %d", value);
+ if (value) {
+ method_call_bt_get_name(c, dbus_message_get_path(s), &name);
+ status = BT_SCO_CONNECTED;
+ } else {
+ status = BT_SCO_DISCONNECTED;
+ }
+ if (_translate_external_value(DEVICE_TYPE_BT_SCO, status, &detected) < 0) {
+ pa_log_warn("failed to translate bt-sco detected value");
+ return -1;
+ }
+ handle_device_status_changed(dm, DEVICE_TYPE_BT_SCO, name, dbus_message_get_path(s), detected);
+
+ } else if (pa_safe_streq(property_name, "Playing")) {
+ pa_tz_device *device;
+ pa_log_info("SCO Playing : %d", value);
+ if ((device = device_list_get_device(dm, DEVICE_TYPE_BT_SCO, NULL, NULL)) != NULL) {
+ device->sco_opened = value;
+ if (value) {
+ /* update BT band/nrec information */
+ bool is_wide_band = false;
+ bool nrec = false;
+ pa_tz_device_sco_get_property(device, &is_wide_band, &nrec);
+ pa_log_info("got new wideband:%d, nrec:%d", is_wide_band, nrec);
+
+ UPDATE_HAL_ROUTE_OPTION(dm->hal_interface, NULL, "bt-wideband", is_wide_band);
+ UPDATE_HAL_ROUTE_OPTION(dm->hal_interface, NULL, "bt-nrec", nrec);
+ }
+ }
+ UPDATE_HAL_ROUTE_OPTION(dm->hal_interface, NULL, "bt-sco-ready", value);
+ }
+
+ return 0;
+}
+
static DBusHandlerResult dbus_filter_device_detect_handler(DBusConnection *c, DBusMessage *s, void *userdata) {
DBusError error;
int status = 0;
dbus_error_init(&error);
if (dbus_message_is_signal(s, DBUS_INTERFACE_DEVICED_SYSNOTI, "ChangedEarjack")) {
- if (!dbus_message_get_args(s, NULL, DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID)) {
+ if (!dbus_message_get_args(s, NULL, DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID))
+ goto fail;
+
+ if (_translate_external_value(DEVICE_TYPE_AUDIO_JACK, status, &detected) < 0) {
+ pa_log_warn("failed to translate audio-jack detected value");
goto fail;
- } else {
- if (_translate_external_value(DEVICE_TYPE_AUDIO_JACK, status, &detected) < 0) {
- pa_log_warn("failed to translate audio-jack detected value");
- goto fail;
- }
- handle_device_status_changed(dm, DEVICE_TYPE_AUDIO_JACK, NULL, NULL, detected);
}
+ handle_device_status_changed(dm, DEVICE_TYPE_AUDIO_JACK, NULL, NULL, detected);
+
} else if (dbus_message_is_signal(s, DBUS_INTERFACE_DEVICED_SYSNOTI, "ChangedHDMIAudio")) {
- if (!dbus_message_get_args(s, NULL, DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID)) {
+ if (!dbus_message_get_args(s, NULL, DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID))
goto fail;
- } else {
- if (_translate_external_value(DEVICE_TYPE_HDMI, status, &detected) < 0) {
- pa_log_warn("failed to translate HDMI detected value");
- goto fail;
- }
- handle_device_status_changed(dm, DEVICE_TYPE_HDMI, NULL, NULL, detected);
- }
- } else if (dbus_message_is_signal(s, DBUS_INTERFACE_MIRRORING_SERVER, "miracast_wfd_source_status_changed")) {
- if (!dbus_message_get_args(s, NULL, DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID)) {
+
+ if (_translate_external_value(DEVICE_TYPE_HDMI, status, &detected) < 0) {
+ pa_log_warn("failed to translate HDMI detected value");
goto fail;
- } else {
- if (_translate_external_value(DEVICE_TYPE_FORWARDING, status, &detected) < 0) {
- pa_log_warn("failed to translate forwarding detected value");
- goto fail;
- }
- handle_device_status_changed(dm, DEVICE_TYPE_FORWARDING, NULL, NULL, detected);
}
- } else if (dbus_message_is_signal(s, DBUS_INTERFACE_BLUEZ_HEADSET, "PropertyChanged")) {
- DBusMessageIter msg_iter, variant_iter;
- char *property_name;
+ handle_device_status_changed(dm, DEVICE_TYPE_HDMI, NULL, NULL, detected);
- pa_log_debug("Got %s PropertyChanged signal", DBUS_INTERFACE_BLUEZ_HEADSET);
- dbus_message_iter_init(s, &msg_iter);
- if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_STRING) {
- pa_log_error("Property name not string");
+ } else if (dbus_message_is_signal(s, DBUS_INTERFACE_MIRRORING_SERVER, "miracast_wfd_source_status_changed")) {
+ if (!dbus_message_get_args(s, NULL, DBUS_TYPE_INT32, &status, DBUS_TYPE_INVALID))
goto fail;
- }
- dbus_message_iter_get_basic(&msg_iter, &property_name);
- pa_log_info("Changed Property name : %s", property_name);
- if (!dbus_message_iter_next(&msg_iter)) {
- pa_log_debug("Property value missing");
+ if (_translate_external_value(DEVICE_TYPE_FORWARDING, status, &detected) < 0) {
+ pa_log_warn("failed to translate forwarding detected value");
goto fail;
}
+ handle_device_status_changed(dm, DEVICE_TYPE_FORWARDING, NULL, NULL, detected);
- if (dbus_message_iter_get_arg_type(&msg_iter) != DBUS_TYPE_VARIANT) {
- pa_log_debug("Property value not a variant.");
+ } else if (dbus_message_is_signal(s, DBUS_INTERFACE_BLUEZ_HEADSET, "PropertyChanged")) {
+ if (handle_bluez_headset_property_changed(c, s, dm) < 0)
goto fail;
- }
- dbus_message_iter_recurse(&msg_iter, &variant_iter);
-
- if (DBUS_TYPE_BOOLEAN == dbus_message_iter_get_arg_type(&variant_iter)) {
- dbus_bool_t value;
- char *name = NULL;
- dbus_message_iter_get_basic(&variant_iter, &value);
- if (pa_safe_streq(property_name, "Connected")) {
- pa_log_info("HFP Connection : %d", value);
- if (value) {
- method_call_bt_get_name(c, dbus_message_get_path(s), &name);
- status = BT_SCO_CONNECTED;
- } else {
- status = BT_SCO_DISCONNECTED;
- }
- if (_translate_external_value(DEVICE_TYPE_BT_SCO, status, &detected) < 0) {
- pa_log_warn("failed to translate bt-sco detected value");
- goto fail;
- }
- handle_device_status_changed(dm, DEVICE_TYPE_BT_SCO,
- name, dbus_message_get_path(s), detected);
- } else if (pa_safe_streq(property_name, "Playing")) {
- pa_tz_device *device;
- pa_log_info("SCO Playing : %d", value);
- if ((device = device_list_get_device(dm, DEVICE_TYPE_BT_SCO, NULL, NULL)) != NULL) {
- device->sco_opened = value;
- if (value) {
- /* update BT band/nrec information */
- bool is_wide_band = false;
- bool nrec = false;
- pa_tz_device_sco_get_property(device, &is_wide_band, &nrec);
- pa_log_info("got new wideband:%d, nrec:%d", is_wide_band, nrec);
-
- UPDATE_HAL_ROUTE_OPTION(dm->hal_interface, NULL, "bt-wideband", is_wide_band);
- UPDATE_HAL_ROUTE_OPTION(dm->hal_interface, NULL, "bt-nrec", nrec);
- }
- }
- UPDATE_HAL_ROUTE_OPTION(dm->hal_interface, NULL, "bt-sco-ready", value);
- }
- }
} else {
pa_log_debug("Unknown message, not handle it");
dbus_error_free(&error);