Merge change I38227501 into eclair
* changes: Add API to get Active Sinks.
This commit is contained in:
@ -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
|
/** Get the state of an A2DP sink
|
||||||
* @param device Remote BT device.
|
* @param device Remote BT device.
|
||||||
* @return State code, one of STATE_
|
* @return State code, one of STATE_
|
||||||
|
@ -29,6 +29,7 @@ interface IBluetoothA2dp {
|
|||||||
boolean suspendSink(in BluetoothDevice device);
|
boolean suspendSink(in BluetoothDevice device);
|
||||||
boolean resumeSink(in BluetoothDevice device);
|
boolean resumeSink(in BluetoothDevice device);
|
||||||
BluetoothDevice[] getConnectedSinks(); // change to Set<> once AIDL supports
|
BluetoothDevice[] getConnectedSinks(); // change to Set<> once AIDL supports
|
||||||
|
BluetoothDevice[] getNonDisconnectedSinks(); // change to Set<> once AIDL supports
|
||||||
int getSinkState(in BluetoothDevice device);
|
int getSinkState(in BluetoothDevice device);
|
||||||
boolean setSinkPriority(in BluetoothDevice device, int priority);
|
boolean setSinkPriority(in BluetoothDevice device, int priority);
|
||||||
int getSinkPriority(in BluetoothDevice device);
|
int getSinkPriority(in BluetoothDevice device);
|
||||||
|
@ -376,6 +376,16 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
return sinks.toArray(new BluetoothDevice[sinks.size()]);
|
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) {
|
public synchronized int getSinkState(BluetoothDevice device) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
||||||
Integer state = mAudioDevices.get(device);
|
Integer state = mAudioDevices.get(device);
|
||||||
|
@ -546,12 +546,14 @@ class BluetoothEventLoop {
|
|||||||
|
|
||||||
boolean authorized = false;
|
boolean authorized = false;
|
||||||
ParcelUuid uuid = ParcelUuid.fromString(deviceUuid);
|
ParcelUuid uuid = ParcelUuid.fromString(deviceUuid);
|
||||||
|
BluetoothA2dp a2dp = new BluetoothA2dp(mContext);
|
||||||
|
|
||||||
// Bluez sends the UUID of the local service being accessed, _not_ the
|
// Bluez sends the UUID of the local service being accessed, _not_ the
|
||||||
// remote service
|
// remote service
|
||||||
if (mBluetoothService.isEnabled() &&
|
if (mBluetoothService.isEnabled() &&
|
||||||
(BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid)
|
(BluetoothUuid.isAudioSource(uuid) || BluetoothUuid.isAvrcpTarget(uuid)
|
||||||
|| BluetoothUuid.isAdvAudioDist(uuid))) {
|
|| BluetoothUuid.isAdvAudioDist(uuid)) &&
|
||||||
BluetoothA2dp a2dp = new BluetoothA2dp(mContext);
|
(a2dp.getNonDisconnectedSinks().size() == 0)) {
|
||||||
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
||||||
authorized = a2dp.getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF;
|
authorized = a2dp.getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF;
|
||||||
if (authorized) {
|
if (authorized) {
|
||||||
|
Reference in New Issue
Block a user