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:
@@ -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.");
|
||||
if (mModule == null) {
|
||||
return STATUS_ERROR;
|
||||
@@ -851,7 +851,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
Slog.w(TAG, "Recognition aborted");
|
||||
MetricsLogger.count(mContext, "sth_recognition_aborted", 1);
|
||||
ModelData modelData = getModelDataForLocked(event.soundModelHandle);
|
||||
if (modelData != null && (modelData.isModelStarted() || modelData.isStopPending())) {
|
||||
if (modelData != null && modelData.isModelStarted()) {
|
||||
modelData.setStopped();
|
||||
try {
|
||||
IRecognitionStatusCallback callback = modelData.getCallback();
|
||||
@@ -865,7 +865,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
.printLog(ALOGW, TAG));
|
||||
forceStopAndUnloadModelLocked(modelData, e);
|
||||
}
|
||||
updateRecognitionLocked(modelData, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -936,7 +935,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
|
||||
private int updateRecognitionLocked(ModelData model, boolean notifyClientOnError) {
|
||||
boolean shouldStartModel = model.isRequested() && isRecognitionAllowedByDeviceState(model);
|
||||
if (shouldStartModel == model.isModelStarted() || model.isStopPending()) {
|
||||
if (shouldStartModel == model.isModelStarted()) {
|
||||
// No-op.
|
||||
return STATUS_OK;
|
||||
}
|
||||
@@ -1041,10 +1040,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
if (mModule == null) {
|
||||
return;
|
||||
}
|
||||
if (modelData.isStopPending()) {
|
||||
// No need to wait for the stop to be confirmed.
|
||||
modelData.setStopped();
|
||||
} else if (modelData.isModelStarted()) {
|
||||
if (modelData.isModelStarted()) {
|
||||
Slog.d(TAG, "Stopping previously started dangling model " + modelData.getHandle());
|
||||
if (mModule.stopRecognition(modelData.getHandle()) == STATUS_OK) {
|
||||
modelData.setStopped();
|
||||
@@ -1256,7 +1252,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
modelData.setStopPending();
|
||||
modelData.setStopped();
|
||||
MetricsLogger.count(mContext, "sth_stop_recognition_success", 1);
|
||||
// Notify of pause if needed.
|
||||
if (notify) {
|
||||
@@ -1303,9 +1299,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
// Started implies model was successfully loaded and start was called.
|
||||
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).
|
||||
private int mModelState;
|
||||
private UUID mModelId;
|
||||
@@ -1383,10 +1376,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
return mModelState == MODEL_NOTLOADED;
|
||||
}
|
||||
|
||||
synchronized boolean isStopPending() {
|
||||
return mModelState == MODEL_STOP_PENDING;
|
||||
}
|
||||
|
||||
synchronized void setStarted() {
|
||||
mModelState = MODEL_STARTED;
|
||||
}
|
||||
@@ -1395,10 +1384,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
|
||||
mModelState = MODEL_LOADED;
|
||||
}
|
||||
|
||||
synchronized void setStopPending() {
|
||||
mModelState = MODEL_STOP_PENDING;
|
||||
}
|
||||
|
||||
synchronized void setLoaded() {
|
||||
mModelState = MODEL_LOADED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user