diff options
4 files changed, 27 insertions, 44 deletions
diff --git a/android/app/src/com/android/bluetooth/hap/HapClientService.java b/android/app/src/com/android/bluetooth/hap/HapClientService.java index 941ec29095..8d3494078c 100644 --- a/android/app/src/com/android/bluetooth/hap/HapClientService.java +++ b/android/app/src/com/android/bluetooth/hap/HapClientService.java @@ -22,6 +22,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED; import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission; +import android.annotation.Nullable; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHapClient; @@ -564,9 +565,9 @@ public class HapClientService extends ProfileService { * Gets the currently active preset info for a HA device * * @param device is the device for which we want to get the currently active preset info - * @return active preset info + * @return active preset info or null if not available */ - public BluetoothHapPresetInfo getActivePresetInfo(BluetoothDevice device) { + public @Nullable BluetoothHapPresetInfo getActivePresetInfo(BluetoothDevice device) { int index = getActivePresetIndex(device); if (index == BluetoothHapClient.PRESET_INDEX_UNAVAILABLE) return null; @@ -684,11 +685,10 @@ public class HapClientService extends ProfileService { * * @param device is the device for which we want to get the preset name * @param presetIndex is an index of one of the available presets - * @return a preset Info corresponding to the requested preset index + * @return a preset Info corresponding to the requested preset index or null if not available */ - public BluetoothHapPresetInfo getPresetInfo(BluetoothDevice device, int presetIndex) { - BluetoothHapPresetInfo defaultValue = new BluetoothHapPresetInfo.Builder().build(); - + public @Nullable BluetoothHapPresetInfo getPresetInfo(BluetoothDevice device, int presetIndex) { + BluetoothHapPresetInfo defaultValue = null; if (presetIndex == BluetoothHapClient.PRESET_INDEX_UNAVAILABLE) return defaultValue; List<BluetoothHapPresetInfo> current_presets = mPresetsMap.get(device); @@ -1400,7 +1400,7 @@ public class HapClientService extends ProfileService { public void getPresetInfo(BluetoothDevice device, int presetIndex, AttributionSource source, SynchronousResultReceiver receiver) { try { - BluetoothHapPresetInfo defaultValue = new BluetoothHapPresetInfo.Builder().build(); + BluetoothHapPresetInfo defaultValue = null; HapClientService service = getService(source); if (service != null) { defaultValue = service.getPresetInfo(device, presetIndex); diff --git a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java index 6d2f61b240..23361b0e6f 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/hap/HapClientTest.java @@ -746,9 +746,7 @@ public class HapClientTest { int info_reason = HapClientStackEvent.PRESET_INFO_REASON_PRESET_INFO_UPDATE; BluetoothHapPresetInfo[] info = - {new BluetoothHapPresetInfo.Builder() - .setIndex(0x01) - .setName("OneChangedToUnavailable") + {new BluetoothHapPresetInfo.Builder(0x01, "OneChangedToUnavailable") .setWritable(true) .setAvailable(false) .build()}; @@ -965,21 +963,15 @@ public class HapClientTest { // Inject some initial presets List<BluetoothHapPresetInfo> presets = new ArrayList<BluetoothHapPresetInfo>(Arrays.asList( - new BluetoothHapPresetInfo.Builder() - .setIndex(0x01) - .setName("One") + new BluetoothHapPresetInfo.Builder(0x01, "One") .setAvailable(true) .setWritable(false) .build(), - new BluetoothHapPresetInfo.Builder() - .setIndex(0x02) - .setName("Two") + new BluetoothHapPresetInfo.Builder(0x02, "Two") .setAvailable(true) .setWritable(true) .build(), - new BluetoothHapPresetInfo.Builder() - .setIndex(0x03) - .setName("Three") + new BluetoothHapPresetInfo.Builder(0x03, "Three") .setAvailable(false) .setWritable(false) .build())); diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt index b5045271a7..5a099afc2f 100644 --- a/framework/api/system-current.txt +++ b/framework/api/system-current.txt @@ -289,15 +289,6 @@ package android.bluetooth { field @NonNull public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothHapPresetInfo> CREATOR; } - public static final class BluetoothHapPresetInfo.Builder { - ctor public BluetoothHapPresetInfo.Builder(); - method @NonNull public android.bluetooth.BluetoothHapPresetInfo build(); - method @NonNull public android.bluetooth.BluetoothHapPresetInfo.Builder setAvailable(boolean); - method @NonNull public android.bluetooth.BluetoothHapPresetInfo.Builder setIndex(int); - method @NonNull public android.bluetooth.BluetoothHapPresetInfo.Builder setName(@NonNull String); - method @NonNull public android.bluetooth.BluetoothHapPresetInfo.Builder setWritable(boolean); - } - public final class BluetoothHeadset implements android.bluetooth.BluetoothProfile { method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean connect(android.bluetooth.BluetoothDevice); method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int connectAudio(); diff --git a/framework/java/android/bluetooth/BluetoothHapPresetInfo.java b/framework/java/android/bluetooth/BluetoothHapPresetInfo.java index 70fb54a3bb..fc5c877909 100644 --- a/framework/java/android/bluetooth/BluetoothHapPresetInfo.java +++ b/framework/java/android/bluetooth/BluetoothHapPresetInfo.java @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; +import android.text.TextUtils; /** * Represents the Hearing Access Profile preset. @@ -127,9 +128,10 @@ public final class BluetoothHapPresetInfo implements Parcelable { /** * Builder for {@link BluetoothHapPresetInfo}. - * <p> By default, the codec type will be set to + * <p> By default, the preset index will be set to * {@link BluetoothHapClient#PRESET_INDEX_UNAVAILABLE}, the name to an empty string, * writability and availability both to false. + * @hide */ public static final class Builder { private int mPresetIndex = BluetoothHapClient.PRESET_INDEX_UNAVAILABLE; @@ -138,25 +140,23 @@ public final class BluetoothHapPresetInfo implements Parcelable { private boolean mIsAvailable = false; /** - * Set preset index for HAP preset info. + * Creates a new builder. * - * @param index of this preset - * @return the same Builder instance + * @param index The preset index for HAP preset info + * @param name The preset name for HAP preset info */ - public @NonNull Builder setIndex(int index) { - mPresetIndex = index; - return this; - } + public Builder(int index, @NonNull String name) { + if (TextUtils.isEmpty(name)) { + throw new IllegalArgumentException("The size of the preset name for HAP shall be at" + + " least one character long."); + } + if (index < 0) { + throw new IllegalArgumentException( + "Preset index for HAP shall be a non-negative value."); + } - /** - * Set preset name for HAP preset info. - * - * @param name of this preset - * @return the same Builder instance - */ - public @NonNull Builder setName(@NonNull String name) { + mPresetIndex = index; mPresetName = name; - return this; } /** |