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
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.app.ActivityThread;
|
||||
import android.app.AppGlobals;
|
||||
import android.app.role.OnRoleHoldersChangedListener;
|
||||
import android.app.role.RoleManager;
|
||||
@@ -51,7 +50,6 @@ import android.hardware.soundtrigger.SoundTrigger.ModuleProperties;
|
||||
import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.permission.Identity;
|
||||
import android.media.permission.IdentityContext;
|
||||
import android.media.permission.PermissionUtil;
|
||||
import android.media.permission.SafeCloseable;
|
||||
import android.os.Binder;
|
||||
@@ -61,7 +59,6 @@ import android.os.IBinder;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteCallback;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
@@ -88,6 +85,7 @@ import com.android.internal.R;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.app.IHotwordRecognitionStatusCallback;
|
||||
import com.android.internal.app.IVisualQueryDetectionAttentionListener;
|
||||
import com.android.internal.app.IVisualQueryRecognitionStatusListener;
|
||||
import com.android.internal.app.IVoiceActionCheckCallback;
|
||||
import com.android.internal.app.IVoiceInteractionManagerService;
|
||||
import com.android.internal.app.IVoiceInteractionSessionListener;
|
||||
@@ -139,6 +137,7 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
|
||||
private final RemoteCallbackList<IVoiceInteractionSessionListener>
|
||||
mVoiceInteractionSessionListeners = new RemoteCallbackList<>();
|
||||
private IVisualQueryRecognitionStatusListener mVisualQueryRecognitionStatusListener;
|
||||
|
||||
public VoiceInteractionManagerService(Context context) {
|
||||
super(context);
|
||||
@@ -1343,6 +1342,17 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
@android.annotation.EnforcePermission(
|
||||
android.Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE)
|
||||
@Override
|
||||
public void subscribeVisualQueryRecognitionStatus(IVisualQueryRecognitionStatusListener
|
||||
listener) {
|
||||
super.subscribeVisualQueryRecognitionStatus_enforcePermission();
|
||||
synchronized (this) {
|
||||
mVisualQueryRecognitionStatusListener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
@android.annotation.EnforcePermission(
|
||||
android.Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE)
|
||||
@Override
|
||||
@@ -1391,7 +1401,10 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
}
|
||||
final long caller = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mImpl.startPerceivingLocked(callback);
|
||||
boolean success = mImpl.startPerceivingLocked(callback);
|
||||
if (success && mVisualQueryRecognitionStatusListener != null) {
|
||||
mVisualQueryRecognitionStatusListener.onStartPerceiving();
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(caller);
|
||||
}
|
||||
@@ -1409,7 +1422,10 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
}
|
||||
final long caller = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mImpl.stopPerceivingLocked();
|
||||
boolean success = mImpl.stopPerceivingLocked();
|
||||
if (success && mVisualQueryRecognitionStatusListener != null) {
|
||||
mVisualQueryRecognitionStatusListener.onStopPerceiving();
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(caller);
|
||||
}
|
||||
|
||||
@@ -784,30 +784,30 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
||||
mHotwordDetectionConnection.setVisualQueryDetectionAttentionListenerLocked(listener);
|
||||
}
|
||||
|
||||
public void startPerceivingLocked(IVisualQueryDetectionVoiceInteractionCallback callback) {
|
||||
public boolean startPerceivingLocked(IVisualQueryDetectionVoiceInteractionCallback callback) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "startPerceivingLocked");
|
||||
}
|
||||
|
||||
if (mHotwordDetectionConnection == null) {
|
||||
// TODO: callback.onError();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
mHotwordDetectionConnection.startPerceivingLocked(callback);
|
||||
return mHotwordDetectionConnection.startPerceivingLocked(callback);
|
||||
}
|
||||
|
||||
public void stopPerceivingLocked() {
|
||||
public boolean stopPerceivingLocked() {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "stopPerceivingLocked");
|
||||
}
|
||||
|
||||
if (mHotwordDetectionConnection == null) {
|
||||
Slog.w(TAG, "stopPerceivingLocked() called but connection isn't established");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
mHotwordDetectionConnection.stopPerceivingLocked();
|
||||
return mHotwordDetectionConnection.stopPerceivingLocked();
|
||||
}
|
||||
|
||||
public void startListeningFromMicLocked(
|
||||
|
||||
Reference in New Issue
Block a user