From 3c3465dd3b4f337e26b3584e1977c743134b3c89 Mon Sep 17 00:00:00 2001 From: lpeter Date: Thu, 5 Aug 2021 12:32:43 +0800 Subject: [PATCH] Shutdown hotword detection service when software hotword detector is shutdown Currently we have AlwaysOnHotwordDetector and SoftwareHotwordDetector, when the app creates the detector, it will create a HotwordDetectionConnection to communicate with HotwordDetectionService. Problem: AlwaysOnHotwordDetector will work incorrectly if the app creates SoftwareHotwordDetector first, then creates AlwaysOnHotwordDetector later. A simple flow is that the app created a SoftwareHotwordDetector and used it. After a while, the app may want to use AlwaysOnHotwordDetector, so it will create a new AlwaysOnHotwordDetector. By the original flow, it only allows to keep one detector, so the system will shutdown the old detector(SoftwareHotwordDetector) and create the new detector(AlwaysOnHotwordDetector). Because we don't clear the connection when shutdowning SoftwareHotwordDetector (PS: We clear the connection when shutdowning AlwaysOnHotwordDetector), it will use the previous connection when creating the AlwaysOnHotwordDetector. Root cause: Because we don't shutdown hotword detection service when software hotword detector is shutdown, the new creating AlwaysOnHotwordDetector will use the previous HotwordDetectionConnection to communicate with HotwordDetectionService. Due to the callback in HotwordDetectionConnection is for SoftwareHotwordDetector, it can not pass the right data to AlwaysOnHotwordDetector. Solution: Shutdown hotword detection service when software hotword detector is shutdown. Bug: 195604579 Test: atest CtsVoiceInteractionTestCases Test: atest CtsVoiceInteractionTestCases --instant Test: manual - DSP and non-DSP Change-Id: I999dc4cc9d5ce858127a9b44db261d7abee98929 --- .../java/android/service/voice/VoiceInteractionService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index 6a0fec7902422..f52c9ff210d65 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -520,6 +520,12 @@ public class VoiceInteractionService extends Service { // Ignore. } + try { + mSystemService.shutdownHotwordDetectionService(); + } catch (Exception ex) { + // Ignore. + } + mSoftwareHotwordDetector = null; }