Add ability to connect to only headset profile.

Fix some SDP records issues.

Change-Id: I42816527b1ae0749b4b59b7947f1acb9d2e6f001
This commit is contained in:
Jaikumar Ganesh
2010-12-10 17:51:52 -08:00
parent 7553ebea45
commit 498d12bac0
3 changed files with 30 additions and 16 deletions

View File

@@ -353,7 +353,7 @@ public class BluetoothSettings extends SettingsPreferenceFragment
case BluetoothDevicePicker.FILTER_TYPE_AUDIO: case BluetoothDevicePicker.FILTER_TYPE_AUDIO:
if (uuids != null) { if (uuids != null) {
if (BluetoothUuid.containsAnyUuid(uuids, if (BluetoothUuid.containsAnyUuid(uuids,
LocalBluetoothProfileManager.A2DP_PROFILE_UUIDS)) return true; LocalBluetoothProfileManager.A2DP_SINK_PROFILE_UUIDS)) return true;
if (BluetoothUuid.containsAnyUuid(uuids, if (BluetoothUuid.containsAnyUuid(uuids,
LocalBluetoothProfileManager.HEADSET_PROFILE_UUIDS)) return true; LocalBluetoothProfileManager.HEADSET_PROFILE_UUIDS)) return true;

View File

@@ -589,7 +589,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
ParcelUuid[] uuids = mDevice.getUuids(); ParcelUuid[] uuids = mDevice.getUuids();
if (uuids == null) return false; if (uuids == null) return false;
LocalBluetoothProfileManager.updateProfiles(uuids, mProfiles); BluetoothAdapter adapter = mLocalManager.getBluetoothAdapter();
ParcelUuid[] localUuids = adapter.getUuids();
if (localUuids == null) return false;
LocalBluetoothProfileManager.updateProfiles(uuids, localUuids, mProfiles);
if (DEBUG) { if (DEBUG) {
Log.e(TAG, "updating profiles for " + mDevice.getName()); Log.e(TAG, "updating profiles for " + mDevice.getName());

View File

@@ -48,11 +48,15 @@ public abstract class LocalBluetoothProfileManager {
BluetoothUuid.Handsfree, BluetoothUuid.Handsfree,
}; };
/* package */ static final ParcelUuid[] A2DP_PROFILE_UUIDS = new ParcelUuid[] { /* package */ static final ParcelUuid[] A2DP_SINK_PROFILE_UUIDS = new ParcelUuid[] {
BluetoothUuid.AudioSink, BluetoothUuid.AudioSink,
BluetoothUuid.AdvAudioDist, BluetoothUuid.AdvAudioDist,
}; };
/* package */ static final ParcelUuid[] A2DP_SRC_PROFILE_UUIDS = new ParcelUuid[] {
BluetoothUuid.AudioSource
};
/* package */ static final ParcelUuid[] OPP_PROFILE_UUIDS = new ParcelUuid[] { /* package */ static final ParcelUuid[] OPP_PROFILE_UUIDS = new ParcelUuid[] {
BluetoothUuid.ObexObjectPush BluetoothUuid.ObexObjectPush
}; };
@@ -124,25 +128,24 @@ public abstract class LocalBluetoothProfileManager {
// TODO(): Combine the init and updateLocalProfiles codes. // TODO(): Combine the init and updateLocalProfiles codes.
// init can get called from various paths, it makes no sense to add and then delete. // init can get called from various paths, it makes no sense to add and then delete.
public static void updateLocalProfiles(LocalBluetoothManager localManager, ParcelUuid[] uuids) { public static void updateLocalProfiles(LocalBluetoothManager localManager, ParcelUuid[] uuids) {
if (!BluetoothUuid.containsAnyUuid(uuids, HEADSET_PROFILE_UUIDS)) { if (!BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree_AG) &&
!BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HSP_AG)) {
sProfileMap.remove(Profile.HEADSET); sProfileMap.remove(Profile.HEADSET);
} }
if (BluetoothUuid.containsAnyUuid(uuids, A2DP_PROFILE_UUIDS)) { if (!BluetoothUuid.containsAnyUuid(uuids, A2DP_SRC_PROFILE_UUIDS)) {
sProfileMap.remove(Profile.A2DP); sProfileMap.remove(Profile.A2DP);
} }
if (BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) { if (!BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) {
sProfileMap.remove(Profile.OPP); sProfileMap.remove(Profile.OPP);
} }
if (BluetoothUuid.containsAnyUuid(uuids, HID_PROFILE_UUIDS)) { if (!BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS)) {
sProfileMap.remove(Profile.HID);
}
if (BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS)) {
sProfileMap.remove(Profile.PAN); sProfileMap.remove(Profile.PAN);
} }
// There is no local SDP record for HID and Settings app doesn't control PBAP
} }
private static LinkedList<ServiceListener> mServiceListeners = private static LinkedList<ServiceListener> mServiceListeners =
@@ -186,21 +189,28 @@ public abstract class LocalBluetoothProfileManager {
* NOTE: This list happens to define the connection order. We should put this logic in a more * NOTE: This list happens to define the connection order. We should put this logic in a more
* well known place when this method is no longer temporary. * well known place when this method is no longer temporary.
* @param uuids of the remote device * @param uuids of the remote device
* @param localUuids UUIDs of the local device
* @param profiles The list of profiles to fill * @param profiles The list of profiles to fill
*/ */
public static void updateProfiles(ParcelUuid[] uuids, List<Profile> profiles) { public static void updateProfiles(ParcelUuid[] uuids, ParcelUuid[] localUuids,
List<Profile> profiles) {
profiles.clear(); profiles.clear();
if (uuids == null) { if (uuids == null) {
return; return;
} }
if (BluetoothUuid.containsAnyUuid(uuids, HEADSET_PROFILE_UUIDS) && if (sProfileMap.containsKey(Profile.HEADSET)) {
sProfileMap.containsKey(Profile.HEADSET)) { if ((BluetoothUuid.isUuidPresent(localUuids, BluetoothUuid.HSP_AG) &&
profiles.add(Profile.HEADSET); BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HSP)) ||
(BluetoothUuid.isUuidPresent(localUuids, BluetoothUuid.Handsfree_AG) &&
BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Handsfree))) {
profiles.add(Profile.HEADSET);
}
} }
if (BluetoothUuid.containsAnyUuid(uuids, A2DP_PROFILE_UUIDS) &&
if (BluetoothUuid.containsAnyUuid(uuids, A2DP_SINK_PROFILE_UUIDS) &&
sProfileMap.containsKey(Profile.A2DP)) { sProfileMap.containsKey(Profile.A2DP)) {
profiles.add(Profile.A2DP); profiles.add(Profile.A2DP);
} }