diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2010-12-11 13:18:30 -0800 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2010-12-11 13:55:58 -0800 |
commit | 2ade576148fe33c5ff6098d30ccfbcf28df70e8e (patch) | |
tree | 56d4b40d5ebbffb9ac4d5005a5f2b4403de25127 /media | |
parent | dfcaeb1677cef0d7bf437f5f0432b6f07b223690 (diff) | |
download | frameworks_base-2ade576148fe33c5ff6098d30ccfbcf28df70e8e.zip frameworks_base-2ade576148fe33c5ff6098d30ccfbcf28df70e8e.tar.gz frameworks_base-2ade576148fe33c5ff6098d30ccfbcf28df70e8e.tar.bz2 |
Fix bug 3275151 Request and abandon audio focus with audio mode changes
Before the introduction of the MODE_IN_COMMUNICATION audio mode,
"calls" were only made through telephony and the PhoneStateListener
was used to request and abandon audio focus as calls where started
and ended. VoIP applications do not cause phone state events to
be broadcast, and set the audio mode to MODE_IN_COMMUNICATION
directly. This change monitors mode changes to automatically
grab and abandon audio focus.
Change-Id: Ie9a4193e35ba8447764fac66a988959a93c4909f
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioService.java | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 2836005..6d47c44 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -752,6 +752,10 @@ public class AudioService extends IAudioService.Stub { mode = mMode; } if (mode != mMode) { + + // automatically handle audio focus for mode changes + handleFocusForCalls(mMode, mode); + if (AudioSystem.setPhoneState(mode) == AudioSystem.AUDIO_STATUS_OK) { mMode = mode; @@ -807,6 +811,38 @@ public class AudioService extends IAudioService.Stub { } } + /** pre-condition: oldMode != newMode */ + private void handleFocusForCalls(int oldMode, int newMode) { + // if ringing + if (newMode == AudioSystem.MODE_RINGTONE) { + // if not ringing silently + int ringVolume = AudioService.this.getStreamVolume(AudioManager.STREAM_RING); + if (ringVolume > 0) { + // request audio focus for the communication focus entry + requestAudioFocus(AudioManager.STREAM_RING, + AudioManager.AUDIOFOCUS_GAIN_TRANSIENT, + null, null /* both allowed to be null only for this clientId */, + IN_VOICE_COMM_FOCUS_ID /*clientId*/); + + } + } + // if entering call + else if ((newMode == AudioSystem.MODE_IN_CALL) + || (newMode == AudioSystem.MODE_IN_COMMUNICATION)) { + // request audio focus for the communication focus entry + // (it's ok if focus was already requested during ringing) + requestAudioFocus(AudioManager.STREAM_RING, + AudioManager.AUDIOFOCUS_GAIN_TRANSIENT, + null, null /* both allowed to be null only for this clientId */, + IN_VOICE_COMM_FOCUS_ID /*clientId*/); + } + // if exiting call + else if (newMode == AudioSystem.MODE_NORMAL) { + // abandon audio focus for communication focus entry + abandonAudioFocus(null, IN_VOICE_COMM_FOCUS_ID); + } + } + /** @see AudioManager#getMode() */ public int getMode() { return mMode; @@ -2093,28 +2129,11 @@ public class AudioService extends IAudioService.Stub { synchronized(mRingingLock) { mIsRinging = true; } - int ringVolume = AudioService.this.getStreamVolume(AudioManager.STREAM_RING); - if (ringVolume > 0) { - requestAudioFocus(AudioManager.STREAM_RING, - AudioManager.AUDIOFOCUS_GAIN_TRANSIENT, - null, null /* both allowed to be null only for this clientId */, - IN_VOICE_COMM_FOCUS_ID /*clientId*/); - } - } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) { - //Log.v(TAG, " CALL_STATE_OFFHOOK"); - synchronized(mRingingLock) { - mIsRinging = false; - } - requestAudioFocus(AudioManager.STREAM_RING, - AudioManager.AUDIOFOCUS_GAIN_TRANSIENT, - null, null /* both allowed to be null only for this clientId */, - IN_VOICE_COMM_FOCUS_ID /*clientId*/); - } else if (state == TelephonyManager.CALL_STATE_IDLE) { - //Log.v(TAG, " CALL_STATE_IDLE"); + } else if ((state == TelephonyManager.CALL_STATE_OFFHOOK) + || (state == TelephonyManager.CALL_STATE_IDLE)) { synchronized(mRingingLock) { mIsRinging = false; } - abandonAudioFocus(null, IN_VOICE_COMM_FOCUS_ID); } } }; |