From 5a485126d8a9561abd3cf724cdf6076b4b5b29cc Mon Sep 17 00:00:00 2001 From: lpeter Date: Wed, 14 Jul 2021 13:56:56 +0800 Subject: [PATCH] Reset HotwordDetectionConnection when VoiceInteractionService crashes I use the command "adb shell kill " and "adb shell am crash " to test, it works well. Bug: 193421614 Test: manual test Test: atest CtsVoiceInteractionTestCases Test: atest CtsVoiceInteractionTestCases --instant Change-Id: I53206f07801b0fac588cb23fa2b91cac561547ed --- .../VoiceInteractionManagerServiceImpl.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java index 6be47e171ed7b..cbcbf52c2c9c5 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java @@ -126,6 +126,9 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne final ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { + if (DEBUG) { + Slog.d(TAG, "onServiceConnected to " + name + " for user(" + mUser + ")"); + } synchronized (mServiceStub) { mService = IVoiceInteractionService.Stub.asInterface(service); try { @@ -137,7 +140,13 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne @Override public void onServiceDisconnected(ComponentName name) { - mService = null; + if (DEBUG) { + Slog.d(TAG, "onServiceDisconnected to " + name); + } + synchronized (mServiceStub) { + mService = null; + resetHotwordDetectionConnectionLocked(); + } } }; @@ -575,6 +584,20 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne mHotwordDetectionConnection.forceRestart(); } + void resetHotwordDetectionConnectionLocked() { + if (DEBUG) { + Slog.d(TAG, "resetHotwordDetectionConnectionLocked"); + } + if (mHotwordDetectionConnection == null) { + if (DEBUG) { + Slog.w(TAG, "reset, but no hotword detection connection"); + } + return; + } + mHotwordDetectionConnection.cancelLocked(); + mHotwordDetectionConnection = null; + } + public void dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args) { if (!mValid) { pw.print(" NOT VALID: ");