diff options
author | 2009-12-07 15:57:28 -0800 | |
---|---|---|
committer | 2009-12-07 15:57:28 -0800 | |
commit | dbdabca716e0873a7c36d4f1ddd0fdb5ca412bc4 (patch) | |
tree | 2980fbe93eb1ebbe866f452486059a659de4740f | |
parent | dbf68aa372078f4f55a267e1eb182dd360384467 (diff) | |
parent | b08170ad7e4ca4908852b0e20759ea740b338a03 (diff) |
am b08170ad: am ae88e2d1: Merge change I38227501 into eclair
Merge commit 'b08170ad7e4ca4908852b0e20759ea740b338a03' into eclair-mr2-plus-aosp
* commit 'b08170ad7e4ca4908852b0e20759ea740b338a03':
Add API to get Active Sinks.
-rw-r--r-- | core/java/android/bluetooth/BluetoothA2dp.java | 16 | ||||
-rw-r--r-- | core/java/android/bluetooth/IBluetoothA2dp.aidl | 1 | ||||
-rw-r--r-- | core/java/android/server/BluetoothA2dpService.java | 10 | ||||
-rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 6 |
4 files changed, 31 insertions, 2 deletions
diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index 7df3637f3189..fda9b81c8f0e 100644 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -199,6 +199,22 @@ public final class BluetoothA2dp { } } + /** Check if any A2DP sink is in Non Disconnected state + * i.e playing, connected, connecting, disconnecting. + * @return a unmodifiable set of connected A2DP sinks, or null on error. + * @hide + */ + public Set<BluetoothDevice> getNonDisconnectedSinks() { + if (DBG) log("getNonDisconnectedSinks()"); + try { + return Collections.unmodifiableSet( + new HashSet<BluetoothDevice>(Arrays.asList(mService.getNonDisconnectedSinks()))); + } catch (RemoteException e) { + Log.e(TAG, "", e); + return null; + } + } + /** Get the state of an A2DP sink * @param device Remote BT device. * @return State code, one of STATE_ diff --git a/core/java/android/bluetooth/IBluetoothA2dp.aidl b/core/java/android/bluetooth/IBluetoothA2dp.aidl index 002cf4efff61..168fe3b252da 100644 --- a/core/java/android/bluetooth/IBluetoothA2dp.aidl +++ b/core/java/android/bluetooth/IBluetoothA2dp.aidl @@ -29,6 +29,7 @@ interface IBluetoothA2dp { boolean suspendSink(in BluetoothDevice device); boolean resumeSink(in BluetoothDevice device); BluetoothDevice[] getConnectedSinks(); // change to Set<> once AIDL supports + BluetoothDevice[] getNonDisconnectedSinks(); // change to Set<> once AIDL supports int getSinkState(in BluetoothDevice device); boolean setSinkPriority(in BluetoothDevice device, int priority); int getSinkPriority(in BluetoothDevice device); diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index 46de708aabcf..f2e132b56fe7 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -376,6 +376,16 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { return sinks.toArray(new BluetoothDevice[sinks.size()]); } + public synchronized BluetoothDevice[] getNonDisconnectedSinks() { + mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + Set<BluetoothDevice> sinks = lookupSinksMatchingStates( + new int[] {BluetoothA2dp.STATE_CONNECTED, + BluetoothA2dp.STATE_PLAYING, + BluetoothA2dp.STATE_CONNECTING, + BluetoothA2dp.STATE_DISCONNECTING}); + return sinks.toArray(new BluetoothDevice[sinks.size()]); + } + public synchronized int getSinkState(BluetoothDevice device) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); Integer state = mAudioDevices.get(device); diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index e960491393bb..0d0d24548954 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -546,12 +546,14 @@ class BluetoothEventLoop { boolean authorized = false; ParcelUuid uuid = ParcelUuid.fromString(deviceUuid); + BluetoothA2dp a2dp = new BluetoothA2dp(mContext); + // Bluez sends the UUID of the local service being accessed, _not_ the // remote service if (mBluetoothService.isEnabled() && (BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid) - || BluetoothUuid.isAdvAudioDist(uuid))) { - BluetoothA2dp a2dp = new BluetoothA2dp(mContext); + || BluetoothUuid.isAdvAudioDist(uuid)) && + (a2dp.getNonDisconnectedSinks().size() == 0)) { BluetoothDevice device = mAdapter.getRemoteDevice(address); authorized = a2dp.getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF; if (authorized) { |