From 392a2bbb52688ebd25768a7784d9edca7f498110 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Mon, 10 May 2010 20:02:46 -0700 Subject: Fix bug 2670395 and 2599698 When the user selects a "Silent" notification sound, the Uri encoded path is an empty string. Setting this Uri as the data source of the MediaPlayer used to play notifications caused the completion listener to not be called, which with the AudioFocus logic causes the Music app to pause and never resume. The NotificationPlayer modifications cause the MediaPlayer for the notification to only request audio focus when the data source is not empty. The audio focus code in AudioService is defensively synchronized against a unique lock, and the exception observed in bug 2670395 is explicitely caught in case another edge case wasn't caught by this fix. The AudioFocus handling in AudioManager is modified so only the requestAudioFocus and abandonAudioFocus methods are meant to be used, as registerAudioFocusListener and unregisterAudioFocusListener provided no additional functionality over the request/abandon methods. abandonAudioFocus() also removes the listener from the map in AudioManager since after abandonning focus, the listener would no longer be called. Change-Id: I3b553ee8a8163c25e01117d7e5479dd5fdfa7c6b --- services/java/com/android/server/NotificationPlayer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'services') diff --git a/services/java/com/android/server/NotificationPlayer.java b/services/java/com/android/server/NotificationPlayer.java index 0b1a03b..52d2381 100644 --- a/services/java/com/android/server/NotificationPlayer.java +++ b/services/java/com/android/server/NotificationPlayer.java @@ -88,12 +88,15 @@ public class NotificationPlayer implements OnCompletionListener { player.setDataSource(mCmd.context, mCmd.uri); player.setLooping(mCmd.looping); player.prepare(); - if (mCmd.looping) { - audioManager.requestAudioFocus(null, mCmd.stream, - AudioManager.AUDIOFOCUS_GAIN); - } else { - audioManager.requestAudioFocus(null, mCmd.stream, - AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); + if ((mCmd.uri != null) && (mCmd.uri.getEncodedPath() != null) + && (mCmd.uri.getEncodedPath().length() > 0)) { + if (mCmd.looping) { + audioManager.requestAudioFocus(null, mCmd.stream, + AudioManager.AUDIOFOCUS_GAIN); + } else { + audioManager.requestAudioFocus(null, mCmd.stream, + AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); + } } player.setOnCompletionListener(NotificationPlayer.this); player.start(); -- cgit v1.1