summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Atneya Nair <atneya@google.com> 2023-04-26 21:42:45 -0700
committer Atneya Nair <atneya@google.com> 2023-05-03 19:30:55 -0700
commit476349f7448a664e20bc74c633d4fbb0a41398dd (patch)
tree3273358061c9e4e4cf0d549a2f11a61f09451424
parent1030b6c63ffa2de7d3098a97efdb996b9030de34 (diff)
Throw if AOHD is inited without a underlying DSP
This prevents an intermediate state where a AlwaysOnHotwordDetector is initialized, but doesn't have an underlying session to connect to. Throw IllegalStateException if VIS creates an AOHD when no module exists. Bug: 272147641 Fixes: 269165460 Test: CtsVoiceInteractionTestCases Test: Manual verification of hotword Change-Id: I1e3d448fbb3e100fd963cc704397a409a4d8b8f0
-rw-r--r--core/java/android/service/voice/AlwaysOnHotwordDetector.java40
-rw-r--r--core/java/android/service/voice/VoiceInteractionService.java18
2 files changed, 46 insertions, 12 deletions
diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
index 91c350aa9aba..17d54b9c34b5 100644
--- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java
+++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java
@@ -30,6 +30,8 @@ import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.ActivityThread;
import android.app.compat.CompatChanges;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.Intent;
@@ -258,6 +260,16 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
public @interface ModelParams {}
/**
+ * Gates returning {@code IllegalStateException} in {@link #initialize(
+ * PersistableBundle, SharedMemory, SoundTrigger.ModuleProperties)} when no DSP module
+ * is available. If the change is not enabled, the existing behavior of not throwing an
+ * exception and delivering {@link STATE_HARDWARE_UNAVAILABLE} is retained.
+ */
+ @ChangeId
+ @EnabledSince(targetSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
+ static final long THROW_ON_INITIALIZE_IF_NO_DSP = 269165460L;
+
+ /**
* Controls the sensitivity threshold adjustment factor for a given model.
* Negative value corresponds to less sensitive model (high threshold) and
* a positive value corresponds to a more sensitive model (low threshold).
@@ -870,8 +882,10 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
.equals(SoundTrigger.FAKE_HAL_ARCH))
.findFirst()
.orElse(null);
- // (@atneya) intentionally let a null moduleProperties through until
- // all CTS tests are fixed
+ if (CompatChanges.isChangeEnabled(THROW_ON_INITIALIZE_IF_NO_DSP) &&
+ moduleProperties == null) {
+ throw new IllegalStateException("No DSP module available to attach to");
+ }
}
mSoundTriggerSession =
mModelManagementService.createSoundTriggerSessionAsOriginator(
@@ -1753,17 +1767,19 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
}
}
- ModuleProperties dspModuleProperties;
- try {
- dspModuleProperties =
- mSoundTriggerSession.getDspModuleProperties();
- } catch (RemoteException e) {
- throw e.rethrowFromSystemServer();
- }
+ if (!CompatChanges.isChangeEnabled(THROW_ON_INITIALIZE_IF_NO_DSP)) {
+ ModuleProperties dspModuleProperties;
+ try {
+ dspModuleProperties =
+ mSoundTriggerSession.getDspModuleProperties();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
- // No DSP available
- if (dspModuleProperties == null) {
- return STATE_HARDWARE_UNAVAILABLE;
+ // No DSP available
+ if (dspModuleProperties == null) {
+ return STATE_HARDWARE_UNAVAILABLE;
+ }
}
return STATE_NOT_READY;
diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java
index 7822ddeb73d8..90e8cedab622 100644
--- a/core/java/android/service/voice/VoiceInteractionService.java
+++ b/core/java/android/service/voice/VoiceInteractionService.java
@@ -463,6 +463,10 @@ public class VoiceInteractionService extends Service {
* @param callback The callback to notify of detection events.
* @return An always-on hotword detector for the given keyphrase and locale.
*
+ * @throws SecurityException if the caller does not hold required permissions
+ * @throws IllegalStateException if there is no DSP hardware support when a caller has a
+ * target SDK of API level 34 or above.
+ *
* @deprecated Use {@link #createAlwaysOnHotwordDetector(String, Locale, Executor,
* AlwaysOnHotwordDetector.Callback)} instead.
* @hide
@@ -500,6 +504,10 @@ public class VoiceInteractionService extends Service {
* @param callback The callback to notify of detection events.
* @return An always-on hotword detector for the given keyphrase and locale.
*
+ * @throws SecurityException if the caller does not hold required permissions
+ * @throws IllegalStateException if there is no DSP hardware support when a caller has a
+ * target SDK of API level 34 or above.
+ *
* @hide
*/
@SystemApi
@@ -581,6 +589,11 @@ public class VoiceInteractionService extends Service {
* @param callback The callback to notify of detection events.
* @return An always-on hotword detector for the given keyphrase and locale.
*
+ * @throws SecurityException if the caller does not hold required permissions
+ * @throws IllegalStateException if the hotword detection service is not set, isolated process
+ * is not set, or there is no DSP hardware support when a caller has a target SDK of API
+ * level 34 or above.
+ *
* @deprecated Use {@link #createAlwaysOnHotwordDetector(String, Locale, PersistableBundle,
* SharedMemory, Executor, AlwaysOnHotwordDetector.Callback)} instead.
* @hide
@@ -631,6 +644,11 @@ public class VoiceInteractionService extends Service {
* @param callback The callback to notify of detection events.
* @return An always-on hotword detector for the given keyphrase and locale.
*
+ * @throws SecurityException if the caller does not hold required permissions
+ * @throws IllegalStateException if the hotword detection service is not set, isolated process
+ * is not set, or there is no DSP hardware support when a caller has a target SDK of API level
+ * 34 or above.
+ *
* @hide
*/
@SystemApi