AudioPolicyManager: Stop the descriptor when closing its output

This fixes the case when the SwAudioOutputDescriptor is part of
duplicated output. In this case, APM::closeOutput finds the
duplicated output, deactivates all the clients for all outputs,
then calls 'close' on the descriptor. Since there are no active
clients, closing the descriptor does not stop it, leaving
pending 'active count' in the profile.

Bug: 128362999
Test: steps from b/124415601
Change-Id: I8fa60ef50efa74ca8cf6e3312e1075a9ec9c63f3
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index e8e9fa6..c971299 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -4828,6 +4828,7 @@
         ALOGW("closeOutput() unknown output %d", output);
         return;
     }
+    const bool closingOutputWasActive = closingOutput->isActive();
     mPolicyMixes.closeOutput(closingOutput);
 
     // look for duplicated outputs connected to the output being removed.
@@ -4867,6 +4868,9 @@
         mpClientInterface->onAudioPatchListUpdate();
     }
 
+    if (closingOutputWasActive) {
+        closingOutput->stop();
+    }
     closingOutput->close();
 
     removeOutput(output);