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

Commit f81abdaa authored by Atneya Nair's avatar Atneya Nair
Browse files

Migrate ST to new error APIs

onError is overloaded, so we will migrate ST to dispatch individual
callbacks depending on error case.

Unify these callbacks with VIService new SoundTriggerFailure class.

Remove onError up to the SDK interface, since it is now redundant.

Fixes: 272123006
Test: atest AlwaysOnHotwordDetectorTest
Change-Id: Ifca877649b5ef361229bc9015b31c77e2e36d758
parent b32371dd
Loading
Loading
Loading
Loading
+24 −6
Original line number Original line Diff line number Diff line
@@ -41,12 +41,6 @@ oneway interface IRecognitionStatusCallback {


    void onGenericSoundTriggerDetected(in SoundTrigger.GenericRecognitionEvent recognitionEvent);
    void onGenericSoundTriggerDetected(in SoundTrigger.GenericRecognitionEvent recognitionEvent);


    /**
     * Called when the detection fails due to an error.
     *
     * @param status The error code that was seen.
     */
    void onError(int status);
    /**
    /**
     * Called when the recognition is paused temporarily for some reason.
     * Called when the recognition is paused temporarily for some reason.
     */
     */
@@ -55,4 +49,28 @@ oneway interface IRecognitionStatusCallback {
     * Called when the recognition is resumed after it was temporarily paused.
     * Called when the recognition is resumed after it was temporarily paused.
     */
     */
    void onRecognitionResumed();
    void onRecognitionResumed();

    // Error callbacks to follow
    /**
     * Called when this recognition has been preempted by another.
     */
    void onPreempted();

    /**
     * Called when the underlying ST module service has died.
     */
    void onModuleDied();

    /**
     * Called when the service failed to gracefully resume recognition following a pause.
     * @param status - The received error code.
     */
    void onResumeFailed(int status);

    /**
     * Called when the service failed to pause recognition when required.
     * TODO(b/276507281) Remove. This should never happen, so we should abort instead.
     * @param status - The received error code.
     */
    void onPauseFailed(int status);
}
}
+6 −10
Original line number Original line Diff line number Diff line
@@ -1572,16 +1572,6 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
            Message.obtain(mHandler, MSG_HOTWORD_REJECTED, result).sendToTarget();
            Message.obtain(mHandler, MSG_HOTWORD_REJECTED, result).sendToTarget();
        }
        }


        @Override
        public void onError(int status) {
            Slog.i(TAG, "onError: " + status);
            // TODO(b/271534248): This is a workaround before the sound trigger uses the new error
            // method.
            Message.obtain(mHandler, MSG_DETECTION_SOUND_TRIGGER_FAILURE,
                    new SoundTriggerFailure(SoundTriggerFailure.ERROR_CODE_UNKNOWN,
                            "Sound trigger error")).sendToTarget();
        }

        @Override
        @Override
        public void onHotwordDetectionServiceFailure(
        public void onHotwordDetectionServiceFailure(
                HotwordDetectionServiceFailure hotwordDetectionServiceFailure) {
                HotwordDetectionServiceFailure hotwordDetectionServiceFailure) {
@@ -1604,6 +1594,12 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
                    "onVisualQueryDetectionServiceFailure: " + visualQueryDetectionServiceFailure);
                    "onVisualQueryDetectionServiceFailure: " + visualQueryDetectionServiceFailure);
        }
        }


        @Override
        public void onSoundTriggerFailure(SoundTriggerFailure soundTriggerFailure) {
            Message.obtain(mHandler, MSG_DETECTION_SOUND_TRIGGER_FAILURE,
                    Objects.requireNonNull(soundTriggerFailure)).sendToTarget();
        }

        @Override
        @Override
        public void onUnknownFailure(String errorMessage) throws RemoteException {
        public void onUnknownFailure(String errorMessage) throws RemoteException {
            Slog.v(TAG, "onUnknownFailure: " + errorMessage);
            Slog.v(TAG, "onUnknownFailure: " + errorMessage);
+7 −8
Original line number Original line Diff line number Diff line
@@ -233,14 +233,6 @@ class SoftwareHotwordDetector extends AbstractDetector {
            }
            }
        }
        }


        @Override
        public void onError(int status) throws RemoteException {
            if (DEBUG) {
                Slog.i(TAG, "Ignored #onError (" + status + ") event");
            }
            // TODO: Check if we still need to implement this method with DetectorFailure mechanism.
        }

        @Override
        @Override
        public void onHotwordDetectionServiceFailure(
        public void onHotwordDetectionServiceFailure(
                HotwordDetectionServiceFailure hotwordDetectionServiceFailure)
                HotwordDetectionServiceFailure hotwordDetectionServiceFailure)
@@ -264,6 +256,13 @@ class SoftwareHotwordDetector extends AbstractDetector {
                    + visualQueryDetectionServiceFailure);
                    + visualQueryDetectionServiceFailure);
        }
        }


        @Override
        public void onSoundTriggerFailure(SoundTriggerFailure onSoundTriggerFailure)
                throws RemoteException {
            // It should never be called here.
            Slog.wtf(TAG, "Unexpected STFailure in software detector: " + onSoundTriggerFailure);
        }

        @Override
        @Override
        public void onUnknownFailure(String errorMessage) throws RemoteException {
        public void onUnknownFailure(String errorMessage) throws RemoteException {
            Slog.v(TAG, "onUnknownFailure: " + errorMessage);
            Slog.v(TAG, "onUnknownFailure: " + errorMessage);
+16 −5
Original line number Original line Diff line number Diff line
@@ -73,18 +73,28 @@ public final class SoundTriggerFailure implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface SoundTriggerErrorCode {}
    public @interface SoundTriggerErrorCode {}


    private int mErrorCode = ERROR_CODE_UNKNOWN;
    private final int mErrorCode;
    private String mErrorMessage = "Unknown";
    private final String mErrorMessage;


    /**
    /**
     * @hide
     * @hide
     */
     */
    @TestApi
    @TestApi
    public SoundTriggerFailure(int errorCode, @NonNull String errorMessage) {
    public SoundTriggerFailure(@SoundTriggerErrorCode int errorCode,
            @NonNull String errorMessage) {
        if (TextUtils.isEmpty(errorMessage)) {
        if (TextUtils.isEmpty(errorMessage)) {
            throw new IllegalArgumentException("errorMessage is empty or null.");
            throw new IllegalArgumentException("errorMessage is empty or null.");
        }
        }
        switch (errorCode) {
            case ERROR_CODE_UNKNOWN:
            case ERROR_CODE_MODULE_DIED:
            case ERROR_CODE_RECOGNITION_RESUME_FAILED:
            case ERROR_CODE_UNEXPECTED_PREEMPTION:
                mErrorCode = errorCode;
                mErrorCode = errorCode;
                break;
            default:
                throw new IllegalArgumentException("Invalid ErrorCode: " + errorCode);
        }
        mErrorMessage = errorMessage;
        mErrorMessage = errorMessage;
    }
    }


@@ -110,13 +120,14 @@ public final class SoundTriggerFailure implements Parcelable {
    @FailureSuggestedAction.FailureSuggestedActionDef
    @FailureSuggestedAction.FailureSuggestedActionDef
    public int getSuggestedAction() {
    public int getSuggestedAction() {
        switch (mErrorCode) {
        switch (mErrorCode) {
            case ERROR_CODE_UNKNOWN:
            case ERROR_CODE_MODULE_DIED:
            case ERROR_CODE_MODULE_DIED:
            case ERROR_CODE_UNEXPECTED_PREEMPTION:
            case ERROR_CODE_UNEXPECTED_PREEMPTION:
                return FailureSuggestedAction.RECREATE_DETECTOR;
                return FailureSuggestedAction.RECREATE_DETECTOR;
            case ERROR_CODE_RECOGNITION_RESUME_FAILED:
            case ERROR_CODE_RECOGNITION_RESUME_FAILED:
                return FailureSuggestedAction.RESTART_RECOGNITION;
                return FailureSuggestedAction.RESTART_RECOGNITION;
            default:
            default:
                return FailureSuggestedAction.NONE;
                throw new AssertionError("Unexpected error code");
        }
        }
    }
    }


+5 −6
Original line number Original line Diff line number Diff line
@@ -390,12 +390,6 @@ public class VisualQueryDetector {
                    () -> mCallback.onVisualQueryDetectionServiceRestarted()));
                    () -> mCallback.onVisualQueryDetectionServiceRestarted()));
        }
        }


        @Override
        public void onError(int status) throws RemoteException {
            Slog.v(TAG, "Initialization Error: (" + status + ")");
            // Do nothing
        }

        @Override
        @Override
        public void onHotwordDetectionServiceFailure(
        public void onHotwordDetectionServiceFailure(
                HotwordDetectionServiceFailure hotwordDetectionServiceFailure)
                HotwordDetectionServiceFailure hotwordDetectionServiceFailure)
@@ -419,6 +413,11 @@ public class VisualQueryDetector {
            }));
            }));
        }
        }


        @Override
        public void onSoundTriggerFailure(SoundTriggerFailure soundTriggerFailure) {
            Slog.wtf(TAG, "Unexpected STFailure in VisualQueryDetector" + soundTriggerFailure);
        }

        @Override
        @Override
        public void onUnknownFailure(String errorMessage) throws RemoteException {
        public void onUnknownFailure(String errorMessage) throws RemoteException {
            Slog.v(TAG, "onUnknownFailure: " + errorMessage);
            Slog.v(TAG, "onUnknownFailure: " + errorMessage);
Loading