From 9aeed0cd6f47359ec64e12ded06863ab272d712e Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Thu, 19 Jan 2017 18:02:52 -0800 Subject: [PATCH] Notification player: do not use stream types Don't go through stream types for the attributes of the notification to play when requesting focus Test: play notification with usage USAGE_NOTIFICATION_EVENT, verify that usage is communicated to MediaFocusControl Bug 30258418 Change-Id: Ieaab969d84728b04a6f34aa8a02cf18ba22d1aca --- .../systemui/media/NotificationPlayer.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java b/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java index 728d558c03b1e..978890301f44e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java +++ b/packages/SystemUI/src/com/android/systemui/media/NotificationPlayer.java @@ -22,6 +22,7 @@ import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnErrorListener; +import android.media.PlayerBase; import android.net.Uri; import android.os.Looper; import android.os.PowerManager; @@ -81,6 +82,12 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener (AudioManager) mCmd.context.getSystemService(Context.AUDIO_SERVICE); try { MediaPlayer player = new MediaPlayer(); + if (mCmd.attributes == null) { + mCmd.attributes = new AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_NOTIFICATION) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .build(); + } player.setAudioAttributes(mCmd.attributes); player.setDataSource(mCmd.context, mCmd.uri); player.setLooping(mCmd.looping); @@ -92,13 +99,11 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener if (mAudioManagerWithAudioFocus == null) { if (mDebug) Log.d(mTag, "requesting AudioFocus"); if (mCmd.looping) { - audioManager.requestAudioFocus(null, - AudioAttributes.toLegacyStreamType(mCmd.attributes), - AudioManager.AUDIOFOCUS_GAIN); + audioManager.requestAudioFocus(null, mCmd.attributes, + AudioManager.AUDIOFOCUS_GAIN, 0); } else { - audioManager.requestAudioFocus(null, - AudioAttributes.toLegacyStreamType(mCmd.attributes), - AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); + audioManager.requestAudioFocus(null, mCmd.attributes, + AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, 0); } mAudioManagerWithAudioFocus = audioManager; } else { @@ -296,6 +301,7 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener */ @Deprecated public void play(Context context, Uri uri, boolean looping, int stream) { + PlayerBase.deprecateStreamTypeForPlayback(stream, "NotificationPlayer", "play"); Command cmd = new Command(); cmd.requestTime = SystemClock.uptimeMillis(); cmd.code = PLAY;