From 0fc282f67503a32c65408171ae95e0da6bb3dfe7 Mon Sep 17 00:00:00 2001 From: Charles Chen Date: Tue, 31 Jan 2023 13:30:20 +0000 Subject: Binder passing for VisualQueryDetectionService Enables ContentCaptureService and SpeechRecognitionService for VisualQueryDetectionService. Bug: 267134219 Test: manual & atest CtsVoiceInteractionTestCases Change-Id: Ideb5871497b65ea0046447b62ce2a85791554a8b --- .../service/voice/VisualQueryDetectionService.java | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/core/java/android/service/voice/VisualQueryDetectionService.java b/core/java/android/service/voice/VisualQueryDetectionService.java index 1783186cd045..7de7b2f86f1a 100644 --- a/core/java/android/service/voice/VisualQueryDetectionService.java +++ b/core/java/android/service/voice/VisualQueryDetectionService.java @@ -20,9 +20,11 @@ import android.annotation.DurationMillisLong; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SdkConstant; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.app.Service; import android.content.ContentCaptureOptions; +import android.content.Context; import android.content.Intent; import android.hardware.soundtrigger.SoundTrigger; import android.media.AudioFormat; @@ -35,6 +37,7 @@ import android.os.RemoteException; import android.os.SharedMemory; import android.speech.IRecognitionServiceManager; import android.util.Log; +import android.view.contentcapture.ContentCaptureManager; import android.view.contentcapture.IContentCaptureManager; import java.util.Objects; @@ -79,6 +82,10 @@ public abstract class VisualQueryDetectionService extends Service public static final String KEY_INITIALIZATION_STATUS = "initialization_status"; private IDetectorSessionVisualQueryDetectionCallback mRemoteCallback = null; + @Nullable + private ContentCaptureManager mContentCaptureManager; + @Nullable + private IRecognitionServiceManager mIRecognitionServiceManager; private final ISandboxedDetectionService mInterface = new ISandboxedDetectionService.Stub() { @@ -139,15 +146,29 @@ public abstract class VisualQueryDetectionService extends Service @Override public void updateContentCaptureManager(IContentCaptureManager manager, ContentCaptureOptions options) { - Log.v(TAG, "Ignore #updateContentCaptureManager"); + mContentCaptureManager = new ContentCaptureManager( + VisualQueryDetectionService.this, manager, options); } @Override public void updateRecognitionServiceManager(IRecognitionServiceManager manager) { - Log.v(TAG, "Ignore #updateRecognitionServiceManager"); + mIRecognitionServiceManager = manager; } }; + @Override + @SuppressLint("OnNameExpected") + public @Nullable Object getSystemService(@ServiceName @NonNull String name) { + if (Context.CONTENT_CAPTURE_MANAGER_SERVICE.equals(name)) { + return mContentCaptureManager; + } else if (Context.SPEECH_RECOGNITION_SERVICE.equals(name) + && mIRecognitionServiceManager != null) { + return mIRecognitionServiceManager.asBinder(); + } else { + return super.getSystemService(name); + } + } + /** * {@inheritDoc} * @hide -- cgit v1.2.3-59-g8ed1b