audioflinger: flush HAL when transitioning to next direct track

Send flush command to the audio HAL when transtioning to
next track on direct output thread, even if both tracks are in the
same audio session.

Commit 43b4dcc to fix issue 21145353 did only flush the HAL if the
audio session was different for the new track because the logic was
copied from the offload thread.

Bug: 22019044.
Change-Id: I89b217580023ed7449a58e9bf3dc068ce7a84487
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index d3ea9d8..966fb5c 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -4482,9 +4482,16 @@
     sp<Track> previousTrack = mPreviousTrack.promote();
     sp<Track> latestTrack = mLatestActiveTrack.promote();
 
-    if (previousTrack != 0 && latestTrack != 0 &&
-        (previousTrack->sessionId() != latestTrack->sessionId())) {
-        mFlushPending = true;
+    if (previousTrack != 0 && latestTrack != 0) {
+        if (mType == DIRECT) {
+            if (previousTrack.get() != latestTrack.get()) {
+                mFlushPending = true;
+            }
+        } else /* mType == OFFLOAD */ {
+            if (previousTrack->sessionId() != latestTrack->sessionId()) {
+                mFlushPending = true;
+            }
+        }
     }
     PlaybackThread::onAddNewTrack_l();
 }
@@ -4577,12 +4584,8 @@
                     if (track != previousTrack.get()) {
                         // Flush any data still being written from last track
                         mBytesRemaining = 0;
-                        // flush data already sent if changing audio session as audio
-                        // comes from a different source. Also invalidate previous track to force a
-                        // seek when resuming.
-                        if (previousTrack->sessionId() != track->sessionId()) {
-                            previousTrack->invalidate();
-                        }
+                        // Invalidate previous track to force a seek when resuming.
+                        previousTrack->invalidate();
                     }
                 }
                 mPreviousTrack = track;