Android audio player: use audio attributes instead of legacy stream type

Use audio attributes to specifcy the use case and make sure performance flags
in audio attributes are reflecting the output flags passed to the AudioTrack by
android_audioPlayer_realize.

Bug: 283003710
Test: repro steps in bug
Change-Id: I2f5c523b4f547f3d769fd56dfac8738f4b28ae9d
diff --git a/src/android/AudioPlayer_to_android.cpp b/src/android/AudioPlayer_to_android.cpp
index 8acc499..5df053d 100644
--- a/src/android/AudioPlayer_to_android.cpp
+++ b/src/android/AudioPlayer_to_android.cpp
@@ -1609,19 +1609,23 @@
         checkAndSetPerformanceModePre(pAudioPlayer);
 
         audio_output_flags_t policy;
+        audio_flags_mask_t attrFlags = AUDIO_FLAG_NONE;
         switch (pAudioPlayer->mPerformanceMode) {
         case ANDROID_PERFORMANCE_MODE_POWER_SAVING:
             policy = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
+            attrFlags = static_cast<audio_flags_mask_t>(attrFlags | AUDIO_FLAG_DEEP_BUFFER);
             break;
         case ANDROID_PERFORMANCE_MODE_NONE:
             policy = AUDIO_OUTPUT_FLAG_NONE;
             break;
         case ANDROID_PERFORMANCE_MODE_LATENCY_EFFECTS:
             policy = AUDIO_OUTPUT_FLAG_FAST;
+            attrFlags = static_cast<audio_flags_mask_t>(attrFlags | AUDIO_FLAG_LOW_LATENCY);
             break;
         case ANDROID_PERFORMANCE_MODE_LATENCY:
         default:
             policy = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_RAW);
+            attrFlags = static_cast<audio_flags_mask_t>(attrFlags | AUDIO_FLAG_LOW_LATENCY);
             break;
         }
 
@@ -1633,9 +1637,13 @@
         } else {
             notificationFrames = 0;
         }
+        audio_attributes_t attributes = AUDIO_ATTRIBUTES_INITIALIZER;
+        attributes.usage = usageForStreamType(pAudioPlayer->mStreamType);
+        attributes.flags = attrFlags;
+
         const auto callbackHandle = android::sp<android::AudioTrackCallback>::make(pAudioPlayer);
         const auto pat = android::sp<android::AudioTrack>::make(
-                pAudioPlayer->mStreamType,                           // streamType
+                AUDIO_STREAM_DEFAULT,                                // streamType
                 sampleRate,                                          // sampleRate
                 sles_to_android_sampleFormat(df_pcm),                // format
                 channelMask,                                         // channel mask
@@ -1643,7 +1651,12 @@
                 policy,                                              // flags
                 callbackHandle,                                      // callback
                 notificationFrames,                                  // see comment above
-                pAudioPlayer->mSessionId);
+                pAudioPlayer->mSessionId,
+                android::AudioTrack::TRANSFER_DEFAULT,               // transferType
+                nullptr,                                             // offloadInfo
+                AttributionSourceState(),                            // attributionSource
+                &attributes                                          // pAttributes
+                );
 
         // Set it here so it can be logged by the destructor if the open failed.
         pat->setCallerName(ANDROID_OPENSLES_CALLER_NAME);