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
This commit is contained in:
Atneya Nair
2023-04-26 21:42:45 -07:00
parent 1030b6c63f
commit 476349f744
2 changed files with 46 additions and 12 deletions

View File

@@ -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;
@@ -257,6 +259,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
@@ -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;

View File

@@ -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