From 247d69aa7edda0f03e0e05fea563a35e4e3b2a32 Mon Sep 17 00:00:00 2001 From: lpeter Date: Tue, 23 Mar 2021 18:32:28 +0800 Subject: [PATCH] Unhide api for setHotwordDetectionServiceConfig We also changed API from setHotwordDetectionServiceConfig to updateState. Bug: 182951186 CTS-Coverage-Bug: 183425641 Test: Test: atest CtsVoiceInteractionTestCases Test: atest CtsVoiceInteractionTestCases --instant Change-Id: I29ed0736f9502d3ac5a29ea26a8386bce7113e54 --- core/api/system-current.txt | 1 + .../voice/AlwaysOnHotwordDetector.java | 24 +++++++++---------- .../voice/HotwordDetectionService.java | 16 ++++++------- .../voice/IHotwordDetectionService.aidl | 2 +- .../app/IVoiceInteractionManagerService.aidl | 11 ++++----- .../HotwordDetectionConnection.java | 8 +++---- .../VoiceInteractionManagerService.java | 8 +++---- .../VoiceInteractionManagerServiceImpl.java | 6 ++--- 8 files changed, 36 insertions(+), 40 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 9bcfe11bfe322..b7c27c48423c1 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -10331,6 +10331,7 @@ package android.service.voice { method @RequiresPermission(allOf={android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.CAPTURE_AUDIO_HOTWORD}) public int setParameter(int, int); method @RequiresPermission(allOf={android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.CAPTURE_AUDIO_HOTWORD}) public boolean startRecognition(int); method @RequiresPermission(allOf={android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.CAPTURE_AUDIO_HOTWORD}) public boolean stopRecognition(); + method public final void updateState(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory); field public static final int AUDIO_CAPABILITY_ECHO_CANCELLATION = 1; // 0x1 field public static final int AUDIO_CAPABILITY_NOISE_SUPPRESSION = 2; // 0x2 field public static final int MODEL_PARAM_THRESHOLD_FACTOR = 0; // 0x0 diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index 1ea40bea8e576..7efcc81ccc2ef 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -508,7 +508,7 @@ public class AlwaysOnHotwordDetector { mTargetSdkVersion = targetSdkVersion; mSupportHotwordDetectionService = supportHotwordDetectionService; if (mSupportHotwordDetectionService) { - setHotwordDetectionServiceConfig(options, sharedMemory); + updateState(options, sharedMemory); } try { Identity identity = new Identity(); @@ -524,30 +524,28 @@ public class AlwaysOnHotwordDetector { /** * Set configuration and pass read-only data to hotword detection service. * - * @param options Application configuration data provided by the - * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or + * @param options Application configuration data to provide to the + * {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or * other contents that can be used to communicate with other processes. - * @param sharedMemory The unrestricted data blob provided by the - * {@link VoiceInteractionService}. Use this to provide the hotword models data or other + * @param sharedMemory The unrestricted data blob to provide to the + * {@link HotwordDetectionService}. Use this to provide the hotword models data or other * such data to the trusted process. * - * @throws IllegalStateException if it doesn't support hotword detection service. - * - * @hide + * @throws IllegalStateException if this AlwaysOnHotwordDetector wasn't specified to use a + * {@link HotwordDetectionService} when it was created. */ - public final void setHotwordDetectionServiceConfig(@Nullable PersistableBundle options, + public final void updateState(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) { if (DBG) { - Slog.d(TAG, "setHotwordDetectionServiceConfig()"); + Slog.d(TAG, "updateState()"); } if (!mSupportHotwordDetectionService) { throw new IllegalStateException( - "setHotwordDetectionServiceConfig called, but it doesn't support hotword" - + " detection service"); + "updateState called, but it doesn't support hotword detection service"); } try { - mModelManagementService.setHotwordDetectionServiceConfig(options, sharedMemory); + mModelManagementService.updateState(options, sharedMemory); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/service/voice/HotwordDetectionService.java b/core/java/android/service/voice/HotwordDetectionService.java index 686268c3d854f..db984c246b2f4 100644 --- a/core/java/android/service/voice/HotwordDetectionService.java +++ b/core/java/android/service/voice/HotwordDetectionService.java @@ -82,10 +82,10 @@ public abstract class HotwordDetectionService extends Service { } @Override - public void setConfig(PersistableBundle options, SharedMemory sharedMemory) + public void updateState(PersistableBundle options, SharedMemory sharedMemory) throws RemoteException { if (DBG) { - Log.d(TAG, "#setConfig"); + Log.d(TAG, "#updateState"); } mHandler.sendMessage(obtainMessage(HotwordDetectionService::onUpdateState, HotwordDetectionService.this, @@ -139,14 +139,14 @@ public abstract class HotwordDetectionService extends Service { /** * Called when the {@link VoiceInteractionService#createAlwaysOnHotwordDetector(String, Locale, * PersistableBundle, SharedMemory, AlwaysOnHotwordDetector.Callback)} or - * {@link AlwaysOnHotwordDetector#setHotwordDetectionServiceConfig(PersistableBundle, - * SharedMemory)} requests an update of the hotword detection parameters. + * {@link AlwaysOnHotwordDetector#updateState(PersistableBundle, SharedMemory)} requests an + * update of the hotword detection parameters. * - * @param options Application configuration data provided by the - * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or + * @param options Application configuration data to provide to the + * {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or * other contents that can be used to communicate with other processes. - * @param sharedMemory The unrestricted data blob provided by the - * {@link VoiceInteractionService}. Use this to provide the hotword models data or other + * @param sharedMemory The unrestricted data blob to provide to the + * {@link HotwordDetectionService}. Use this to provide the hotword models data or other * such data to the trusted process. * * @hide diff --git a/core/java/android/service/voice/IHotwordDetectionService.aidl b/core/java/android/service/voice/IHotwordDetectionService.aidl index 8d01dd1bf3403..0791f1ca49eb5 100644 --- a/core/java/android/service/voice/IHotwordDetectionService.aidl +++ b/core/java/android/service/voice/IHotwordDetectionService.aidl @@ -34,5 +34,5 @@ oneway interface IHotwordDetectionService { long timeoutMillis, in IDspHotwordDetectionCallback callback); - void setConfig(in PersistableBundle options, in SharedMemory sharedMemory); + void updateState(in PersistableBundle options, in SharedMemory sharedMemory); } diff --git a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl index 2a022e6e6736d..e2732867d195b 100644 --- a/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl +++ b/core/java/com/android/internal/app/IVoiceInteractionManagerService.aidl @@ -229,15 +229,14 @@ interface IVoiceInteractionManagerService { /** * Set configuration and pass read-only data to hotword detection service. * - * @param options Application configuration data provided by the - * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or + * @param options Application configuration data to provide to the + * {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or * other contents that can be used to communicate with other processes. - * @param sharedMemory The unrestricted data blob provided by the - * {@link VoiceInteractionService}. Use this to provide the hotword models data or other + * @param sharedMemory The unrestricted data blob to provide to the + * {@link HotwordDetectionService}. Use this to provide the hotword models data or other * such data to the trusted process. */ - void setHotwordDetectionServiceConfig( - in PersistableBundle options, in SharedMemory sharedMemory); + void updateState(in PersistableBundle options, in SharedMemory sharedMemory); /** * Requests to shutdown hotword detection service. diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index 6541774e9ac3e..11ccfd88c1003 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -96,10 +96,10 @@ final class HotwordDetectionConnection { mBound = connected; if (connected) { try { - service.setConfig(options, sharedMemory); + service.updateState(options, sharedMemory); } catch (RemoteException e) { // TODO: (b/181842909) Report an error to voice interactor - Slog.w(TAG, "Failed to setConfig for HotwordDetectionService", e); + Slog.w(TAG, "Failed to updateState for HotwordDetectionService", e); } } } @@ -129,9 +129,9 @@ final class HotwordDetectionConnection { } } - void setConfigLocked(PersistableBundle options, SharedMemory sharedMemory) { + void updateStateLocked(PersistableBundle options, SharedMemory sharedMemory) { mRemoteHotwordDetectionService.run( - service -> service.setConfig(options, sharedMemory)); + service -> service.updateState(options, sharedMemory)); } private void detectFromDspSource(SoundTrigger.KeyphraseRecognitionEvent recognitionEvent, diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 29354eb0fd1f2..c110b231bd0e5 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -984,21 +984,19 @@ public class VoiceInteractionManagerService extends SystemService { } @Override - public void setHotwordDetectionServiceConfig(@Nullable PersistableBundle options, + public void updateState(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) { enforceCallingPermission(Manifest.permission.MANAGE_HOTWORD_DETECTION); synchronized (this) { enforceIsCurrentVoiceInteractionService(); if (mImpl == null) { - Slog.w(TAG, - "setHotwordDetectionServiceConfig without running voice" - + " interaction service"); + Slog.w(TAG, "updateState without running voice interaction service"); return; } final long caller = Binder.clearCallingIdentity(); try { - mImpl.setHotwordDetectionServiceConfigLocked(options, sharedMemory); + mImpl.updateStateLocked(options, sharedMemory); } finally { Binder.restoreCallingIdentity(caller); } diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index c9b0a3e30ca35..d54b4114395f5 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -402,10 +402,10 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne return mInfo.getSupportsLocalInteraction(); } - public void setHotwordDetectionServiceConfigLocked(@Nullable PersistableBundle options, + public void updateStateLocked(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory) { if (DEBUG) { - Slog.d(TAG, "setHotwordDetectionServiceConfigLocked"); + Slog.d(TAG, "updateStateLocked"); } if (mHotwordDetectionComponentName == null) { Slog.w(TAG, "Hotword detection service name not found"); @@ -427,7 +427,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mHotwordDetectionComponentName, mUser, /* bindInstantServiceAllowed= */ false, options, sharedMemory); } else { - mHotwordDetectionConnection.setConfigLocked(options, sharedMemory); + mHotwordDetectionConnection.updateStateLocked(options, sharedMemory); } }