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

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

Correctly initialize recognition events

The default-constructed objects have null for non-nullable fields.

Fixes: 224483943
Test: Manual verification of soundtrigger use-cases.
Change-Id: I1dc49d87fc935d608e482ab2cd0713231ccb545f
parent 5095a528
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.media.permission.SafeCloseable;
import android.media.soundtrigger.ModelParameterRange;
import android.media.soundtrigger.PhraseRecognitionEvent;
import android.media.soundtrigger.PhraseRecognitionExtra;
import android.media.soundtrigger.PhraseSoundModel;
import android.media.soundtrigger.Properties;
import android.media.soundtrigger.RecognitionConfig;
@@ -392,7 +393,7 @@ public class SoundTriggerHalConcurrentCaptureHandler implements ISoundTriggerHal
    private static void notifyAbort(int modelHandle, LoadedModel model) {
        switch (model.type) {
            case SoundModelType.GENERIC: {
                RecognitionEvent event = new RecognitionEvent();
                RecognitionEvent event = newEmptyRecognitionEvent();
                event.status = RecognitionStatus.ABORTED;
                event.type = SoundModelType.GENERIC;
                model.callback.recognitionCallback(modelHandle, event);
@@ -400,7 +401,7 @@ public class SoundTriggerHalConcurrentCaptureHandler implements ISoundTriggerHal
            break;

            case SoundModelType.KEYPHRASE: {
                PhraseRecognitionEvent event = new PhraseRecognitionEvent();
                PhraseRecognitionEvent event = newEmptyPhraseRecognitionEvent();
                event.common.status = RecognitionStatus.ABORTED;
                event.common.type = SoundModelType.KEYPHRASE;
                model.callback.phraseRecognitionCallback(modelHandle, event);
@@ -415,6 +416,19 @@ public class SoundTriggerHalConcurrentCaptureHandler implements ISoundTriggerHal
        mNotifier.unregisterListener(this);
    }

    private static PhraseRecognitionEvent newEmptyPhraseRecognitionEvent() {
        PhraseRecognitionEvent result = new PhraseRecognitionEvent();
        result.common = newEmptyRecognitionEvent();
        result.phraseExtras = new PhraseRecognitionExtra[0];
        return result;
    }

    private static RecognitionEvent newEmptyRecognitionEvent() {
        RecognitionEvent result = new RecognitionEvent();
        result.data = new byte[0];
        return result;
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // All methods below do trivial delegation - no interesting logic.
    @Override