Fix odd values in aaudio metrics.
1. Do not log the AudioStream information if it is from the service. The
service side may automatically create an AudioStreamInternal instance
when a shared endpoint is used. This is not the interesting part for the
metrics.
2. If the aaudio stream uses legacy path, only channel mask will be
logged. Calculate channel count from channel mask for logging aaudio
metrics.
Test: atest AAudioTests MediaMetricsAtomTests
Test: dumpsys media.metrics
Bug: 194937266
Change-Id: I183224a4acc59c40d511ee2eb37da05210851348
diff --git a/media/libaaudio/src/client/AudioStreamInternal.cpp b/media/libaaudio/src/client/AudioStreamInternal.cpp
index cf2abe8..6d2d464 100644
--- a/media/libaaudio/src/client/AudioStreamInternal.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternal.cpp
@@ -155,8 +155,11 @@
// This must match the key generated in oboeservice/AAudioServiceStreamBase.cpp
// so the client can have permission to log.
- mMetricsId = std::string(AMEDIAMETRICS_KEY_PREFIX_AUDIO_STREAM)
- + std::to_string(mServiceStreamHandle);
+ if (!mInService) {
+ // No need to log if it is from service side.
+ mMetricsId = std::string(AMEDIAMETRICS_KEY_PREFIX_AUDIO_STREAM)
+ + std::to_string(mServiceStreamHandle);
+ }
android::mediametrics::LogItem(mMetricsId)
.set(AMEDIAMETRICS_PROP_PERFORMANCEMODE,