From aef17248499384e63fcaecec9fa8c10187b1f5cb Mon Sep 17 00:00:00 2001 From: Nicholas Ambur Date: Tue, 18 Apr 2023 01:03:49 +0000 Subject: [PATCH 1/2] unbind from HotwordDetectionService when all sessions are destroyed Test: atest AlwaysOnHotwordDetectorTest Bug: 277392480 Change-Id: I15855ad174bebd97409e6baa7c0256d2b0440d1a --- .../server/voiceinteraction/HotwordDetectionConnection.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index 486945d9159ed..edaaf3fbbcccd 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -913,8 +913,10 @@ final class HotwordDetectionConnection { } // Handle case where all hotword detector sessions are destroyed with only the visual // detector session left - if (mDetectorSessions.size() == 1 - && mDetectorSessions.get(0) instanceof VisualQueryDetectorSession) { + boolean allHotwordDetectionServiceSessionsRemoved = mDetectorSessions.size() == 0 + || (mDetectorSessions.size() == 1 && mDetectorSessions.get(0) + instanceof VisualQueryDetectorSession); + if (allHotwordDetectionServiceSessionsRemoved) { unbindHotwordDetectionService(); } } From ea8b1a551457c00a33b2af458c720f1ec249ec68 Mon Sep 17 00:00:00 2001 From: Nicholas Ambur Date: Mon, 10 Apr 2023 23:35:20 +0000 Subject: [PATCH 2/2] AOHD do not unbind HotwordDetectionService on destroy AlwaysOnHotwordDetector should not be required to tear down the HotwordDetectionService. The VoiceInteractionManagerService will handle the unbinding and shutdown of the service on its own. Bug: 277392480 Test: atest AlwaysOnHotwordDetectorTest Change-Id: Iec0af794595f0e8d143d7bab118c4b1f02569c31 --- .../service/voice/VoiceInteractionService.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index 79a4f54bac0ad..6e85de2062a7f 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -1070,21 +1070,6 @@ public class VoiceInteractionService extends Service { mActiveVisualQueryDetector = null; } mActiveDetectors.remove(detector); - shutdownHotwordDetectionServiceIfRequiredLocked(); - } - } - - private void shutdownHotwordDetectionServiceIfRequiredLocked() { - for (HotwordDetector detector : mActiveDetectors) { - if (detector.isUsingSandboxedDetectionService()) { - return; - } - } - - try { - mSystemService.shutdownHotwordDetectionService(); - } catch (RemoteException e) { - e.rethrowFromSystemServer(); } }