From 40f7e04f74cd499cab85cd49a312403ecc540f68 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Wed, 11 Sep 2019 19:13:08 -0700 Subject: [PATCH] AudioTrack: fix default low power mode selection Fix AudioAttributes flags checking logic in shouldEnablePowerSaving() to take into account flags that are compatible with deep buffer. Bug: 140899988 Test: check that playback with Spotify goes to deep buffer Change-Id: I492410b7837b15e248d61ec50dbb468e78e04524 --- media/java/android/media/AudioTrack.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java index e29e5698439df..7cd09de413464 100644 --- a/media/java/android/media/AudioTrack.java +++ b/media/java/android/media/AudioTrack.java @@ -1184,8 +1184,15 @@ public class AudioTrack extends PlayerBase int bufferSizeInBytes, int mode) { // If no attributes, OK // otherwise check attributes for USAGE_MEDIA and CONTENT_UNKNOWN, MUSIC, or MOVIE. + // Only consider flags that are not compatible with FLAG_DEEP_BUFFER. We include + // FLAG_DEEP_BUFFER because if set the request is explicit and + // shouldEnablePowerSaving() should return false. + final int flags = attributes.getAllFlags() + & (AudioAttributes.FLAG_DEEP_BUFFER | AudioAttributes.FLAG_LOW_LATENCY + | AudioAttributes.FLAG_HW_AV_SYNC | AudioAttributes.FLAG_BEACON); + if (attributes != null && - (attributes.getAllFlags() != 0 // cannot have any special flags + (flags != 0 // cannot have any special flags || attributes.getUsage() != AudioAttributes.USAGE_MEDIA || (attributes.getContentType() != AudioAttributes.CONTENT_TYPE_UNKNOWN && attributes.getContentType() != AudioAttributes.CONTENT_TYPE_MUSIC