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

Commit 3eb52599 authored by Joanne Chung's avatar Joanne Chung
Browse files

Notify VIS the detector callback remote exception occurred

It's possible the VIMS fails to notify client because of the IPC
exception error, some unknown reason that causes the binder object
may have problem to callback. We assume the system still have binders
that is available to use, we try to notify the client procrss not use
callback object.

If the system is in a bad state that cannot get any binder, we do not
have a good solution to resolve this case now. More details can be
found in go/b244391070. The RemoteException for VQS if not be
included in this change, we focus on the hotword part.

Bug: 244391070
Test: manual. Force to call the method to trigger call path. The
onError() callback is called.

Change-Id: I30186d7efdb14c9ef0c7ed65bc089b89199d2e16
parent 27e03dfc
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