AudioOutputDescriptor: improve refcount logging
Improve refcount to match exact client descriptor
Abort on invalid client descriptor refcounts
Log changes to active clients and refcounts
Test: dumpsys of media.audio_policy
Bug: 112067674
Change-Id: I5fe4d3e7135efbf9bc5bffb258374115d87c24e6
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 380f0fb..4543dd0 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -4529,10 +4529,9 @@
// and as they were also referenced on the other output, the reference
// count for their stream type must be adjusted accordingly on
// the other output.
- bool wasActive = outputDesc2->isActive();
- for (int j = 0; j < AUDIO_STREAM_CNT; j++) {
- int activeCount = dupOutputDesc->streamActiveCount((audio_stream_type_t)j);
- outputDesc2->changeStreamActiveCount((audio_stream_type_t)j,-activeCount);
+ const bool wasActive = outputDesc2->isActive();
+ for (const auto &clientPair : dupOutputDesc->getActiveClients()) {
+ outputDesc2->changeStreamActiveCount(clientPair.first, -clientPair.second);
}
// stop() will be a no op if the output is still active but is needed in case all
// active streams refcounts where cleared above