• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.Nullable;
20 import android.annotation.UnsupportedAppUsage;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import java.util.Arrays;
25 import 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  */
35 public 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      */
42     @UnsupportedAppUsage
43     public static final String EXTRA_CODEC_STATUS =
44             "android.bluetooth.codec.extra.CODEC_STATUS";
45 
46     private final @Nullable BluetoothCodecConfig mCodecConfig;
47     private final BluetoothCodecConfig[] mCodecsLocalCapabilities;
48     private final BluetoothCodecConfig[] mCodecsSelectableCapabilities;
49 
BluetoothCodecStatus(BluetoothCodecConfig codecConfig, BluetoothCodecConfig[] codecsLocalCapabilities, BluetoothCodecConfig[] codecsSelectableCapabilities)50     public BluetoothCodecStatus(BluetoothCodecConfig codecConfig,
51             BluetoothCodecConfig[] codecsLocalCapabilities,
52             BluetoothCodecConfig[] codecsSelectableCapabilities) {
53         mCodecConfig = codecConfig;
54         mCodecsLocalCapabilities = codecsLocalCapabilities;
55         mCodecsSelectableCapabilities = codecsSelectableCapabilities;
56     }
57 
58     @Override
equals(Object o)59     public boolean equals(Object o) {
60         if (o instanceof BluetoothCodecStatus) {
61             BluetoothCodecStatus other = (BluetoothCodecStatus) o;
62             return (Objects.equals(other.mCodecConfig, mCodecConfig)
63                     && sameCapabilities(other.mCodecsLocalCapabilities, mCodecsLocalCapabilities)
64                     && sameCapabilities(other.mCodecsSelectableCapabilities,
65                     mCodecsSelectableCapabilities));
66         }
67         return false;
68     }
69 
70     /**
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      */
sameCapabilities(BluetoothCodecConfig[] c1, BluetoothCodecConfig[] c2)78     public 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 
92     @Override
hashCode()93     public int hashCode() {
94         return Objects.hash(mCodecConfig, mCodecsLocalCapabilities,
95                 mCodecsLocalCapabilities);
96     }
97 
98     @Override
toString()99     public String toString() {
100         return "{mCodecConfig:" + mCodecConfig
101                 + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities)
102                 + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities)
103                 + "}";
104     }
105 
106     @Override
describeContents()107     public int describeContents() {
108         return 0;
109     }
110 
111     public static final @android.annotation.NonNull Parcelable.Creator<BluetoothCodecStatus> CREATOR =
112             new Parcelable.Creator<BluetoothCodecStatus>() {
113                 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);
120 
121                     return new BluetoothCodecStatus(codecConfig,
122                             codecsLocalCapabilities,
123                             codecsSelectableCapabilities);
124                 }
125 
126                 public BluetoothCodecStatus[] newArray(int size) {
127                     return new BluetoothCodecStatus[size];
128                 }
129             };
130 
131     @Override
writeToParcel(Parcel out, int flags)132     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      */
143     @UnsupportedAppUsage
getCodecConfig()144     public @Nullable BluetoothCodecConfig getCodecConfig() {
145         return mCodecConfig;
146     }
147 
148     /**
149      * Gets the codecs local capabilities.
150      *
151      * @return an array with the codecs local capabilities
152      */
153     @UnsupportedAppUsage
getCodecsLocalCapabilities()154     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      */
163     @UnsupportedAppUsage
getCodecsSelectableCapabilities()164     public BluetoothCodecConfig[] getCodecsSelectableCapabilities() {
165         return mCodecsSelectableCapabilities;
166     }
167 }
168