summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sergey Volnov <volnov@google.com> 2021-04-16 17:17:40 +0100
committer Sergey Volnov <volnov@google.com> 2021-04-16 22:23:06 +0100
commit307f51a17db6acd85d28ad63cdb0cd5a5eba20a0 (patch)
tree45d3b0f9a9150ef76d55382daff0bc8f0bc901d5
parent43dfe44a0f339bd5f2b536b5db054f148abfbf3e (diff)
Ensure updateState() is available for software hotword.
We accidentally missed propagating this method to the interface before the previous deadline. Otherwise the change should be trivial and backwards compatible. Bug: 168305377 CTS-Coverage-Bug: 183425641 Test: atest CtsVoiceInteractionTestCases Change-Id: Ib85f5264932aeab73ff67a3371f2304d368383ae
-rw-r--r--core/api/system-current.txt1
-rw-r--r--core/java/android/service/voice/AbstractHotwordDetector.java41
-rw-r--r--core/java/android/service/voice/AlwaysOnHotwordDetector.java27
-rw-r--r--core/java/android/service/voice/HotwordDetector.java16
-rw-r--r--core/java/android/service/voice/SoftwareHotwordDetector.java8
5 files changed, 62 insertions, 31 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 5b978e5cdae2..4ab4f854bcb2 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -10504,6 +10504,7 @@ package android.service.voice {
method @RequiresPermission(allOf={android.Manifest.permission.RECORD_AUDIO, android.Manifest.permission.CAPTURE_AUDIO_HOTWORD}) public boolean startRecognition();
method public boolean startRecognition(@NonNull android.os.ParcelFileDescriptor, @NonNull android.media.AudioFormat, @Nullable android.os.PersistableBundle);
method public boolean stopRecognition();
+ method public void updateState(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory);
field public static final int CONFIDENCE_LEVEL_HIGH = 3; // 0x3
field public static final int CONFIDENCE_LEVEL_LOW = 1; // 0x1
field public static final int CONFIDENCE_LEVEL_MEDIUM = 2; // 0x2
diff --git a/core/java/android/service/voice/AbstractHotwordDetector.java b/core/java/android/service/voice/AbstractHotwordDetector.java
index e4eefc4e3a81..48967482fbdf 100644
--- a/core/java/android/service/voice/AbstractHotwordDetector.java
+++ b/core/java/android/service/voice/AbstractHotwordDetector.java
@@ -26,8 +26,10 @@ import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.RemoteException;
+import android.os.SharedMemory;
import android.util.Slog;
+import com.android.internal.app.IHotwordRecognitionStatusCallback;
import com.android.internal.app.IVoiceInteractionManagerService;
/** Base implementation of {@link HotwordDetector}. */
@@ -35,6 +37,8 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
private static final String TAG = AbstractHotwordDetector.class.getSimpleName();
private static final boolean DEBUG = false;
+ protected final Object mLock = new Object();
+
private final IVoiceInteractionManagerService mManagerService;
private final Handler mHandler;
private final HotwordDetector.Callback mCallback;
@@ -79,6 +83,43 @@ abstract class AbstractHotwordDetector implements HotwordDetector {
return true;
}
+ /**
+ * Set configuration and pass read-only data to hotword detection service.
+ *
+ * @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 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 this AlwaysOnHotwordDetector wasn't specified to use a
+ * {@link HotwordDetectionService} when it was created. In addition, if this
+ * AlwaysOnHotwordDetector is in an invalid or error state.
+ */
+ @Override
+ public void updateState(@Nullable PersistableBundle options,
+ @Nullable SharedMemory sharedMemory) {
+ if (DEBUG) {
+ Slog.d(TAG, "updateState()");
+ }
+ synchronized (mLock) {
+ updateStateLocked(options, sharedMemory, null /* callback */);
+ }
+ }
+
+ protected void updateStateLocked(@Nullable PersistableBundle options,
+ @Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback) {
+ if (DEBUG) {
+ Slog.d(TAG, "updateStateLocked()");
+ }
+ try {
+ mManagerService.updateState(options, sharedMemory, callback);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
private static class BinderCallback
extends IMicrophoneHotwordDetectionVoiceInteractionCallback.Stub {
private final Handler mHandler;
diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
index 8ca0e7ccff37..a2a9a76c4ffc 100644
--- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java
+++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
@@ -276,7 +276,6 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
private final IVoiceInteractionSoundTriggerSession mSoundTriggerSession;
private final SoundTriggerListener mInternalCallback;
private final Callback mExternalCallback;
- private final Object mLock = new Object();
private final Handler mHandler;
private final IBinder mBinder = new Binder();
private final int mTargetSdkVersion;
@@ -584,24 +583,15 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
}
/**
- * Set configuration and pass read-only data to hotword detection service.
- *
- * @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 to provide to the
- * {@link HotwordDetectionService}. Use this to provide the hotword models data or other
- * such data to the trusted process.
+ * {@inheritDoc}
*
* @throws IllegalStateException if this AlwaysOnHotwordDetector wasn't specified to use a
* {@link HotwordDetectionService} when it was created. In addition, if this
* AlwaysOnHotwordDetector is in an invalid or error state.
*/
+ @Override
public final void updateState(@Nullable PersistableBundle options,
@Nullable SharedMemory sharedMemory) {
- if (DBG) {
- Slog.d(TAG, "updateState()");
- }
synchronized (mLock) {
if (!mSupportHotwordDetectionService) {
throw new IllegalStateException(
@@ -611,20 +601,9 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
throw new IllegalStateException(
"updateState called on an invalid detector or error state");
}
- updateStateLocked(options, sharedMemory, null /* callback */);
}
- }
- private void updateStateLocked(@Nullable PersistableBundle options,
- @Nullable SharedMemory sharedMemory, IHotwordRecognitionStatusCallback callback) {
- if (DBG) {
- Slog.d(TAG, "updateStateLocked()");
- }
- try {
- mModelManagementService.updateState(options, sharedMemory, callback);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
+ super.updateState(options, sharedMemory);
}
/**
diff --git a/core/java/android/service/voice/HotwordDetector.java b/core/java/android/service/voice/HotwordDetector.java
index f4e5ddaa31a6..ab7d9cd5ae5c 100644
--- a/core/java/android/service/voice/HotwordDetector.java
+++ b/core/java/android/service/voice/HotwordDetector.java
@@ -27,6 +27,7 @@ import android.annotation.SystemApi;
import android.media.AudioFormat;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
+import android.os.SharedMemory;
import android.service.voice.HotwordDetectionService.InitializationStatus;
/**
@@ -106,6 +107,21 @@ public interface HotwordDetector {
@Nullable PersistableBundle options);
/**
+ * Set configuration and pass read-only data to hotword detection service.
+ *
+ * @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 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 this HotwordDetector wasn't specified to use a
+ * {@link HotwordDetectionService} when it was created.
+ */
+ void updateState(@Nullable PersistableBundle options, @Nullable SharedMemory sharedMemory);
+
+ /**
* The callback to notify of detection events.
*/
interface Callback {
diff --git a/core/java/android/service/voice/SoftwareHotwordDetector.java b/core/java/android/service/voice/SoftwareHotwordDetector.java
index 376596b9b0d0..87037f4def6a 100644
--- a/core/java/android/service/voice/SoftwareHotwordDetector.java
+++ b/core/java/android/service/voice/SoftwareHotwordDetector.java
@@ -51,7 +51,6 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
private final HotwordDetector.Callback mCallback;
private final AudioFormat mAudioFormat;
private final Handler mHandler;
- private final Object mLock = new Object();
SoftwareHotwordDetector(
IVoiceInteractionManagerService managerService,
@@ -65,12 +64,7 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector {
mAudioFormat = audioFormat;
mCallback = callback;
mHandler = new Handler(Looper.getMainLooper());
-
- try {
- mManagerService.updateState(options, sharedMemory, null /* callback */);
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
+ updateStateLocked(options, sharedMemory, null /* callback */);
}
@RequiresPermission(RECORD_AUDIO)