Merge "Fix auto connection priority handling." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
1bc3a407ce
@@ -71,7 +71,6 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
private final BluetoothService mBluetoothService;
|
private final BluetoothService mBluetoothService;
|
||||||
private final BluetoothAdapter mAdapter;
|
private final BluetoothAdapter mAdapter;
|
||||||
private int mTargetA2dpState;
|
private int mTargetA2dpState;
|
||||||
private boolean mAdjustedPriority = false;
|
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -326,7 +325,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
|
|
||||||
String path = mBluetoothService.getObjectPathFromAddress(device.getAddress());
|
String path = mBluetoothService.getObjectPathFromAddress(device.getAddress());
|
||||||
|
|
||||||
// State is DISCONNECTED
|
// State is DISCONNECTED and we are connecting.
|
||||||
|
if (getSinkPriority(device) < BluetoothA2dp.PRIORITY_AUTO_CONNECT) {
|
||||||
|
setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO_CONNECT);
|
||||||
|
}
|
||||||
handleSinkStateChange(device, state, BluetoothA2dp.STATE_CONNECTING);
|
handleSinkStateChange(device, state, BluetoothA2dp.STATE_CONNECTING);
|
||||||
|
|
||||||
if (!connectSinkNative(path)) {
|
if (!connectSinkNative(path)) {
|
||||||
@@ -491,14 +493,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
mTargetA2dpState = -1;
|
mTargetA2dpState = -1;
|
||||||
|
|
||||||
if (getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF &&
|
if (getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF &&
|
||||||
state == BluetoothA2dp.STATE_CONNECTING ||
|
|
||||||
state == BluetoothA2dp.STATE_CONNECTED) {
|
state == BluetoothA2dp.STATE_CONNECTED) {
|
||||||
// We have connected or attempting to connect.
|
// We have connected or attempting to connect.
|
||||||
// Bump priority
|
// Bump priority
|
||||||
setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO_CONNECT);
|
setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO_CONNECT);
|
||||||
}
|
|
||||||
|
|
||||||
if (state == BluetoothA2dp.STATE_CONNECTED) {
|
|
||||||
// We will only have 1 device with AUTO_CONNECT priority
|
// We will only have 1 device with AUTO_CONNECT priority
|
||||||
// To be backward compatible set everyone else to have PRIORITY_ON
|
// To be backward compatible set everyone else to have PRIORITY_ON
|
||||||
adjustOtherSinkPriorities(device);
|
adjustOtherSinkPriorities(device);
|
||||||
@@ -515,14 +513,11 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void adjustOtherSinkPriorities(BluetoothDevice connectedDevice) {
|
private void adjustOtherSinkPriorities(BluetoothDevice connectedDevice) {
|
||||||
if (!mAdjustedPriority) {
|
for (BluetoothDevice device : mAdapter.getBondedDevices()) {
|
||||||
for (BluetoothDevice device : mAdapter.getBondedDevices()) {
|
if (getSinkPriority(device) >= BluetoothA2dp.PRIORITY_AUTO_CONNECT &&
|
||||||
if (getSinkPriority(device) >= BluetoothA2dp.PRIORITY_AUTO_CONNECT &&
|
!device.equals(connectedDevice)) {
|
||||||
!device.equals(connectedDevice)) {
|
setSinkPriority(device, BluetoothA2dp.PRIORITY_ON);
|
||||||
setSinkPriority(device, BluetoothA2dp.PRIORITY_ON);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mAdjustedPriority = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user