From a53e3816656b145bfdc165e81849d245883a2884 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Fri, 25 Sep 2009 10:51:39 -0400 Subject: [PATCH] Fix volume key handling when in-call and screen is off due to proximity sensor. Fixes bug b/2136633 Change-Id: If963d0267496878978ad82d915f821af2bd03383 Signed-off-by: Mike Lockwood --- .../policy/impl/PhoneWindowManager.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/policy/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/com/android/internal/policy/impl/PhoneWindowManager.java index 448265c5406b1..967817c54e2c2 100644 --- a/policy/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/com/android/internal/policy/impl/PhoneWindowManager.java @@ -1565,10 +1565,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { * Tell the audio service to adjust the volume appropriate to the event. * @param keycode */ - void sendVolToMusic(int keycode) { + void handleVolumeKey(int stream, int keycode) { final IAudioService audio = getAudioInterface(); if (audio == null) { - Log.w(TAG, "sendVolToMusic: couldn't get IAudioService reference"); + Log.w(TAG, "handleVolumeKey: couldn't get IAudioService reference"); return; } try { @@ -1576,8 +1576,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { // during the call, but we do it as a precaution for the rare possibility // that the music stops right before we call this mBroadcastWakeLock.acquire(); - audio.adjustStreamVolume( - AudioManager.STREAM_MUSIC, + audio.adjustStreamVolume(stream, keycode == KeyEvent.KEYCODE_VOLUME_UP ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER, @@ -1639,12 +1638,22 @@ public class PhoneWindowManager implements WindowManagerPolicy { } else if (isMusicActive()) { // when keyguard is showing and screen off, we need // to handle the volume key for music here - sendVolToMusic(event.keycode); + handleVolumeKey(AudioManager.STREAM_MUSIC, event.keycode); } } } } } else if (!screenIsOn) { + // If we are in-call with screen off and keyguard is not showing, + // then handle the volume key ourselves. + // This is necessary because the phone app will disable the keyguard + // when the proximity sensor is in use. + if (isInCall() && event.type == RawInputEvent.EV_KEY && + (event.keycode == KeyEvent.KEYCODE_VOLUME_DOWN + || event.keycode == KeyEvent.KEYCODE_VOLUME_UP)) { + result &= ~ACTION_PASS_TO_USER; + handleVolumeKey(AudioManager.STREAM_VOICE_CALL, event.keycode); + } if (isWakeKey) { // a wake key has a sole purpose of waking the device; don't pass // it to the user