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

Commit 321950f3 authored by lpeter's avatar lpeter Committed by Peter Li
Browse files

Improve error handling for Trusted Hotword

Add a new callback with an DetectorFailure parameter to let the
assistant know what went wrong during using the hotword detector.

Bug: 256780491
Bug: 261012843
Test: atest CtsVoiceInteractionTestCases

Change-Id: I0b7d9625abfa10f93ad8564e85faedd1db4fa51d
parent 7137d916
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -13141,7 +13141,8 @@ package android.service.voice {
  public static interface HotwordDetector.Callback {
    method public void onDetected(@NonNull android.service.voice.AlwaysOnHotwordDetector.EventPayload);
    method public void onError();
    method @Deprecated public void onError();
    method public default void onFailure(@NonNull android.service.voice.DetectorFailure);
    method public void onHotwordDetectionServiceInitialized(int);
    method public void onHotwordDetectionServiceRestarted();
    method public void onRecognitionPaused();
@@ -13202,7 +13203,7 @@ package android.service.voice {
  }
  public static interface VisualQueryDetector.Callback {
    method public void onError();
    method public void onFailure(@NonNull android.service.voice.DetectorFailure);
    method public void onQueryDetected(@NonNull String);
    method public void onQueryFinished();
    method public void onQueryRejected();
+6 −3
Original line number Diff line number Diff line
@@ -231,9 +231,12 @@ abstract class AbstractDetector implements HotwordDetector {

        /** Called when the detection fails due to an error. */
        @Override
        public void onError() {
            Slog.v(TAG, "BinderCallback#onError");
            Binder.withCleanCallingIdentity(() -> mExecutor.execute(() -> mCallback.onError()));
        public void onError(DetectorFailure detectorFailure) {
            Slog.v(TAG, "BinderCallback#onError detectorFailure: " + detectorFailure);
            Binder.withCleanCallingIdentity(() -> mExecutor.execute(() -> {
                mCallback.onFailure(detectorFailure != null ? detectorFailure
                        : new UnknownFailure("Error data is null"));
            }));
        }

        @Override
+18 −3
Original line number Diff line number Diff line
@@ -732,7 +732,13 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
         */
        public abstract void onDetected(@NonNull EventPayload eventPayload);

        /** {@inheritDoc} */
        /**
         * {@inheritDoc}
         *
         * @deprecated Use {@link HotwordDetector.Callback#onError(DetectorFailure)} instead.
         */
        @Deprecated
        @Override
        public abstract void onError();

        /** {@inheritDoc} */
@@ -1658,9 +1664,18 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
        @Override
        public void onError(int status) {
            Slog.i(TAG, "onError: " + status);
            mHandler.sendEmptyMessage(MSG_DETECTION_ERROR);
            // This is a workaround before the sound trigger uses the onDetectionFailure method.
            Message.obtain(mHandler, MSG_DETECTION_ERROR,
                    new SoundTriggerFailure(status, "Sound trigger error")).sendToTarget();
        }

        @Override
        public void onDetectionFailure(DetectorFailure detectorFailure) {
            Slog.v(TAG, "onDetectionFailure detectorFailure: " + detectorFailure);
            Message.obtain(mHandler, MSG_DETECTION_ERROR,
                    detectorFailure != null ? detectorFailure
                            : new UnknownFailure("Error data is null")).sendToTarget();
        }
        @Override
        public void onRecognitionPaused() {
            Slog.i(TAG, "onRecognitionPaused");
@@ -1716,7 +1731,7 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
                        mExternalCallback.onDetected((EventPayload) message.obj);
                        break;
                    case MSG_DETECTION_ERROR:
                        mExternalCallback.onError();
                        mExternalCallback.onFailure((DetectorFailure) msg.obj);
                        break;
                    case MSG_DETECTION_PAUSE:
                        mExternalCallback.onRecognitionPaused();
+19 −0
Original line number Diff line number Diff line
@@ -231,9 +231,28 @@ public interface HotwordDetector {

        /**
         * Called when the detection fails due to an error.
         *
         * @deprecated On Android 14 and above, implement {@link #onFailure(DetectorFailure)}
         * instead.
         */
        @Deprecated
        void onError();

        /**
         * Called when the detection fails due to an error, the subclasses of
         * {@link DetectorFailure} will be reported to the detector.
         *
         * @see android.service.voice.HotwordDetectionServiceFailure
         * @see android.service.voice.SoundTriggerFailure
         * @see android.service.voice.UnknownFailure
         * @see android.service.voice.VisualQueryDetectionServiceFailure
         *
         * @param detectorFailure It provides the error code, error message and suggested action.
         */
        default void onFailure(@NonNull DetectorFailure detectorFailure) {
            onError();
        }

        /**
         * Called when the recognition is paused temporarily for some reason.
         * This is an informational callback, and the clients shouldn't be doing anything here
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.service.voice;

import android.media.AudioFormat;
import android.service.voice.DetectorFailure;
import android.service.voice.HotwordDetectedResult;
import android.service.voice.HotwordRejectedResult;

@@ -38,7 +39,7 @@ oneway interface IMicrophoneHotwordDetectionVoiceInteractionCallback {
    /**
     * Called when the detection fails due to an error.
     */
    void onError();
    void onError(in DetectorFailure detectorFailure);

    /**
     * Called when the detected result was not detected.
Loading