Skip to content

Commit

Permalink
audio/transport: Propagate errors from avrcp_set_volume to DBus
Browse files Browse the repository at this point in the history
Any error while setting absolute volume on the peer, or notifying the
peer of changes was previously going completely unnoticed.  Propagate it
to the logs and back to the DBus "Volume" property setter so that they
aren't misled into thinking that the AVRCP command succeeded.

Note that an error is mostly harmless when the setter of the property is
an audio sink and the peer the audio source: in this case we're only
_notifying_ the peer of the change when it has already been applied on
the sink.

Also improve the other two error messages to more closely describe what
was "invalid" about the argument.
  • Loading branch information
MarijnS95 authored and Vudentz committed Mar 21, 2023
1 parent 4a3f465 commit 1de4178
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions profiles/audio/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,22 @@ static void set_volume(const GDBusPropertyTable *property,
uint16_t arg;
int8_t volume;
bool notify;
int err;

if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT16)
goto error;
if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT16) {
g_dbus_pending_property_error(id,
ERROR_INTERFACE ".InvalidArguments",
"Expected UINT16");
return;
}

dbus_message_iter_get_basic(iter, &arg);
if (arg > INT8_MAX)
goto error;

g_dbus_pending_property_success(id);
if (arg > INT8_MAX) {
g_dbus_pending_property_error(id,
ERROR_INTERFACE ".InvalidArguments",
"Volume must not be larger than 127");
return;
}

volume = (int8_t)arg;
if (a2dp->volume == volume)
Expand All @@ -757,12 +764,17 @@ static void set_volume(const GDBusPropertyTable *property,
"Volume");
}

avrcp_set_volume(transport->device, volume, notify);
return;
err = avrcp_set_volume(transport->device, volume, notify);
if (err) {
error("avrcp_set_volume returned %s (%d)", strerror(-err), err);
g_dbus_pending_property_error(id,
ERROR_INTERFACE ".Failed",
"Internal error %s (%d)",
strerror(-err), err);
return;
}

error:
g_dbus_pending_property_error(id, ERROR_INTERFACE ".InvalidArguments",
"Invalid arguments in method call");
g_dbus_pending_property_success(id);
}

static gboolean endpoint_exists(const GDBusPropertyTable *property, void *data)
Expand Down

0 comments on commit 1de4178

Please sign in to comment.