Reset HotwordDetectionConnection when VoiceInteractionService crashes

I use the command "adb shell kill <pid>" and "adb shell am crash
<package>" to test, it works well.

Bug: 193421614
Test: manual test
Test: atest CtsVoiceInteractionTestCases
Test: atest CtsVoiceInteractionTestCases --instant
Change-Id: I53206f07801b0fac588cb23fa2b91cac561547ed
This commit is contained in:
lpeter
2021-07-14 13:56:56 +08:00
parent 369f574bb0
commit 5a485126d8

View File

@@ -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: ");