Prevent old callback events when track is recycled

When a track is reused from SoundPool and started again, the
previous callback events could be done after track started,
then the new playback will be stopped unintentionally.
Clear the old cblk flags when recycled track is started again
to avoid triggering unexpected callback events.

Bug: 112269355
Test: Playback with SoundPool frequently
Change-Id: I111b085d08b73c333fbb0fc2896efe1c013c584c
diff --git a/media/libaudioclient/AudioTrack.cpp b/media/libaudioclient/AudioTrack.cpp
index c6622cd..0edb04b 100644
--- a/media/libaudioclient/AudioTrack.cpp
+++ b/media/libaudioclient/AudioTrack.cpp
@@ -631,6 +631,13 @@
         // force refresh of remaining frames by processAudioBuffer() as last
         // write before stop could be partial.
         mRefreshRemaining = true;
+
+        // for static track, clear the old flags when starting from stopped state
+        if (mSharedBuffer != 0) {
+            android_atomic_and(
+            ~(CBLK_LOOP_CYCLE | CBLK_LOOP_FINAL | CBLK_BUFFER_END),
+            &mCblk->mFlags);
+        }
     }
     mNewPosition = mPosition + mUpdatePeriod;
     int32_t flags = android_atomic_and(~(CBLK_STREAM_END_DONE | CBLK_DISABLED), &mCblk->mFlags);