diff options
author | Jon Eklund <e11237@motorola.com> | 2014-01-23 17:53:48 -0600 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2014-10-08 01:06:15 +0000 |
commit | 318f0fe43bdc4b2f6764edd91d6b78d9875ffdeb (patch) | |
tree | 751e5a19a44f0063ef8f3474b8abb90a8024ae17 | |
parent | fdbbed6090d47c5ebbf254dfda7a87ef154c8a2c (diff) | |
download | frameworks_base-318f0fe43bdc4b2f6764edd91d6b78d9875ffdeb.zip frameworks_base-318f0fe43bdc4b2f6764edd91d6b78d9875ffdeb.tar.gz frameworks_base-318f0fe43bdc4b2f6764edd91d6b78d9875ffdeb.tar.bz2 |
AudioService: Fix monitorRotation for landscape applications
Current implmentation only sends rotation updates on orientation
changes, so does not handle direct 0<->180 or 90<->270 transitions.
Update rotation based on an OrientationEventListener instead of
Intent.ACTION_CONFIGURATION_CHANGED
Bug 17606902
Change-Id: I01dfcd1c587f5b2e8a96365c2389782ad77936ef
-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 96ce2c1..5aee2e8 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -76,6 +76,7 @@ import android.view.KeyEvent; import android.view.Surface; import android.view.WindowManager; import android.view.accessibility.AccessibilityManager; +import android.view.OrientationEventListener; import com.android.internal.telephony.ITelephony; import com.android.internal.util.XmlUtils; @@ -510,6 +511,8 @@ public class AudioService extends IAudioService.Stub { // If absolute volume is supported in AVRCP device private boolean mAvrcpAbsVolSupported = false; + private AudioOrientationEventListener mOrientationListener; + /////////////////////////////////////////////////////////////////////////// // Construction /////////////////////////////////////////////////////////////////////////// @@ -618,6 +621,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(); } @@ -903,6 +910,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 /////////////////////////////////////////////////////////////////////////// @@ -4828,8 +4854,16 @@ public class AudioService extends IAudioService.Stub { sendStickyBroadcastToAll(newIntent); } } 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); @@ -4932,14 +4966,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, |