Remove STHAL 2.4

This version was only created as an intermediate version for
development and was never intended for release. STHAL 3 (AIDL) has
feature-parity with this one and is intended for release.

Bug: 181996624
Test: Manual verification of soundtrigger use-cases.
Test: atest FrameworksServicesTests:SoundTriggerMiddlewareImplTest FrameworksServicesTests:SoundHw2CompatTest
Change-Id: Ie7babd2aa37b1cb2830656808cce540a0e143a09
This commit is contained in:
Ytai Ben-Tsvi
2021-08-24 16:04:29 -07:00
parent 46adda46ee
commit 6f1c5a78a1
4 changed files with 39 additions and 369 deletions

View File

@@ -154,7 +154,7 @@ java_library_static {
"android.hardware.configstore-V1.0-java",
"android.hardware.contexthub-V1.0-java",
"android.hardware.rebootescrow-V1-java",
"android.hardware.soundtrigger-V2.4-java",
"android.hardware.soundtrigger-V2.3-java",
"android.hardware.power.stats-V1-java",
"android.hidl.manager-V1.2-java",
"capture_state_listener-aidl-java",

View File

@@ -60,7 +60,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
private @Nullable android.hardware.soundtrigger.V2_1.ISoundTriggerHw mUnderlying_2_1;
private @Nullable android.hardware.soundtrigger.V2_2.ISoundTriggerHw mUnderlying_2_2;
private @Nullable android.hardware.soundtrigger.V2_3.ISoundTriggerHw mUnderlying_2_3;
private @Nullable android.hardware.soundtrigger.V2_4.ISoundTriggerHw mUnderlying_2_4;
// HAL <=2.1 requires us to pass a callback argument to startRecognition. We will store the one
// passed on load and then pass it on start. We don't bother storing the callback on newer
@@ -89,13 +88,10 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
ICaptureStateNotifier notifier) {
SoundTriggerHw2Compat compat = new SoundTriggerHw2Compat(binder, rebootRunnable);
ISoundTriggerHal result = compat;
// Add max model limiter for versions <2.4.
if (compat.mUnderlying_2_4 == null) {
result = new SoundTriggerHalMaxModelLimiter(result,
compat.mProperties.maxSoundModels);
}
// Add concurrent capture handler for versions <2.4 which do not support concurrent capture.
if (compat.mUnderlying_2_4 == null && !compat.mProperties.concurrentCapture) {
// Add max model limiter for versions.
result = new SoundTriggerHalMaxModelLimiter(result, compat.mProperties.maxSoundModels);
// Add concurrent capture handler for HALs which do not support concurrent capture.
if (!compat.mProperties.concurrentCapture) {
result = new SoundTriggerHalConcurrentCaptureHandler(result, notifier);
}
return result;
@@ -113,21 +109,11 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
// version, so we go down the versions in descending order to find the latest one supported,
// and then simply up-cast it to obtain all the versions that are earlier.
// Attempt 2.4
android.hardware.soundtrigger.V2_4.ISoundTriggerHw as2_4 =
android.hardware.soundtrigger.V2_4.ISoundTriggerHw.asInterface(binder);
if (as2_4 != null) {
mUnderlying_2_0 =
mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = mUnderlying_2_4 = as2_4;
return;
}
// Attempt 2.3
android.hardware.soundtrigger.V2_3.ISoundTriggerHw as2_3 =
android.hardware.soundtrigger.V2_3.ISoundTriggerHw.asInterface(binder);
if (as2_3 != null) {
mUnderlying_2_0 = mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = as2_3;
mUnderlying_2_4 = null;
return;
}
@@ -136,7 +122,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
android.hardware.soundtrigger.V2_2.ISoundTriggerHw.asInterface(binder);
if (as2_2 != null) {
mUnderlying_2_0 = mUnderlying_2_1 = mUnderlying_2_2 = as2_2;
mUnderlying_2_3 = mUnderlying_2_4 = null;
mUnderlying_2_3 = null;
return;
}
@@ -145,7 +131,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
android.hardware.soundtrigger.V2_1.ISoundTriggerHw.asInterface(binder);
if (as2_1 != null) {
mUnderlying_2_0 = mUnderlying_2_1 = as2_1;
mUnderlying_2_2 = mUnderlying_2_3 = mUnderlying_2_4 = null;
mUnderlying_2_2 = mUnderlying_2_3 = null;
return;
}
@@ -154,7 +140,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
android.hardware.soundtrigger.V2_0.ISoundTriggerHw.asInterface(binder);
if (as2_0 != null) {
mUnderlying_2_0 = as2_0;
mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = mUnderlying_2_4 = null;
mUnderlying_2_1 = mUnderlying_2_2 = mUnderlying_2_3 = null;
return;
}
@@ -213,16 +199,8 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
@Override
public void registerCallback(GlobalCallback callback) {
try {
try {
as2_4().registerGlobalCallback(new GlobalCallbackWrapper(callback));
} catch (NotSupported e) {
// In versions < 2.4 the events represented by this callback don't exist, we can
// safely ignore this.
}
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
// In versions 2.x the events represented by this callback don't exist, we can
// safely ignore this.
}
@Override
@@ -232,29 +210,18 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
try {
AtomicInteger retval = new AtomicInteger(-1);
AtomicInteger handle = new AtomicInteger(0);
try {
as2_4().loadSoundModel_2_4(hidlModel, new ModelCallbackWrapper(callback),
as2_1().loadSoundModel_2_1(hidlModel, new ModelCallbackWrapper(callback),
0,
(r, h) -> {
retval.set(r);
handle.set(h);
});
handleHalStatusAllowBusy(retval.get(), "loadSoundModel_2_4");
} catch (NotSupported e) {
// Fall-back to the 2.1 version:
try {
as2_1().loadSoundModel_2_1(hidlModel, new ModelCallbackWrapper(callback),
0,
(r, h) -> {
retval.set(r);
handle.set(h);
});
handleHalStatus(retval.get(), "loadSoundModel_2_1");
mModelCallbacks.put(handle.get(), callback);
} catch (NotSupported ee) {
// Fall-back to the 2.0 version:
return loadSoundModel_2_0(hidlModel, callback);
}
handleHalStatus(retval.get(), "loadSoundModel_2_1");
mModelCallbacks.put(handle.get(), callback);
} catch (NotSupported ee) {
// Fall-back to the 2.0 version:
return loadSoundModel_2_0(hidlModel, callback);
}
return handle.get();
} catch (RemoteException e) {
@@ -270,27 +237,17 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
AtomicInteger retval = new AtomicInteger(-1);
AtomicInteger handle = new AtomicInteger(0);
try {
as2_4().loadPhraseSoundModel_2_4(hidlModel, new ModelCallbackWrapper(callback),
as2_1().loadPhraseSoundModel_2_1(hidlModel, new ModelCallbackWrapper(callback),
0,
(r, h) -> {
retval.set(r);
handle.set(h);
});
handleHalStatusAllowBusy(retval.get(), "loadPhraseSoundModel_2_4");
} catch (NotSupported e) {
// Fall-back to the 2.1 version:
try {
as2_1().loadPhraseSoundModel_2_1(hidlModel, new ModelCallbackWrapper(callback),
0,
(r, h) -> {
retval.set(r);
handle.set(h);
});
handleHalStatus(retval.get(), "loadPhraseSoundModel_2_1");
mModelCallbacks.put(handle.get(), callback);
} catch (NotSupported ee) {
// Fall-back to the 2.0 version:
return loadPhraseSoundModel_2_0(hidlModel, callback);
}
handleHalStatus(retval.get(), "loadPhraseSoundModel_2_1");
mModelCallbacks.put(handle.get(), callback);
} catch (NotSupported ee) {
// Fall-back to the 2.0 version:
return loadPhraseSoundModel_2_0(hidlModel, callback);
}
return handle.get();
} catch (RemoteException e) {
@@ -328,17 +285,11 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
ConversionUtil.aidl2hidlRecognitionConfig(config, deviceHandle, ioHandle);
try {
try {
int retval = as2_4().startRecognition_2_4(modelHandle, hidlConfig);
handleHalStatusAllowBusy(retval, "startRecognition_2_4");
} catch (NotSupported e) {
// Fall-back to the 2.3 version:
try {
int retval = as2_3().startRecognition_2_3(modelHandle, hidlConfig);
handleHalStatus(retval, "startRecognition_2_3");
} catch (NotSupported ee) {
// Fall-back to the 2.0 version:
startRecognition_2_1(modelHandle, hidlConfig);
}
int retval = as2_3().startRecognition_2_3(modelHandle, hidlConfig);
handleHalStatus(retval, "startRecognition_2_3");
} catch (NotSupported ee) {
// Fall-back to the 2.0 version:
startRecognition_2_1(modelHandle, hidlConfig);
}
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
@@ -551,14 +502,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
return mUnderlying_2_3;
}
private @NonNull
android.hardware.soundtrigger.V2_4.ISoundTriggerHw as2_4() throws NotSupported {
if (mUnderlying_2_4 == null) {
throw new NotSupported("Underlying driver version < 2.4");
}
return mUnderlying_2_4;
}
/**
* A checked exception representing the requested interface version not being supported.
* At the public interface layer, use {@link #throwAsRecoverableException()} to propagate it to
@@ -580,22 +523,8 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
}
}
private static class GlobalCallbackWrapper extends
android.hardware.soundtrigger.V2_4.ISoundTriggerHwGlobalCallback.Stub {
private final @NonNull GlobalCallback mDelegate;
private GlobalCallbackWrapper(@NonNull GlobalCallback delegate) {
mDelegate = delegate;
}
@Override
public void onResourcesAvailable() {
mDelegate.onResourcesAvailable();
}
}
private static class ModelCallbackWrapper extends
android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback.Stub {
android.hardware.soundtrigger.V2_1.ISoundTriggerHwCallback.Stub {
private final @NonNull ModelCallback mDelegate;
private ModelCallbackWrapper(
@@ -603,11 +532,6 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
mDelegate = Objects.requireNonNull(delegate);
}
@Override
public void modelUnloaded(int modelHandle) {
mDelegate.modelUnloaded(modelHandle);
}
@Override
public void recognitionCallback_2_1(
android.hardware.soundtrigger.V2_1.ISoundTriggerHwCallback.RecognitionEvent event,

View File

@@ -76,7 +76,7 @@ public class SoundHw2CompatTest {
public static Iterable<Object[]> data() {
List<Object[]> result = new LinkedList<>();
for (String version : new String[]{"V2_0", "V2_1", "V2_2", "V2_3", "V2_4",}) {
for (String version : new String[]{"V2_0", "V2_1", "V2_2", "V2_3",}) {
for (boolean concurrentCapture : new boolean[]{false, true}) {
result.add(new Object[]{version, concurrentCapture});
}
@@ -113,9 +113,7 @@ public class SoundHw2CompatTest {
|| descriptor.equals("android.hardware.soundtrigger@2.2::ISoundTriggerHw")
&& mHalDriver instanceof android.hardware.soundtrigger.V2_2.ISoundTriggerHw
|| descriptor.equals("android.hardware.soundtrigger@2.3::ISoundTriggerHw")
&& mHalDriver instanceof android.hardware.soundtrigger.V2_3.ISoundTriggerHw
|| descriptor.equals("android.hardware.soundtrigger@2.4::ISoundTriggerHw")
&& mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
&& mHalDriver instanceof android.hardware.soundtrigger.V2_3.ISoundTriggerHw) {
return mHalDriver;
}
return null;
@@ -269,44 +267,9 @@ public class SoundHw2CompatTest {
return handle;
}
private int loadGenericModel_2_4(ISoundTriggerHal.ModelCallback canonicalCallback)
throws Exception {
final android.hardware.soundtrigger.V2_4.ISoundTriggerHw driver_2_4 =
(android.hardware.soundtrigger.V2_4.ISoundTriggerHw) mHalDriver;
final int handle = 29;
ArgumentCaptor<android.hardware.soundtrigger.V2_1.ISoundTriggerHw.SoundModel> modelCaptor =
ArgumentCaptor.forClass(
android.hardware.soundtrigger.V2_1.ISoundTriggerHw.SoundModel.class);
ArgumentCaptor<android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback> callbackCaptor =
ArgumentCaptor.forClass(
android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback.class);
doAnswer(invocation -> {
android.hardware.soundtrigger.V2_4.ISoundTriggerHw.loadSoundModel_2_4Callback
resultCallback = invocation.getArgument(2);
// This is the return of this method.
resultCallback.onValues(0, handle);
return null;
}).when(driver_2_4).loadSoundModel_2_4(any(), any(), any());
assertEquals(handle,
mCanonical.loadSoundModel(TestUtil.createGenericSoundModel(), canonicalCallback));
verify(driver_2_4).loadSoundModel_2_4(modelCaptor.capture(), callbackCaptor.capture(),
any());
TestUtil.validateGenericSoundModel_2_1(modelCaptor.getValue());
validateCallback_2_4(callbackCaptor.getValue(), canonicalCallback);
return handle;
}
private int loadGenericModel(ISoundTriggerHal.ModelCallback canonicalCallback)
throws Exception {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
return loadGenericModel_2_4(canonicalCallback);
} else if (mHalDriver instanceof android.hardware.soundtrigger.V2_1.ISoundTriggerHw) {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_1.ISoundTriggerHw) {
return loadGenericModel_2_1(canonicalCallback);
} else {
return loadGenericModel_2_0(canonicalCallback);
@@ -322,8 +285,6 @@ public class SoundHw2CompatTest {
@Test
public void testMaxModels() throws Exception {
assumeFalse(mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw);
// Register global callback.
ISoundTriggerHal.GlobalCallback globalCallback = mock(
ISoundTriggerHal.GlobalCallback.class);
@@ -358,37 +319,6 @@ public class SoundHw2CompatTest {
verify(globalCallback).onResourcesAvailable();
}
private void testLoadGenericModelBusy_2_4() throws Exception {
final android.hardware.soundtrigger.V2_4.ISoundTriggerHw driver_2_4 =
(android.hardware.soundtrigger.V2_4.ISoundTriggerHw) mHalDriver;
doAnswer(invocation -> {
android.hardware.soundtrigger.V2_4.ISoundTriggerHw.loadSoundModel_2_4Callback
resultCallback = invocation.getArgument(2);
// This is the return of this method.
resultCallback.onValues(-OsConstants.EBUSY, 0);
return null;
}).when(driver_2_4).loadSoundModel_2_4(any(), any(), any());
ISoundTriggerHal.ModelCallback canonicalCallback = mock(
ISoundTriggerHal.ModelCallback.class);
try {
mCanonical.loadSoundModel(TestUtil.createGenericSoundModel(), canonicalCallback);
fail("Expected an exception");
} catch (RecoverableException e) {
assertEquals(Status.RESOURCE_CONTENTION, e.errorCode);
}
verify(driver_2_4).loadSoundModel_2_4(any(), any(), any());
}
@Test
public void testLoadGenericModelBusy() throws Exception {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
testLoadGenericModelBusy_2_4();
}
}
private int loadPhraseModel_2_0(ISoundTriggerHal.ModelCallback canonicalCallback)
throws Exception {
final int handle = 29;
@@ -452,43 +382,8 @@ public class SoundHw2CompatTest {
return handle;
}
private int loadPhraseModel_2_4(ISoundTriggerHal.ModelCallback canonicalCallback)
throws Exception {
final android.hardware.soundtrigger.V2_4.ISoundTriggerHw driver_2_4 =
(android.hardware.soundtrigger.V2_4.ISoundTriggerHw) mHalDriver;
final int handle = 29;
ArgumentCaptor<android.hardware.soundtrigger.V2_1.ISoundTriggerHw.PhraseSoundModel>
modelCaptor = ArgumentCaptor.forClass(
android.hardware.soundtrigger.V2_1.ISoundTriggerHw.PhraseSoundModel.class);
ArgumentCaptor<android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback> callbackCaptor =
ArgumentCaptor.forClass(
android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback.class);
doAnswer(invocation -> {
android.hardware.soundtrigger.V2_4.ISoundTriggerHw.loadPhraseSoundModel_2_4Callback
resultCallback = invocation.getArgument(2);
// This is the return of this method.
resultCallback.onValues(0, handle);
return null;
}).when(driver_2_4).loadPhraseSoundModel_2_4(any(), any(), any());
assertEquals(handle, mCanonical.loadPhraseSoundModel(TestUtil.createPhraseSoundModel(),
canonicalCallback));
verify(driver_2_4).loadPhraseSoundModel_2_4(modelCaptor.capture(), callbackCaptor.capture(),
any());
TestUtil.validatePhraseSoundModel_2_1(modelCaptor.getValue());
validateCallback_2_4(callbackCaptor.getValue(), canonicalCallback);
return handle;
}
public int loadPhraseModel(ISoundTriggerHal.ModelCallback canonicalCallback) throws Exception {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
return loadPhraseModel_2_4(canonicalCallback);
} else if (mHalDriver instanceof android.hardware.soundtrigger.V2_1.ISoundTriggerHw) {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_1.ISoundTriggerHw) {
return loadPhraseModel_2_1(canonicalCallback);
} else {
return loadPhraseModel_2_0(canonicalCallback);
@@ -502,37 +397,6 @@ public class SoundHw2CompatTest {
loadPhraseModel(canonicalCallback);
}
private void testLoadPhraseModelBusy_2_4() throws Exception {
final android.hardware.soundtrigger.V2_4.ISoundTriggerHw driver_2_4 =
(android.hardware.soundtrigger.V2_4.ISoundTriggerHw) mHalDriver;
doAnswer(invocation -> {
android.hardware.soundtrigger.V2_4.ISoundTriggerHw.loadPhraseSoundModel_2_4Callback
resultCallback = invocation.getArgument(2);
// This is the return of this method.
resultCallback.onValues(-OsConstants.EBUSY, 0);
return null;
}).when(driver_2_4).loadPhraseSoundModel_2_4(any(), any(), any());
ISoundTriggerHal.ModelCallback canonicalCallback = mock(
ISoundTriggerHal.ModelCallback.class);
try {
mCanonical.loadPhraseSoundModel(TestUtil.createPhraseSoundModel(), canonicalCallback);
fail("Expected an exception");
} catch (RecoverableException e) {
assertEquals(Status.RESOURCE_CONTENTION, e.errorCode);
}
verify(driver_2_4).loadPhraseSoundModel_2_4(any(), any(), any());
}
@Test
public void testLoadPhraseModelBusy() throws Exception {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
testLoadPhraseModelBusy_2_4();
}
}
@Test
public void testUnloadModel() throws Exception {
mCanonical.unloadSoundModel(14);
@@ -596,25 +460,9 @@ public class SoundHw2CompatTest {
TestUtil.validateRecognitionConfig_2_3(configCaptor.getValue(), 808, 909);
}
private void startRecognition_2_4(int handle) throws Exception {
final android.hardware.soundtrigger.V2_4.ISoundTriggerHw driver_2_4 =
(android.hardware.soundtrigger.V2_4.ISoundTriggerHw) mHalDriver;
ArgumentCaptor<android.hardware.soundtrigger.V2_3.RecognitionConfig> configCaptor =
ArgumentCaptor.forClass(android.hardware.soundtrigger.V2_3.RecognitionConfig.class);
when(driver_2_4.startRecognition_2_4(eq(handle), any())).thenReturn(0);
RecognitionConfig config = TestUtil.createRecognitionConfig();
mCanonical.startRecognition(handle, 21, 22, config);
verify(driver_2_4).startRecognition_2_4(eq(handle), configCaptor.capture());
TestUtil.validateRecognitionConfig_2_3(configCaptor.getValue(), 21, 22);
}
private void startRecognition(int handle, ISoundTriggerHal.ModelCallback canonicalCallback)
throws Exception {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
startRecognition_2_4(handle);
} else if (mHalDriver instanceof android.hardware.soundtrigger.V2_3.ISoundTriggerHw) {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_3.ISoundTriggerHw) {
startRecognition_2_3(handle);
} else if (mHalDriver instanceof android.hardware.soundtrigger.V2_1.ISoundTriggerHw) {
startRecognition_2_1(handle, canonicalCallback);
@@ -634,41 +482,9 @@ public class SoundHw2CompatTest {
startRecognition(handle, canonicalCallback);
}
private void testStartRecognitionBusy_2_4() throws Exception {
final android.hardware.soundtrigger.V2_4.ISoundTriggerHw driver_2_4 =
(android.hardware.soundtrigger.V2_4.ISoundTriggerHw) mHalDriver;
final int handle = 68;
when(driver_2_4.startRecognition_2_4(eq(handle), any())).thenReturn(-OsConstants.EBUSY);
RecognitionConfig config = TestUtil.createRecognitionConfig();
try {
mCanonical.startRecognition(handle, 34, 35, config);
fail("Expected an exception");
} catch (RecoverableException e) {
assertEquals(Status.RESOURCE_CONTENTION, e.errorCode);
}
verify(driver_2_4).startRecognition_2_4(eq(handle), any());
}
@Test
public void testStartRecognitionBusy() throws Exception {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
testStartRecognitionBusy_2_4();
}
}
@Test
public void testNoRegisterCaptureStateListener() {
assumeTrue(mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw
|| mSupportConcurrentCapture);
verify(mCaptureStateNotifier, never()).registerListener(any());
}
@Test
public void testConcurrentCaptureAbort() throws Exception {
assumeFalse(mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw
|| mSupportConcurrentCapture);
assumeFalse(mSupportConcurrentCapture);
verify(mCaptureStateNotifier, atLeast(1)).registerListener(any());
// Register global callback.
@@ -707,8 +523,7 @@ public class SoundHw2CompatTest {
@Test
public void testConcurrentCaptureReject() throws Exception {
assumeFalse(mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw
|| mSupportConcurrentCapture);
assumeFalse(mSupportConcurrentCapture);
verify(mCaptureStateNotifier, atLeast(1)).registerListener(any());
// Register global callback.
@@ -858,28 +673,9 @@ public class SoundHw2CompatTest {
// We just care that it doesn't throw.
}
private void testGlobalCallback_2_4() throws Exception {
android.hardware.soundtrigger.V2_4.ISoundTriggerHw driver_2_4 =
(android.hardware.soundtrigger.V2_4.ISoundTriggerHw) mHalDriver;
ISoundTriggerHal.GlobalCallback canonicalCallback = mock(
ISoundTriggerHal.GlobalCallback.class);
mCanonical.registerCallback(canonicalCallback);
ArgumentCaptor<android.hardware.soundtrigger.V2_4.ISoundTriggerHwGlobalCallback>
callbackCaptor = ArgumentCaptor.forClass(
android.hardware.soundtrigger.V2_4.ISoundTriggerHwGlobalCallback.class);
verify(driver_2_4).registerGlobalCallback(callbackCaptor.capture());
validateGlobalCallback_2_4(callbackCaptor.getValue(), canonicalCallback);
}
@Test
public void testGlobalCallback() throws Exception {
if (mHalDriver instanceof android.hardware.soundtrigger.V2_4.ISoundTriggerHw) {
testGlobalCallback_2_4();
} else {
testGlobalCallback_2_0();
}
testGlobalCallback_2_0();
}
@Test
@@ -908,14 +704,6 @@ public class SoundHw2CompatTest {
verify(mHalDriver).interfaceDescriptor();
}
private void validateGlobalCallback_2_4(
android.hardware.soundtrigger.V2_4.ISoundTriggerHwGlobalCallback hwCallback,
ISoundTriggerHal.GlobalCallback canonicalCallback) throws Exception {
hwCallback.onResourcesAvailable();
mCanonical.flushCallbacks();
verify(canonicalCallback).onResourcesAvailable();
}
private void validateCallback_2_0(
android.hardware.soundtrigger.V2_0.ISoundTriggerHwCallback hwCallback,
ISoundTriggerHal.ModelCallback canonicalCallback) throws Exception {
@@ -985,48 +773,6 @@ public class SoundHw2CompatTest {
clearInvocations(canonicalCallback);
}
private void validateCallback_2_4(
android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback hwCallback,
ISoundTriggerHal.ModelCallback canonicalCallback) throws Exception {
{
final int handle = 85;
final int status =
android.hardware.soundtrigger.V2_0.ISoundTriggerHwCallback.RecognitionStatus.ABORT;
ArgumentCaptor<RecognitionEvent> eventCaptor = ArgumentCaptor.forClass(
RecognitionEvent.class);
hwCallback.recognitionCallback_2_1(TestUtil.createRecognitionEvent_2_1(handle, status),
99);
mCanonical.flushCallbacks();
verify(canonicalCallback).recognitionCallback(eq(handle), eventCaptor.capture());
TestUtil.validateRecognitionEvent(eventCaptor.getValue(), RecognitionStatus.ABORTED);
}
{
final int handle = 92;
final int status =
android.hardware.soundtrigger.V2_0.ISoundTriggerHwCallback.RecognitionStatus.SUCCESS;
ArgumentCaptor<PhraseRecognitionEvent> eventCaptor = ArgumentCaptor.forClass(
PhraseRecognitionEvent.class);
hwCallback.phraseRecognitionCallback_2_1(
TestUtil.createPhraseRecognitionEvent_2_1(handle, status), 99);
mCanonical.flushCallbacks();
verify(canonicalCallback).phraseRecognitionCallback(eq(handle), eventCaptor.capture());
TestUtil.validatePhraseRecognitionEvent(eventCaptor.getValue(),
RecognitionStatus.SUCCESS);
}
{
final int handle = 23;
hwCallback.modelUnloaded(handle);
mCanonical.flushCallbacks();
verify(canonicalCallback).modelUnloaded(handle);
}
verifyNoMoreInteractions(canonicalCallback);
clearInvocations(canonicalCallback);
}
public static class CaptureStateNotifier implements ICaptureStateNotifier {
private final List<Listener> mListeners = new LinkedList<>();

View File

@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
import android.annotation.NonNull;
import android.hardware.soundtrigger.V2_1.ISoundTriggerHw;
import android.hardware.soundtrigger.V2_4.ISoundTriggerHwCallback;
import android.hardware.soundtrigger.V2_1.ISoundTriggerHwCallback;
import android.media.AudioFormat;
import android.media.MediaFormat;
import android.media.audio.common.AudioChannelLayout;