Merge "Remove ST INTERCEPTED state" into udc-dev am: 528cd329f0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23065725

Change-Id: Id60714c6a34715290482cba653cff3aa5a4ff431
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Atneya Nair
2023-05-09 21:44:11 +00:00
committed by Automerger Merge Worker

View File

@@ -264,13 +264,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
LOADED,
/** Model is loaded, recognition is active. */
ACTIVE,
/**
* Model is active as far as the client is concerned, but loaded as far as the
* layers are concerned. This condition occurs when a recognition event that indicates
* the recognition for this model arrived from the underlying layer, but had not been
* delivered to the caller (most commonly, for permission reasons).
*/
INTERCEPTED,
/**
* Model has been preemptively unloaded by the HAL.
*/
@@ -483,18 +476,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
throw new IllegalStateException("Invalid handle: " + modelHandle);
}
// stopRecognition is idempotent - no need to check model state.
// From here on, every exception isn't client's fault.
try {
// If the activity state is INTERCEPTED, we skip delegating the command, but
// still consider the call valid.
if (modelState.activityState == ModelState.Activity.INTERCEPTED) {
modelState.activityState = ModelState.Activity.LOADED;
return;
}
} catch (Exception e) {
throw handleException(e);
}
}
// Calling the delegate's stop must be done without the lock.
@@ -518,27 +499,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
}
}
private void restartIfIntercepted(int modelHandle) {
synchronized (SoundTriggerMiddlewareValidation.this) {
// State validation.
if (mState == ModuleStatus.DETACHED) {
return;
}
ModelState modelState = mLoadedModels.get(modelHandle);
if (modelState == null
|| modelState.activityState != ModelState.Activity.INTERCEPTED) {
return;
}
try {
mDelegate.startRecognition(modelHandle, modelState.config);
modelState.activityState = ModelState.Activity.ACTIVE;
Log.i(TAG, "Restarted intercepted model " + modelHandle);
} catch (Exception e) {
Log.i(TAG, "Failed to restart intercepted model " + modelHandle, e);
}
}
}
@Override
public void forceRecognitionEvent(int modelHandle) {
// Input validation (always valid).
@@ -742,18 +702,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
mCallback.onRecognition(modelHandle, event, captureSession);
} catch (Exception e) {
Log.w(TAG, "Client callback exception.", e);
synchronized (SoundTriggerMiddlewareValidation.this) {
ModelState modelState = mLoadedModels.get(modelHandle);
if (event.recognitionEvent.status != RecognitionStatus.FORCED) {
modelState.activityState = ModelState.Activity.INTERCEPTED;
// If we failed to deliver an actual event to the client, they would
// never know to restart it whenever circumstances change. Thus, we
// restart it here. We do this from a separate thread to avoid any
// race conditions.
new Thread(() -> restartIfIntercepted(modelHandle)).start();
}
}
}
}
}
@Override
@@ -771,18 +720,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
mCallback.onPhraseRecognition(modelHandle, event, captureSession);
} catch (Exception e) {
Log.w(TAG, "Client callback exception.", e);
synchronized (SoundTriggerMiddlewareValidation.this) {
ModelState modelState = mLoadedModels.get(modelHandle);
if (!event.phraseRecognitionEvent.common.recognitionStillActive) {
modelState.activityState = ModelState.Activity.INTERCEPTED;
// If we failed to deliver an actual event to the client, they would
// never know to restart it whenever circumstances change. Thus, we
// restart it here. We do this from a separate thread to avoid any
// race conditions.
new Thread(() -> restartIfIntercepted(modelHandle)).start();
}
}
}
}
}
@Override