blob: 2cb7b2d3c7e9177298f87b3e1564138c9eca3f0a [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
Jean-Michel Trivi58850372018-09-14 16:01:28 -070019import android.annotation.Nullable;
Mathew Inwood7acad5e2018-08-01 15:00:35 +010020import android.annotation.UnsupportedAppUsage;
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080021import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.util.Arrays;
25import java.util.Objects;
26
27/**
28 * Represents the codec status (configuration and capability) for a Bluetooth
29 * A2DP source device.
30 *
31 * {@see BluetoothA2dp}
32 *
33 * {@hide}
34 */
35public final class BluetoothCodecStatus implements Parcelable {
36 /**
37 * Extra for the codec configuration intents of the individual profiles.
38 *
39 * This extra represents the current codec status of the A2DP
40 * profile.
41 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +010042 @UnsupportedAppUsage
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080043 public static final String EXTRA_CODEC_STATUS =
Jack Hea355e5e2017-08-22 16:06:54 -070044 "android.bluetooth.codec.extra.CODEC_STATUS";
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080045
Jean-Michel Trivi58850372018-09-14 16:01:28 -070046 private final @Nullable BluetoothCodecConfig mCodecConfig;
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080047 private final BluetoothCodecConfig[] mCodecsLocalCapabilities;
48 private final BluetoothCodecConfig[] mCodecsSelectableCapabilities;
49
50 public BluetoothCodecStatus(BluetoothCodecConfig codecConfig,
Jack Hea355e5e2017-08-22 16:06:54 -070051 BluetoothCodecConfig[] codecsLocalCapabilities,
52 BluetoothCodecConfig[] codecsSelectableCapabilities) {
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080053 mCodecConfig = codecConfig;
54 mCodecsLocalCapabilities = codecsLocalCapabilities;
55 mCodecsSelectableCapabilities = codecsSelectableCapabilities;
56 }
57
58 @Override
59 public boolean equals(Object o) {
60 if (o instanceof BluetoothCodecStatus) {
Jack Hea355e5e2017-08-22 16:06:54 -070061 BluetoothCodecStatus other = (BluetoothCodecStatus) o;
Jack He2992cd02017-08-22 21:21:23 -070062 return (Objects.equals(other.mCodecConfig, mCodecConfig)
Pavlin Radoslavov9d36e6b2018-04-19 14:16:15 -070063 && sameCapabilities(other.mCodecsLocalCapabilities, mCodecsLocalCapabilities)
64 && sameCapabilities(other.mCodecsSelectableCapabilities,
Jack He2992cd02017-08-22 21:21:23 -070065 mCodecsSelectableCapabilities));
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080066 }
67 return false;
68 }
69
Pavlin Radoslavov9d36e6b2018-04-19 14:16:15 -070070 /**
71 * Checks whether two arrays of capabilities contain same capabilities.
72 * The order of the capabilities in each array is ignored.
73 *
74 * @param c1 the first array of capabilities to compare
75 * @param c2 the second array of capabilities to compare
76 * @return true if both arrays contain same capabilities
77 */
78 private static boolean sameCapabilities(BluetoothCodecConfig[] c1,
79 BluetoothCodecConfig[] c2) {
80 if (c1 == null) {
81 return (c2 == null);
82 }
83 if (c2 == null) {
84 return false;
85 }
86 if (c1.length != c2.length) {
87 return false;
88 }
89 return Arrays.asList(c1).containsAll(Arrays.asList(c2));
90 }
91
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080092 @Override
93 public int hashCode() {
94 return Objects.hash(mCodecConfig, mCodecsLocalCapabilities,
Jack Hea355e5e2017-08-22 16:06:54 -070095 mCodecsLocalCapabilities);
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -080096 }
97
98 @Override
99 public String toString() {
Jack He2992cd02017-08-22 21:21:23 -0700100 return "{mCodecConfig:" + mCodecConfig
101 + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities)
102 + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities)
103 + "}";
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800104 }
105
Jack He2992cd02017-08-22 21:21:23 -0700106 @Override
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800107 public int describeContents() {
108 return 0;
109 }
110
111 public static final Parcelable.Creator<BluetoothCodecStatus> CREATOR =
112 new Parcelable.Creator<BluetoothCodecStatus>() {
Jack Hea355e5e2017-08-22 16:06:54 -0700113 public BluetoothCodecStatus createFromParcel(Parcel in) {
114 final BluetoothCodecConfig codecConfig = in.readTypedObject(
115 BluetoothCodecConfig.CREATOR);
116 final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray(
117 BluetoothCodecConfig.CREATOR);
118 final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray(
119 BluetoothCodecConfig.CREATOR);
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800120
Jack Hea355e5e2017-08-22 16:06:54 -0700121 return new BluetoothCodecStatus(codecConfig,
122 codecsLocalCapabilities,
123 codecsSelectableCapabilities);
124 }
125
126 public BluetoothCodecStatus[] newArray(int size) {
127 return new BluetoothCodecStatus[size];
128 }
129 };
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800130
Jack He2992cd02017-08-22 21:21:23 -0700131 @Override
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800132 public void writeToParcel(Parcel out, int flags) {
133 out.writeTypedObject(mCodecConfig, 0);
134 out.writeTypedArray(mCodecsLocalCapabilities, 0);
135 out.writeTypedArray(mCodecsSelectableCapabilities, 0);
136 }
137
138 /**
139 * Gets the current codec configuration.
140 *
141 * @return the current codec configuration
142 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100143 @UnsupportedAppUsage
Jean-Michel Trivi58850372018-09-14 16:01:28 -0700144 public @Nullable BluetoothCodecConfig getCodecConfig() {
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800145 return mCodecConfig;
146 }
147
148 /**
149 * Gets the codecs local capabilities.
150 *
151 * @return an array with the codecs local capabilities
152 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100153 @UnsupportedAppUsage
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800154 public BluetoothCodecConfig[] getCodecsLocalCapabilities() {
155 return mCodecsLocalCapabilities;
156 }
157
158 /**
159 * Gets the codecs selectable capabilities.
160 *
161 * @return an array with the codecs selectable capabilities
162 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100163 @UnsupportedAppUsage
Pavlin Radoslavovb37f1812017-01-25 16:54:07 -0800164 public BluetoothCodecConfig[] getCodecsSelectableCapabilities() {
165 return mCodecsSelectableCapabilities;
166 }
167}