Update supported profiles for voice capability.
Change-Id: If12f97ccc5d7d54d8d3e470dd4bc91fe9119b9cd
This commit is contained in:
@@ -25,6 +25,7 @@ import android.app.AlertDialog;
|
|||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@@ -584,42 +585,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.e(TAG, "updating profiles for " + mDevice.getName());
|
Log.e(TAG, "updating profiles for " + mDevice.getName());
|
||||||
|
|
||||||
boolean printUuids = true;
|
|
||||||
BluetoothClass bluetoothClass = mDevice.getBluetoothClass();
|
BluetoothClass bluetoothClass = mDevice.getBluetoothClass();
|
||||||
|
|
||||||
if (bluetoothClass != null) {
|
if (bluetoothClass != null) Log.v(TAG, "Class: " + bluetoothClass.toString());
|
||||||
if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET) !=
|
Log.v(TAG, "UUID:");
|
||||||
mProfiles.contains(Profile.HEADSET)) {
|
for (int i = 0; i < uuids.length; i++) {
|
||||||
Log.v(TAG, "headset classbits != uuid");
|
Log.v(TAG, " " + uuids[i]);
|
||||||
printUuids = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_A2DP) !=
|
|
||||||
mProfiles.contains(Profile.A2DP)) {
|
|
||||||
Log.v(TAG, "a2dp classbits != uuid");
|
|
||||||
printUuids = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_OPP) !=
|
|
||||||
mProfiles.contains(Profile.OPP)) {
|
|
||||||
Log.v(TAG, "opp classbits != uuid");
|
|
||||||
printUuids = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_HID) !=
|
|
||||||
mProfiles.contains(Profile.HID)) {
|
|
||||||
Log.v(TAG, "hid classbits != uuid");
|
|
||||||
printUuids = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (printUuids) {
|
|
||||||
if (bluetoothClass != null) Log.v(TAG, "Class: " + bluetoothClass.toString());
|
|
||||||
Log.v(TAG, "UUID:");
|
|
||||||
for (int i = 0; i < uuids.length; i++) {
|
|
||||||
Log.v(TAG, " " + uuids[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@@ -26,13 +26,13 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.ParcelUuid;
|
||||||
import android.util.Config;
|
import android.util.Config;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
// TODO: have some notion of shutting down. Maybe a minute after they leave BT settings?
|
// TODO: have some notion of shutting down. Maybe a minute after they leave BT settings?
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +48,6 @@ public class LocalBluetoothManager {
|
|||||||
|
|
||||||
/** Singleton instance. */
|
/** Singleton instance. */
|
||||||
private static LocalBluetoothManager sInstance;
|
private static LocalBluetoothManager sInstance;
|
||||||
private boolean mInitialized;
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
/** If a BT-related activity is in the foreground, this will be it. */
|
/** If a BT-related activity is in the foreground, this will be it. */
|
||||||
@@ -89,22 +88,17 @@ public class LocalBluetoothManager {
|
|||||||
synchronized (LocalBluetoothManager.class) {
|
synchronized (LocalBluetoothManager.class) {
|
||||||
if (sInstance == null) {
|
if (sInstance == null) {
|
||||||
sInstance = new LocalBluetoothManager();
|
sInstance = new LocalBluetoothManager();
|
||||||
|
if (!sInstance.init(context)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
LocalBluetoothProfileManager.init(sInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sInstance.init(context)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalBluetoothProfileManager.init(sInstance);
|
|
||||||
|
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean init(Context context) {
|
private boolean init(Context context) {
|
||||||
if (mInitialized) return true;
|
|
||||||
mInitialized = true;
|
|
||||||
|
|
||||||
// This will be around as long as this process is
|
// This will be around as long as this process is
|
||||||
mContext = context.getApplicationContext();
|
mContext = context.getApplicationContext();
|
||||||
|
|
||||||
@@ -226,6 +220,12 @@ public class LocalBluetoothManager {
|
|||||||
|
|
||||||
void setBluetoothStateInt(int state) {
|
void setBluetoothStateInt(int state) {
|
||||||
mState = state;
|
mState = state;
|
||||||
|
|
||||||
|
if (state == BluetoothAdapter.STATE_ON) {
|
||||||
|
ParcelUuid[] uuids = mAdapter.getUuids();
|
||||||
|
LocalBluetoothProfileManager.updateLocalProfiles(getInstance(mContext), uuids);
|
||||||
|
}
|
||||||
|
|
||||||
if (state == BluetoothAdapter.STATE_ON ||
|
if (state == BluetoothAdapter.STATE_ON ||
|
||||||
state == BluetoothAdapter.STATE_OFF) {
|
state == BluetoothAdapter.STATE_OFF) {
|
||||||
mCachedDeviceManager.onBluetoothStateChanged(state ==
|
mCachedDeviceManager.onBluetoothStateChanged(state ==
|
||||||
|
@@ -121,6 +121,30 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(): Combine the init and updateLocalProfiles codes.
|
||||||
|
// init can get called from various paths, it makes no sense to add and then delete.
|
||||||
|
public static void updateLocalProfiles(LocalBluetoothManager localManager, ParcelUuid[] uuids) {
|
||||||
|
if (!BluetoothUuid.containsAnyUuid(uuids, HEADSET_PROFILE_UUIDS)) {
|
||||||
|
sProfileMap.remove(Profile.HEADSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BluetoothUuid.containsAnyUuid(uuids, A2DP_PROFILE_UUIDS)) {
|
||||||
|
sProfileMap.remove(Profile.A2DP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) {
|
||||||
|
sProfileMap.remove(Profile.OPP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BluetoothUuid.containsAnyUuid(uuids, HID_PROFILE_UUIDS)) {
|
||||||
|
sProfileMap.remove(Profile.HID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS)) {
|
||||||
|
sProfileMap.remove(Profile.PAN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static LinkedList<ServiceListener> mServiceListeners =
|
private static LinkedList<ServiceListener> mServiceListeners =
|
||||||
new LinkedList<ServiceListener>();
|
new LinkedList<ServiceListener>();
|
||||||
|
|
||||||
@@ -171,23 +195,28 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BluetoothUuid.containsAnyUuid(uuids, HEADSET_PROFILE_UUIDS)) {
|
if (BluetoothUuid.containsAnyUuid(uuids, HEADSET_PROFILE_UUIDS) &&
|
||||||
|
sProfileMap.containsKey(Profile.HEADSET)) {
|
||||||
profiles.add(Profile.HEADSET);
|
profiles.add(Profile.HEADSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BluetoothUuid.containsAnyUuid(uuids, A2DP_PROFILE_UUIDS)) {
|
if (BluetoothUuid.containsAnyUuid(uuids, A2DP_PROFILE_UUIDS) &&
|
||||||
|
sProfileMap.containsKey(Profile.A2DP)) {
|
||||||
profiles.add(Profile.A2DP);
|
profiles.add(Profile.A2DP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) {
|
if (BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS) &&
|
||||||
|
sProfileMap.containsKey(Profile.OPP)) {
|
||||||
profiles.add(Profile.OPP);
|
profiles.add(Profile.OPP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BluetoothUuid.containsAnyUuid(uuids, HID_PROFILE_UUIDS)) {
|
if (BluetoothUuid.containsAnyUuid(uuids, HID_PROFILE_UUIDS) &&
|
||||||
|
sProfileMap.containsKey(Profile.HID)) {
|
||||||
profiles.add(Profile.HID);
|
profiles.add(Profile.HID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS)) {
|
if (BluetoothUuid.containsAnyUuid(uuids, PANU_PROFILE_UUIDS) &&
|
||||||
|
sProfileMap.containsKey(Profile.PAN)) {
|
||||||
profiles.add(Profile.PAN);
|
profiles.add(Profile.PAN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user