Merge "Add triggerOnResourceAvailable to fake STHAL" into udc-dev

This commit is contained in:
Atneya Nair
2023-04-01 01:52:02 +00:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 12 deletions

View File

@@ -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();
}

View File

@@ -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));