From 73689f5664c471aa7d49e53b2c3e9430ba4e0fad Mon Sep 17 00:00:00 2001 From: Atneya Nair Date: Tue, 25 Apr 2023 18:58:41 -0700 Subject: [PATCH] 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 --- .../soundtrigger/SoundTriggerHelper.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java index b4066ab1ff392..abf2199771b9c 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java @@ -322,12 +322,31 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { modelData.setRunInBatterySaverMode(runInBatterySaverMode); modelData.setSoundModel(soundModel); - if (!isRecognitionAllowedByDeviceState(modelData)) { - return STATUS_OK; + 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; + } } - - return updateRecognitionLocked(modelData, - false /* Don't notify for synchronous calls */); + // 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; } }