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
This commit is contained in:
Atneya Nair
2023-04-25 18:58:41 -07:00
parent e10a748963
commit 73689f5664

View File

@@ -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;
}
}