1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.bluetooth; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SystemApi; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 import java.util.Objects; 29 30 /** 31 * This class contains the subgroup settings information for this Broadcast Subgroup. 32 * 33 * @hide 34 */ 35 @SystemApi 36 public final class BluetoothLeBroadcastSubgroupSettings implements Parcelable { 37 private final @Quality int mPreferredQuality; 38 private final BluetoothLeAudioContentMetadata mContentMetadata; 39 40 /** 41 * Audio quality for this broadcast subgroup 42 * 43 * <p>Audio quality for this broadcast subgroup. 44 * 45 * @hide 46 */ 47 @IntDef( 48 prefix = "QUALITY_", 49 value = { 50 QUALITY_STANDARD, 51 QUALITY_HIGH, 52 }) 53 @Retention(RetentionPolicy.SOURCE) 54 public @interface Quality {} 55 56 /** 57 * Indicates standard quality for this subgroup audio configuration. 58 * 59 * @hide 60 */ 61 @SystemApi public static final int QUALITY_STANDARD = 0; 62 63 /** 64 * Indicates high quality for this subgroup audio configuration. 65 * 66 * @hide 67 */ 68 @SystemApi public static final int QUALITY_HIGH = 1; 69 BluetoothLeBroadcastSubgroupSettings( int preferredQuality, BluetoothLeAudioContentMetadata contentMetadata)70 private BluetoothLeBroadcastSubgroupSettings( 71 int preferredQuality, BluetoothLeAudioContentMetadata contentMetadata) { 72 mPreferredQuality = preferredQuality; 73 mContentMetadata = contentMetadata; 74 } 75 76 @Override equals(@ullable Object o)77 public boolean equals(@Nullable Object o) { 78 if (!(o instanceof BluetoothLeBroadcastSubgroupSettings)) { 79 return false; 80 } 81 final BluetoothLeBroadcastSubgroupSettings other = (BluetoothLeBroadcastSubgroupSettings) o; 82 return mPreferredQuality == other.getPreferredQuality() 83 && mContentMetadata.equals(other.getContentMetadata()); 84 } 85 86 @Override hashCode()87 public int hashCode() { 88 return Objects.hash(mPreferredQuality, mContentMetadata); 89 } 90 91 /** 92 * Get content metadata for this Broadcast Source subgroup. 93 * 94 * @return content metadata for this Broadcast Source subgroup 95 * @hide 96 */ 97 @SystemApi 98 @NonNull getContentMetadata()99 public BluetoothLeAudioContentMetadata getContentMetadata() { 100 return mContentMetadata; 101 } 102 103 /** 104 * Get preferred audio quality for this Broadcast Source subgroup. 105 * 106 * @return preferred audio quality for this Broadcast Source subgroup 107 * @hide 108 */ 109 @SystemApi getPreferredQuality()110 public @Quality int getPreferredQuality() { 111 return mPreferredQuality; 112 } 113 114 /** 115 * {@inheritDoc} 116 * 117 * @hide 118 */ 119 @Override describeContents()120 public int describeContents() { 121 return 0; 122 } 123 124 /** 125 * {@inheritDoc} 126 * 127 * @hide 128 */ 129 @Override writeToParcel(Parcel out, int flags)130 public void writeToParcel(Parcel out, int flags) { 131 out.writeInt(mPreferredQuality); 132 out.writeTypedObject(mContentMetadata, 0); 133 } 134 135 /** 136 * A {@link Parcelable.Creator} to create {@link BluetoothLeBroadcastSubgroupSettings} from 137 * parcel. 138 * 139 * @hide 140 */ 141 @SystemApi @NonNull 142 public static final Creator<BluetoothLeBroadcastSubgroupSettings> CREATOR = 143 new Creator<>() { 144 public @NonNull BluetoothLeBroadcastSubgroupSettings createFromParcel( 145 @NonNull Parcel in) { 146 Builder builder = new Builder(); 147 builder.setPreferredQuality(in.readInt()); 148 builder.setContentMetadata( 149 in.readTypedObject(BluetoothLeAudioContentMetadata.CREATOR)); 150 return builder.build(); 151 } 152 153 public @NonNull BluetoothLeBroadcastSubgroupSettings[] newArray(int size) { 154 return new BluetoothLeBroadcastSubgroupSettings[size]; 155 } 156 }; 157 158 /** 159 * Builder for {@link BluetoothLeBroadcastSubgroupSettings}. 160 * 161 * @hide 162 */ 163 @SystemApi 164 public static final class Builder { 165 private BluetoothLeAudioContentMetadata mContentMetadata = null; 166 private @Quality int mPreferredQuality = QUALITY_STANDARD; 167 168 /** 169 * Create an empty constructor. 170 * 171 * @hide 172 */ 173 @SystemApi Builder()174 public Builder() {} 175 176 /** 177 * Create a builder with copies of information from original object. 178 * 179 * @param original original object 180 * @hide 181 */ 182 @SystemApi Builder(@onNull BluetoothLeBroadcastSubgroupSettings original)183 public Builder(@NonNull BluetoothLeBroadcastSubgroupSettings original) { 184 mPreferredQuality = original.getPreferredQuality(); 185 mContentMetadata = original.getContentMetadata(); 186 } 187 188 /** 189 * Set preferred audio quality for this Broadcast Source subgroup. 190 * 191 * @param preferredQuality audio quality for this Broadcast Source subgroup 192 * @return this builder 193 * @hide 194 */ 195 @SystemApi 196 @NonNull setPreferredQuality(@uality int preferredQuality)197 public Builder setPreferredQuality(@Quality int preferredQuality) { 198 mPreferredQuality = preferredQuality; 199 return this; 200 } 201 202 /** 203 * Set content metadata for this Broadcast Source subgroup. 204 * 205 * @param contentMetadata content metadata for this Broadcast Source subgroup 206 * @throws NullPointerException if contentMetadata is null 207 * @return this builder 208 * @hide 209 */ 210 @SystemApi 211 @NonNull setContentMetadata( @onNull BluetoothLeAudioContentMetadata contentMetadata)212 public Builder setContentMetadata( 213 @NonNull BluetoothLeAudioContentMetadata contentMetadata) { 214 Objects.requireNonNull(contentMetadata, "contentMetadata cannot be null"); 215 mContentMetadata = contentMetadata; 216 return this; 217 } 218 219 /** 220 * Build {@link BluetoothLeBroadcastSubgroupSettings}. 221 * 222 * @return constructed {@link BluetoothLeBroadcastSubgroupSettings} 223 * @throws NullPointerException if {@link NonNull} items are null 224 * @throws IllegalArgumentException if the object cannot be built 225 * @hide 226 */ 227 @SystemApi 228 @NonNull build()229 public BluetoothLeBroadcastSubgroupSettings build() { 230 Objects.requireNonNull(mContentMetadata, "ContentMetadata is null"); 231 if (mPreferredQuality != QUALITY_STANDARD && mPreferredQuality != QUALITY_HIGH) { 232 throw new IllegalArgumentException( 233 "Must set audio quality to either Standard or High"); 234 } 235 return new BluetoothLeBroadcastSubgroupSettings(mPreferredQuality, mContentMetadata); 236 } 237 } 238 } 239