Minor FakeSoundTriggerHal fixes

- Make sure setResourceContention is acked even when it is a no-op
- Make sure we don't send a null recognitionSession on stopRecognition,
  which is possible since the call is idempotent.

Bug: 236826280
Fixes: 280379313
Test: SoundTriggerManagerTest
Test: AlwaysOnHotwordDetectorTest
Change-Id: Ia62e6937f1a011aee0e37faa0cff8a0fd2bcbcac
This commit is contained in:
Atneya Nair
2023-05-01 21:57:57 -07:00
parent 62c81b84ad
commit abbe7c5638

View File

@@ -310,15 +310,16 @@ public class FakeSoundTriggerHal extends ISoundTriggerHw.Stub {
IAcknowledgeEvent callback) {
synchronized (FakeSoundTriggerHal.this.mLock) {
// oneway, so don't throw on death
if (mIsDead || mIsResourceContended == isResourcesContended) {
if (mIsDead) {
return;
}
boolean oldIsResourcesContended = mIsResourceContended;
mIsResourceContended = isResourcesContended;
// Introducing contention is the only injection which can't be
// observed by the ST client.
mInjectionDispatcher.wrap((ISoundTriggerInjection unused) ->
callback.eventReceived());
if (!mIsResourceContended) {
if (!mIsResourceContended && oldIsResourcesContended) {
mGlobalCallbackDispatcher.wrap((ISoundTriggerHwGlobalCallback cb) ->
cb.onResourcesAvailable());
}
@@ -501,8 +502,10 @@ public class FakeSoundTriggerHal extends ISoundTriggerHw.Stub {
Slog.wtf(TAG, "Attempted to stop recognition with invalid handle");
}
ModelSession.RecognitionSession recogSession = session.stopRecognitionForModel();
mInjectionDispatcher.wrap((ISoundTriggerInjection cb) ->
cb.onRecognitionStopped(recogSession));
if (recogSession != null) {
mInjectionDispatcher.wrap((ISoundTriggerInjection cb) ->
cb.onRecognitionStopped(recogSession));
}
}
}