Merge "Remove ST INTERCEPTED state" into udc-dev

This commit is contained in:
Atneya Nair
2023-05-09 21:41:32 +00:00
committed by Android (Google) Code Review

View File

@@ -264,13 +264,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
LOADED, LOADED,
/** Model is loaded, recognition is active. */ /** Model is loaded, recognition is active. */
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. * Model has been preemptively unloaded by the HAL.
*/ */
@@ -483,18 +476,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
throw new IllegalStateException("Invalid handle: " + modelHandle); throw new IllegalStateException("Invalid handle: " + modelHandle);
} }
// stopRecognition is idempotent - no need to check model state. // 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. // 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 @Override
public void forceRecognitionEvent(int modelHandle) { public void forceRecognitionEvent(int modelHandle) {
// Input validation (always valid). // Input validation (always valid).
@@ -742,17 +702,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
mCallback.onRecognition(modelHandle, event, captureSession); mCallback.onRecognition(modelHandle, event, captureSession);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Client callback 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();
}
}
} }
} }
@@ -771,17 +720,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
mCallback.onPhraseRecognition(modelHandle, event, captureSession); mCallback.onPhraseRecognition(modelHandle, event, captureSession);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Client callback 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();
}
}
} }
} }