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

Commit c3ac1dec authored by Andrea Ambu's avatar Andrea Ambu Committed by Android (Google) Code Review
Browse files

Merge "Create attention listener for VisualQueryDetection"

parents 55292258 7fda1afd
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -229,6 +229,35 @@ public class AssistUtils {
        }
    }

    /**
     * Enables visual detection service.
     *
     * @param listener to receive visual attention gained/lost events.
     */
    public void enableVisualQueryDetection(
            IVisualQueryDetectionAttentionListener listener) {
        try {
            if (mVoiceInteractionManagerService != null) {
                mVoiceInteractionManagerService.enableVisualQueryDetection(listener);
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to register visual query detection attention listener", e);
        }
    }

    /**
     * Disables visual query detection.
     */
    public void disableVisualQueryDetection() {
        try {
            if (mVoiceInteractionManagerService != null) {
                mVoiceInteractionManagerService.disableVisualQueryDetection();
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to register visual query detection attention listener", e);
        }
    }

    @UnsupportedAppUsage
    public ComponentName getAssistComponentForUser(int userId) {
        final String setting = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+33 −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;

/**
 * Allows sysui to notify users the assistant is ready to take a query without notifying the
 * assistant app.
 */
oneway interface IVisualQueryDetectionAttentionListener {
   /**
    * Called when attention signal is sent.
    */
   void onAttentionGained();

   /**
    * Called when a attention signal is lost.
    */
   void onAttentionLost();
}
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.internal.app.IVoiceInteractionSessionListener;
import com.android.internal.app.IVoiceInteractionSessionShowCallback;
import com.android.internal.app.IVoiceInteractionSoundTriggerSession;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.IVisualQueryDetectionAttentionListener;

interface IVoiceInteractionManagerService {
    void showSession(in Bundle sessionArgs, int flags, String attributionTag);
@@ -300,6 +301,12 @@ interface IVoiceInteractionManagerService {
     */
    void shutdownHotwordDetectionService();

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

    @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE")
    void disableVisualQueryDetection();

    void startPerceiving(in IVisualQueryDetectionVoiceInteractionCallback callback);

    void stopPerceiving();
+10 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.view.contentcapture.IContentCaptureManager;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IHotwordRecognitionStatusCallback;
import com.android.internal.app.IVisualQueryDetectionAttentionListener;
import com.android.internal.infra.ServiceConnector;
import com.android.server.LocalServices;
import com.android.server.pm.permission.PermissionManagerServiceInternal;
@@ -328,6 +329,15 @@ final class HotwordDetectionConnection {
        session.startListeningFromMicLocked(audioFormat, callback);
    }

    public void setVisualQueryDetectionAttentionListenerLocked(
            @Nullable IVisualQueryDetectionAttentionListener listener) {
        final VisualQueryDetectorSession session = getVisualQueryDetectorSessionLocked();
        if (session == null) {
            return;
        }
        session.setVisualQueryDetectionAttentionListenerLocked(listener);
    }

    /**
     * This method is only used by VisualQueryDetector.
     */
+26 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.service.voice.IVisualQueryDetectionVoiceInteractionCallback;
import android.util.Slog;

import com.android.internal.app.IHotwordRecognitionStatusCallback;
import com.android.internal.app.IVisualQueryDetectionAttentionListener;

import java.io.PrintWriter;
import java.util.Objects;
@@ -49,6 +50,7 @@ import java.util.concurrent.ScheduledExecutorService;
final class VisualQueryDetectorSession extends DetectorSession {

    private static final String TAG = "VisualQueryDetectorSession";
    private IVisualQueryDetectionAttentionListener mAttentionListener;
    private boolean mEgressingData;
    private boolean mQueryStreaming;

@@ -64,6 +66,7 @@ final class VisualQueryDetectorSession extends DetectorSession {
                logging);
        mEgressingData = false;
        mQueryStreaming = false;
        mAttentionListener = null;
    }

    @Override
@@ -74,6 +77,11 @@ final class VisualQueryDetectorSession extends DetectorSession {
        //TODO(b/261783819): Starts detection in VisualQueryDetectionService.
    }

    void setVisualQueryDetectionAttentionListenerLocked(
            @Nullable IVisualQueryDetectionAttentionListener listener) {
        mAttentionListener = listener;
    }

    @SuppressWarnings("GuardedBy")
    void startPerceivingLocked(IVisualQueryDetectionVoiceInteractionCallback callback) {
        if (DEBUG) {
@@ -86,15 +94,31 @@ final class VisualQueryDetectorSession extends DetectorSession {
            @Override
            public void onAttentionGained() {
                Slog.v(TAG, "BinderCallback#onAttentionGained");
                //TODO check to see if there is an active SysUI listener registered
                mEgressingData = true;
                if (mAttentionListener == null) {
                    return;
                }
                try {
                    mAttentionListener.onAttentionGained();
                } catch (RemoteException e) {
                    Slog.e(TAG, "Error delivering attention gained event.", e);
                    return;
                }
            }

            @Override
            public void onAttentionLost() {
                Slog.v(TAG, "BinderCallback#onAttentionLost");
                //TODO check to see if there is an active SysUI listener registered
                mEgressingData = false;
                if (mAttentionListener == null) {
                    return;
                }
                try {
                    mAttentionListener.onAttentionLost();
                } catch (RemoteException e) {
                    Slog.e(TAG, "Error delivering attention lost event.", e);
                    return;
                }
            }

            @Override
Loading