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

Commit a891b2b6 authored by Michael Dooley's avatar Michael Dooley Committed by Android (Google) Code Review
Browse files

Merge "Converting sound trigger v2.2 getModelState to be asynchronous"

parents ff5365ac 74a792ec
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -16,25 +16,27 @@

package android.hardware.soundtrigger@2.2;

import @2.0::ISoundTriggerHwCallback.RecognitionEvent;
import @2.0::SoundModelHandle;
import @2.1::ISoundTriggerHw;

/**
 * SoundTrigger HAL interface. Used for hardware recognition of hotwords.
 * SoundTrigger HAL interface. Used for hardware recognition of hotwords
 * and other sounds.
 */
interface ISoundTriggerHw extends @2.1::ISoundTriggerHw {

    /**
     * Get the state of a given model.
     * The model state is returned as a RecognitionEvent.
     * @param modelHandle The handle of the sound model to use for recognition
     * The model state is returned asynchronously as a RecognitionEvent via
     * the callback that was registered in StartRecognition().
     * @param modelHandle The handle of the sound model whose state is being
     *                    queried.
     * @return retval Operation completion status: 0 in case of success,
     *                -ENOSYS in case of invalid model handle,
     *                -ENOMEM in case of memory allocation failure,
     *                -ENODEV in case of initialization error.
     * @return state  RecognitionEvent in case of success
     *                -ENODEV in case of initialization error,
     *                -EINVAL in case where a recognition event is already
     *                        being processed.
     */
    getModelState(SoundModelHandle modelHandle)
            generates (int32_t retval, @2.0::ISoundTriggerHwCallback.RecognitionEvent state);
    getModelState(SoundModelHandle modelHandle) generates (int32_t retval);
};
+5 −24
Original line number Diff line number Diff line
@@ -690,45 +690,26 @@ void SoundTriggerHw::SoundModelClient_2_1::soundModelCallback(

// Begin V2_2 implementation

Return<void> SoundTriggerHw::getModelState(int32_t modelHandle, getModelState_cb hidl_cb) {
    int ret = 0;
    V2_0::ISoundTriggerHwCallback::RecognitionEvent event;
    struct sound_trigger_recognition_event* halEvent = NULL;
Return<int32_t> SoundTriggerHw::getModelState(int32_t modelHandle) {
    sp<SoundModelClient> client;
    if (mHwDevice == NULL) {
        ret = -ENODEV;
        goto exit;
        return -ENODEV;
    }

    {
        AutoMutex lock(mLock);
        client = mClients.valueFor(modelHandle);
        if (client == 0) {
            ret = -ENOSYS;
            goto exit;
            return -ENOSYS;
        }
    }

    if (mHwDevice->get_model_state == NULL) {
        ALOGE("Failed to get model state from device, no such method");
        ret = -ENODEV;
        goto exit;
    }

    // Get the state from the device (as a recognition event)
    halEvent = mHwDevice->get_model_state(mHwDevice, client->getHalHandle());
    if (halEvent == NULL) {
        ALOGE("Failed to get model state from device");
        ret = -ENODEV;
        goto exit;
        return -ENODEV;
    }

    convertRecognitionEventFromHal(&event, halEvent);

exit:
    hidl_cb(ret, event);
    free(halEvent);
    return Void();
    return mHwDevice->get_model_state(mHwDevice, client->getHalHandle());
}

// Methods from ::android::hidl::base::V1_0::IBase follow.
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ struct SoundTriggerHw : public ISoundTriggerHw {
                                         int32_t cookie) override;

    // Methods from V2_2::ISoundTriggerHw follow.
    Return<void> getModelState(int32_t modelHandle, getModelState_cb _hidl_cb) override;
    Return<int32_t> getModelState(int32_t modelHandle) override;

    SoundTriggerHw();

+3 −10
Original line number Diff line number Diff line
@@ -74,21 +74,14 @@ class SoundTriggerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 * Test ISoundTriggerHw::getModelState() method
 *
 * Verifies that:
 *  - the implementation returns -EINVAL with invalid model handle
 *  - the implementation returns -ENOSYS with invalid model handle
 *
 */
TEST_F(SoundTriggerHidlTest, GetModelStateInvalidModel) {
    int ret = android::OK;
    ::android::hardware::soundtrigger::V2_0::ISoundTriggerHwCallback::RecognitionEvent event;
    SoundModelHandle handle = 0;
    Return<void> hidlReturn =
        mSoundTriggerHal->getModelState(handle, [&](int32_t retval, auto res) {
            ret = retval;
            event = res;
        });

    Return<int32_t> hidlReturn = mSoundTriggerHal->getModelState(handle);
    EXPECT_TRUE(hidlReturn.isOk());
    EXPECT_EQ(-ENOSYS, ret);
    EXPECT_EQ(-ENOSYS, hidlReturn);
}

int main(int argc, char** argv) {