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

Commit 74a792ec authored by mike dooley's avatar mike dooley
Browse files

Converting sound trigger v2.2 getModelState to be asynchronous

Test: built android with checkbuild flag

Change-Id: I68bebde980d2c3a76765cee4c70e213f4430dec1
Bug-Id: 70206501
parent efb5f951
Loading
Loading
Loading
Loading
+10 −8
Original line number Original line Diff line number Diff line
@@ -16,25 +16,27 @@


package android.hardware.soundtrigger@2.2;
package android.hardware.soundtrigger@2.2;


import @2.0::ISoundTriggerHwCallback.RecognitionEvent;
import @2.0::SoundModelHandle;
import @2.0::SoundModelHandle;
import @2.1::ISoundTriggerHw;
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 {
interface ISoundTriggerHw extends @2.1::ISoundTriggerHw {


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


// Begin V2_2 implementation
// Begin V2_2 implementation


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


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


    if (mHwDevice->get_model_state == NULL) {
    if (mHwDevice->get_model_state == NULL) {
        ALOGE("Failed to get model state from device, no such method");
        ALOGE("Failed to get model state from device, no such method");
        ret = -ENODEV;
        return -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;
    }
    }


    convertRecognitionEventFromHal(&event, halEvent);
    return mHwDevice->get_model_state(mHwDevice, client->getHalHandle());

exit:
    hidl_cb(ret, event);
    free(halEvent);
    return Void();
}
}


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


    // Methods from V2_2::ISoundTriggerHw follow.
    // 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();
    SoundTriggerHw();


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

    EXPECT_TRUE(hidlReturn.isOk());
    EXPECT_TRUE(hidlReturn.isOk());
    EXPECT_EQ(-ENOSYS, ret);
    EXPECT_EQ(-ENOSYS, hidlReturn);
}
}


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