Remove SoundTriggerService stopping state

Essentially reverts f3e7be0058

The addition of this state caused several state mismatch issues, and
spurious error callbacks.

Removing, and solving the underlying race condition in a subsequent
commit.

Bug: 236826280
Bug: 268217943
Fixes: 275079746
Test: AlwaysOnHotwordDetectorTest#
    testAbortRecognitionAndOnResourceAvailable_recognitionPausedAndResumed
Test: CtsSoundTriggerTestCases
Test: CtsVoiceInteractionTestCases
Test: Manual verification
Change-Id: Icedc330c9fefbe6444dfec886672a97d603098e4
This commit is contained in:
Atneya Nair
2023-04-21 18:48:20 -07:00
parent c4a891c6bc
commit 70b1371bbc

View File

@@ -468,7 +468,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
} }
} }
if (unloadModel && (modelData.isModelLoaded() || modelData.isStopPending())) { if (unloadModel && modelData.isModelLoaded()) {
Slog.d(TAG, "Unloading previously loaded stale model."); Slog.d(TAG, "Unloading previously loaded stale model.");
if (mModule == null) { if (mModule == null) {
return STATUS_ERROR; return STATUS_ERROR;
@@ -851,7 +851,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
Slog.w(TAG, "Recognition aborted"); Slog.w(TAG, "Recognition aborted");
MetricsLogger.count(mContext, "sth_recognition_aborted", 1); MetricsLogger.count(mContext, "sth_recognition_aborted", 1);
ModelData modelData = getModelDataForLocked(event.soundModelHandle); ModelData modelData = getModelDataForLocked(event.soundModelHandle);
if (modelData != null && (modelData.isModelStarted() || modelData.isStopPending())) { if (modelData != null && modelData.isModelStarted()) {
modelData.setStopped(); modelData.setStopped();
try { try {
IRecognitionStatusCallback callback = modelData.getCallback(); IRecognitionStatusCallback callback = modelData.getCallback();
@@ -865,7 +865,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
.printLog(ALOGW, TAG)); .printLog(ALOGW, TAG));
forceStopAndUnloadModelLocked(modelData, e); forceStopAndUnloadModelLocked(modelData, e);
} }
updateRecognitionLocked(modelData, true);
} }
} }
@@ -936,7 +935,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
private int updateRecognitionLocked(ModelData model, boolean notifyClientOnError) { private int updateRecognitionLocked(ModelData model, boolean notifyClientOnError) {
boolean shouldStartModel = model.isRequested() && isRecognitionAllowedByDeviceState(model); boolean shouldStartModel = model.isRequested() && isRecognitionAllowedByDeviceState(model);
if (shouldStartModel == model.isModelStarted() || model.isStopPending()) { if (shouldStartModel == model.isModelStarted()) {
// No-op. // No-op.
return STATUS_OK; return STATUS_OK;
} }
@@ -1041,10 +1040,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
if (mModule == null) { if (mModule == null) {
return; return;
} }
if (modelData.isStopPending()) { if (modelData.isModelStarted()) {
// No need to wait for the stop to be confirmed.
modelData.setStopped();
} else if (modelData.isModelStarted()) {
Slog.d(TAG, "Stopping previously started dangling model " + modelData.getHandle()); Slog.d(TAG, "Stopping previously started dangling model " + modelData.getHandle());
if (mModule.stopRecognition(modelData.getHandle()) == STATUS_OK) { if (mModule.stopRecognition(modelData.getHandle()) == STATUS_OK) {
modelData.setStopped(); modelData.setStopped();
@@ -1256,7 +1252,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
} }
} }
} else { } else {
modelData.setStopPending(); modelData.setStopped();
MetricsLogger.count(mContext, "sth_stop_recognition_success", 1); MetricsLogger.count(mContext, "sth_stop_recognition_success", 1);
// Notify of pause if needed. // Notify of pause if needed.
if (notify) { if (notify) {
@@ -1303,9 +1299,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
// Started implies model was successfully loaded and start was called. // Started implies model was successfully loaded and start was called.
static final int MODEL_STARTED = 2; static final int MODEL_STARTED = 2;
// Model stop request has been sent. Waiting for an event to signal model being stopped.
static final int MODEL_STOP_PENDING = 3;
// One of MODEL_NOTLOADED, MODEL_LOADED, MODEL_STARTED (which implies loaded). // One of MODEL_NOTLOADED, MODEL_LOADED, MODEL_STARTED (which implies loaded).
private int mModelState; private int mModelState;
private UUID mModelId; private UUID mModelId;
@@ -1383,10 +1376,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
return mModelState == MODEL_NOTLOADED; return mModelState == MODEL_NOTLOADED;
} }
synchronized boolean isStopPending() {
return mModelState == MODEL_STOP_PENDING;
}
synchronized void setStarted() { synchronized void setStarted() {
mModelState = MODEL_STARTED; mModelState = MODEL_STARTED;
} }
@@ -1395,10 +1384,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
mModelState = MODEL_LOADED; mModelState = MODEL_LOADED;
} }
synchronized void setStopPending() {
mModelState = MODEL_STOP_PENDING;
}
synchronized void setLoaded() { synchronized void setLoaded() {
mModelState = MODEL_LOADED; mModelState = MODEL_LOADED;
} }