audioflinger: avoid cross deadlock with when releasing effect

There is a possible cross deadlock between EffectModule mutexes in
AudioFlinger and AudioPolicyService mutex when destroying an
EffectHandle in audio flinger.

This change reduces this likelyhood of this happening but does not
fix the root cause.

Bug: 180941720
Test: make.
Change-Id: Ib2cd04869143c9146accee468cc5d40f65c373b9
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index 392d339..031e0cf 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -261,6 +261,12 @@
         }
         registered = mPolicyRegistered;
         enabled = mPolicyEnabled;
+        // The simultaneous release of two EffectHandles with the same EffectModule
+        // may cause us to call this method at the same time.
+        // This may deadlock under some circumstances (b/180941720).  Avoid this.
+        if (!doRegister && !(registered && doEnable)) {
+            return NO_ERROR;
+        }
         mPolicyLock.lock();
     }
     ALOGV("%s name %s id %d session %d doRegister %d registered %d doEnable %d enabled %d",