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 62 public static final int QUALITY_STANDARD = 0; 63 64 /** 65 * Indicates high quality for this subgroup audio configuration. 66 * 67 * @hide 68 */ 69 @SystemApi 70 public static final int QUALITY_HIGH = 1; 71 BluetoothLeBroadcastSubgroupSettings( int preferredQuality, BluetoothLeAudioContentMetadata contentMetadata)72 private BluetoothLeBroadcastSubgroupSettings( 73 int preferredQuality, BluetoothLeAudioContentMetadata contentMetadata) { 74 mPreferredQuality = preferredQuality; 75 mContentMetadata = contentMetadata; 76 } 77 78 @Override equals(@ullable Object o)79 public boolean equals(@Nullable Object o) { 80 if (!(o instanceof BluetoothLeBroadcastSubgroupSettings)) { 81 return false; 82 } 83 final BluetoothLeBroadcastSubgroupSettings other = (BluetoothLeBroadcastSubgroupSettings) o; 84 return mPreferredQuality == other.getPreferredQuality() 85 && mContentMetadata.equals(other.getContentMetadata()); 86 } 87 88 @Override hashCode()89 public int hashCode() { 90 return Objects.hash(mPreferredQuality, mContentMetadata); 91 } 92 93 /** 94 * Get content metadata for this Broadcast Source subgroup. 95 * 96 * @return content metadata for this Broadcast Source subgroup 97 * @hide 98 */ 99 @SystemApi 100 @NonNull getContentMetadata()101 public BluetoothLeAudioContentMetadata getContentMetadata() { 102 return mContentMetadata; 103 } 104 105 /** 106 * Get preferred audio quality for this Broadcast Source subgroup. 107 * 108 * @return preferred audio quality for this Broadcast Source subgroup 109 * @hide 110 */ 111 @SystemApi getPreferredQuality()112 public @Quality int getPreferredQuality() { 113 return mPreferredQuality; 114 } 115 116 /** 117 * {@inheritDoc} 118 * 119 * @hide 120 */ 121 @Override describeContents()122 public int describeContents() { 123 return 0; 124 } 125 126 /** 127 * {@inheritDoc} 128 * 129 * @hide 130 */ 131 @Override writeToParcel(Parcel out, int flags)132 public void writeToParcel(Parcel out, int flags) { 133 out.writeInt(mPreferredQuality); 134 out.writeTypedObject(mContentMetadata, 0); 135 } 136 137 /** 138 * A {@link Parcelable.Creator} to create {@link BluetoothLeBroadcastSubgroupSettings} from 139 * parcel. 140 * 141 * @hide 142 */ 143 @SystemApi 144 @NonNull 145 public static final Creator<BluetoothLeBroadcastSubgroupSettings> CREATOR = 146 new Creator<>() { 147 public @NonNull BluetoothLeBroadcastSubgroupSettings createFromParcel( 148 @NonNull Parcel in) { 149 Builder builder = new Builder(); 150 builder.setPreferredQuality(in.readInt()); 151 builder.setContentMetadata( 152 in.readTypedObject(BluetoothLeAudioContentMetadata.CREATOR)); 153 return builder.build(); 154 } 155 156 public @NonNull BluetoothLeBroadcastSubgroupSettings[] newArray(int size) { 157 return new BluetoothLeBroadcastSubgroupSettings[size]; 158 } 159 }; 160 161 /** 162 * Builder for {@link BluetoothLeBroadcastSubgroupSettings}. 163 * 164 * @hide 165 */ 166 @SystemApi 167 public static final class Builder { 168 private BluetoothLeAudioContentMetadata mContentMetadata = null; 169 private @Quality int mPreferredQuality = QUALITY_STANDARD; 170 171 /** 172 * Create an empty constructor. 173 * 174 * @hide 175 */ 176 @SystemApi Builder()177 public Builder() {} 178 179 /** 180 * Create a builder with copies of information from original object. 181 * 182 * @param original original object 183 * @hide 184 */ 185 @SystemApi Builder(@onNull BluetoothLeBroadcastSubgroupSettings original)186 public Builder(@NonNull BluetoothLeBroadcastSubgroupSettings original) { 187 mPreferredQuality = original.getPreferredQuality(); 188 mContentMetadata = original.getContentMetadata(); 189 } 190 191 /** 192 * Set preferred audio quality for this Broadcast Source subgroup. 193 * 194 * @param preferredQuality audio quality for this Broadcast Source subgroup 195 * @return this builder 196 * @hide 197 */ 198 @SystemApi 199 @NonNull setPreferredQuality(@uality int preferredQuality)200 public Builder setPreferredQuality(@Quality int preferredQuality) { 201 mPreferredQuality = preferredQuality; 202 return this; 203 } 204 205 /** 206 * Set content metadata for this Broadcast Source subgroup. 207 * 208 * @param contentMetadata content metadata for this Broadcast Source subgroup 209 * @throws NullPointerException if contentMetadata is null 210 * @return this builder 211 * @hide 212 */ 213 @SystemApi 214 @NonNull setContentMetadata( @onNull BluetoothLeAudioContentMetadata contentMetadata)215 public Builder setContentMetadata( 216 @NonNull BluetoothLeAudioContentMetadata contentMetadata) { 217 Objects.requireNonNull(contentMetadata, "contentMetadata cannot be null"); 218 mContentMetadata = contentMetadata; 219 return this; 220 } 221 222 /** 223 * Build {@link BluetoothLeBroadcastSubgroupSettings}. 224 * 225 * @return constructed {@link BluetoothLeBroadcastSubgroupSettings} 226 * @throws NullPointerException if {@link NonNull} items are null 227 * @throws IllegalArgumentException if the object cannot be built 228 * @hide 229 */ 230 @SystemApi 231 @NonNull build()232 public BluetoothLeBroadcastSubgroupSettings build() { 233 Objects.requireNonNull(mContentMetadata, "ContentMetadata is null"); 234 if (mPreferredQuality != QUALITY_STANDARD && mPreferredQuality != QUALITY_HIGH) { 235 throw new IllegalArgumentException( 236 "Must set audio quality to either Standard or High"); 237 } 238 return new BluetoothLeBroadcastSubgroupSettings(mPreferredQuality, mContentMetadata); 239 } 240 } 241 } 242