diff options
author | 2023-03-31 11:39:54 -0700 | |
---|---|---|
committer | 2023-03-31 16:08:22 -0700 | |
commit | 147d90ed7e49c1ac14f95c06efd764ac7bb0f0f6 (patch) | |
tree | e233dc7b5db2909b536ca8e4d19c2b2dce7b8841 | |
parent | 585f81858050eaa995610b5ffba5f94eb1392d06 (diff) |
Add triggerOnResourceAvailable to fake STHAL
Exposing this functionality directly affords additional flexibility
to the test instrumentation
Test: atest AlwaysOnHotwordDetectorTest#isCorrectOnFailureReceived_onResumeFailed
Fixes: 276474853
Change-Id: I585c721966731327fe4b99a064edfb779cd28be7
-rw-r--r-- | media/aidl/android/media/soundtrigger_middleware/IInjectGlobalEvent.aidl | 13 | ||||
-rw-r--r-- | services/voiceinteraction/java/com/android/server/soundtrigger_middleware/FakeSoundTriggerHal.java | 29 |
2 files changed, 30 insertions, 12 deletions
diff --git a/media/aidl/android/media/soundtrigger_middleware/IInjectGlobalEvent.aidl b/media/aidl/android/media/soundtrigger_middleware/IInjectGlobalEvent.aidl index dcf39458b261..47d84264a9cd 100644 --- a/media/aidl/android/media/soundtrigger_middleware/IInjectGlobalEvent.aidl +++ b/media/aidl/android/media/soundtrigger_middleware/IInjectGlobalEvent.aidl @@ -25,14 +25,14 @@ import android.media.soundtrigger_middleware.IAcknowledgeEvent; oneway interface IInjectGlobalEvent { /** - * Request a fake STHAL restart. + * Trigger a fake STHAL restart. * This invalidates the {@link IInjectGlobalEvent}. */ void triggerRestart(); /** - * Triggers global resource contention into the fake STHAL. Loads/startRecognition - * will fail with RESOURCE_CONTENTION. + * Set global resource contention within the fake STHAL. Loads/startRecognition + * will fail with {@code RESOURCE_CONTENTION} until unset. * @param isContended - true to enable resource contention. false to disable resource contention * and resume normal functionality. * @param callback - Call {@link IAcknowledgeEvent#eventReceived()} on this interface once @@ -40,4 +40,11 @@ oneway interface IInjectGlobalEvent { */ void setResourceContention(boolean isContended, IAcknowledgeEvent callback); + /** + * Trigger an + * {@link android.hardware.soundtrigger3.ISoundTriggerHwGlobalCallback#onResourcesAvailable} + * callback from the fake STHAL. This callback is used to signal to the framework that + * previous operations which failed may now succeed. + */ + void triggerOnResourcesAvailable(); } diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger_middleware/FakeSoundTriggerHal.java b/services/voiceinteraction/java/com/android/server/soundtrigger_middleware/FakeSoundTriggerHal.java index b76e3e90fade..37a325e09e56 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger_middleware/FakeSoundTriggerHal.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger_middleware/FakeSoundTriggerHal.java @@ -276,16 +276,15 @@ public class FakeSoundTriggerHal extends ISoundTriggerHw.Stub { // for our clients. mGlobalEventSession = new IInjectGlobalEvent.Stub() { /** - * Overrides IInjectGlobalEvent method. * Simulate a HAL process restart. This method is not included in regular HAL interface, * since the entire process is restarted by sending a signal. * Since we run in-proc, we must offer an explicit restart method. * oneway */ @Override - public void triggerRestart() throws RemoteException { + public void triggerRestart() { synchronized (FakeSoundTriggerHal.this.mLock) { - if (mIsDead) throw new DeadObjectException(); + if (mIsDead) return; mIsDead = true; mInjectionDispatcher.wrap((ISoundTriggerInjection cb) -> cb.onRestarted(this)); @@ -305,15 +304,15 @@ public class FakeSoundTriggerHal extends ISoundTriggerHw.Stub { } } - /** - * Overrides IInjectGlobalEvent method. - * oneway - */ + // oneway @Override public void setResourceContention(boolean isResourcesContended, - IAcknowledgeEvent callback) throws RemoteException { + IAcknowledgeEvent callback) { synchronized (FakeSoundTriggerHal.this.mLock) { - if (mIsDead) throw new DeadObjectException(); + // oneway, so don't throw on death + if (mIsDead || mIsResourceContended == isResourcesContended) { + return; + } mIsResourceContended = isResourcesContended; // Introducing contention is the only injection which can't be // observed by the ST client. @@ -325,7 +324,19 @@ public class FakeSoundTriggerHal extends ISoundTriggerHw.Stub { } } } + + // oneway + @Override + public void triggerOnResourcesAvailable() { + synchronized (FakeSoundTriggerHal.this.mLock) { + // oneway, so don't throw on death + if (mIsDead) return; + mGlobalCallbackDispatcher.wrap((ISoundTriggerHwGlobalCallback cb) -> + cb.onResourcesAvailable()); + } + } }; + // Register the global event injection interface mInjectionDispatcher.wrap((ISoundTriggerInjection cb) -> cb.registerGlobalEventInjection(mGlobalEventSession)); |