1 /* 2 * Copyright (C) 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 static java.util.Objects.requireNonNull; 20 21 import android.annotation.IntDef; 22 import android.annotation.NonNull; 23 import android.annotation.Nullable; 24 import android.annotation.SystemApi; 25 import android.os.Parcel; 26 import android.os.Parcelable; 27 28 import java.lang.annotation.Retention; 29 import java.lang.annotation.RetentionPolicy; 30 import java.util.Objects; 31 32 /** 33 * This class contains the subgroup settings information for this Broadcast Subgroup. 34 * 35 * @hide 36 */ 37 @SystemApi 38 public final class BluetoothLeBroadcastSubgroupSettings implements Parcelable { 39 private final @Quality int mPreferredQuality; 40 private final BluetoothLeAudioContentMetadata mContentMetadata; 41 42 /** 43 * Audio quality for this broadcast subgroup 44 * 45 * <p>Audio quality for this broadcast subgroup. 46 * 47 * @hide 48 */ 49 @IntDef( 50 prefix = "QUALITY_", 51 value = { 52 QUALITY_STANDARD, 53 QUALITY_HIGH, 54 }) 55 @Retention(RetentionPolicy.SOURCE) 56 public @interface Quality {} 57 58 /** 59 * Indicates standard quality for this subgroup audio configuration. 60 * 61 * @hide 62 */ 63 @SystemApi public static final int QUALITY_STANDARD = 0; 64 65 /** 66 * Indicates high quality for this subgroup audio configuration. 67 * 68 * @hide 69 */ 70 @SystemApi 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 @NonNull 144 public static final Creator<BluetoothLeBroadcastSubgroupSettings> CREATOR = 145 new Creator<>() { 146 public @NonNull BluetoothLeBroadcastSubgroupSettings createFromParcel( 147 @NonNull Parcel in) { 148 Builder builder = new Builder(); 149 builder.setPreferredQuality(in.readInt()); 150 builder.setContentMetadata( 151 in.readTypedObject(BluetoothLeAudioContentMetadata.CREATOR)); 152 return builder.build(); 153 } 154 155 public @NonNull BluetoothLeBroadcastSubgroupSettings[] newArray(int size) { 156 return new BluetoothLeBroadcastSubgroupSettings[size]; 157 } 158 }; 159 160 /** 161 * Builder for {@link BluetoothLeBroadcastSubgroupSettings}. 162 * 163 * @hide 164 */ 165 @SystemApi 166 public static final class Builder { 167 private BluetoothLeAudioContentMetadata mContentMetadata = null; 168 private @Quality int mPreferredQuality = QUALITY_STANDARD; 169 170 /** 171 * Create an empty constructor. 172 * 173 * @hide 174 */ 175 @SystemApi Builder()176 public Builder() {} 177 178 /** 179 * Create a builder with copies of information from original object. 180 * 181 * @param original original object 182 * @hide 183 */ 184 @SystemApi Builder(@onNull BluetoothLeBroadcastSubgroupSettings original)185 public Builder(@NonNull BluetoothLeBroadcastSubgroupSettings original) { 186 mPreferredQuality = original.getPreferredQuality(); 187 mContentMetadata = original.getContentMetadata(); 188 } 189 190 /** 191 * Set preferred audio quality for this Broadcast Source subgroup. 192 * 193 * @param preferredQuality audio quality for this Broadcast Source subgroup 194 * @return this builder 195 * @hide 196 */ 197 @SystemApi 198 @NonNull setPreferredQuality(@uality int preferredQuality)199 public Builder setPreferredQuality(@Quality int preferredQuality) { 200 mPreferredQuality = preferredQuality; 201 return this; 202 } 203 204 /** 205 * Set content metadata for this Broadcast Source subgroup. 206 * 207 * @param contentMetadata content metadata for this Broadcast Source subgroup 208 * @throws NullPointerException if contentMetadata is null 209 * @return this builder 210 * @hide 211 */ 212 @SystemApi 213 @NonNull setContentMetadata( @onNull BluetoothLeAudioContentMetadata contentMetadata)214 public Builder setContentMetadata( 215 @NonNull BluetoothLeAudioContentMetadata contentMetadata) { 216 requireNonNull(contentMetadata); 217 mContentMetadata = contentMetadata; 218 return this; 219 } 220 221 /** 222 * Build {@link BluetoothLeBroadcastSubgroupSettings}. 223 * 224 * @return constructed {@link BluetoothLeBroadcastSubgroupSettings} 225 * @throws NullPointerException if {@link NonNull} items are null 226 * @throws IllegalArgumentException if the object cannot be built 227 * @hide 228 */ 229 @SystemApi 230 @NonNull build()231 public BluetoothLeBroadcastSubgroupSettings build() { 232 requireNonNull(mContentMetadata); 233 if (mPreferredQuality != QUALITY_STANDARD && mPreferredQuality != QUALITY_HIGH) { 234 throw new IllegalArgumentException( 235 "Must set audio quality to either Standard or High"); 236 } 237 return new BluetoothLeBroadcastSubgroupSettings(mPreferredQuality, mContentMetadata); 238 } 239 } 240 } 241