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

Commit f7353078 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Dependency injection of STHAL compatibility

Providing the middleware implementation with the canonical driver (the
one that abstracts away which specific underlying version is used)
allows us to test the middlware implementation and the driver compat
layer in isolation from each other, making the tests simpler and
increasing coverage.

Test: atest SoundTriggerMiddlewareImplTest SoundHw2CompatTest
Change-Id: I978b151d9111c4e007dcfdd4cc5df35d46249615
parent 33b097d5
Loading
Loading
Loading
Loading
+3 −5
Original line number Original line Diff line number Diff line
@@ -16,16 +16,14 @@


package com.android.server.soundtrigger_middleware;
package com.android.server.soundtrigger_middleware;


import android.hardware.soundtrigger.V2_0.ISoundTriggerHw;

/**
/**
 * A factory for creating instances of {@link ISoundTriggerHw}.
 * A factory for creating instances of {@link ISoundTriggerHw2}.
 *
 *
 * @hide
 * @hide
 */
 */
public interface HalFactory {
public interface HalFactory {
    /**
    /**
     * @return An instance of {@link ISoundTriggerHw}.
     * @return An instance of {@link ISoundTriggerHw2}.
     */
     */
    ISoundTriggerHw create();
    ISoundTriggerHw2 create();
}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -208,6 +208,9 @@ public class SoundTriggerHw2Enforcer implements ISoundTriggerHw2 {
    }
    }


    private static RuntimeException handleException(RuntimeException e) {
    private static RuntimeException handleException(RuntimeException e) {
        if (e instanceof RecoverableException) {
            throw e;
        }
        if (e.getCause() instanceof DeadObjectException) {
        if (e.getCause() instanceof DeadObjectException) {
            // Server is dead, no need to reboot.
            // Server is dead, no need to reboot.
            Log.e(TAG, "HAL died");
            Log.e(TAG, "HAL died");
+1 −1
Original line number Original line Diff line number Diff line
@@ -235,7 +235,7 @@ public class SoundTriggerMiddlewareService extends ISoundTriggerMiddlewareServic
            HalFactory[] factories = new HalFactory[]{() -> {
            HalFactory[] factories = new HalFactory[]{() -> {
                try {
                try {
                    Log.d(TAG, "Connecting to default ISoundTriggerHw");
                    Log.d(TAG, "Connecting to default ISoundTriggerHw");
                    return ISoundTriggerHw.getService(true);
                    return new SoundTriggerHw2Compat(ISoundTriggerHw.getService(true));
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    throw e.rethrowAsRuntimeException();
                    throw e.rethrowAsRuntimeException();
                }
                }
+1 −2
Original line number Original line Diff line number Diff line
@@ -218,8 +218,7 @@ class SoundTriggerModule implements IHwBinder.DeathRecipient, ISoundTriggerHw2.G
     */
     */
    private void attachToHal() {
    private void attachToHal() {
        mHalService = new SoundTriggerHw2Enforcer(
        mHalService = new SoundTriggerHw2Enforcer(
                new SoundTriggerHw2Watchdog(
                new SoundTriggerHw2Watchdog(mHalFactory.create()));
                        new SoundTriggerHw2Compat(mHalFactory.create())));
        mHalService.linkToDeath(this, 0);
        mHalService.linkToDeath(this, 0);
        mHalService.registerCallback(this);
        mHalService.registerCallback(this);
    }
    }
+805 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading