Crash audioserver if EPIPE (DEAD_OBJECT) is received from the HAL
audioflinger doesn't have a proper way to re-establish all
the opened streams if HAL crashes. The only valid way of dealing
with them is to restart the audioserver.
Although broadcastradio and sountrigger have cleaner protocols
for dealing with HAL failures and can handle HAL crash and restart,
since the audio side will anyway get broken, it makes sense
to also kill the audioserver when they detect HAL crash.
Test: kill audio-hal process, watch dmesg and logcat
Change-Id: Ib2150b69c791ac49de9404de08fc6c309a3fcbd5
diff --git a/services/soundtrigger/SoundTriggerHalHidl.cpp b/services/soundtrigger/SoundTriggerHalHidl.cpp
index ecbdec4..c027799 100644
--- a/services/soundtrigger/SoundTriggerHalHidl.cpp
+++ b/services/soundtrigger/SoundTriggerHalHidl.cpp
@@ -59,9 +59,7 @@
}
} else {
ret = (int)hidlReturn.getStatus().transactionError();
- if (ret == -EPIPE) {
- clearService();
- }
+ crashIfHalIsDead(ret);
}
ALOGI("getProperties ret %d", ret);
return ret;
@@ -135,9 +133,7 @@
} else {
ret = (int)hidlReturn.getStatus().transactionError();
ALOGE("loadSoundModel error %d", ret);
- if (ret == -EPIPE) {
- clearService();
- }
+ crashIfHalIsDead(ret);
}
@@ -164,9 +160,7 @@
}
int ret = (int)hidlReturn.getStatus().transactionError();
ALOGE_IF(ret != 0, "unloadSoundModel error %d", ret);
- if (ret == -EPIPE) {
- clearService();
- }
+ crashIfHalIsDead(ret);
if (ret == 0) {
ret = hidlReturn;
}
@@ -205,9 +199,7 @@
int ret = (int)hidlReturn.getStatus().transactionError();
ALOGE_IF(ret != 0, "startRecognition error %d", ret);
- if (ret == -EPIPE) {
- clearService();
- }
+ crashIfHalIsDead(ret);
if (ret == 0) {
ret = hidlReturn;
}
@@ -235,9 +227,7 @@
int ret = (int)hidlReturn.getStatus().transactionError();
ALOGE_IF(ret != 0, "stopRecognition error %d", ret);
- if (ret == -EPIPE) {
- clearService();
- }
+ crashIfHalIsDead(ret);
if (ret == 0) {
ret = hidlReturn;
}
@@ -259,9 +249,7 @@
int ret = (int)hidlReturn.getStatus().transactionError();
ALOGE_IF(ret != 0, "stopAllRecognitions error %d", ret);
- if (ret == -EPIPE) {
- clearService();
- }
+ crashIfHalIsDead(ret);
if (ret == 0) {
ret = hidlReturn;
}
@@ -291,10 +279,9 @@
return mISoundTrigger;
}
-void SoundTriggerHalHidl::clearService()
+void SoundTriggerHalHidl::crashIfHalIsDead(int ret)
{
- AutoMutex lock(mLock);
- mISoundTrigger = 0;
+ LOG_ALWAYS_FATAL_IF(ret == -EPIPE, "HAL server crashed, need to restart");
}
sp<SoundTriggerHalHidl::SoundModel> SoundTriggerHalHidl::getModel(sound_model_handle_t handle)