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

Commit 73689f56 authored by Atneya Nair's avatar Atneya Nair
Browse files

Fix ST recognition requested after start error

When recognition does not succeed due to contention, device state, or
another unexpected error, the STService session is left in a requested
state, which can resume recognition later unbeknownst to the client.

Return success and send an immediate pause if the service will handle
resuming. Otherwise, set the state to be not requested.

Fixes: 268218045
Test: new AlwaysOnHotwordDetectorTest methods
Test: Manual verification with EBS for AGSA/now playing
Change-Id: I01c6a49a859bde9cd6574d0df9325f6fa7b0b685
parent e10a7489
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -322,12 +322,31 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
            modelData.setRunInBatterySaverMode(runInBatterySaverMode);
            modelData.setSoundModel(soundModel);

            if (!isRecognitionAllowedByDeviceState(modelData)) {
                return STATUS_OK;
            }

            return updateRecognitionLocked(modelData,
            if (isRecognitionAllowedByDeviceState(modelData)) {
                int startRecoResult = updateRecognitionLocked(modelData,
                        false /* Don't notify for synchronous calls */);
                if (startRecoResult == SoundTrigger.STATUS_OK) {
                    return startRecoResult;
                } else if (startRecoResult != SoundTrigger.STATUS_BUSY) {
                    // If we are returning an unexpected error, don't mark the model as requested
                    modelData.setRequested(false);
                    return startRecoResult;
                }
            }
            // Either recognition isn't allowed by device state, or the module is busy.
            // Dispatch a pause.
            try {
                if (callback != null) {
                    mEventLogger.enqueue(new SessionEvent(Type.PAUSE, modelData.getModelId()));
                    callback.onRecognitionPaused();
                }
            } catch (RemoteException e) {
                mEventLogger.enqueue(new SessionEvent(
                            Type.PAUSE, modelData.getModelId(), "RemoteException")
                        .printLog(ALOGW, TAG));
                forceStopAndUnloadModelLocked(modelData, e);
            }
            return STATUS_OK;
        }
    }