TrackMetrics: Fix volume computation

Average volume should be weighted based on active time
not total lifetime.

Improve the numerical accuracy of average volume using
West's algorithm.

Remove unneeded variables.

Test: youtube, play/pause, adb shell dumpsys media.metrics
Bug: 233409482
Merged-In: I9fadb7287bd0bccbf5c74aad5a07eab277303d02
Change-Id: I9fadb7287bd0bccbf5c74aad5a07eab277303d02
(cherry picked from commit a81a4b4c947ff4aa483603f2ca6c44d6fc3d1380)
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 76892cd..b422bb2 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -1123,6 +1123,7 @@
                     .mPosition[ExtendedTimestamp::LOCATION_KERNEL];
             mLogLatencyMs = 0.;
         }
+        mLogForceVolumeUpdate = true;  // at least one volume logged for metrics when starting.
 
         if (status == NO_ERROR || status == ALREADY_EXISTS) {
             // for streaming tracks, remove the buffer read stop limit.
@@ -1394,7 +1395,11 @@
     if (mFinalVolume != volume) { // Compare to an epsilon if too many meaningless updates
         mFinalVolume = volume;
         setMetadataHasChanged();
-        mTrackMetrics.logVolume(volume);
+        mLogForceVolumeUpdate = true;
+    }
+    if (mLogForceVolumeUpdate) {
+        mLogForceVolumeUpdate = false;
+        mTrackMetrics.logVolume(mFinalVolume);
     }
 }