From 01ae5f68cd4df65ea54b317aed6500db8face0d0 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Tue, 25 Dec 2012 14:03:03 +0100 Subject: Properly handle changes in phone audio focus. Change-Id: I921651684f4369a47aa83e93010266c40be71a41 --- media/java/android/media/AudioService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'media') diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 140363d..4c0acf6 100755 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -4183,10 +4183,11 @@ public class AudioService extends IAudioService.Stub implements OnFinished { private void notifyTopOfAudioFocusStack() { // notify the top of the stack it gained focus if (!mFocusStack.empty() && (mFocusStack.peek().mFocusDispatcher != null)) { - if (canReassignAudioFocus()) { + String clientId = mFocusStack.peek().mClientId; + if (canReassignAudioFocusTo(clientId)) { try { mFocusStack.peek().mFocusDispatcher.dispatchAudioFocusChange( - AudioManager.AUDIOFOCUS_GAIN, mFocusStack.peek().mClientId); + AudioManager.AUDIOFOCUS_GAIN, clientId); } catch (RemoteException e) { Log.e(TAG, "Failure to signal gain of audio control focus due to "+ e); e.printStackTrace(); @@ -4334,9 +4335,12 @@ public class AudioService extends IAudioService.Stub implements OnFinished { * Helper function: * Returns true if the system is in a state where the focus can be reevaluated, false otherwise. */ - private boolean canReassignAudioFocus() { + private boolean canReassignAudioFocusTo(String clientId) { // focus requests are rejected during a phone call or when the phone is ringing // this is equivalent to IN_VOICE_COMM_FOCUS_ID having the focus + if (IN_VOICE_COMM_FOCUS_ID.equals(clientId)) { + return true; + } if (!mFocusStack.isEmpty() && IN_VOICE_COMM_FOCUS_ID.equals(mFocusStack.peek().mClientId)) { return false; } @@ -4381,7 +4385,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished { } synchronized(mAudioFocusLock) { - if (!canReassignAudioFocus()) { + if (!canReassignAudioFocusTo(clientId)) { return AudioManager.AUDIOFOCUS_REQUEST_FAILED; } -- cgit v1.1