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

Commit c980048d authored by Atneya Nair's avatar Atneya Nair Committed by Automerger Merge Worker
Browse files

Revert "Generate an abort event when stopping" am: c4a891c6

parents e211747e c4a891c6
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -225,13 +225,6 @@ public class SoundTriggerMiddlewareImplTest {
        // Stop the recognition.
        stopRecognition(module, handle, hwHandle);

        ArgumentCaptor<RecognitionEventSys> eventCaptor = ArgumentCaptor.forClass(
                RecognitionEventSys.class);
        verify(callback).onRecognition(eq(handle), eventCaptor.capture(), eq(101));
        RecognitionEventSys lastEvent = eventCaptor.getValue();
        assertEquals(-1, lastEvent.halEventReceivedMillis);
        assertEquals(RecognitionStatus.ABORTED, lastEvent.recognitionEvent.status);

        // Unload the model.
        unloadModel(module, handle, hwHandle);
        module.detach();
@@ -276,13 +269,6 @@ public class SoundTriggerMiddlewareImplTest {
        // Stop the recognition.
        stopRecognition(module, handle, hwHandle);

        ArgumentCaptor<PhraseRecognitionEventSys> eventCaptor = ArgumentCaptor.forClass(
                PhraseRecognitionEventSys.class);
        verify(callback).onPhraseRecognition(eq(handle), eventCaptor.capture(), eq(101));
        PhraseRecognitionEventSys lastEvent = eventCaptor.getValue();
        assertEquals(-1, lastEvent.halEventReceivedMillis);
        assertEquals(RecognitionStatus.ABORTED, lastEvent.phraseRecognitionEvent.common.status);

        // Unload the model.
        unloadModel(module, handle, hwHandle);
        module.detach();
+2 −31
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.media.soundtrigger.PhraseSoundModel;
import android.media.soundtrigger.Properties;
import android.media.soundtrigger.RecognitionConfig;
import android.media.soundtrigger.SoundModel;
import android.media.soundtrigger.SoundModelType;
import android.media.soundtrigger.Status;
import android.media.soundtrigger_middleware.ISoundTriggerCallback;
import android.media.soundtrigger_middleware.ISoundTriggerModule;
@@ -385,7 +384,6 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
        private class Model implements ISoundTriggerHal.ModelCallback {
            public int mHandle;
            private ModelState mState = ModelState.INIT;
            private int mType = SoundModelType.INVALID;
            private SoundTriggerMiddlewareImpl.AudioSessionProvider.AudioSession mSession;

            private @NonNull
@@ -402,7 +400,6 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
                    SoundTriggerMiddlewareImpl.AudioSessionProvider.AudioSession audioSession) {
                mSession = audioSession;
                mHandle = mHalService.loadSoundModel(model, this);
                mType = SoundModelType.GENERIC;
                setState(ModelState.LOADED);
                mLoadedModels.put(mHandle, this);
                return mHandle;
@@ -412,7 +409,7 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
                    SoundTriggerMiddlewareImpl.AudioSessionProvider.AudioSession audioSession) {
                mSession = audioSession;
                mHandle = mHalService.loadPhraseSoundModel(model, this);
                mType = SoundModelType.KEYPHRASE;

                setState(ModelState.LOADED);
                mLoadedModels.put(mHandle, this);
                return mHandle;
@@ -441,36 +438,11 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
                        return;
                    }
                }
                // This must be invoked outside the lock.
                mHalService.stopRecognition(mHandle);

                // No more callbacks for this model after this point.
                synchronized (SoundTriggerModule.this) {
                    // Generate an abortion callback to the client if the model is still active.
                    if (getState() == ModelState.ACTIVE) {
                        if (mCallback != null) {
                            try {
                                switch (mType) {
                                    case SoundModelType.GENERIC:
                                        mCallback.onRecognition(mHandle, AidlUtil.newAbortEvent(),
                                                mSession.mSessionHandle);
                                        break;
                                    case SoundModelType.KEYPHRASE:
                                        mCallback.onPhraseRecognition(mHandle,
                                                AidlUtil.newAbortPhraseEvent(),
                                                mSession.mSessionHandle);
                                        break;
                                    default:
                                        throw new RuntimeException(
                                                "Unexpected model type: " + mType);
                                }
                            } catch (RemoteException e) {
                            }
                        }
                    setState(ModelState.LOADED);
                }
            }
            }

            /** Request a forced recognition event. Will do nothing if recognition is inactive. */
            private void forceRecognitionEvent() {
@@ -559,5 +531,4 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
            }
        }
    }

}