Move AudioSystem errorCallback call out from gLock

Since the error callback ends up calling into Java,
there is a potential for a deadlock with Java code
that takes AudioSystem.class lock and calls into
native code that takes gLock in its own turn.

Bug: 152819012
Test: use audio on a phone, also
      killing native audioserver while watching YT,
      also while making cellular calls
Change-Id: Ib288ba96ae2f7b5ab36c1b0a1db4adde487d6a49
diff --git a/media/libaudioclient/AudioSystem.cpp b/media/libaudioclient/AudioSystem.cpp
index 74fa343..6357da4 100644
--- a/media/libaudioclient/AudioSystem.cpp
+++ b/media/libaudioclient/AudioSystem.cpp
@@ -55,6 +55,7 @@
 {
     sp<IAudioFlinger> af;
     sp<AudioFlingerClient> afc;
+    bool reportNoError = false;
     {
         Mutex::Autolock _l(gLock);
         if (gAudioFlinger == 0) {
@@ -70,7 +71,7 @@
             if (gAudioFlingerClient == NULL) {
                 gAudioFlingerClient = new AudioFlingerClient();
             } else {
-                reportError(NO_ERROR);
+                reportNoError = true;
             }
             binder->linkToDeath(gAudioFlingerClient);
             gAudioFlinger = interface_cast<IAudioFlinger>(binder);
@@ -86,6 +87,7 @@
         af->registerClient(afc);
         IPCThreadState::self()->restoreCallingIdentity(token);
     }
+    if (reportNoError) reportError(NO_ERROR);
     return af;
 }