Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3fb19e90 authored by Atneya Nair's avatar Atneya Nair Committed by Android (Google) Code Review
Browse files

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

parents e7d9a123 147d90ed
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -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();
}
+20 −9
Original line number Diff line number Diff line
@@ -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));