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

Commit 4030b561 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "sound trigger: fix cross deadlock between service and client" into lmp-dev

parents 9a63396f 886561f0
Loading
Loading
Loading
Loading
+38 −20
Original line number Diff line number Diff line
@@ -653,7 +653,6 @@ void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& eve
{
    ALOGV("onCallbackEvent type %d", event->mType);

    AutoMutex lock(mLock);
    sp<IMemory> eventMemory = event->mMemory;

    if (eventMemory == 0 || eventMemory->pointer() == NULL) {
@@ -668,7 +667,9 @@ void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& eve
    case CallbackEvent::TYPE_RECOGNITION: {
        struct sound_trigger_recognition_event *recognitionEvent =
                (struct sound_trigger_recognition_event *)eventMemory->pointer();

        sp<ISoundTriggerClient> client;
        {
            AutoMutex lock(mLock);
            sp<Model> model = getModel(recognitionEvent->model);
            if (model == 0) {
                ALOGW("%s model == 0", __func__);
@@ -680,22 +681,39 @@ void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& eve
            }

            recognitionEvent->capture_session = model->mCaptureSession;
        mClient->onRecognitionEvent(eventMemory);
            model->mState = Model::STATE_IDLE;
            client = mClient;
        }
        if (client != 0) {
            client->onRecognitionEvent(eventMemory);
        }
    } break;
    case CallbackEvent::TYPE_SOUNDMODEL: {
        struct sound_trigger_model_event *soundmodelEvent =
                (struct sound_trigger_model_event *)eventMemory->pointer();

        sp<ISoundTriggerClient> client;
        {
            AutoMutex lock(mLock);
            sp<Model> model = getModel(soundmodelEvent->model);
            if (model == 0) {
                ALOGW("%s model == 0", __func__);
                return;
            }
        mClient->onSoundModelEvent(eventMemory);
            client = mClient;
        }
        if (client != 0) {
            client->onSoundModelEvent(eventMemory);
        }
    } break;
    case CallbackEvent::TYPE_SERVICE_STATE: {
        mClient->onServiceStateChange(eventMemory);
        sp<ISoundTriggerClient> client;
        {
            AutoMutex lock(mLock);
            client = mClient;
        }
        if (client != 0) {
            client->onServiceStateChange(eventMemory);
        }
    } break;
    default:
        LOG_ALWAYS_FATAL("onCallbackEvent unknown event type %d", event->mType);