Merge "Monitor device rotation" into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c1d47c50d6
@@ -70,7 +70,9 @@ import android.telephony.TelephonyManager;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.Surface;
|
||||||
import android.view.VolumePanel;
|
import android.view.VolumePanel;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.android.internal.telephony.ITelephony;
|
import com.android.internal.telephony.ITelephony;
|
||||||
import com.android.internal.util.XmlUtils;
|
import com.android.internal.util.XmlUtils;
|
||||||
@@ -412,6 +414,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
private volatile IRingtonePlayer mRingtonePlayer;
|
private volatile IRingtonePlayer mRingtonePlayer;
|
||||||
|
|
||||||
private int mDeviceOrientation = Configuration.ORIENTATION_UNDEFINED;
|
private int mDeviceOrientation = Configuration.ORIENTATION_UNDEFINED;
|
||||||
|
private int mDeviceRotation = Surface.ROTATION_0;
|
||||||
|
|
||||||
// Request to override default use of A2DP for media.
|
// Request to override default use of A2DP for media.
|
||||||
private boolean mBluetoothA2dpEnabled;
|
private boolean mBluetoothA2dpEnabled;
|
||||||
@@ -433,7 +436,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET |
|
AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET |
|
||||||
AudioSystem.DEVICE_OUT_ALL_USB;
|
AudioSystem.DEVICE_OUT_ALL_USB;
|
||||||
|
|
||||||
|
// TODO merge orientation and rotation
|
||||||
private final boolean mMonitorOrientation;
|
private final boolean mMonitorOrientation;
|
||||||
|
private final boolean mMonitorRotation;
|
||||||
|
|
||||||
private boolean mDockAudioMediaEnabled = true;
|
private boolean mDockAudioMediaEnabled = true;
|
||||||
|
|
||||||
@@ -525,14 +530,21 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
|
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||||
|
|
||||||
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
||||||
// Register a configuration change listener only if requested by system properties
|
// TODO merge orientation and rotation
|
||||||
// to monitor orientation changes (off by default)
|
|
||||||
mMonitorOrientation = SystemProperties.getBoolean("ro.audio.monitorOrientation", false);
|
mMonitorOrientation = SystemProperties.getBoolean("ro.audio.monitorOrientation", false);
|
||||||
if (mMonitorOrientation) {
|
if (mMonitorOrientation) {
|
||||||
Log.v(TAG, "monitoring device orientation");
|
Log.v(TAG, "monitoring device orientation");
|
||||||
// initialize orientation in AudioSystem
|
// initialize orientation in AudioSystem
|
||||||
setOrientationForAudioSystem();
|
setOrientationForAudioSystem();
|
||||||
}
|
}
|
||||||
|
mMonitorRotation = SystemProperties.getBoolean("ro.audio.monitorRotation", false);
|
||||||
|
if (mMonitorRotation) {
|
||||||
|
mDeviceRotation = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE))
|
||||||
|
.getDefaultDisplay().getRotation();
|
||||||
|
Log.v(TAG, "monitoring device rotation, initial=" + mDeviceRotation);
|
||||||
|
// initialize rotation in AudioSystem
|
||||||
|
setRotationForAudioSystem();
|
||||||
|
}
|
||||||
|
|
||||||
context.registerReceiver(mReceiver, intentFilter);
|
context.registerReceiver(mReceiver, intentFilter);
|
||||||
|
|
||||||
@@ -3457,6 +3469,9 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
if (mMonitorOrientation) {
|
if (mMonitorOrientation) {
|
||||||
setOrientationForAudioSystem();
|
setOrientationForAudioSystem();
|
||||||
}
|
}
|
||||||
|
if (mMonitorRotation) {
|
||||||
|
setRotationForAudioSystem();
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (mBluetoothA2dpEnabledLock) {
|
synchronized (mBluetoothA2dpEnabledLock) {
|
||||||
AudioSystem.setForceUse(AudioSystem.FOR_MEDIA,
|
AudioSystem.setForceUse(AudioSystem.FOR_MEDIA,
|
||||||
@@ -6326,15 +6341,17 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
// Device orientation
|
// Device orientation
|
||||||
//==========================================================================================
|
//==========================================================================================
|
||||||
/**
|
/**
|
||||||
* Handles device configuration changes that may map to a change in the orientation.
|
* Handles device configuration changes that may map to a change in the orientation
|
||||||
* This feature is optional, and is defined by the definition and value of the
|
* or orientation.
|
||||||
* "ro.audio.monitorOrientation" system property.
|
* Monitoring orientation and rotation is optional, and is defined by the definition and value
|
||||||
|
* of the "ro.audio.monitorOrientation" and "ro.audio.monitorRotation" system properties.
|
||||||
*/
|
*/
|
||||||
private void handleConfigurationChanged(Context context) {
|
private void handleConfigurationChanged(Context context) {
|
||||||
try {
|
try {
|
||||||
// reading new orientation "safely" (i.e. under try catch) in case anything
|
// reading new orientation "safely" (i.e. under try catch) in case anything
|
||||||
// goes wrong when obtaining resources and configuration
|
// goes wrong when obtaining resources and configuration
|
||||||
Configuration config = context.getResources().getConfiguration();
|
Configuration config = context.getResources().getConfiguration();
|
||||||
|
// TODO merge rotation and orientation
|
||||||
if (mMonitorOrientation) {
|
if (mMonitorOrientation) {
|
||||||
int newOrientation = config.orientation;
|
int newOrientation = config.orientation;
|
||||||
if (newOrientation != mDeviceOrientation) {
|
if (newOrientation != mDeviceOrientation) {
|
||||||
@@ -6342,6 +6359,14 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
setOrientationForAudioSystem();
|
setOrientationForAudioSystem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mMonitorRotation) {
|
||||||
|
int newRotation = ((WindowManager) context.getSystemService(
|
||||||
|
Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
|
||||||
|
if (newRotation != mDeviceRotation) {
|
||||||
|
mDeviceRotation = newRotation;
|
||||||
|
setRotationForAudioSystem();
|
||||||
|
}
|
||||||
|
}
|
||||||
sendMsg(mAudioHandler,
|
sendMsg(mAudioHandler,
|
||||||
MSG_CONFIGURE_SAFE_MEDIA_VOLUME,
|
MSG_CONFIGURE_SAFE_MEDIA_VOLUME,
|
||||||
SENDMSG_REPLACE,
|
SENDMSG_REPLACE,
|
||||||
@@ -6390,7 +6415,7 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
}
|
}
|
||||||
mVolumePanel.setLayoutDirection(config.getLayoutDirection());
|
mVolumePanel.setLayoutDirection(config.getLayoutDirection());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Error retrieving device orientation: " + e);
|
Log.e(TAG, "Error handling configuration change: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6417,6 +6442,25 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setRotationForAudioSystem() {
|
||||||
|
switch (mDeviceRotation) {
|
||||||
|
case Surface.ROTATION_0:
|
||||||
|
AudioSystem.setParameters("rotation=0");
|
||||||
|
break;
|
||||||
|
case Surface.ROTATION_90:
|
||||||
|
AudioSystem.setParameters("rotation=90");
|
||||||
|
break;
|
||||||
|
case Surface.ROTATION_180:
|
||||||
|
AudioSystem.setParameters("rotation=180");
|
||||||
|
break;
|
||||||
|
case Surface.ROTATION_270:
|
||||||
|
AudioSystem.setParameters("rotation=270");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.e(TAG, "Unknown device rotation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handles request to override default use of A2DP for media.
|
// Handles request to override default use of A2DP for media.
|
||||||
public void setBluetoothA2dpOnInt(boolean on) {
|
public void setBluetoothA2dpOnInt(boolean on) {
|
||||||
|
|||||||
Reference in New Issue
Block a user