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

Commit ad1d0284 authored by Charles Chen's avatar Charles Chen
Browse files

Provides VisualQueryDetection start recognition signal for SysUI

We provides extra signal for clients such that it can register their
attention callback or perform desired actions at the correct timing.

Bug: 279828541
Test: CtsVoiceInteractionTestCases
Change-Id: Ib689203af0ee53ce3754761f196e4f5b4136d300
parent 00c31ff2
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -233,6 +233,23 @@ public class AssistUtils {
        }
    }

    /**
     * Allows subscription to {@link android.service.voice.VisualQueryDetectionService} service
     * status.
     *
     * @param listener to receive visual service start/stop events.
     */
    public void subscribeVisualQueryRecognitionStatus(IVisualQueryRecognitionStatusListener
            listener) {
        try {
            if (mVoiceInteractionManagerService != null) {
                mVoiceInteractionManagerService.subscribeVisualQueryRecognitionStatus(listener);
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to register visual query detection start listener", e);
        }
    }

    /**
     * Enables visual detection service.
     *
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 package com.android.internal.app;


 oneway interface IVisualQueryRecognitionStatusListener {
    /**
     * Called when {@link VisualQueryDetectionService#onStartDetection} is scheduled from the system
     * server via {@link VoiceInteractionManagerService#StartPerceiving}.
     */
    void onStartPerceiving();

    /**
     * Called when {@link VisualQueryDetectionService#onStopDetection} is scheduled from the system
     * server via {@link VoiceInteractionManagerService#StopPerceiving}.
     */
    void onStopPerceiving();
 }
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.internal.app.IVoiceInteractionSessionShowCallback;
import com.android.internal.app.IVoiceInteractionSoundTriggerSession;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.IVisualQueryDetectionAttentionListener;
import com.android.internal.app.IVisualQueryRecognitionStatusListener;

interface IVoiceInteractionManagerService {
    void showSession(in Bundle sessionArgs, int flags, String attributionTag);
@@ -324,6 +325,9 @@ interface IVoiceInteractionManagerService {
     */
    void shutdownHotwordDetectionService();

    @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE")
    void subscribeVisualQueryRecognitionStatus(in IVisualQueryRecognitionStatusListener listener);

    @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE")
    void enableVisualQueryDetection(in IVisualQueryDetectionAttentionListener Listener);

+6 −6
Original line number Diff line number Diff line
@@ -368,29 +368,29 @@ final class HotwordDetectionConnection {
    /**
     * This method is only used by VisualQueryDetector.
     */
    void startPerceivingLocked(IVisualQueryDetectionVoiceInteractionCallback callback) {
    boolean startPerceivingLocked(IVisualQueryDetectionVoiceInteractionCallback callback) {
        if (DEBUG) {
            Slog.d(TAG, "startPerceivingLocked");
        }
        final VisualQueryDetectorSession session = getVisualQueryDetectorSessionLocked();
        if (session == null) {
            return;
            return false;
        }
        session.startPerceivingLocked(callback);
        return session.startPerceivingLocked(callback);
    }

    /**
     * This method is only used by VisaulQueryDetector.
     */
    void stopPerceivingLocked() {
    boolean stopPerceivingLocked() {
        if (DEBUG) {
            Slog.d(TAG, "stopPerceivingLocked");
        }
        final VisualQueryDetectorSession session = getVisualQueryDetectorSessionLocked();
        if (session == null) {
            return;
            return false;
        }
        session.stopPerceivingLocked();
        return session.stopPerceivingLocked();
    }

    public void startListeningFromExternalSourceLocked(
+5 −4
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ final class VisualQueryDetectorSession extends DetectorSession {
    }

    @SuppressWarnings("GuardedBy")
    void startPerceivingLocked(IVisualQueryDetectionVoiceInteractionCallback callback) {
    boolean startPerceivingLocked(IVisualQueryDetectionVoiceInteractionCallback callback) {
        if (DEBUG) {
            Slog.d(TAG, "startPerceivingLocked");
        }
@@ -198,15 +198,16 @@ final class VisualQueryDetectorSession extends DetectorSession {
                mQueryStreaming = false;
            }
        };
        mRemoteDetectionService.run(service -> service.detectWithVisualSignals(internalCallback));
        return mRemoteDetectionService.run(
                service -> service.detectWithVisualSignals(internalCallback));
    }

    @SuppressWarnings("GuardedBy")
    void stopPerceivingLocked() {
    boolean stopPerceivingLocked() {
        if (DEBUG) {
            Slog.d(TAG, "stopPerceivingLocked");
        }
        mRemoteDetectionService.run(ISandboxedDetectionService::stopDetection);
        return mRemoteDetectionService.run(ISandboxedDetectionService::stopDetection);
    }

    @Override
Loading