diff options
| author | 2016-11-01 23:20:16 +0000 | |
|---|---|---|
| committer | 2016-11-01 23:20:16 +0000 | |
| commit | 6f84631d8da968ec09e14d75622c53abec9fa300 (patch) | |
| tree | 2825f9e4e779a0148e366eb0ca763496e5739feb | |
| parent | fdfc79a8788aefe7a26d54a85c14398602811165 (diff) | |
| parent | 0a86c936a6490064d8cbd99d5f11e17473a04e22 (diff) | |
Merge "Add a way to query for supported Bluetooth profiles."
am: 0a86c936a6
Change-Id: Id10ad10a5dbcab92e390a7a245772d2b551ad30c
| -rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 30 | ||||
| -rw-r--r-- | core/java/android/bluetooth/BluetoothProfile.java | 7 | ||||
| -rw-r--r-- | core/java/android/bluetooth/IBluetooth.aidl | 1 |
3 files changed, 38 insertions, 0 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index acdbe5e5c471..b4a6495b1a4b 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -1492,6 +1492,36 @@ public final class BluetoothAdapter { } /** + * Gets the currently supported profiles by the adapter. + * + *<p> This can be used to check whether a profile is supported before attempting + * to connect to its respective proxy. + * + * @return a list of integers indicating the ids of supported profiles as defined in + * {@link BluetoothProfile}. + * @hide + */ + public List<Integer> getSupportedProfiles() { + final ArrayList<Integer> supportedProfiles = new ArrayList<Integer>(); + + try { + synchronized (mManagerCallback) { + if (mService != null) { + final long supportedProfilesBitMask = mService.getSupportedProfiles(); + + for (int i = 0; i <= BluetoothProfile.MAX_PROFILE_ID; i++) { + if ((supportedProfilesBitMask & (1 << i)) != 0) { + supportedProfiles.add(i); + } + } + } + } + } catch (RemoteException e) {Log.e(TAG, "getSupportedProfiles:", e);} + + return supportedProfiles; + } + + /** * Get the current connection state of the local Bluetooth adapter. * This can be used to check whether the local Bluetooth adapter is connected * to any profile of any other remote Bluetooth Device. diff --git a/core/java/android/bluetooth/BluetoothProfile.java b/core/java/android/bluetooth/BluetoothProfile.java index eee66d193fe4..20d95ccc3835 100644 --- a/core/java/android/bluetooth/BluetoothProfile.java +++ b/core/java/android/bluetooth/BluetoothProfile.java @@ -137,6 +137,13 @@ public interface BluetoothProfile { public static final int PBAP_CLIENT = 17; /** + * Max profile ID. This value should be updated whenever a new profile is added to match + * the largest value assigned to a profile. + * @hide + */ + public static final int MAX_PROFILE_ID = 17; + + /** * Default priority for devices that we try to auto-connect to and * and allow incoming connections for the profile * @hide diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl index 8c985364f6ab..96a1ae8b9455 100644 --- a/core/java/android/bluetooth/IBluetooth.aidl +++ b/core/java/android/bluetooth/IBluetooth.aidl @@ -63,6 +63,7 @@ interface IBluetooth boolean removeBond(in BluetoothDevice device); int getBondState(in BluetoothDevice device); boolean isBondingInitiatedLocally(in BluetoothDevice device); + long getSupportedProfiles(); int getConnectionState(in BluetoothDevice device); String getRemoteName(in BluetoothDevice device); |