b/2293042 Fixed the problem where A2DP connections may fail if there's an existing connection to another device.

Change-Id: I1b4963a167b633c0905e2719ab3f651ff8be9f2c
This commit is contained in:
Michael Chan
2009-12-03 00:25:29 -08:00
parent 9f1d9c1688
commit 3327f78873
2 changed files with 45 additions and 3 deletions

View File

@@ -41,6 +41,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
/**
* CachedBluetoothDevice represents a remote Bluetooth device. It contains
@@ -401,6 +402,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
.getProfileManager(mLocalManager, profile);
if (profileManager.isPreferred(mDevice)) {
++preferredProfiles;
disconnectConnected(profile);
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
}
}
@@ -423,6 +425,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
.getProfileManager(mLocalManager, profile);
profileManager.setPreferred(mDevice, false);
disconnectConnected(profile);
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
}
}
@@ -432,9 +435,24 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
mConnectAttempted = SystemClock.elapsedRealtime();
// Reset the only-show-one-error-dialog tracking variable
mIsConnectingErrorPossible = true;
disconnectConnected(profile);
queueCommand(new BluetoothJob(BluetoothCommand.CONNECT, this, profile));
}
private void disconnectConnected(Profile profile) {
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
CachedBluetoothDeviceManager cachedDeviceManager = mLocalManager.getCachedDeviceManager();
Set<BluetoothDevice> devices = profileManager.getConnectedDevices();
if (devices == null) return;
for (BluetoothDevice device : devices) {
CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(device);
if (cachedDevice != null) {
queueCommand(new BluetoothJob(BluetoothCommand.DISCONNECT, cachedDevice, profile));
}
}
}
private boolean connectInt(CachedBluetoothDevice cachedDevice, Profile profile) {
if (!cachedDevice.ensurePaired()) return false;

View File

@@ -16,17 +16,18 @@
package com.android.settings.bluetooth;
import com.android.settings.R;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothUuid;
import android.os.ParcelUuid;
import android.os.Handler;
import android.os.ParcelUuid;
import android.util.Log;
import com.android.settings.R;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -121,6 +122,8 @@ public abstract class LocalBluetoothProfileManager {
mLocalManager = localManager;
}
public abstract Set<BluetoothDevice> getConnectedDevices();
public abstract boolean connect(BluetoothDevice device);
public abstract boolean disconnect(BluetoothDevice device);
@@ -163,6 +166,11 @@ public abstract class LocalBluetoothProfileManager {
mService = new BluetoothA2dp(localManager.getContext());
}
@Override
public Set<BluetoothDevice> getConnectedDevices() {
return mService.getConnectedSinks();
}
@Override
public boolean connect(BluetoothDevice device) {
Set<BluetoothDevice> sinks = mService.getConnectedSinks();
@@ -260,6 +268,17 @@ public abstract class LocalBluetoothProfileManager {
public void onServiceDisconnected() {
}
@Override
public Set<BluetoothDevice> getConnectedDevices() {
Set<BluetoothDevice> devices = null;
BluetoothDevice device = mService.getCurrentHeadset();
if (device != null) {
devices = new HashSet<BluetoothDevice>();
devices.add(device);
}
return devices;
}
@Override
public boolean connect(BluetoothDevice device) {
// Since connectHeadset fails if already connected to a headset, we
@@ -333,6 +352,11 @@ public abstract class LocalBluetoothProfileManager {
super(localManager);
}
@Override
public Set<BluetoothDevice> getConnectedDevices() {
return null;
}
@Override
public boolean connect(BluetoothDevice device) {
return false;