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

Commit 533f78f4 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Add IDevice.setConnectedState_7_1 method

This is an updated version of IDevice.setConnectedState which
accepts a full AudioPort so that additional data like extra
audio descriptors can be passed to the audio HAL.

Bug: 211601178
Test: atest VtsHalAudioV7_1TargetTest
Change-Id: Id746caa32122dabfb83feb5b515bed7717bcb67c
parent 01035edd
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -85,4 +85,16 @@ interface IDevice extends @7.0::IDevice {
                    Result retval,
                    Result retval,
                    IStreamIn inStream,
                    IStreamIn inStream,
                    AudioConfig suggestedConfig);
                    AudioConfig suggestedConfig);

    /**
     * Notifies the device module about the connection state of an input/output
     * device attached to it. The devicePort identifies the device and may also
     * provide extra information such as raw audio descriptors.
     *
     * @param devicePort audio device port.
     * @param connected whether the device is connected.
     * @return retval operation completion status.
     */
    setConnectedState_7_1(AudioPort devicePort, bool connected)
            generates (Result retval);
};
};
+15 −0
Original line number Original line Diff line number Diff line
@@ -616,6 +616,21 @@ Return<void> Device::updateAudioPatch(int32_t previousPatch,


#endif
#endif


#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<Result> Device::setConnectedState_7_1(const AudioPort& devicePort, bool connected) {
    if (version() >= AUDIO_DEVICE_API_VERSION_3_2 &&
        mDevice->set_device_connected_state_v7 != nullptr) {
        audio_port_v7 halPort;
        if (status_t status = HidlUtils::audioPortToHal(devicePort, &halPort); status != NO_ERROR) {
            return analyzeStatus("audioPortToHal", status);
        }
        return analyzeStatus("set_device_connected_state_v7",
                             mDevice->set_device_connected_state_v7(mDevice, &halPort, connected));
    }
    return Result::NOT_SUPPORTED;
}
#endif

}  // namespace implementation
}  // namespace implementation
}  // namespace CPP_VERSION
}  // namespace CPP_VERSION
}  // namespace audio
}  // namespace audio
+3 −0
Original line number Original line Diff line number Diff line
@@ -162,6 +162,9 @@ struct Device : public IDevice, public ParametersUtil {
    Return<void> updateAudioPatch(int32_t previousPatch, const hidl_vec<AudioPortConfig>& sources,
    Return<void> updateAudioPatch(int32_t previousPatch, const hidl_vec<AudioPortConfig>& sources,
                                  const hidl_vec<AudioPortConfig>& sinks,
                                  const hidl_vec<AudioPortConfig>& sinks,
                                  createAudioPatch_cb _hidl_cb) override;
                                  createAudioPatch_cb _hidl_cb) override;
#endif
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
    Return<Result> setConnectedState_7_1(const AudioPort& devicePort, bool connected) override;
#endif
#endif
    Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
    Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;


+31 −0
Original line number Original line Diff line number Diff line
@@ -16,3 +16,34 @@


// pull in all the <= 7.0 tests
// pull in all the <= 7.0 tests
#include "7.0/AudioPrimaryHidlHalTest.cpp"
#include "7.0/AudioPrimaryHidlHalTest.cpp"

TEST_P(AudioHidlDeviceTest, SetConnectedState_7_1) {
    doc::test("Check that the HAL can be notified of device connection and disconnection");
    using AD = xsd::AudioDevice;
    for (auto deviceType : {AD::AUDIO_DEVICE_OUT_HDMI, AD::AUDIO_DEVICE_OUT_WIRED_HEADPHONE,
                            AD::AUDIO_DEVICE_IN_USB_HEADSET}) {
        SCOPED_TRACE("device=" + toString(deviceType));
        for (bool state : {true, false}) {
            SCOPED_TRACE("state=" + ::testing::PrintToString(state));
            DeviceAddress address = {};
            address.deviceType = toString(deviceType);
            if (deviceType == AD::AUDIO_DEVICE_IN_USB_HEADSET) {
                address.address.alsa({0, 0});
            }
            AudioPort devicePort;
            devicePort.ext.device(address);
            auto ret = getDevice()->setConnectedState_7_1(devicePort, state);
            ASSERT_TRUE(ret.isOk());
            if (ret == Result::NOT_SUPPORTED) {
                doc::partialTest("setConnectedState_7_1 is not supported");
                break;  // other deviceType might be supported
            }
            ASSERT_OK(ret);
        }
    }

    // Because there is no way of knowing if the devices were connected before
    // calling setConnectedState, there is no way to restore the HAL to its
    // initial state. To workaround this, destroy the HAL at the end of this test.
    ASSERT_TRUE(resetDevice());
}