diff --git a/core/api/current.txt b/core/api/current.txt index 20f318dc29cad..6a79153c628d8 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -9014,11 +9014,15 @@ package android.bluetooth { public final class BluetoothClass implements android.os.Parcelable { method public int describeContents(); + method public boolean doesClassMatch(int); method public int getDeviceClass(); method public int getMajorDeviceClass(); method public boolean hasService(int); method public void writeToParcel(android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator CREATOR; + field public static final int PROFILE_A2DP = 1; // 0x1 + field public static final int PROFILE_HEADSET = 0; // 0x0 + field public static final int PROFILE_HID = 3; // 0x3 } public static class BluetoothClass.Device { diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 28917351801fa..c754bc5fdcd33 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -2016,6 +2016,13 @@ package android.bluetooth { method public void onOobData(int, @NonNull android.bluetooth.OobData); } + public final class BluetoothClass implements android.os.Parcelable { + field public static final int PROFILE_A2DP_SINK = 6; // 0x6 + field public static final int PROFILE_NAP = 5; // 0x5 + field public static final int PROFILE_OPP = 2; // 0x2 + field public static final int PROFILE_PANU = 4; // 0x4 + } + public final class BluetoothCsipSetCoordinator implements java.lang.AutoCloseable android.bluetooth.BluetoothProfile { method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public java.util.List getAllGroupIds(@Nullable android.os.ParcelUuid); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice); diff --git a/core/java/android/bluetooth/BluetoothClass.java b/core/java/android/bluetooth/BluetoothClass.java index 7fe18a0704ba1..69525b543478c 100755 --- a/core/java/android/bluetooth/BluetoothClass.java +++ b/core/java/android/bluetooth/BluetoothClass.java @@ -17,6 +17,7 @@ package android.bluetooth; import android.annotation.Nullable; +import android.annotation.SystemApi; import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; @@ -327,21 +328,26 @@ public final class BluetoothClass implements Parcelable { return Arrays.copyOfRange(bytes, 1, bytes.length); } - /** @hide */ - @UnsupportedAppUsage public static final int PROFILE_HEADSET = 0; - /** @hide */ - @UnsupportedAppUsage + public static final int PROFILE_A2DP = 1; + /** @hide */ + @SystemApi public static final int PROFILE_OPP = 2; - /** @hide */ + public static final int PROFILE_HID = 3; + /** @hide */ + @SystemApi public static final int PROFILE_PANU = 4; + /** @hide */ + @SystemApi public static final int PROFILE_NAP = 5; + /** @hide */ + @SystemApi public static final int PROFILE_A2DP_SINK = 6; /** @@ -350,11 +356,9 @@ public final class BluetoothClass implements Parcelable { * given class bits might support specified profile. It is not accurate for all * devices. It tries to err on the side of false positives. * - * @param profile The profile to be checked - * @return True if this device might support specified profile. - * @hide + * @param profile the profile to be checked + * @return whether this device supports specified profile */ - @UnsupportedAppUsage public boolean doesClassMatch(int profile) { if (profile == PROFILE_A2DP) { if (hasService(Service.RENDER)) { diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDeviceFilter.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDeviceFilter.java index b8ad321d6dd30..0b436a9a8df5a 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDeviceFilter.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothDeviceFilter.java @@ -16,6 +16,7 @@ package com.android.settingslib.bluetooth; +import android.annotation.SuppressLint; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothUuid; @@ -118,8 +119,8 @@ public final class BluetoothDeviceFilter { return true; } } else if (btClass != null) { - if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP) || - btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) { + if (doesClassMatch(btClass, BluetoothClass.PROFILE_A2DP) + || doesClassMatch(btClass, BluetoothClass.PROFILE_HEADSET)) { return true; } } @@ -137,7 +138,7 @@ public final class BluetoothDeviceFilter { } } return btClass != null - && btClass.doesClassMatch(BluetoothClass.PROFILE_OPP); + && doesClassMatch(btClass, BluetoothClass.PROFILE_OPP); } } @@ -151,7 +152,7 @@ public final class BluetoothDeviceFilter { } } return btClass != null - && btClass.doesClassMatch(BluetoothClass.PROFILE_PANU); + && doesClassMatch(btClass, BluetoothClass.PROFILE_PANU); } } @@ -165,7 +166,12 @@ public final class BluetoothDeviceFilter { } } return btClass != null - && btClass.doesClassMatch(BluetoothClass.PROFILE_NAP); + && doesClassMatch(btClass, BluetoothClass.PROFILE_NAP); } } + + @SuppressLint("NewApi") // Hidden API made public + private static boolean doesClassMatch(BluetoothClass btClass, int classId) { + return btClass.doesClassMatch(classId); + } } diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java index 253629c8d1282..c9af4d53f9a83 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java @@ -2,6 +2,7 @@ package com.android.settingslib.bluetooth; import static com.android.settingslib.widget.AdaptiveOutlineDrawable.ICON_TYPE_ADVANCED; +import android.annotation.SuppressLint; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; @@ -70,6 +71,12 @@ public class BluetoothUtils { void onShowError(Context context, String name, int messageResId); } + /** + * @param context to access resources from + * @param cachedDevice to get class from + * @return pair containing the drawable and the description of the Bluetooth class + * of the device. + */ public static Pair getBtClassDrawableWithDescription(Context context, CachedBluetoothDevice cachedDevice) { BluetoothClass btClass = cachedDevice.getBtClass(); @@ -110,13 +117,13 @@ public class BluetoothUtils { } } if (btClass != null) { - if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) { + if (doesClassMatch(btClass, BluetoothClass.PROFILE_HEADSET)) { return new Pair<>( getBluetoothDrawable(context, com.android.internal.R.drawable.ic_bt_headset_hfp), context.getString(R.string.bluetooth_talkback_headset)); } - if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) { + if (doesClassMatch(btClass, BluetoothClass.PROFILE_A2DP)) { return new Pair<>( getBluetoothDrawable(context, com.android.internal.R.drawable.ic_bt_headphones_a2dp), @@ -376,4 +383,9 @@ public class BluetoothUtils { } return Uri.parse(data); } + + @SuppressLint("NewApi") // Hidden API made public + private static boolean doesClassMatch(BluetoothClass btClass, int classId) { + return btClass.doesClassMatch(classId); + } }