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

Commit cf7ddae6 authored by Joanne Chung's avatar Joanne Chung Committed by Automerger Merge Worker
Browse files

Merge "Notify VIS the detector callback remote exception occurred" into udc-dev am: f2c2675d

parents 768322ec f2c2675d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -77,6 +77,13 @@ abstract class AbstractDetector implements HotwordDetector {
        mIsDetectorActive = new AtomicBoolean(true);
    }

    boolean isSameToken(IBinder token) {
        if (token == null) {
            return false;
        }
        return mToken == token;
    }

    /**
     * Method to be called for the detector to ready/register itself with underlying system
     * services.
+7 −0
Original line number Diff line number Diff line
@@ -1707,6 +1707,13 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
        }
    }

    void onDetectorRemoteException() {
        Message.obtain(mHandler, MSG_DETECTION_ERROR,
                new HotwordDetectionServiceFailure(
                        HotwordDetectionServiceFailure.ERROR_CODE_REMOTE_EXCEPTION,
                        "Detector remote exception occurs")).sendToTarget();
    }

    class MyHandler extends Handler {
        MyHandler(@NonNull Looper looper) {
            super(looper);
+1 −0
Original line number Diff line number Diff line
@@ -32,4 +32,5 @@ oneway interface IVoiceInteractionService {
     in IVoiceActionCheckCallback callback);
    void prepareToShowSession(in Bundle args, int flags);
    void showSessionFailed(in Bundle args);
    void detectorRemoteExceptionOccurred(in IBinder token, int detectorType);
}
+7 −0
Original line number Diff line number Diff line
@@ -77,6 +77,13 @@ class SoftwareHotwordDetector extends AbstractDetector {
                DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE);
    }

    void onDetectorRemoteException() {
        Binder.withCleanCallingIdentity(() -> mExecutor.execute(() ->
                mCallback.onFailure(new HotwordDetectionServiceFailure(
                HotwordDetectionServiceFailure.ERROR_CODE_REMOTE_EXCEPTION,
                "Detector remote exception occurs"))));
    }

    @RequiresPermission(RECORD_AUDIO)
    @Override
    public boolean startRecognition() throws IllegalDetectorStateException {
+31 −1
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ import android.content.Context;
import android.content.Intent;
import android.hardware.soundtrigger.KeyphraseEnrollmentInfo;
import android.hardware.soundtrigger.SoundTrigger;
import android.media.voice.KeyphraseModelManager;
import android.media.permission.Identity;
import android.media.voice.KeyphraseModelManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -180,6 +180,14 @@ public class VoiceInteractionService extends Service {
                    VoiceInteractionService::onShowSessionFailed,
                    VoiceInteractionService.this, args));
        }

        @Override
        public void detectorRemoteExceptionOccurred(@NonNull IBinder token, int detectorType) {
            Log.d(TAG, "detectorRemoteExceptionOccurred");
            Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
                    VoiceInteractionService::onDetectorRemoteException,
                    VoiceInteractionService.this, token, detectorType));
        }
    };

    IVoiceInteractionManagerService mSystemService;
@@ -192,6 +200,28 @@ public class VoiceInteractionService extends Service {

    private final Set<HotwordDetector> mActiveDetectors = new ArraySet<>();


    private void onDetectorRemoteException(@NonNull IBinder token, int detectorType) {
        Log.d(TAG, "onDetectorRemoteException for " + HotwordDetector.detectorTypeToString(
                detectorType));
        mActiveDetectors.forEach(detector -> {
            // TODO: handle normal detector, VQD
            if (detectorType == HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_DSP
                    && detector instanceof AlwaysOnHotwordDetector) {
                AlwaysOnHotwordDetector alwaysOnDetector = (AlwaysOnHotwordDetector) detector;
                if (alwaysOnDetector.isSameToken(token)) {
                    alwaysOnDetector.onDetectorRemoteException();
                }
            } else if (detectorType == HotwordDetector.DETECTOR_TYPE_TRUSTED_HOTWORD_SOFTWARE
                    && detector instanceof SoftwareHotwordDetector) {
                SoftwareHotwordDetector softwareDetector = (SoftwareHotwordDetector) detector;
                if (softwareDetector.isSameToken(token)) {
                    softwareDetector.onDetectorRemoteException();
                }
            }
        });
    }

    /**
     * Called when a user has activated an affordance to launch voice assist from the Keyguard.
     *
Loading