From e10a748963871fb2cff4c36a3e12972dd60d748f Mon Sep 17 00:00:00 2001 From: Atneya Nair Date: Wed, 19 Apr 2023 10:12:05 -0700 Subject: [PATCH] Add test API for phone call state ST observes and reacts to phone calls by pausing recognition. Instrumenting a fake phone call through the telephony stack is hard, so add a test API which mocks this callback from the telephony service to enable CTS tests for the ST response. Bug: 272147641 Fixes: 278904783 Test: AlwaysOnHotwordDetectorTest# testOnPhoneCall_recognitionPausedAndResumed Change-Id: I409cbaca11294291d4b504e4fc2bf9971686f1ff --- core/api/test-current.txt | 1 + .../internal/app/ISoundTriggerService.aidl | 6 +++++ .../SoundTriggerInstrumentation.java | 22 +++++++++++++++++++ .../soundtrigger/SoundTriggerService.java | 6 +++++ 4 files changed, 35 insertions(+) diff --git a/core/api/test-current.txt b/core/api/test-current.txt index d97f718475925..934622305a054 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -2037,6 +2037,7 @@ package android.media.metrics { package android.media.soundtrigger { public final class SoundTriggerInstrumentation { + method public void setInPhoneCallState(boolean); method public void setResourceContention(boolean); method public void triggerOnResourcesAvailable(); method public void triggerRestart(); diff --git a/core/java/com/android/internal/app/ISoundTriggerService.aidl b/core/java/com/android/internal/app/ISoundTriggerService.aidl index ed751cb481c5e..512ff4816cc48 100644 --- a/core/java/com/android/internal/app/ISoundTriggerService.aidl +++ b/core/java/com/android/internal/app/ISoundTriggerService.aidl @@ -79,4 +79,10 @@ interface ISoundTriggerService { * Attach an HAL injection interface. */ void attachInjection(ISoundTriggerInjection injection); + + /** + * Test API to override the phone call state. + */ + void setInPhoneCallState(boolean isInPhoneCall); + } diff --git a/media/java/android/media/soundtrigger/SoundTriggerInstrumentation.java b/media/java/android/media/soundtrigger/SoundTriggerInstrumentation.java index 3dfc58788e8a5..c376f2566cbb5 100644 --- a/media/java/android/media/soundtrigger/SoundTriggerInstrumentation.java +++ b/media/java/android/media/soundtrigger/SoundTriggerInstrumentation.java @@ -66,6 +66,8 @@ public final class SoundTriggerInstrumentation { @GuardedBy("mLock") private IBinder mClientToken = null; + private final ISoundTriggerService mService; + private final GlobalCallback mClientCallback; private final Executor mGlobalCallbackExecutor; @@ -562,6 +564,7 @@ public final class SoundTriggerInstrumentation { @NonNull GlobalCallback callback) { mClientCallback = Objects.requireNonNull(callback); mGlobalCallbackExecutor = Objects.requireNonNull(executor); + mService = service; try { service.attachInjection(new Injection()); } catch (RemoteException e) { @@ -651,5 +654,24 @@ public final class SoundTriggerInstrumentation { } } } + + /** + * Simulate a phone call for {@link com.android.server.soundtrigger.SoundTriggerService}. + * If the phone call state changes, the service will be notified to respond. + * The service should pause recognition for the duration of the call. + * + * @param isInPhoneCall - {@code true} to cause the SoundTriggerService to + * see the phone call state as off-hook. {@code false} to cause the service to + * see the state as normal. + * @hide + */ + @TestApi + public void setInPhoneCallState(boolean isInPhoneCall) { + try { + mService.setInPhoneCallState(isInPhoneCall); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } } diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java index 3151781ff7ba9..67320009e9aa7 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java @@ -412,6 +412,12 @@ public class SoundTriggerService extends SystemService { } } + @Override + public void setInPhoneCallState(boolean isInPhoneCall) { + Slog.i(TAG, "Overriding phone call state: " + isInPhoneCall); + mDeviceStateHandler.onPhoneCallStateChanged(isInPhoneCall); + } + @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { // Event loggers