diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2010-02-16 11:57:06 -0800 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2010-02-16 13:21:05 -0800 |
commit | 4f773a13043ec22ccd2f9d33ee86a305738c5b23 (patch) | |
tree | 1d1720937fd8ca4f1b9be7bd76816d1ee99ca1e3 /core/java/android/server | |
parent | 965e37ec88609c36a3c5461ece459a96abb6f7ca (diff) | |
download | frameworks_base-4f773a13043ec22ccd2f9d33ee86a305738c5b23.zip frameworks_base-4f773a13043ec22ccd2f9d33ee86a305738c5b23.tar.gz frameworks_base-4f773a13043ec22ccd2f9d33ee86a305738c5b23.tar.bz2 |
AVRCP volume controls for the docks.
Send volume updates to the dock when the user presses volume buttons
on the device.
Bug: 2311007
Diffstat (limited to 'core/java/android/server')
-rw-r--r-- | core/java/android/server/BluetoothA2dpService.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index 22bb43c..096ad39 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -121,10 +121,44 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { handleSinkStateChange(device, state, BluetoothA2dp.STATE_DISCONNECTED); } } + } else if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { + int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); + if (streamType == AudioManager.STREAM_MUSIC) { + BluetoothDevice sinks[] = getConnectedSinks(); + if (sinks.length != 0 && isPhoneDocked(sinks[0])) { + String address = sinks[0].getAddress(); + int newVolLevel = + intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); + int oldVolLevel = + intent.getIntExtra(AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, 0); + String path = mBluetoothService.getObjectPathFromAddress(address); + if (newVolLevel > oldVolLevel) { + avrcpVolumeUpNative(path); + } else if (newVolLevel < oldVolLevel) { + avrcpVolumeDownNative(path); + } + } + } } } }; + + private boolean isPhoneDocked(BluetoothDevice device) { + // This works only because these broadcast intents are "sticky" + Intent i = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT)); + if (i != null) { + int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED); + if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) { + BluetoothDevice dockDevice = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + if (dockDevice != null && device.equals(dockDevice)) { + return true; + } + } + } + return false; + } + public BluetoothA2dpService(Context context, BluetoothService bluetoothService) { mContext = context; @@ -145,6 +179,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { mIntentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); mIntentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); + mIntentFilter.addAction(AudioManager.VOLUME_CHANGED_ACTION); mContext.registerReceiver(mReceiver, mIntentFilter); mAudioDevices = new HashMap<BluetoothDevice, Integer>(); @@ -551,4 +586,6 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { private synchronized native boolean suspendSinkNative(String path); private synchronized native boolean resumeSinkNative(String path); private synchronized native Object []getSinkPropertiesNative(String path); + private synchronized native boolean avrcpVolumeUpNative(String path); + private synchronized native boolean avrcpVolumeDownNative(String path); } |