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

Commit f47f173b authored by Arunesh Mishra's avatar Arunesh Mishra
Browse files

Fix AlwaysOnHotwordDetector recognition event bug.

Parcelables don't work well with inheritance. So changed the
IRecognitionStatusCallback to have onKeyphraseDetected() and
onGenericSoundTriggerDetected() for those respective events.

Made corresponding changes to AlwaysOnHotwordDetector and SoundTriggerDetector.

Bug: 27250528
Change-Id: Ic08a431e7cc4248c688b05c865348170246de576
parent a572e4a8
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -26,10 +26,20 @@ oneway interface IRecognitionStatusCallback {
     * Called when the keyphrase is spoken.
     *
     * @param recognitionEvent Object containing data relating to the
     *                         recognition event such as trigger audio data, if it was requested
     *                         and is available.
     *                         keyphrase recognition event such as keyphrase
     *                         extras.
     */
    void onDetected(in SoundTrigger.RecognitionEvent recognitionEvent);
    void onKeyphraseDetected(in SoundTrigger.KeyphraseRecognitionEvent recognitionEvent);

   /**
     * Called when a generic sound trigger event is witnessed.
     *
     * @param recognitionEvent Object containing data relating to the
     *                         recognition event such as trigger audio data (if
     *                         requested).
     */

    void onGenericSoundTriggerDetected(in SoundTrigger.GenericRecognitionEvent recognitionEvent);

    /**
     * Called when the detection fails due to an error.
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ parcelable SoundTrigger.ConfidenceLevel;
parcelable SoundTrigger.Keyphrase;
parcelable SoundTrigger.RecognitionEvent;
parcelable SoundTrigger.KeyphraseRecognitionEvent;
parcelable SoundTrigger.GenericSoundRecognitionEvent;
parcelable SoundTrigger.GenericRecognitionEvent;
parcelable SoundTrigger.KeyphraseRecognitionExtra;
parcelable SoundTrigger.KeyphraseSoundModel;
parcelable SoundTrigger.GenericSoundModel;
+37 −3
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ public class SoundTrigger {
            }
        };

        private static RecognitionEvent fromParcel(Parcel in) {
        protected static RecognitionEvent fromParcel(Parcel in) {
            int status = in.readInt();
            int soundModelHandle = in.readInt();
            boolean captureAvailable = in.readByte() == 1;
@@ -980,7 +980,7 @@ public class SoundTrigger {
        public static final Parcelable.Creator<KeyphraseRecognitionEvent> CREATOR
                = new Parcelable.Creator<KeyphraseRecognitionEvent>() {
            public KeyphraseRecognitionEvent createFromParcel(Parcel in) {
                return KeyphraseRecognitionEvent.fromParcel(in);
                return KeyphraseRecognitionEvent.fromParcelForKeyphrase(in);
            }

            public KeyphraseRecognitionEvent[] newArray(int size) {
@@ -988,7 +988,7 @@ public class SoundTrigger {
            }
        };

        private static KeyphraseRecognitionEvent fromParcel(Parcel in) {
        private static KeyphraseRecognitionEvent fromParcelForKeyphrase(Parcel in) {
            int status = in.readInt();
            int soundModelHandle = in.readInt();
            boolean captureAvailable = in.readByte() == 1;
@@ -1094,6 +1094,40 @@ public class SoundTrigger {
                    captureDelayMs, capturePreambleMs, triggerInData, captureFormat,
                    data);
        }

        public static final Parcelable.Creator<GenericRecognitionEvent> CREATOR
                = new Parcelable.Creator<GenericRecognitionEvent>() {
            public GenericRecognitionEvent createFromParcel(Parcel in) {
                return GenericRecognitionEvent.fromParcelForGeneric(in);
            }

            public GenericRecognitionEvent[] newArray(int size) {
                return new GenericRecognitionEvent[size];
            }
        };

        private static GenericRecognitionEvent fromParcelForGeneric(Parcel in) {
            RecognitionEvent event = RecognitionEvent.fromParcel(in);
            return new GenericRecognitionEvent(event.status, event.soundModelHandle,
                    event.captureAvailable, event.captureSession, event.captureDelayMs,
                    event.capturePreambleMs, event.triggerInData, event.captureFormat, event.data);
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass()) return false;
            RecognitionEvent other = (RecognitionEvent) obj;
            return super.equals(obj);
        }

        @Override
        public String toString() {
            return "GenericRecognitionEvent ::" + super.toString();
        }
    }

    /**
+5 −5
Original line number Diff line number Diff line
@@ -617,11 +617,7 @@ public class AlwaysOnHotwordDetector {
        }

        @Override
        public void onDetected(RecognitionEvent event) {
            if (! (event instanceof KeyphraseRecognitionEvent)) {
                Slog.e(TAG, "onDetected() called for a soundtrigger event.");
                return;
            }
        public void onKeyphraseDetected(KeyphraseRecognitionEvent event) {
            if (DBG) {
                Slog.d(TAG, "onDetected(" + event + ")");
            } else {
@@ -632,6 +628,10 @@ public class AlwaysOnHotwordDetector {
                            event.captureFormat, event.captureSession, event.data))
                    .sendToTarget();
        }
        @Override
        public void onGenericSoundTriggerDetected(SoundTrigger.GenericRecognitionEvent event) {
            Slog.w(TAG, "Generic sound trigger event detected at AOHD: " + event);
        }

        @Override
        public void onError(int status) {
+7 −2
Original line number Diff line number Diff line
@@ -289,8 +289,8 @@ public final class SoundTriggerDetector {
         * @hide
         */
        @Override
        public void onDetected(SoundTrigger.RecognitionEvent event) {
            Slog.d(TAG, "onDetected()" + event);
        public void onGenericSoundTriggerDetected(SoundTrigger.GenericRecognitionEvent event) {
            Slog.d(TAG, "onGenericSoundTriggerDetected()" + event);
            Message.obtain(mHandler,
                    MSG_SOUND_TRIGGER_DETECTED,
                    new EventPayload(event.triggerInData, event.captureAvailable,
@@ -298,6 +298,11 @@ public final class SoundTriggerDetector {
                    .sendToTarget();
        }

        @Override
        public void onKeyphraseDetected(SoundTrigger.KeyphraseRecognitionEvent event) {
            Slog.e(TAG, "Ignoring onKeyphraseDetected() called for " + event);
        }

        /**
         * @hide
         */
Loading