Merge "Made BluetoothClass#doesClassMatch public."

This commit is contained in:
Etienne Ruffieux
2021-11-30 09:08:48 +00:00
committed by Android (Google) Code Review
5 changed files with 49 additions and 16 deletions

View File

@@ -9037,11 +9037,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<android.bluetooth.BluetoothClass> 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 {

View File

@@ -2024,6 +2024,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<java.lang.Integer> getAllGroupIds(@Nullable android.os.ParcelUuid);
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);

View File

@@ -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)) {

View File

@@ -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);
}
}

View File

@@ -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<Drawable, String> 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);
}
}