audioflinger: fix redundant adding to tracksToRemove

In order to avoid track to be added to tracksToRemove
redundantly, merge the adding operation under exclusive
condition check.
This can make sure the add can happen only one time within
one prepareTracks iterator.

authored-by: Zhou Song <zhous@codeaurora.org>

Test: AF active track removal with audio playback pause
Bug: 123375253
Change-Id: If35348af2144a28b84241e1cb93f497d5eec9a8a
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index f438493..6dd9cab 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -5508,7 +5508,6 @@
                 doHwPause = true;
                 mHwPaused = true;
             }
-            tracksToRemove->add(track);
         } else if (track->isFlushPending()) {
             track->flushAck();
             if (last) {
@@ -5605,7 +5604,8 @@
 
                 int64_t framesWritten = mBytesWritten / mFrameSize;
                 if (mStandby || !last ||
-                        track->presentationComplete(framesWritten, audioHALFrames)) {
+                        track->presentationComplete(framesWritten, audioHALFrames) ||
+                        track->isPaused()) {
                     if (track->isStopping_2()) {
                         track->mState = TrackBase::STOPPED;
                     }