audioflinger: fix duplicating thread standby

The code that waits for a track presentation to be complete
before disabling it caused a regression for duplicating threads.
Because of the way output tracks activity is managed, the number
of frames output by the duplicating thread would never
reach the target set for a track to be considered presented.
The track would not be removed from active list and the thread would
not go to standby and keep its wakelock held.

Bug 6606922.

Change-Id: I4b46b420ac4cbf79a86b6791ae6589d407b01c92
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index e7ababa..67dbfe9 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -3891,6 +3891,7 @@
     }
     sleepTime = 0;
     writeFrames = mNormalFrameCount;
+    standbyTime = systemTime() + standbyDelay;
 }
 
 void AudioFlinger::DuplicatingThread::threadLoop_sleepTime()
@@ -3902,21 +3903,19 @@
             sleepTime = idleSleepTime;
         }
     } else if (mBytesWritten != 0) {
-        // flush remaining overflow buffers in output tracks
-        for (size_t i = 0; i < outputTracks.size(); i++) {
-            if (outputTracks[i]->isActive()) {
-                sleepTime = 0;
-                writeFrames = 0;
-                memset(mMixBuffer, 0, mixBufferSize);
-                break;
-            }
+        if (mMixerStatus == MIXER_TRACKS_ENABLED) {
+            writeFrames = mNormalFrameCount;
+            memset(mMixBuffer, 0, mixBufferSize);
+        } else {
+            // flush remaining overflow buffers in output tracks
+            writeFrames = 0;
         }
+        sleepTime = 0;
     }
 }
 
 void AudioFlinger::DuplicatingThread::threadLoop_write()
 {
-    standbyTime = systemTime() + standbyDelay;
     for (size_t i = 0; i < outputTracks.size(); i++) {
         outputTracks[i]->write(mMixBuffer, writeFrames);
     }