Auto connect hf/a2dp

Change-Id: I4cb260a1f794c2e094a0b19bdc1df919c4287232
This commit is contained in:
Swaminatha Balaji
2012-04-27 09:18:38 -07:00
committed by Matthew Xie
parent 83b0d575dd
commit 2ac143fff7
4 changed files with 109 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* LocalBluetoothProfileManager provides access to the LocalBluetoothProfile
@@ -77,6 +78,8 @@ final class LocalBluetoothProfileManager {
private final HidProfile mHidProfile;
private OppProfile mOppProfile;
private final PanProfile mPanProfile;
private boolean isHfServiceUp;
private boolean isA2dpServiceUp;
/**
* Mapping from profile name, e.g. "HEADSET" to profile object.
@@ -128,7 +131,7 @@ final class LocalBluetoothProfileManager {
if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.AudioSource)) {
if (mA2dpProfile == null) {
Log.d(TAG, "Adding local A2DP profile");
mA2dpProfile = new A2dpProfile(mContext);
mA2dpProfile = new A2dpProfile(mContext, this);
addProfile(mA2dpProfile, A2dpProfile.NAME,
BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
}
@@ -264,6 +267,51 @@ final class LocalBluetoothProfileManager {
}
}
synchronized void setHfServiceUp(boolean isUp) {
isHfServiceUp = isUp;
if (isHfServiceUp && isA2dpServiceUp) {
// connect hf and then a2dp
// this order is maintained as per the white paper
handleAutoConnect(mHeadsetProfile);
handleAutoConnect(mA2dpProfile);
}
}
synchronized void setA2dpServiceUp(boolean isUp) {
isA2dpServiceUp= isUp;
if (isHfServiceUp && isA2dpServiceUp) {
// connect hf and then a2dp
// this order is maintained as per the white paper
handleAutoConnect(mHeadsetProfile);
handleAutoConnect(mA2dpProfile);
}
}
private void handleAutoConnect(LocalBluetoothProfile profile) {
Set<BluetoothDevice> bondedDevices = mLocalAdapter.getBondedDevices();
for (BluetoothDevice device : bondedDevices) {
if (profile.getPreferred(device) ==
BluetoothProfile.PRIORITY_AUTO_CONNECT) {
Log.d(TAG,"handleAutoConnect for device");
CachedBluetoothDevice cacheDevice = mDeviceManager.findDevice(device);
if (null != cacheDevice) {
cacheDevice.connectInt(profile);
break;
}
else
Log.e(TAG,"Bluetooth cache devices mismatch with actual");
}
}
}
public void enableAutoConnectForHf(BluetoothDevice device,boolean enable) {
mHeadsetProfile.enableAutoConnect(device,enable);
}
public void enableAutoConnectForA2dp(BluetoothDevice device,boolean enable) {
mA2dpProfile.enableAutoConnect(device,enable);
}
// This is called by DockService, so check Headset and A2DP.
public synchronized boolean isManagerReady() {
// Getting just the headset profile is fine for now. Will need to deal with A2DP