Merge "Avoid deadlock on soundtrigger HAL death" into rvc-dev am: 5c5a830c9a

Change-Id: Ie9f2771cd8e942c6751b2fb73e5a06033fa924e4
This commit is contained in:
Ytai Ben-tsvi
2020-05-05 17:40:08 +00:00
committed by Automerger Merge Worker
2 changed files with 33 additions and 20 deletions

View File

@@ -783,15 +783,17 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
@Override
public void onModuleDied() {
synchronized (SoundTriggerMiddlewareValidation.this) {
try {
mState = ModuleStatus.DEAD;
mCallback.onModuleDied();
} catch (RemoteException e) {
// Dead client will be handled by binderDied() - no need to handle here.
// In any case, client callbacks are considered best effort.
Log.e(TAG, "Client callback exception.", e);
}
mState = ModuleStatus.DEAD;
}
// Trigger the callback outside of the lock to avoid deadlocks.
try {
mCallback.onModuleDied();
} catch (RemoteException e) {
// Dead client will be handled by binderDied() - no need to handle here.
// In any case, client callbacks are considered best effort.
Log.e(TAG, "Client callback exception.", e);
}
}
@Override

View File

@@ -35,8 +35,10 @@ import android.os.RemoteException;
import android.os.ServiceSpecificException;
import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -166,12 +168,23 @@ class SoundTriggerModule implements IHwBinder.DeathRecipient {
}
@Override
public synchronized void serviceDied(long cookie) {
public void serviceDied(long cookie) {
Log.w(TAG, String.format("Underlying HAL driver died."));
for (Session session : mActiveSessions) {
session.moduleDied();
List<ISoundTriggerCallback> callbacks = new ArrayList<>(mActiveSessions.size());
synchronized (this) {
for (Session session : mActiveSessions) {
callbacks.add(session.moduleDied());
}
reset();
}
// Trigger the callbacks outside of the lock to avoid deadlocks.
for (ISoundTriggerCallback callback : callbacks) {
try {
callback.onModuleDied();
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
reset();
}
/**
@@ -379,15 +392,13 @@ class SoundTriggerModule implements IHwBinder.DeathRecipient {
/**
* The underlying module HAL is dead.
* @return The client callback that needs to be invoked to notify the client.
*/
private void moduleDied() {
try {
mCallback.onModuleDied();
removeSession(this);
mCallback = null;
} catch (RemoteException e) {
e.rethrowAsRuntimeException();
}
private ISoundTriggerCallback moduleDied() {
ISoundTriggerCallback callback = mCallback;
removeSession(this);
mCallback = null;
return callback;
}
private void checkValid() {