1 /* 2 * Copyright (C) 2017 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.os.Parcel; 20 import android.os.Parcelable; 21 22 import java.util.Arrays; 23 import java.util.Objects; 24 25 /** 26 * Represents the codec status (configuration and capability) for a Bluetooth 27 * A2DP source device. 28 * 29 * {@see BluetoothA2dp} 30 * 31 * {@hide} 32 */ 33 public final class BluetoothCodecStatus implements Parcelable { 34 /** 35 * Extra for the codec configuration intents of the individual profiles. 36 * 37 * This extra represents the current codec status of the A2DP 38 * profile. 39 */ 40 public static final String EXTRA_CODEC_STATUS = 41 "android.bluetooth.codec.extra.CODEC_STATUS"; 42 43 private final BluetoothCodecConfig mCodecConfig; 44 private final BluetoothCodecConfig[] mCodecsLocalCapabilities; 45 private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; 46 BluetoothCodecStatus(BluetoothCodecConfig codecConfig, BluetoothCodecConfig[] codecsLocalCapabilities, BluetoothCodecConfig[] codecsSelectableCapabilities)47 public BluetoothCodecStatus(BluetoothCodecConfig codecConfig, 48 BluetoothCodecConfig[] codecsLocalCapabilities, 49 BluetoothCodecConfig[] codecsSelectableCapabilities) { 50 mCodecConfig = codecConfig; 51 mCodecsLocalCapabilities = codecsLocalCapabilities; 52 mCodecsSelectableCapabilities = codecsSelectableCapabilities; 53 } 54 55 @Override equals(Object o)56 public boolean equals(Object o) { 57 if (o instanceof BluetoothCodecStatus) { 58 BluetoothCodecStatus other = (BluetoothCodecStatus)o; 59 return (Objects.equals(other.mCodecConfig, mCodecConfig) && 60 Objects.equals(other.mCodecsLocalCapabilities, 61 mCodecsLocalCapabilities) && 62 Objects.equals(other.mCodecsSelectableCapabilities, 63 mCodecsSelectableCapabilities)); 64 } 65 return false; 66 } 67 68 @Override hashCode()69 public int hashCode() { 70 return Objects.hash(mCodecConfig, mCodecsLocalCapabilities, 71 mCodecsLocalCapabilities); 72 } 73 74 @Override toString()75 public String toString() { 76 return "{mCodecConfig:" + mCodecConfig + 77 ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) + 78 ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + 79 "}"; 80 } 81 describeContents()82 public int describeContents() { 83 return 0; 84 } 85 86 public static final Parcelable.Creator<BluetoothCodecStatus> CREATOR = 87 new Parcelable.Creator<BluetoothCodecStatus>() { 88 public BluetoothCodecStatus createFromParcel(Parcel in) { 89 final BluetoothCodecConfig codecConfig = in.readTypedObject(BluetoothCodecConfig.CREATOR); 90 final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); 91 final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); 92 93 return new BluetoothCodecStatus(codecConfig, 94 codecsLocalCapabilities, 95 codecsSelectableCapabilities); 96 } 97 public BluetoothCodecStatus[] newArray(int size) { 98 return new BluetoothCodecStatus[size]; 99 } 100 }; 101 writeToParcel(Parcel out, int flags)102 public void writeToParcel(Parcel out, int flags) { 103 out.writeTypedObject(mCodecConfig, 0); 104 out.writeTypedArray(mCodecsLocalCapabilities, 0); 105 out.writeTypedArray(mCodecsSelectableCapabilities, 0); 106 } 107 108 /** 109 * Gets the current codec configuration. 110 * 111 * @return the current codec configuration 112 */ getCodecConfig()113 public BluetoothCodecConfig getCodecConfig() { 114 return mCodecConfig; 115 } 116 117 /** 118 * Gets the codecs local capabilities. 119 * 120 * @return an array with the codecs local capabilities 121 */ getCodecsLocalCapabilities()122 public BluetoothCodecConfig[] getCodecsLocalCapabilities() { 123 return mCodecsLocalCapabilities; 124 } 125 126 /** 127 * Gets the codecs selectable capabilities. 128 * 129 * @return an array with the codecs selectable capabilities 130 */ getCodecsSelectableCapabilities()131 public BluetoothCodecConfig[] getCodecsSelectableCapabilities() { 132 return mCodecsSelectableCapabilities; 133 } 134 } 135