Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a743237 authored by Kevin Rocard's avatar Kevin Rocard
Browse files

Audio HIDL wrapper: Improve status_t to Return conversion for get_parameter



set_parameter wrapper was converting status_t as such:
OK -> OK
-ENOSYS -> INVALID_STATE
everything else -> INVALID_ARGUMENTS

Which was inconsistent with the rest of the wrapper which was doing:
OK -> OK
-EINVAL -> INVALID_ARGUMENTS
-ENODATA -> INVALID_STATE
-ENODEV -> NOT_INITIALIZED
-ENOSYS -> NOT_SUPPORTED
everything else -> INVALID_STATE

Unfortunately, identical conversion can not be achieve as legacy
set_parameter specifically require
-ENOSYS -> INVALID_STATE
in `get_parameter` docstring:

     * If the implementation does not accept a parameter change while
     * the output is active but the parameter is acceptable otherwise, it must
     * return -ENOSYS.

As a result implement:
OK -> OK
-EINVAL -> INVALID_ARGUMENTS
-ENODATA -> INVALID_STATE
-ENODEV -> NOT_INITIALIZED
-ENOSYS -> INVALID_STATE              <--- unchanged
everything else -> INVALID_ARGUMENTS  <--- unchanged

Test: Playback and record over builtin & USB. Hangout call
Test: vts-tradefed run commandAndExit vts --module VtsHalAudioV2_0Target
Bug: 67030461
Change-Id: I13649eb00f8465921e5c718c5d5df120e1262ff7
Signed-off-by: default avatarKevin Rocard <krocard@google.com>
parent 2371f287
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ namespace audio {
namespace V2_0 {
namespace implementation {

// Static method and not private method to avoid leaking status_t dependency
/** Converts a status_t in Result according to the rules of AudioParameter::get*
 * Note: Static method and not private method to avoid leaking status_t dependency
 */
static Result getHalStatusToResult(status_t status) {
    switch (status) {
        case OK:
@@ -141,12 +143,20 @@ Result ParametersUtil::setParametersImpl(

Result ParametersUtil::setParams(const AudioParameter& param) {
    int halStatus = halSetParameters(param.toString().string());
    if (halStatus == OK)
        return Result::OK;
    else if (halStatus == -ENOSYS)
        return Result::INVALID_STATE;
    else
        return Result::INVALID_ARGUMENTS;
    switch (halStatus) {
        case OK: return Result::OK;
        case -EINVAL: return Result::INVALID_ARGUMENTS;
        case -ENODATA: return Result::INVALID_STATE;
        case -ENODEV: return Result::NOT_INITIALIZED;
        // The rest of the API (*::analyseStatus) returns NOT_SUPPORTED
        // when the legacy API returns -ENOSYS
        // However the legacy API explicitly state that for get_paramers,
        // -ENOSYS should be returned if
        // "the implementation does not accept a parameter change while the
        //  output is active but the parameter is acceptable otherwise"
        case -ENOSYS: return Result::INVALID_STATE;
        default: return Result::INVALID_ARGUMENTS;
    }
}

}  // namespace implementation