diff options
author | Glenn Kasten <gkasten@android.com> | 2014-10-02 16:19:12 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-10-02 16:19:12 +0000 |
commit | 6ba13ac56663a45a7f16feb465d451f0180fae26 (patch) | |
tree | 7ca83bd6b8d7b5bd7badfd4409216eb75f94ff30 | |
parent | 0c1faf43aecadc37b78c4ad6cb669eb351d21385 (diff) | |
parent | 3e9774aba950e25cfba8a428dc9129e698d4b965 (diff) | |
download | base-6ba13ac56663a45a7f16feb465d451f0180fae26.tar.gz |
Merge "AudioService: Fix monitorRotation for landscape applications"
-rw-r--r-- | media/java/android/media/AudioService.java | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 72568640a161..b863a8ee6928 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -77,6 +77,7 @@ import android.view.KeyEvent; import android.view.Surface; import android.view.VolumePanel; import android.view.WindowManager; +import android.view.OrientationEventListener; import com.android.internal.telephony.ITelephony; import com.android.internal.util.XmlUtils; @@ -460,6 +461,8 @@ public class AudioService extends IAudioService.Stub { // If absolute volume is supported in AVRCP device private boolean mAvrcpAbsVolSupported = false; + private AudioOrientationEventListener mOrientationListener; + /////////////////////////////////////////////////////////////////////////// // Construction /////////////////////////////////////////////////////////////////////////// @@ -558,6 +561,10 @@ public class AudioService extends IAudioService.Stub { mDeviceRotation = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getRotation(); Log.v(TAG, "monitoring device rotation, initial=" + mDeviceRotation); + + mOrientationListener = new AudioOrientationEventListener(mContext); + mOrientationListener.enable(); + // initialize rotation in AudioSystem setRotationForAudioSystem(); } @@ -754,6 +761,25 @@ public class AudioService extends IAudioService.Stub { return (index * mStreamStates[dstStream].getMaxIndex() + mStreamStates[srcStream].getMaxIndex() / 2) / mStreamStates[srcStream].getMaxIndex(); } + private class AudioOrientationEventListener + extends OrientationEventListener { + public AudioOrientationEventListener(Context context) { + super(context); + } + + @Override + public void onOrientationChanged(int orientation) { + //Even though we're responding to phone orientation events, + //use display rotation so audio stays in sync with video/dialogs + int newRotation = ((WindowManager) mContext.getSystemService( + Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); + if (newRotation != mDeviceRotation) { + mDeviceRotation = newRotation; + setRotationForAudioSystem(); + } + } + } + /////////////////////////////////////////////////////////////////////////// // IPC methods /////////////////////////////////////////////////////////////////////////// @@ -4195,8 +4221,16 @@ public class AudioService extends IAudioService.Stub { null, SAFE_VOLUME_CONFIGURE_TIMEOUT_MS); } else if (action.equals(Intent.ACTION_SCREEN_ON)) { + if (mMonitorRotation) { + mOrientationListener.onOrientationChanged(0); //argument is ignored anyway + mOrientationListener.enable(); + } AudioSystem.setParameters("screen_state=on"); } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { + if (mMonitorRotation) { + //reduce wakeups (save current) by only listening when display is on + mOrientationListener.disable(); + } AudioSystem.setParameters("screen_state=off"); } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { handleConfigurationChanged(context); @@ -4359,14 +4393,6 @@ public class AudioService extends IAudioService.Stub { setOrientationForAudioSystem(); } } - if (mMonitorRotation) { - int newRotation = ((WindowManager) context.getSystemService( - Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); - if (newRotation != mDeviceRotation) { - mDeviceRotation = newRotation; - setRotationForAudioSystem(); - } - } sendMsg(mAudioHandler, MSG_CONFIGURE_SAFE_MEDIA_VOLUME, SENDMSG_REPLACE, |