summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java
diff options
context:
space:
mode:
authorJack He <siyuanh@google.com>2022-03-17 21:58:28 -0700
committerJack He <siyuanh@google.com>2022-03-18 02:26:14 -0700
commitee12f766d410a8d183bec4357626eadf591135ce (patch)
tree3ed7c9291c2be5d02afc1dc771fbd098d2d848b5 /framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java
parentb8918397ebc6422d6eed5b90a0306b5a4eaf3e3f (diff)
Broadcast: Strict argument checking for data structures
* Require @Nonnull elements to be not null when building or constructing objects * Enfore argument range Bug: 218683032 Test: make, cts Tag: #feature Change-Id: I53a6657323c9b93c971c9f43994a4a7c6b88e40d
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java b/framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java
index 676692ae4a..05f7f4a56d 100644
--- a/framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java
+++ b/framework/java/android/bluetooth/BluetoothLeBroadcastChannel.java
@@ -21,6 +21,8 @@ import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
+import java.util.Objects;
+
/**
* This class contains the Broadcast Isochronous Channel level information as defined in the BASE
* structure of the Basic Audio Profile.
@@ -168,11 +170,17 @@ public final class BluetoothLeBroadcastChannel implements Parcelable {
/**
* Set the Broadcast Isochronous Channel index of this Broadcast Channel.
*
- * @return Broadcast Isochronous Channel index
+ * @param channelIndex Broadcast Isochronous Channel index
+ * @throws IllegalArgumentException if the input argument is not valid
+ * @return this builder
* @hide
*/
@SystemApi
public @NonNull Builder setChannelIndex(int channelIndex) {
+ if (channelIndex == UNKNOWN_VALUE_PLACEHOLDER) {
+ throw new IllegalArgumentException("channelIndex cannot be "
+ + UNKNOWN_VALUE_PLACEHOLDER);
+ }
mChannelIndex = channelIndex;
return this;
}
@@ -181,12 +189,14 @@ public final class BluetoothLeBroadcastChannel implements Parcelable {
* Set the codec specific configuration for this Broadcast Channel.
*
* @param codecMetadata codec specific configuration for this Broadcast Channel
+ * @throws NullPointerException if codecMetadata is null
* @return this builder
* @hide
*/
@SystemApi
public @NonNull Builder setCodecMetadata(
@NonNull BluetoothLeAudioCodecConfigMetadata codecMetadata) {
+ Objects.requireNonNull(codecMetadata, "codecMetadata cannot be null");
mCodecMetadata = codecMetadata;
return this;
}
@@ -195,13 +205,16 @@ public final class BluetoothLeBroadcastChannel implements Parcelable {
* Build {@link BluetoothLeBroadcastChannel}.
*
* @return constructed {@link BluetoothLeBroadcastChannel}
+ * @throws NullPointerException if {@link NonNull} items are null
* @throws IllegalArgumentException if the object cannot be built
* @hide
*/
@SystemApi
public @NonNull BluetoothLeBroadcastChannel build() {
- if (mCodecMetadata == null) {
- throw new IllegalArgumentException("codec metadata cannot be null");
+ Objects.requireNonNull(mCodecMetadata, "codec metadata cannot be null");
+ if (mChannelIndex == UNKNOWN_VALUE_PLACEHOLDER) {
+ throw new IllegalArgumentException("mChannelIndex cannot be "
+ + UNKNOWN_VALUE_PLACEHOLDER);
}
return new BluetoothLeBroadcastChannel(mIsSelected, mChannelIndex, mCodecMetadata);
}