blob: 78560d2de420176a29194dddef52dbd51421d367 [file] [log] [blame]
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -08001/*
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
17package android.bluetooth;
18
Mathew Inwood4dc66d32018-08-01 15:07:20 +010019import android.annotation.UnsupportedAppUsage;
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080020import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.Arrays;
24import java.util.Objects;
25
26/**
27 * Represents the codec status (configuration and capability) for a Bluetooth
28 * A2DP source device.
29 *
30 * {@see BluetoothA2dp}
31 *
32 * {@hide}
33 */
34public final class BluetoothCodecStatus implements Parcelable {
35 /**
36 * Extra for the codec configuration intents of the individual profiles.
37 *
38 * This extra represents the current codec status of the A2DP
39 * profile.
40 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +010041 @UnsupportedAppUsage
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080042 public static final String EXTRA_CODEC_STATUS =
Jack Hea355e5e2017-08-22 16:06:54 -070043 "android.bluetooth.codec.extra.CODEC_STATUS";
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080044
45 private final BluetoothCodecConfig mCodecConfig;
46 private final BluetoothCodecConfig[] mCodecsLocalCapabilities;
47 private final BluetoothCodecConfig[] mCodecsSelectableCapabilities;
48
49 public BluetoothCodecStatus(BluetoothCodecConfig codecConfig,
Jack Hea355e5e2017-08-22 16:06:54 -070050 BluetoothCodecConfig[] codecsLocalCapabilities,
51 BluetoothCodecConfig[] codecsSelectableCapabilities) {
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080052 mCodecConfig = codecConfig;
53 mCodecsLocalCapabilities = codecsLocalCapabilities;
54 mCodecsSelectableCapabilities = codecsSelectableCapabilities;
55 }
56
57 @Override
58 public boolean equals(Object o) {
59 if (o instanceof BluetoothCodecStatus) {
Jack Hea355e5e2017-08-22 16:06:54 -070060 BluetoothCodecStatus other = (BluetoothCodecStatus) o;
Jack He2992cd02017-08-22 21:21:23 -070061 return (Objects.equals(other.mCodecConfig, mCodecConfig)
Pavlin Radoslavov9d36e6b2018-04-19 14:16:15 -070062 && sameCapabilities(other.mCodecsLocalCapabilities, mCodecsLocalCapabilities)
63 && sameCapabilities(other.mCodecsSelectableCapabilities,
Jack He2992cd02017-08-22 21:21:23 -070064 mCodecsSelectableCapabilities));
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080065 }
66 return false;
67 }
68
Pavlin Radoslavov9d36e6b2018-04-19 14:16:15 -070069 /**
70 * Checks whether two arrays of capabilities contain same capabilities.
71 * The order of the capabilities in each array is ignored.
72 *
73 * @param c1 the first array of capabilities to compare
74 * @param c2 the second array of capabilities to compare
75 * @return true if both arrays contain same capabilities
76 */
77 private static boolean sameCapabilities(BluetoothCodecConfig[] c1,
78 BluetoothCodecConfig[] c2) {
79 if (c1 == null) {
80 return (c2 == null);
81 }
82 if (c2 == null) {
83 return false;
84 }
85 if (c1.length != c2.length) {
86 return false;
87 }
88 return Arrays.asList(c1).containsAll(Arrays.asList(c2));
89 }
90
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080091 @Override
92 public int hashCode() {
93 return Objects.hash(mCodecConfig, mCodecsLocalCapabilities,
Jack Hea355e5e2017-08-22 16:06:54 -070094 mCodecsLocalCapabilities);
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080095 }
96
97 @Override
98 public String toString() {
Jack He2992cd02017-08-22 21:21:23 -070099 return "{mCodecConfig:" + mCodecConfig
100 + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities)
101 + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities)
102 + "}";
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800103 }
104
Jack He2992cd02017-08-22 21:21:23 -0700105 @Override
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800106 public int describeContents() {
107 return 0;
108 }
109
110 public static final Parcelable.Creator<BluetoothCodecStatus> CREATOR =
111 new Parcelable.Creator<BluetoothCodecStatus>() {
Jack Hea355e5e2017-08-22 16:06:54 -0700112 public BluetoothCodecStatus createFromParcel(Parcel in) {
113 final BluetoothCodecConfig codecConfig = in.readTypedObject(
114 BluetoothCodecConfig.CREATOR);
115 final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray(
116 BluetoothCodecConfig.CREATOR);
117 final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray(
118 BluetoothCodecConfig.CREATOR);
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800119
Jack Hea355e5e2017-08-22 16:06:54 -0700120 return new BluetoothCodecStatus(codecConfig,
121 codecsLocalCapabilities,
122 codecsSelectableCapabilities);
123 }
124
125 public BluetoothCodecStatus[] newArray(int size) {
126 return new BluetoothCodecStatus[size];
127 }
128 };
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800129
Jack He2992cd02017-08-22 21:21:23 -0700130 @Override
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800131 public void writeToParcel(Parcel out, int flags) {
132 out.writeTypedObject(mCodecConfig, 0);
133 out.writeTypedArray(mCodecsLocalCapabilities, 0);
134 out.writeTypedArray(mCodecsSelectableCapabilities, 0);
135 }
136
137 /**
138 * Gets the current codec configuration.
139 *
140 * @return the current codec configuration
141 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100142 @UnsupportedAppUsage
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800143 public BluetoothCodecConfig getCodecConfig() {
144 return mCodecConfig;
145 }
146
147 /**
148 * Gets the codecs local capabilities.
149 *
150 * @return an array with the codecs local capabilities
151 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100152 @UnsupportedAppUsage
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800153 public BluetoothCodecConfig[] getCodecsLocalCapabilities() {
154 return mCodecsLocalCapabilities;
155 }
156
157 /**
158 * Gets the codecs selectable capabilities.
159 *
160 * @return an array with the codecs selectable capabilities
161 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100162 @UnsupportedAppUsage
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800163 public BluetoothCodecConfig[] getCodecsSelectableCapabilities() {
164 return mCodecsSelectableCapabilities;
165 }
166}