diff options
author | Pavlin Radoslavov <pavlin@google.com> | 2017-01-25 16:54:07 -0800 |
---|---|---|
committer | Pavlin Radoslavov <pavlin@google.com> | 2017-01-31 18:58:27 +0000 |
commit | f6d543a7d0e6919a7d9055f4911d57e209e3e9db (patch) | |
tree | 969b28984fc987b20da1ea45fd86d4f5db1a99a4 /framework/java/android/bluetooth/BluetoothCodecStatus.java | |
parent | e692bd35430c6a52ba59a734fdc37925fce5d30e (diff) |
Update the A2DP Codec Config API
Previously, the JNI upcall would contain only the current codec config.
In the new API, the upcall contains:
1. The current codec config
2. The list of codecs containing the local codecs capabilities
3. The list of codecs containing the selectable codecs capabilities.
This list is the intersection of the local codecs capabilities
and the capabilities of the paired device.
Also, refactored the Java internals to accomodate the extra information:
* Added new class BluetoothCodecStatus that contains the extra info:
current codec config, local codecs capabilities and selectable
codecs capabilities
* Renamed method getCodecConfig() to getCodecStatus() and return the
corresponding BluetoothCodecStatus object.
* Updates to class BluetoothCodecConfig:
new methods isValid(), getCodecName(), and updated toString()
so it is more user friendly
* Removed BluetoothCodecConfig.EXTRA_CODEC_CONFIG and
EXTRA_PREVIOUS_CODEC_CONFIG.
The former is superseded by BluetoothCodecStatus.EXTRA_CODEC_STATUS;
the latter is not really used.
Test: A2DP streaming with headsets and switching the codecs
Change-Id: Ia1af2c22e521e863e28a360610aca49f7e62d31b
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothCodecStatus.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothCodecStatus.java | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothCodecStatus.java b/framework/java/android/bluetooth/BluetoothCodecStatus.java new file mode 100644 index 0000000000..c8cd8d17ce --- /dev/null +++ b/framework/java/android/bluetooth/BluetoothCodecStatus.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.bluetooth; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Arrays; +import java.util.Objects; + +/** + * Represents the codec status (configuration and capability) for a Bluetooth + * A2DP source device. + * + * {@see BluetoothA2dp} + * + * {@hide} + */ +public final class BluetoothCodecStatus implements Parcelable { + /** + * Extra for the codec configuration intents of the individual profiles. + * + * This extra represents the current codec status of the A2DP + * profile. + */ + public static final String EXTRA_CODEC_STATUS = + "android.bluetooth.codec.extra.CODEC_STATUS"; + + private final BluetoothCodecConfig mCodecConfig; + private final BluetoothCodecConfig[] mCodecsLocalCapabilities; + private final BluetoothCodecConfig[] mCodecsSelectableCapabilities; + + public BluetoothCodecStatus(BluetoothCodecConfig codecConfig, + BluetoothCodecConfig[] codecsLocalCapabilities, + BluetoothCodecConfig[] codecsSelectableCapabilities) { + mCodecConfig = codecConfig; + mCodecsLocalCapabilities = codecsLocalCapabilities; + mCodecsSelectableCapabilities = codecsSelectableCapabilities; + } + + @Override + public boolean equals(Object o) { + if (o instanceof BluetoothCodecStatus) { + BluetoothCodecStatus other = (BluetoothCodecStatus)o; + return (Objects.equals(other.mCodecConfig, mCodecConfig) && + Objects.equals(other.mCodecsLocalCapabilities, + mCodecsLocalCapabilities) && + Objects.equals(other.mCodecsSelectableCapabilities, + mCodecsSelectableCapabilities)); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(mCodecConfig, mCodecsLocalCapabilities, + mCodecsLocalCapabilities); + } + + @Override + public String toString() { + return "{mCodecConfig:" + mCodecConfig + + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities) + + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities) + + "}"; + } + + public int describeContents() { + return 0; + } + + public static final Parcelable.Creator<BluetoothCodecStatus> CREATOR = + new Parcelable.Creator<BluetoothCodecStatus>() { + public BluetoothCodecStatus createFromParcel(Parcel in) { + final BluetoothCodecConfig codecConfig = in.readTypedObject(BluetoothCodecConfig.CREATOR); + final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); + final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray(BluetoothCodecConfig.CREATOR); + + return new BluetoothCodecStatus(codecConfig, + codecsLocalCapabilities, + codecsSelectableCapabilities); + } + public BluetoothCodecStatus[] newArray(int size) { + return new BluetoothCodecStatus[size]; + } + }; + + public void writeToParcel(Parcel out, int flags) { + out.writeTypedObject(mCodecConfig, 0); + out.writeTypedArray(mCodecsLocalCapabilities, 0); + out.writeTypedArray(mCodecsSelectableCapabilities, 0); + } + + /** + * Gets the current codec configuration. + * + * @return the current codec configuration + */ + public BluetoothCodecConfig getCodecConfig() { + return mCodecConfig; + } + + /** + * Gets the codecs local capabilities. + * + * @return an array with the codecs local capabilities + */ + public BluetoothCodecConfig[] getCodecsLocalCapabilities() { + return mCodecsLocalCapabilities; + } + + /** + * Gets the codecs selectable capabilities. + * + * @return an array with the codecs selectable capabilities + */ + public BluetoothCodecConfig[] getCodecsSelectableCapabilities() { + return mCodecsSelectableCapabilities; + } +} |