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

Commit f656f905 authored by Ytai Ben-tsvi's avatar Ytai Ben-tsvi Committed by Android (Google) Code Review
Browse files

Merge "Remove STHAL 2.4"

parents 4081969f 6f1c5a78
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ java_library_static {
        "android.hardware.configstore-V1.0-java",
        "android.hardware.contexthub-V1.0-java",
        "android.hardware.rebootescrow-V1-java",
        "android.hardware.soundtrigger-V2.4-java",
        "android.hardware.soundtrigger-V2.3-java",
        "android.hardware.power.stats-V1-java",
        "android.hidl.manager-V1.2-java",
        "capture_state_listener-aidl-java",
+29 −105
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
    private @Nullable android.hardware.soundtrigger.V2_1.ISoundTriggerHw mUnderlying_2_1;
    private @Nullable android.hardware.soundtrigger.V2_2.ISoundTriggerHw mUnderlying_2_2;
    private @Nullable android.hardware.soundtrigger.V2_3.ISoundTriggerHw mUnderlying_2_3;
    private @Nullable android.hardware.soundtrigger.V2_4.ISoundTriggerHw mUnderlying_2_4;

    // HAL <=2.1 requires us to pass a callback argument to startRecognition. We will store the one
    // passed on load and then pass it on start. We don't bother storing the callback on newer
@@ -89,13 +88,10 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
            ICaptureStateNotifier notifier) {
        SoundTriggerHw2Compat compat = new SoundTriggerHw2Compat(binder, rebootRunnable);
        ISoundTriggerHal result = compat;
        // Add max model limiter for versions <2.4.
        if (compat.mUnderlying_2_4 == null) {
            result = new SoundTriggerHalMaxModelLimiter(result,
                    compat.mProperties.maxSoundModels);
        }
        // Add concurrent capture handler for versions <2.4 which do not support concurrent capture.
        if (compat.mUnderlying_2_4 == null && !compat.mProperties.concurrentCapture) {
        // Add max model limiter for versions.
        result = new SoundTriggerHalMaxModelLimiter(result, compat.mProperties.maxSoundModels);
        // Add concurrent capture handler for HALs which do not support concurrent capture.
        if (!compat.mProperties.concurrentCapture) {
            result = new SoundTriggerHalConcurrentCaptureHandler(result, notifier);
        }
        return result;
@@ -113,21 +109,11 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
        // version, so we go down the versions in descending order to find the latest one supported,
        // and then simply up-cast it to obtain all the versions that are earlier.

        // Attempt 2.4
        android.hardware.soundtrigger.V2_4.ISoundTriggerHw as2_4 =
                android.hardware.soundtrigger.V2_4.ISoundTriggerHw.asInterface(binder);
        if (as2_4 != null) {
            mUnderlying_2_0 =
                    mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = mUnderlying_2_4 = as2_4;
            return;
        }

        // Attempt 2.3
        android.hardware.soundtrigger.V2_3.ISoundTriggerHw as2_3 =
                android.hardware.soundtrigger.V2_3.ISoundTriggerHw.asInterface(binder);
        if (as2_3 != null) {
            mUnderlying_2_0 = mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = as2_3;
            mUnderlying_2_4 = null;
            return;
        }

@@ -136,7 +122,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
                android.hardware.soundtrigger.V2_2.ISoundTriggerHw.asInterface(binder);
        if (as2_2 != null) {
            mUnderlying_2_0 = mUnderlying_2_1 = mUnderlying_2_2 = as2_2;
            mUnderlying_2_3 = mUnderlying_2_4 = null;
            mUnderlying_2_3 = null;
            return;
        }

@@ -145,7 +131,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
                android.hardware.soundtrigger.V2_1.ISoundTriggerHw.asInterface(binder);
        if (as2_1 != null) {
            mUnderlying_2_0 = mUnderlying_2_1 = as2_1;
            mUnderlying_2_2 = mUnderlying_2_3 = mUnderlying_2_4 = null;
            mUnderlying_2_2 = mUnderlying_2_3 = null;
            return;
        }

@@ -154,7 +140,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
                android.hardware.soundtrigger.V2_0.ISoundTriggerHw.asInterface(binder);
        if (as2_0 != null) {
            mUnderlying_2_0 = as2_0;
            mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = mUnderlying_2_4 = null;
            mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = null;
            return;
        }

@@ -213,17 +199,9 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {

    @Override
    public void registerCallback(GlobalCallback callback) {
        try {
            try {
                as2_4().registerGlobalCallback(new GlobalCallbackWrapper(callback));
            } catch (NotSupported e) {
                // In versions < 2.4 the events represented by this callback don't exist, we can
        // In versions 2.x the events represented by this callback don't exist, we can
        // safely ignore this.
    }
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
    }

    @Override
    public int loadSoundModel(SoundModel soundModel, ModelCallback callback) {
@@ -232,16 +210,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
        try {
            AtomicInteger retval = new AtomicInteger(-1);
            AtomicInteger handle = new AtomicInteger(0);

            try {
                as2_4().loadSoundModel_2_4(hidlModel, new ModelCallbackWrapper(callback),
                        (r, h) -> {
                            retval.set(r);
                            handle.set(h);
                        });
                handleHalStatusAllowBusy(retval.get(), "loadSoundModel_2_4");
            } catch (NotSupported e) {
                // Fall-back to the 2.1 version:
            try {
                as2_1().loadSoundModel_2_1(hidlModel, new ModelCallbackWrapper(callback),
                        0,
@@ -255,7 +223,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
                // Fall-back to the 2.0 version:
                return loadSoundModel_2_0(hidlModel, callback);
            }
            }
            return handle.get();
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
@@ -269,15 +236,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
        try {
            AtomicInteger retval = new AtomicInteger(-1);
            AtomicInteger handle = new AtomicInteger(0);
            try {
                as2_4().loadPhraseSoundModel_2_4(hidlModel, new ModelCallbackWrapper(callback),
                        (r, h) -> {
                            retval.set(r);
                            handle.set(h);
                        });
                handleHalStatusAllowBusy(retval.get(), "loadPhraseSoundModel_2_4");
            } catch (NotSupported e) {
                // Fall-back to the 2.1 version:
            try {
                as2_1().loadPhraseSoundModel_2_1(hidlModel, new ModelCallbackWrapper(callback),
                        0,
@@ -291,7 +249,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
                // Fall-back to the 2.0 version:
                return loadPhraseSoundModel_2_0(hidlModel, callback);
            }
            }
            return handle.get();
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
@@ -327,11 +284,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
        android.hardware.soundtrigger.V2_3.RecognitionConfig hidlConfig =
                ConversionUtil.aidl2hidlRecognitionConfig(config, deviceHandle, ioHandle);
        try {
            try {
                int retval = as2_4().startRecognition_2_4(modelHandle, hidlConfig);
                handleHalStatusAllowBusy(retval, "startRecognition_2_4");
            } catch (NotSupported e) {
                // Fall-back to the 2.3 version:
            try {
                int retval = as2_3().startRecognition_2_3(modelHandle, hidlConfig);
                handleHalStatus(retval, "startRecognition_2_3");
@@ -339,7 +291,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
                // Fall-back to the 2.0 version:
                startRecognition_2_1(modelHandle, hidlConfig);
            }
            }
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -551,14 +502,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
        return mUnderlying_2_3;
    }

    private @NonNull
    android.hardware.soundtrigger.V2_4.ISoundTriggerHw as2_4() throws NotSupported {
        if (mUnderlying_2_4 == null) {
            throw new NotSupported("Underlying driver version < 2.4");
        }
        return mUnderlying_2_4;
    }

    /**
     * A checked exception representing the requested interface version not being supported.
     * At the public interface layer, use {@link #throwAsRecoverableException()} to propagate it to
@@ -580,22 +523,8 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
        }
    }

    private static class GlobalCallbackWrapper extends
            android.hardware.soundtrigger.V2_4.ISoundTriggerHwGlobalCallback.Stub {
        private final @NonNull GlobalCallback mDelegate;

        private GlobalCallbackWrapper(@NonNull GlobalCallback delegate) {
            mDelegate = delegate;
        }

        @Override
        public void onResourcesAvailable() {
            mDelegate.onResourcesAvailable();
        }
    }

    private static class ModelCallbackWrapper extends
            android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback.Stub {
            android.hardware.soundtrigger.V2_1.ISoundTriggerHwCallback.Stub {
        private final @NonNull ModelCallback mDelegate;

        private ModelCallbackWrapper(
@@ -603,11 +532,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
            mDelegate = Objects.requireNonNull(delegate);
        }

        @Override
        public void modelUnloaded(int modelHandle) {
            mDelegate.modelUnloaded(modelHandle);
        }

        @Override
        public void recognitionCallback_2_1(
                android.hardware.soundtrigger.V2_1.ISoundTriggerHwCallback.RecognitionEvent event,
+8 −262

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;

import android.annotation.NonNull;
import android.hardware.soundtrigger.V2_1.ISoundTriggerHw;
import android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback;
import android.hardware.soundtrigger.V2_1.ISoundTriggerHwCallback;
import android.media.AudioFormat;
import android.media.MediaFormat;
import android.media.audio.common.AudioChannelLayout;