audiohal: Restart audioserver if HAL services can't be obtained

HAL services are crucial for the audioflinger to work.
If for some reason device or effect factories can't be obtained,
log a error message and crash af. If the problem with obtaining
services is transient, restarting af helps to restore audio.

Bug: 36153684
Change-Id: Iec17a6c6e19650cf1d1de1ec30caf05753b9bce1
Test: reproed the bug, checked that af restarts and finds devices
(cherry picked from commit 425a50282ebdcc68a4fc01a268be87426889152e)
diff --git a/media/libaudiohal/DevicesFactoryHalHidl.cpp b/media/libaudiohal/DevicesFactoryHalHidl.cpp
index 6d73e2d..758a5805 100644
--- a/media/libaudiohal/DevicesFactoryHalHidl.cpp
+++ b/media/libaudiohal/DevicesFactoryHalHidl.cpp
@@ -41,9 +41,11 @@
 DevicesFactoryHalHidl::DevicesFactoryHalHidl() {
     mDevicesFactory = IDevicesFactory::getService();
     if (mDevicesFactory != 0) {
-        // It is assumet that DevicesFactory is owned by AudioFlinger
+        // It is assumed that DevicesFactory is owned by AudioFlinger
         // and thus have the same lifespan.
         mDevicesFactory->linkToDeath(HalDeathHandler::getInstance(), 0 /*cookie*/);
+    } else {
+        LOG_ALWAYS_FATAL("Failed to obtain IDevicesFactory service");
     }
 }
 
diff --git a/media/libaudiohal/EffectsFactoryHalHidl.cpp b/media/libaudiohal/EffectsFactoryHalHidl.cpp
index fd3e207..f7dbb9c 100644
--- a/media/libaudiohal/EffectsFactoryHalHidl.cpp
+++ b/media/libaudiohal/EffectsFactoryHalHidl.cpp
@@ -44,6 +44,7 @@
 
 EffectsFactoryHalHidl::EffectsFactoryHalHidl() : ConversionHelperHidl("EffectsFactory") {
     mEffectsFactory = IEffectsFactory::getService();
+    LOG_ALWAYS_FATAL_IF(mEffectsFactory == 0, "Failed to obtain IEffectsFactory service");
 }
 
 EffectsFactoryHalHidl::~EffectsFactoryHalHidl() {