From 74b69a25161e7b6e02c5083a3a5c3c19f20526b6 Mon Sep 17 00:00:00 2001 From: lpeter Date: Tue, 7 Sep 2021 10:38:20 +0800 Subject: [PATCH] Remove the isBound() check for HotwordDetectionService. There will be a race condition (Ex:Create AlwaysOnHotwordDetector twice quickly) where it will miss unbinding HotwordDetectionService and clearing HotwordDetectionServiceProvider when using the isBound() check for HotwordDetectionService. Because we use "ServiceConnector.Impl" to create the connection, it is unnecessary to use isBound() function to check if the HotwordDetectionService should be unbound. Bug: 195457729 Test: atest CtsVoiceInteractionTestCases Test: atest CtsVoiceInteractionTestCases --instant Test: manual - DSP and non-DSP Change-Id: Ib74e0dc9364af3713007b115f7d170bf6e833810 --- .../voiceinteraction/HotwordDetectionConnection.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java index a9aeb985d115d..4dc83ae98d895 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/HotwordDetectionConnection.java @@ -269,13 +269,11 @@ final class HotwordDetectionConnection { Slog.v(TAG, "cancelLocked"); clearDebugHotwordLoggingTimeoutLocked(); mDebugHotwordLogging = false; - if (mRemoteHotwordDetectionService.isBound()) { - mRemoteHotwordDetectionService.unbind(); - LocalServices.getService(PermissionManagerServiceInternal.class) - .setHotwordDetectionServiceProvider(null); - mIdentity = null; - updateServiceUidForAudioPolicy(Process.INVALID_UID); - } + mRemoteHotwordDetectionService.unbind(); + LocalServices.getService(PermissionManagerServiceInternal.class) + .setHotwordDetectionServiceProvider(null); + mIdentity = null; + updateServiceUidForAudioPolicy(Process.INVALID_UID); mCancellationTaskFuture.cancel(/* may interrupt */ true); if (mAudioFlinger != null) { mAudioFlinger.unlinkToDeath(mAudioServerDeathRecipient, /* flags= */ 0);