From fabe3ca4ba8f18bb397a09d1f7f59acc8be7da0e Mon Sep 17 00:00:00 2001 From: Nicholas Ambur Date: Sun, 6 Mar 2022 23:05:50 -0800 Subject: [PATCH] catch stopRecognition exceptions in destroy() Ignore any exceptions coming out of the HotwordDetector#destroy() method when stopRecognition is called. The stopRecognition call here is a best effort call which should not be retried if it fails. Test: atest CtsVoiceInteractionTestCases Test: atest CtsVoiceInteractionHostTestCases Bug: 193232191 Change-Id: Ie4f8e68ca9078dca0e30fe73408947a2525c5b9a --- .../android/service/voice/AlwaysOnHotwordDetector.java | 6 +++++- .../android/service/voice/SoftwareHotwordDetector.java | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index 64b66b6a6d42e..f428b5d466c05 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -1215,7 +1215,11 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector { public void destroy() { synchronized (mLock) { if (mAvailability == STATE_KEYPHRASE_ENROLLED) { - stopRecognition(); + try { + stopRecognition(); + } catch (Exception e) { + Log.i(TAG, "failed to stopRecognition in destroy", e); + } } mAvailability = STATE_INVALID; diff --git a/core/java/android/service/voice/SoftwareHotwordDetector.java b/core/java/android/service/voice/SoftwareHotwordDetector.java index cae9598978e9c..d4c58d281a51e 100644 --- a/core/java/android/service/voice/SoftwareHotwordDetector.java +++ b/core/java/android/service/voice/SoftwareHotwordDetector.java @@ -30,6 +30,7 @@ import android.os.ParcelFileDescriptor; import android.os.PersistableBundle; import android.os.RemoteException; import android.os.SharedMemory; +import android.util.Log; import android.util.Slog; import com.android.internal.app.IHotwordRecognitionStatusCallback; @@ -117,7 +118,11 @@ class SoftwareHotwordDetector extends AbstractHotwordDetector { @Override public void destroy() { - stopRecognition(); + try { + stopRecognition(); + } catch (Exception e) { + Log.i(TAG, "failed to stopRecognition in destroy", e); + } maybeCloseExistingSession(); try {