From 178a3d23c6b0a2bab98e4333936939bd5c2e725a Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Wed, 21 Dec 2016 12:05:51 -0800 Subject: Add a mechanism for configuring the A2DP Source codecs * Added a new class BluetoothCodecConfig that contains codec-related configuration or capabilities: codec type, priority, sample rate, bits per sample, channel mode, and codec specific fields. * Extended the Bluetooth A2DP AIDL interface to get/set the current codec configuration * Added new call handleBluetoothA2dpDeviceConfigChange() to the Media Framework that is called when there are changes in the Bluetooth A2DP device configuration - e.g., the A2DP codec is changed. Test: A2DP streaming to headsets, TestPlans/71390 Bug: 30958229 Change-Id: I9a82716cbc2a5efbe77352a031ac80c88f6a2459 --- .../android/bluetooth/BluetoothCodecConfig.java | 287 +++++++++++++++++++++ 1 file changed, 287 insertions(+) create mode 100644 framework/java/android/bluetooth/BluetoothCodecConfig.java (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java new file mode 100644 index 0000000000..5cc127766e --- /dev/null +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2016 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.Objects; + +/** + * Represents the codec configuration for a Bluetooth A2DP source device. + * + * {@see BluetoothA2dp} + * + * {@hide} + */ +public final class BluetoothCodecConfig implements Parcelable { + + /** + * Extra for the codec configuration intents of the individual profiles. + * + * This extra represents the current codec configuration of the A2DP + * profile. + */ + public static final String EXTRA_CODEC_CONFIG = "android.bluetooth.codec.extra.CODEC_CONFIG"; + + /** + * Extra for the codec configuration intents of the individual profiles. + * + * This extra represents the previous codec configuration of the A2DP + * profile. + */ + public static final String EXTRA_PREVIOUS_CODEC_CONFIG = + "android.bluetooth.codec.extra.PREVIOUS_CODEC_CONFIG"; + + public static final int SOURCE_CODEC_TYPE_SBC = 0; + public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; + + public static final int CODEC_PRIORITY_DEFAULT = 0; + public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; + + public static final int SAMPLE_RATE_NONE = 0; + public static final int SAMPLE_RATE_44100 = 0x1 << 0; + public static final int SAMPLE_RATE_48000 = 0x1 << 1; + public static final int SAMPLE_RATE_88200 = 0x1 << 2; + public static final int SAMPLE_RATE_96000 = 0x1 << 3; + public static final int SAMPLE_RATE_176400 = 0x1 << 4; + public static final int SAMPLE_RATE_192000 = 0x1 << 5; + + public static final int BITS_PER_SAMPLE_NONE = 0; + public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; + public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; + public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; + + public static final int CHANNEL_MODE_NONE = 0; + public static final int CHANNEL_MODE_MONO = 0x1 << 0; + public static final int CHANNEL_MODE_STEREO = 0x1 << 1; + + private final int mCodecType; + private final int mCodecPriority; + private final int mSampleRate; + private final int mBitsPerSample; + private final int mChannelMode; + private final long mCodecSpecific1; + private final long mCodecSpecific2; + private final long mCodecSpecific3; + private final long mCodecSpecific4; + + public BluetoothCodecConfig(int codecType, int codecPriority, + int sampleRate, int bitsPerSample, + int channelMode,long codecSpecific1, + long codecSpecific2, long codecSpecific3, + long codecSpecific4) { + mCodecType = codecType; + mCodecPriority = codecPriority; + mSampleRate = sampleRate; + mBitsPerSample = bitsPerSample; + mChannelMode = channelMode; + mCodecSpecific1 = codecSpecific1; + mCodecSpecific2 = codecSpecific2; + mCodecSpecific3 = codecSpecific3; + mCodecSpecific4 = codecSpecific4; + } + + @Override + public boolean equals(Object o) { + if (o instanceof BluetoothCodecConfig) { + BluetoothCodecConfig other = (BluetoothCodecConfig)o; + return (other.mCodecType == mCodecType && + other.mCodecPriority == mCodecPriority && + other.mSampleRate == mSampleRate && + other.mBitsPerSample == mBitsPerSample && + other.mChannelMode == mChannelMode && + other.mCodecSpecific1 == mCodecSpecific1 && + other.mCodecSpecific2 == mCodecSpecific2 && + other.mCodecSpecific3 == mCodecSpecific3 && + other.mCodecSpecific4 == mCodecSpecific4); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(mCodecType, mCodecPriority, mSampleRate, + mBitsPerSample, mChannelMode, mCodecSpecific1, + mCodecSpecific2, mCodecSpecific3, mCodecSpecific4); + } + + @Override + public String toString() { + return "{mCodecType:" + mCodecType + + ",mCodecPriority:" + mCodecPriority + + ",mSampleRate:" + String.format("0x%x", mSampleRate) + + ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) + + ",mChannelMode:" + String.format("0x%x", mChannelMode) + + ",mCodecSpecific1:" + mCodecSpecific1 + + ",mCodecSpecific2:" + mCodecSpecific2 + + ",mCodecSpecific3:" + mCodecSpecific3 + + ",mCodecSpecific4:" + mCodecSpecific4 + "}"; + } + + public int describeContents() { + return 0; + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public BluetoothCodecConfig createFromParcel(Parcel in) { + final int codecType = in.readInt(); + final int codecPriority = in.readInt(); + final int sampleRate = in.readInt(); + final int bitsPerSample = in.readInt(); + final int channelMode = in.readInt(); + final long codecSpecific1 = in.readLong(); + final long codecSpecific2 = in.readLong(); + final long codecSpecific3 = in.readLong(); + final long codecSpecific4 = in.readLong(); + return new BluetoothCodecConfig(codecType, codecPriority, + sampleRate, bitsPerSample, + channelMode, codecSpecific1, + codecSpecific2, codecSpecific3, + codecSpecific4); + } + public BluetoothCodecConfig[] newArray(int size) { + return new BluetoothCodecConfig[size]; + } + }; + + public void writeToParcel(Parcel out, int flags) { + out.writeInt(mCodecType); + out.writeInt(mCodecPriority); + out.writeInt(mSampleRate); + out.writeInt(mBitsPerSample); + out.writeInt(mChannelMode); + out.writeLong(mCodecSpecific1); + out.writeLong(mCodecSpecific2); + out.writeLong(mCodecSpecific3); + out.writeLong(mCodecSpecific4); + } + + /** + * Returns the codec type. + * See {@link android.bluetooth.BluetoothCodecConfig#SOURCE_CODEC_TYPE_SBC}. + * + * @return the codec type + */ + public int getCodecType() { + return mCodecType; + } + + /** + * Returns the codec selection priority. + * The codec selection priority is relative to other codecs: larger value + * means higher priority. If 0, reset to default. + * + * @return the codec priority + */ + public int getCodecPriority() { + return mCodecPriority; + } + + /** + * Returns the codec sample rate. The value can be a bitmask with all + * supported sample rates: + * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_NONE} or + * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_44100} or + * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_48000} or + * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_88200} or + * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_96000} or + * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_176400} or + * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_192000} + * + * @return the codec sample rate + */ + public int getSampleRate() { + return mSampleRate; + } + + /** + * Returns the codec bits per sample. The value can be a bitmask with all + * bits per sample supported: + * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_NONE} or + * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_16} or + * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_24} or + * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_32} + * + * @return the codec bits per sample + */ + public int getBitsPerSample() { + return mBitsPerSample; + } + + /** + * Returns the codec channel mode. The value can be a bitmask with all + * supported channel modes: + * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_NONE} or + * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_MONO} or + * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_STEREO} + * + * @return the codec channel mode + */ + public int getChannelMode() { + return mChannelMode; + } + + /** + * Returns a codec specific value1. + * + * @return a codec specific value1. + */ + public long getCodecSpecific1() { + return mCodecSpecific1; + } + + /** + * Returns a codec specific value2. + * + * @return a codec specific value2 + */ + public long getCodecSpecific2() { + return mCodecSpecific2; + } + + /** + * Returns a codec specific value3. + * + * @return a codec specific value3 + */ + public long getCodecSpecific3() { + return mCodecSpecific3; + } + + /** + * Returns a codec specific value4. + * + * @return a codec specific value4 + */ + public long getCodecSpecific4() { + return mCodecSpecific4; + } + + /** + * Checks whether the audio feeding parameters are same. + * + * @param other the codec config to compare against + * @return true if the audio feeding parameters are same, otherwise false + */ + public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) { + return (other != null && other.mSampleRate == mSampleRate && + other.mBitsPerSample == mBitsPerSample && + other.mChannelMode == mChannelMode); + } +} -- cgit v1.2.3 From 7ad3acbfcb80294a3fa03afbdca89663f2e581ef Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Wed, 4 Jan 2017 16:10:09 -0800 Subject: Integration of the aptX and aptX-HD codecs for A2DP source Each of the codecs can be used if the corresponding encoding shared library is installed on the device: - aptX: libaptX.so - aptX-HD: libaptXHD.so Test: A2DP streaming to aptX and aptX-HD headsets Bug: 30958229 Change-Id: I24faddc8cd88ae3e1370922c633f30e13124a867 --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 5cc127766e..67fdb0caf8 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -47,7 +47,13 @@ public final class BluetoothCodecConfig implements Parcelable { public static final String EXTRA_PREVIOUS_CODEC_CONFIG = "android.bluetooth.codec.extra.PREVIOUS_CODEC_CONFIG"; + // Add an entry for each source codec here. + // NOTE: The values should be same as those listed in the following file: + // hardware/libhardware/include/hardware/bt_av.h public static final int SOURCE_CODEC_TYPE_SBC = 0; + public static final int SOURCE_CODEC_TYPE_APTX = 1; + public static final int SOURCE_CODEC_TYPE_APTX_HD = 2; + public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; public static final int CODEC_PRIORITY_DEFAULT = 0; -- cgit v1.2.3 From cc854d67e7d699f5f4e9a94f80110c4130cdfd4e Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Wed, 4 Jan 2017 16:47:02 -0800 Subject: Integration of the LDAC codec for A2DP source The codec can be used if the encoding shared library is installed on the device: libldacBT_enc.so Test: A2DP streaming to LDAC headsets Bug: 30958229 Change-Id: I524805fd308b5181427515617eda05625a7c4ae5 --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 1 + 1 file changed, 1 insertion(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 67fdb0caf8..52cd2de4c2 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -53,6 +53,7 @@ public final class BluetoothCodecConfig implements Parcelable { public static final int SOURCE_CODEC_TYPE_SBC = 0; public static final int SOURCE_CODEC_TYPE_APTX = 1; public static final int SOURCE_CODEC_TYPE_APTX_HD = 2; + public static final int SOURCE_CODEC_TYPE_LDAC = 3; public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; -- cgit v1.2.3 From ba5e29919dcc67bba3677902b342194bf82c4dda Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Sat, 14 Jan 2017 00:41:05 -0800 Subject: Integration of the AAC codec for A2DP source Test: A2DP streaming to AAC headsets Bug: 30958229 Change-Id: I1b530f1c5c495b8231fd68bed788d4567096683d --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 52cd2de4c2..a37a0b38aa 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -51,9 +51,10 @@ public final class BluetoothCodecConfig implements Parcelable { // NOTE: The values should be same as those listed in the following file: // hardware/libhardware/include/hardware/bt_av.h public static final int SOURCE_CODEC_TYPE_SBC = 0; - public static final int SOURCE_CODEC_TYPE_APTX = 1; - public static final int SOURCE_CODEC_TYPE_APTX_HD = 2; - public static final int SOURCE_CODEC_TYPE_LDAC = 3; + public static final int SOURCE_CODEC_TYPE_AAC = 1; + public static final int SOURCE_CODEC_TYPE_APTX = 2; + public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; + public static final int SOURCE_CODEC_TYPE_LDAC = 4; public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; -- cgit v1.2.3 From f6d543a7d0e6919a7d9055f4911d57e209e3e9db Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Wed, 25 Jan 2017 16:54:07 -0800 Subject: 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 --- .../android/bluetooth/BluetoothCodecConfig.java | 143 +++++++++++++++++---- 1 file changed, 115 insertions(+), 28 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index a37a0b38aa..a48210340e 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -29,24 +29,6 @@ import java.util.Objects; * {@hide} */ public final class BluetoothCodecConfig implements Parcelable { - - /** - * Extra for the codec configuration intents of the individual profiles. - * - * This extra represents the current codec configuration of the A2DP - * profile. - */ - public static final String EXTRA_CODEC_CONFIG = "android.bluetooth.codec.extra.CODEC_CONFIG"; - - /** - * Extra for the codec configuration intents of the individual profiles. - * - * This extra represents the previous codec configuration of the A2DP - * profile. - */ - public static final String EXTRA_PREVIOUS_CODEC_CONFIG = - "android.bluetooth.codec.extra.PREVIOUS_CODEC_CONFIG"; - // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: // hardware/libhardware/include/hardware/bt_av.h @@ -128,13 +110,93 @@ public final class BluetoothCodecConfig implements Parcelable { mCodecSpecific2, mCodecSpecific3, mCodecSpecific4); } + /** + * Checks whether the object contains valid codec configuration. + * + * @return true if the object contains valid codec configuration, + * otherwise false. + */ + public boolean isValid() { + return (mSampleRate != SAMPLE_RATE_NONE) && + (mBitsPerSample != BITS_PER_SAMPLE_NONE) && + (mChannelMode != CHANNEL_MODE_NONE); + } + + /** + * Adds capability string to an existing string. + * + * @param prevStr the previous string with the capabilities. Can be + * a null pointer. + * @param capStr the capability string to append to prevStr argument. + * @return the result string in the form "prevStr|capStr". + */ + private static String appendCapabilityToString(String prevStr, + String capStr) { + if (prevStr == null) { + return capStr; + } + return prevStr + "|" + capStr; + } + @Override public String toString() { - return "{mCodecType:" + mCodecType + + String sampleRateStr = null; + if (mSampleRate == SAMPLE_RATE_NONE) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "NONE"); + } + if ((mSampleRate & SAMPLE_RATE_44100) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "44100"); + } + if ((mSampleRate & SAMPLE_RATE_48000) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "48000"); + } + if ((mSampleRate & SAMPLE_RATE_88200) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "88200"); + } + if ((mSampleRate & SAMPLE_RATE_96000) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "96000"); + } + if ((mSampleRate & SAMPLE_RATE_176400) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "176400"); + } + if ((mSampleRate & SAMPLE_RATE_192000) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "192000"); + } + + String bitsPerSampleStr = null; + if (mBitsPerSample == BITS_PER_SAMPLE_NONE) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "NONE"); + } + if ((mBitsPerSample & BITS_PER_SAMPLE_16) != 0) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "16"); + } + if ((mBitsPerSample & BITS_PER_SAMPLE_24) != 0) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "24"); + } + if ((mBitsPerSample & BITS_PER_SAMPLE_32) != 0) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "32"); + } + + String channelModeStr = null; + if (mChannelMode == CHANNEL_MODE_NONE) { + channelModeStr = appendCapabilityToString(channelModeStr, "NONE"); + } + if ((mChannelMode & CHANNEL_MODE_MONO) != 0) { + channelModeStr = appendCapabilityToString(channelModeStr, "MONO"); + } + if ((mChannelMode & CHANNEL_MODE_STEREO) != 0) { + channelModeStr = appendCapabilityToString(channelModeStr, "STEREO"); + } + + return "{codecName:" + getCodecName() + + ",mCodecType:" + mCodecType + ",mCodecPriority:" + mCodecPriority + ",mSampleRate:" + String.format("0x%x", mSampleRate) + + "(" + sampleRateStr + ")" + ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) + + "(" + bitsPerSampleStr + ")" + ",mChannelMode:" + String.format("0x%x", mChannelMode) + + "(" + channelModeStr + ")" + ",mCodecSpecific1:" + mCodecSpecific1 + ",mCodecSpecific2:" + mCodecSpecific2 + ",mCodecSpecific3:" + mCodecSpecific3 + @@ -181,7 +243,32 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec type. + * Gets the codec name. + * + * @return the codec name + */ + public String getCodecName() { + switch (mCodecType) { + case SOURCE_CODEC_TYPE_SBC: + return "SBC"; + case SOURCE_CODEC_TYPE_AAC: + return "AAC"; + case SOURCE_CODEC_TYPE_APTX: + return "aptX"; + case SOURCE_CODEC_TYPE_APTX_HD: + return "aptX HD"; + case SOURCE_CODEC_TYPE_LDAC: + return "LDAC"; + case SOURCE_CODEC_TYPE_INVALID: + return "INVALID CODEC"; + default: + break; + } + return "UNKNOWN CODEC(" + mCodecType + ")"; + } + + /** + * Gets the codec type. * See {@link android.bluetooth.BluetoothCodecConfig#SOURCE_CODEC_TYPE_SBC}. * * @return the codec type @@ -191,7 +278,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec selection priority. + * Gets the codec selection priority. * The codec selection priority is relative to other codecs: larger value * means higher priority. If 0, reset to default. * @@ -202,7 +289,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec sample rate. The value can be a bitmask with all + * Gets the codec sample rate. The value can be a bitmask with all * supported sample rates: * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_NONE} or * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_44100} or @@ -219,7 +306,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec bits per sample. The value can be a bitmask with all + * Gets the codec bits per sample. The value can be a bitmask with all * bits per sample supported: * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_NONE} or * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_16} or @@ -233,7 +320,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec channel mode. The value can be a bitmask with all + * Gets the codec channel mode. The value can be a bitmask with all * supported channel modes: * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_NONE} or * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_MONO} or @@ -246,7 +333,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value1. + * Gets a codec specific value1. * * @return a codec specific value1. */ @@ -255,7 +342,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value2. + * Gets a codec specific value2. * * @return a codec specific value2 */ @@ -264,7 +351,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value3. + * Gets a codec specific value3. * * @return a codec specific value3 */ @@ -273,7 +360,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value4. + * Gets a codec specific value4. * * @return a codec specific value4 */ -- cgit v1.2.3 From 23f591d8e8c7009f314f227db5bb16afe1d8be5d Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Sun, 5 Feb 2017 15:45:06 -0800 Subject: Add a mechanism to configure the default A2DP codec priorities Previously, the relative codec priorities were hard-codec internally. The new mechanism uses the following configurable resources in packages/apps/Bluetooth/res/values/config.xml to re-assign the default codec priorities per device, or to explicitly disable a codec. - a2dp_source_codec_priority_sbc - a2dp_source_codec_priority_aac - a2dp_source_codec_priority_aptx - a2dp_source_codec_priority_aptx_hd - a2dp_source_codec_priority_ldac Those values are assigned on startup. Also, they can be changed per device by using an overlay: device///overlay/packages/apps/Bluetooth/res/values/config.xml Test: Manually streaming to a headset Change-Id: Ic4da3a51ac73f00cbae731156cb7878c8fadee06 --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index a48210340e..176e48fb6e 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -37,9 +37,11 @@ public final class BluetoothCodecConfig implements Parcelable { public static final int SOURCE_CODEC_TYPE_APTX = 2; public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; public static final int SOURCE_CODEC_TYPE_LDAC = 4; + public static final int SOURCE_CODEC_TYPE_MAX = 5; public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; + public static final int CODEC_PRIORITY_DISABLED = -1; public static final int CODEC_PRIORITY_DEFAULT = 0; public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; @@ -72,7 +74,7 @@ public final class BluetoothCodecConfig implements Parcelable { public BluetoothCodecConfig(int codecType, int codecPriority, int sampleRate, int bitsPerSample, - int channelMode,long codecSpecific1, + int channelMode, long codecSpecific1, long codecSpecific2, long codecSpecific3, long codecSpecific4) { mCodecType = codecType; -- cgit v1.2.3 From 6319d47c4fed4f35af17fb2e906e5d97c07b3bb6 Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Fri, 24 Feb 2017 10:19:14 -0800 Subject: Add new internal API: enableOptionalCodecs()/disableOptionalCodecs() This API can be used to enable the optional codecs, or disable them and use only the mandatory SBC. Internally, it is implemented by raising the SBC priority to highest (so SBC will be used/selected), or reducing the SBC priority to its default value (lowest). Test: A2DP streaming and enabling/disabling/selecting optional codecs Bug: 35873828 Change-Id: Ia82036ac33590a3a402b1f5a36102264d47a9029 --- .../android/bluetooth/BluetoothCodecConfig.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 176e48fb6e..d5e1429810 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -63,7 +63,7 @@ public final class BluetoothCodecConfig implements Parcelable { public static final int CHANNEL_MODE_STEREO = 0x1 << 1; private final int mCodecType; - private final int mCodecPriority; + private int mCodecPriority; private final int mSampleRate; private final int mBitsPerSample; private final int mChannelMode; @@ -279,6 +279,15 @@ public final class BluetoothCodecConfig implements Parcelable { return mCodecType; } + /** + * Checks whether the codec is mandatory. + * + * @return true if the codec is mandatory, otherwise false. + */ + public boolean isMandatoryCodec() { + return mCodecType == SOURCE_CODEC_TYPE_SBC; + } + /** * Gets the codec selection priority. * The codec selection priority is relative to other codecs: larger value @@ -290,6 +299,17 @@ public final class BluetoothCodecConfig implements Parcelable { return mCodecPriority; } + /** + * Sets the codec selection priority. + * The codec selection priority is relative to other codecs: larger value + * means higher priority. If 0, reset to default. + * + * @param codecPriority the codec priority + */ + public void setCodecPriority(int codecPriority) { + mCodecPriority = codecPriority; + } + /** * Gets the codec sample rate. The value can be a bitmask with all * supported sample rates: -- cgit v1.2.3 From 910201beb0bde1dcf6b33e4ec5d1eb60042419d8 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 16:06:54 -0700 Subject: Fix checkstyle errors (1/2) * Automatic style corrections through IDE Bug: 63596319 Test: make checkbuild, no manual changes, no functional changes Change-Id: I2397d55abc34c9b7a9b748bec6137778df3421a7 --- .../android/bluetooth/BluetoothCodecConfig.java | 149 ++++++++++----------- 1 file changed, 74 insertions(+), 75 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index d5e1429810..1e463f7baf 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -32,12 +32,12 @@ public final class BluetoothCodecConfig implements Parcelable { // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: // hardware/libhardware/include/hardware/bt_av.h - public static final int SOURCE_CODEC_TYPE_SBC = 0; - public static final int SOURCE_CODEC_TYPE_AAC = 1; - public static final int SOURCE_CODEC_TYPE_APTX = 2; + public static final int SOURCE_CODEC_TYPE_SBC = 0; + public static final int SOURCE_CODEC_TYPE_AAC = 1; + public static final int SOURCE_CODEC_TYPE_APTX = 2; public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; - public static final int SOURCE_CODEC_TYPE_LDAC = 4; - public static final int SOURCE_CODEC_TYPE_MAX = 5; + public static final int SOURCE_CODEC_TYPE_LDAC = 4; + public static final int SOURCE_CODEC_TYPE_MAX = 5; public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; @@ -45,21 +45,21 @@ public final class BluetoothCodecConfig implements Parcelable { public static final int CODEC_PRIORITY_DEFAULT = 0; public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; - public static final int SAMPLE_RATE_NONE = 0; - public static final int SAMPLE_RATE_44100 = 0x1 << 0; - public static final int SAMPLE_RATE_48000 = 0x1 << 1; - public static final int SAMPLE_RATE_88200 = 0x1 << 2; - public static final int SAMPLE_RATE_96000 = 0x1 << 3; + public static final int SAMPLE_RATE_NONE = 0; + public static final int SAMPLE_RATE_44100 = 0x1 << 0; + public static final int SAMPLE_RATE_48000 = 0x1 << 1; + public static final int SAMPLE_RATE_88200 = 0x1 << 2; + public static final int SAMPLE_RATE_96000 = 0x1 << 3; public static final int SAMPLE_RATE_176400 = 0x1 << 4; public static final int SAMPLE_RATE_192000 = 0x1 << 5; public static final int BITS_PER_SAMPLE_NONE = 0; - public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; - public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; - public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; + public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; + public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; + public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; - public static final int CHANNEL_MODE_NONE = 0; - public static final int CHANNEL_MODE_MONO = 0x1 << 0; + public static final int CHANNEL_MODE_NONE = 0; + public static final int CHANNEL_MODE_MONO = 0x1 << 0; public static final int CHANNEL_MODE_STEREO = 0x1 << 1; private final int mCodecType; @@ -73,10 +73,10 @@ public final class BluetoothCodecConfig implements Parcelable { private final long mCodecSpecific4; public BluetoothCodecConfig(int codecType, int codecPriority, - int sampleRate, int bitsPerSample, - int channelMode, long codecSpecific1, - long codecSpecific2, long codecSpecific3, - long codecSpecific4) { + int sampleRate, int bitsPerSample, + int channelMode, long codecSpecific1, + long codecSpecific2, long codecSpecific3, + long codecSpecific4) { mCodecType = codecType; mCodecPriority = codecPriority; mSampleRate = sampleRate; @@ -91,7 +91,7 @@ public final class BluetoothCodecConfig implements Parcelable { @Override public boolean equals(Object o) { if (o instanceof BluetoothCodecConfig) { - BluetoothCodecConfig other = (BluetoothCodecConfig)o; + BluetoothCodecConfig other = (BluetoothCodecConfig) o; return (other.mCodecType == mCodecType && other.mCodecPriority == mCodecPriority && other.mSampleRate == mSampleRate && @@ -108,32 +108,30 @@ public final class BluetoothCodecConfig implements Parcelable { @Override public int hashCode() { return Objects.hash(mCodecType, mCodecPriority, mSampleRate, - mBitsPerSample, mChannelMode, mCodecSpecific1, - mCodecSpecific2, mCodecSpecific3, mCodecSpecific4); + mBitsPerSample, mChannelMode, mCodecSpecific1, + mCodecSpecific2, mCodecSpecific3, mCodecSpecific4); } /** * Checks whether the object contains valid codec configuration. * - * @return true if the object contains valid codec configuration, - * otherwise false. + * @return true if the object contains valid codec configuration, otherwise false. */ public boolean isValid() { return (mSampleRate != SAMPLE_RATE_NONE) && - (mBitsPerSample != BITS_PER_SAMPLE_NONE) && - (mChannelMode != CHANNEL_MODE_NONE); + (mBitsPerSample != BITS_PER_SAMPLE_NONE) && + (mChannelMode != CHANNEL_MODE_NONE); } /** * Adds capability string to an existing string. * - * @param prevStr the previous string with the capabilities. Can be - * a null pointer. + * @param prevStr the previous string with the capabilities. Can be a null pointer. * @param capStr the capability string to append to prevStr argument. * @return the result string in the form "prevStr|capStr". */ private static String appendCapabilityToString(String prevStr, - String capStr) { + String capStr) { if (prevStr == null) { return capStr; } @@ -191,18 +189,18 @@ public final class BluetoothCodecConfig implements Parcelable { } return "{codecName:" + getCodecName() + - ",mCodecType:" + mCodecType + - ",mCodecPriority:" + mCodecPriority + - ",mSampleRate:" + String.format("0x%x", mSampleRate) + - "(" + sampleRateStr + ")" + - ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) + - "(" + bitsPerSampleStr + ")" + - ",mChannelMode:" + String.format("0x%x", mChannelMode) + - "(" + channelModeStr + ")" + - ",mCodecSpecific1:" + mCodecSpecific1 + - ",mCodecSpecific2:" + mCodecSpecific2 + - ",mCodecSpecific3:" + mCodecSpecific3 + - ",mCodecSpecific4:" + mCodecSpecific4 + "}"; + ",mCodecType:" + mCodecType + + ",mCodecPriority:" + mCodecPriority + + ",mSampleRate:" + String.format("0x%x", mSampleRate) + + "(" + sampleRateStr + ")" + + ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) + + "(" + bitsPerSampleStr + ")" + + ",mChannelMode:" + String.format("0x%x", mChannelMode) + + "(" + channelModeStr + ")" + + ",mCodecSpecific1:" + mCodecSpecific1 + + ",mCodecSpecific2:" + mCodecSpecific2 + + ",mCodecSpecific3:" + mCodecSpecific3 + + ",mCodecSpecific4:" + mCodecSpecific4 + "}"; } public int describeContents() { @@ -211,26 +209,27 @@ public final class BluetoothCodecConfig implements Parcelable { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public BluetoothCodecConfig createFromParcel(Parcel in) { - final int codecType = in.readInt(); - final int codecPriority = in.readInt(); - final int sampleRate = in.readInt(); - final int bitsPerSample = in.readInt(); - final int channelMode = in.readInt(); - final long codecSpecific1 = in.readLong(); - final long codecSpecific2 = in.readLong(); - final long codecSpecific3 = in.readLong(); - final long codecSpecific4 = in.readLong(); - return new BluetoothCodecConfig(codecType, codecPriority, - sampleRate, bitsPerSample, - channelMode, codecSpecific1, - codecSpecific2, codecSpecific3, - codecSpecific4); - } - public BluetoothCodecConfig[] newArray(int size) { - return new BluetoothCodecConfig[size]; - } - }; + public BluetoothCodecConfig createFromParcel(Parcel in) { + final int codecType = in.readInt(); + final int codecPriority = in.readInt(); + final int sampleRate = in.readInt(); + final int bitsPerSample = in.readInt(); + final int channelMode = in.readInt(); + final long codecSpecific1 = in.readLong(); + final long codecSpecific2 = in.readLong(); + final long codecSpecific3 = in.readLong(); + final long codecSpecific4 = in.readLong(); + return new BluetoothCodecConfig(codecType, codecPriority, + sampleRate, bitsPerSample, + channelMode, codecSpecific1, + codecSpecific2, codecSpecific3, + codecSpecific4); + } + + public BluetoothCodecConfig[] newArray(int size) { + return new BluetoothCodecConfig[size]; + } + }; public void writeToParcel(Parcel out, int flags) { out.writeInt(mCodecType); @@ -251,20 +250,20 @@ public final class BluetoothCodecConfig implements Parcelable { */ public String getCodecName() { switch (mCodecType) { - case SOURCE_CODEC_TYPE_SBC: - return "SBC"; - case SOURCE_CODEC_TYPE_AAC: - return "AAC"; - case SOURCE_CODEC_TYPE_APTX: - return "aptX"; - case SOURCE_CODEC_TYPE_APTX_HD: - return "aptX HD"; - case SOURCE_CODEC_TYPE_LDAC: - return "LDAC"; - case SOURCE_CODEC_TYPE_INVALID: - return "INVALID CODEC"; - default: - break; + case SOURCE_CODEC_TYPE_SBC: + return "SBC"; + case SOURCE_CODEC_TYPE_AAC: + return "AAC"; + case SOURCE_CODEC_TYPE_APTX: + return "aptX"; + case SOURCE_CODEC_TYPE_APTX_HD: + return "aptX HD"; + case SOURCE_CODEC_TYPE_LDAC: + return "LDAC"; + case SOURCE_CODEC_TYPE_INVALID: + return "INVALID CODEC"; + default: + break; } return "UNKNOWN CODEC(" + mCodecType + ")"; } -- cgit v1.2.3 From 9e045d26d0128826b40520f523307d8d16473779 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 21:21:23 -0700 Subject: Fix checkstyle errors (2/2) * Manual style corrections with IDE assistance * Variable name refactors are done through IDE * Corrected general style errors such as: - "final private var" -> "private final var" - "&&", "+", "||" should not be at the end of line - Non-static private variable should be like "mVar" - Private static variable should be like "sVar" - Code file should always end with newline - Inherited methods should be annotated with @Override and no @hide tags - Public methods should always have a JavaDoc entry - "int[] array" is preferred over "int array[]" - private methods should be accessed without "this." when there is no name collisions. - "boolean ? true : false" -> boolean - "boolean ? false : true" -> !boolean - "boolean == true" OR "boolean != false" -> boolean - "boolean != true" OR "boolean == false" -> !boolean Bug: 63596319 Test: make checkbuild, no functional changes Change-Id: Iabdc2be912a32dd63a53213d175cf1bfef268ccd --- .../android/bluetooth/BluetoothCodecConfig.java | 58 +++++++++++----------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 1e463f7baf..e3a6e06472 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -92,15 +92,15 @@ public final class BluetoothCodecConfig implements Parcelable { public boolean equals(Object o) { if (o instanceof BluetoothCodecConfig) { BluetoothCodecConfig other = (BluetoothCodecConfig) o; - return (other.mCodecType == mCodecType && - other.mCodecPriority == mCodecPriority && - other.mSampleRate == mSampleRate && - other.mBitsPerSample == mBitsPerSample && - other.mChannelMode == mChannelMode && - other.mCodecSpecific1 == mCodecSpecific1 && - other.mCodecSpecific2 == mCodecSpecific2 && - other.mCodecSpecific3 == mCodecSpecific3 && - other.mCodecSpecific4 == mCodecSpecific4); + return (other.mCodecType == mCodecType + && other.mCodecPriority == mCodecPriority + && other.mSampleRate == mSampleRate + && other.mBitsPerSample == mBitsPerSample + && other.mChannelMode == mChannelMode + && other.mCodecSpecific1 == mCodecSpecific1 + && other.mCodecSpecific2 == mCodecSpecific2 + && other.mCodecSpecific3 == mCodecSpecific3 + && other.mCodecSpecific4 == mCodecSpecific4); } return false; } @@ -118,9 +118,9 @@ public final class BluetoothCodecConfig implements Parcelable { * @return true if the object contains valid codec configuration, otherwise false. */ public boolean isValid() { - return (mSampleRate != SAMPLE_RATE_NONE) && - (mBitsPerSample != BITS_PER_SAMPLE_NONE) && - (mChannelMode != CHANNEL_MODE_NONE); + return (mSampleRate != SAMPLE_RATE_NONE) + && (mBitsPerSample != BITS_PER_SAMPLE_NONE) + && (mChannelMode != CHANNEL_MODE_NONE); } /** @@ -188,21 +188,22 @@ public final class BluetoothCodecConfig implements Parcelable { channelModeStr = appendCapabilityToString(channelModeStr, "STEREO"); } - return "{codecName:" + getCodecName() + - ",mCodecType:" + mCodecType + - ",mCodecPriority:" + mCodecPriority + - ",mSampleRate:" + String.format("0x%x", mSampleRate) + - "(" + sampleRateStr + ")" + - ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) + - "(" + bitsPerSampleStr + ")" + - ",mChannelMode:" + String.format("0x%x", mChannelMode) + - "(" + channelModeStr + ")" + - ",mCodecSpecific1:" + mCodecSpecific1 + - ",mCodecSpecific2:" + mCodecSpecific2 + - ",mCodecSpecific3:" + mCodecSpecific3 + - ",mCodecSpecific4:" + mCodecSpecific4 + "}"; + return "{codecName:" + getCodecName() + + ",mCodecType:" + mCodecType + + ",mCodecPriority:" + mCodecPriority + + ",mSampleRate:" + String.format("0x%x", mSampleRate) + + "(" + sampleRateStr + ")" + + ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) + + "(" + bitsPerSampleStr + ")" + + ",mChannelMode:" + String.format("0x%x", mChannelMode) + + "(" + channelModeStr + ")" + + ",mCodecSpecific1:" + mCodecSpecific1 + + ",mCodecSpecific2:" + mCodecSpecific2 + + ",mCodecSpecific3:" + mCodecSpecific3 + + ",mCodecSpecific4:" + mCodecSpecific4 + "}"; } + @Override public int describeContents() { return 0; } @@ -231,6 +232,7 @@ public final class BluetoothCodecConfig implements Parcelable { } }; + @Override public void writeToParcel(Parcel out, int flags) { out.writeInt(mCodecType); out.writeInt(mCodecPriority); @@ -396,8 +398,8 @@ public final class BluetoothCodecConfig implements Parcelable { * @return true if the audio feeding parameters are same, otherwise false */ public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) { - return (other != null && other.mSampleRate == mSampleRate && - other.mBitsPerSample == mBitsPerSample && - other.mChannelMode == mChannelMode); + return (other != null && other.mSampleRate == mSampleRate + && other.mBitsPerSample == mBitsPerSample + && other.mChannelMode == mChannelMode); } } -- cgit v1.2.3 From 7d543894e0497651fc160728d659543483500f87 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Wed, 1 Aug 2018 15:07:20 +0100 Subject: Add @UnsupportedAppUsage annotations For packages: android.bluetooth.le android.bluetooth This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: Ifcf24c0617acd7facc0e03f30a95c3a6b09b205c Merged-In: I88a1311e27c5f9a5f9d1035db76034f86f650efc --- .../android/bluetooth/BluetoothCodecConfig.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index e3a6e06472..79c0a3a207 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -16,6 +16,7 @@ package android.bluetooth; +import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -32,34 +33,58 @@ public final class BluetoothCodecConfig implements Parcelable { // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: // hardware/libhardware/include/hardware/bt_av.h + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_SBC = 0; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_AAC = 1; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_APTX = 2; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_LDAC = 4; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_MAX = 5; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_DISABLED = -1; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_DEFAULT = 0; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; + @UnsupportedAppUsage public static final int SAMPLE_RATE_NONE = 0; + @UnsupportedAppUsage public static final int SAMPLE_RATE_44100 = 0x1 << 0; + @UnsupportedAppUsage public static final int SAMPLE_RATE_48000 = 0x1 << 1; + @UnsupportedAppUsage public static final int SAMPLE_RATE_88200 = 0x1 << 2; + @UnsupportedAppUsage public static final int SAMPLE_RATE_96000 = 0x1 << 3; + @UnsupportedAppUsage public static final int SAMPLE_RATE_176400 = 0x1 << 4; + @UnsupportedAppUsage public static final int SAMPLE_RATE_192000 = 0x1 << 5; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_NONE = 0; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; + @UnsupportedAppUsage public static final int CHANNEL_MODE_NONE = 0; + @UnsupportedAppUsage public static final int CHANNEL_MODE_MONO = 0x1 << 0; + @UnsupportedAppUsage public static final int CHANNEL_MODE_STEREO = 0x1 << 1; private final int mCodecType; @@ -72,6 +97,7 @@ public final class BluetoothCodecConfig implements Parcelable { private final long mCodecSpecific3; private final long mCodecSpecific4; + @UnsupportedAppUsage public BluetoothCodecConfig(int codecType, int codecPriority, int sampleRate, int bitsPerSample, int channelMode, long codecSpecific1, @@ -276,6 +302,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec type */ + @UnsupportedAppUsage public int getCodecType() { return mCodecType; } @@ -296,6 +323,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec priority */ + @UnsupportedAppUsage public int getCodecPriority() { return mCodecPriority; } @@ -307,6 +335,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @param codecPriority the codec priority */ + @UnsupportedAppUsage public void setCodecPriority(int codecPriority) { mCodecPriority = codecPriority; } @@ -324,6 +353,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec sample rate */ + @UnsupportedAppUsage public int getSampleRate() { return mSampleRate; } @@ -338,6 +368,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec bits per sample */ + @UnsupportedAppUsage public int getBitsPerSample() { return mBitsPerSample; } @@ -351,6 +382,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec channel mode */ + @UnsupportedAppUsage public int getChannelMode() { return mChannelMode; } @@ -360,6 +392,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value1. */ + @UnsupportedAppUsage public long getCodecSpecific1() { return mCodecSpecific1; } @@ -369,6 +402,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value2 */ + @UnsupportedAppUsage public long getCodecSpecific2() { return mCodecSpecific2; } @@ -378,6 +412,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value3 */ + @UnsupportedAppUsage public long getCodecSpecific3() { return mCodecSpecific3; } @@ -387,6 +422,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value4 */ + @UnsupportedAppUsage public long getCodecSpecific4() { return mCodecSpecific4; } -- cgit v1.2.3 From de2b201ddbf64e0a14475155ce5635d829ea5692 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Wed, 1 Aug 2018 15:00:35 +0100 Subject: Add @UnsupportedAppUsage annotations For packages: android.bluetooth.le android.bluetooth This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: I88a1311e27c5f9a5f9d1035db76034f86f650efc --- .../android/bluetooth/BluetoothCodecConfig.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index e3a6e06472..79c0a3a207 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -16,6 +16,7 @@ package android.bluetooth; +import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -32,34 +33,58 @@ public final class BluetoothCodecConfig implements Parcelable { // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: // hardware/libhardware/include/hardware/bt_av.h + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_SBC = 0; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_AAC = 1; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_APTX = 2; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_LDAC = 4; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_MAX = 5; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_DISABLED = -1; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_DEFAULT = 0; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; + @UnsupportedAppUsage public static final int SAMPLE_RATE_NONE = 0; + @UnsupportedAppUsage public static final int SAMPLE_RATE_44100 = 0x1 << 0; + @UnsupportedAppUsage public static final int SAMPLE_RATE_48000 = 0x1 << 1; + @UnsupportedAppUsage public static final int SAMPLE_RATE_88200 = 0x1 << 2; + @UnsupportedAppUsage public static final int SAMPLE_RATE_96000 = 0x1 << 3; + @UnsupportedAppUsage public static final int SAMPLE_RATE_176400 = 0x1 << 4; + @UnsupportedAppUsage public static final int SAMPLE_RATE_192000 = 0x1 << 5; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_NONE = 0; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; + @UnsupportedAppUsage public static final int CHANNEL_MODE_NONE = 0; + @UnsupportedAppUsage public static final int CHANNEL_MODE_MONO = 0x1 << 0; + @UnsupportedAppUsage public static final int CHANNEL_MODE_STEREO = 0x1 << 1; private final int mCodecType; @@ -72,6 +97,7 @@ public final class BluetoothCodecConfig implements Parcelable { private final long mCodecSpecific3; private final long mCodecSpecific4; + @UnsupportedAppUsage public BluetoothCodecConfig(int codecType, int codecPriority, int sampleRate, int bitsPerSample, int channelMode, long codecSpecific1, @@ -276,6 +302,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec type */ + @UnsupportedAppUsage public int getCodecType() { return mCodecType; } @@ -296,6 +323,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec priority */ + @UnsupportedAppUsage public int getCodecPriority() { return mCodecPriority; } @@ -307,6 +335,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @param codecPriority the codec priority */ + @UnsupportedAppUsage public void setCodecPriority(int codecPriority) { mCodecPriority = codecPriority; } @@ -324,6 +353,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec sample rate */ + @UnsupportedAppUsage public int getSampleRate() { return mSampleRate; } @@ -338,6 +368,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec bits per sample */ + @UnsupportedAppUsage public int getBitsPerSample() { return mBitsPerSample; } @@ -351,6 +382,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec channel mode */ + @UnsupportedAppUsage public int getChannelMode() { return mChannelMode; } @@ -360,6 +392,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value1. */ + @UnsupportedAppUsage public long getCodecSpecific1() { return mCodecSpecific1; } @@ -369,6 +402,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value2 */ + @UnsupportedAppUsage public long getCodecSpecific2() { return mCodecSpecific2; } @@ -378,6 +412,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value3 */ + @UnsupportedAppUsage public long getCodecSpecific3() { return mCodecSpecific3; } @@ -387,6 +422,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value4 */ + @UnsupportedAppUsage public long getCodecSpecific4() { return mCodecSpecific4; } -- cgit v1.2.3 From 5113dd680716211be7b7c23c267abf45c51b729c Mon Sep 17 00:00:00 2001 From: Arun Mirpuri Date: Fri, 11 Jan 2019 18:39:21 -0800 Subject: audio: Add API for BT to query offload A2DP encoding formats Add API in AudioManager to query offload A2DP encoding formats supported on primary HAL. This can be used instead of reading from property Bug: 111812273 Test: make Change-Id: I168f288d0bf32d6c9733c9b57934084667e794ee --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 79c0a3a207..c9d0ef247c 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -114,6 +114,19 @@ public final class BluetoothCodecConfig implements Parcelable { mCodecSpecific4 = codecSpecific4; } + @UnsupportedAppUsage + public BluetoothCodecConfig(int codecType) { + mCodecType = codecType; + mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; + mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE; + mBitsPerSample = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE; + mChannelMode = BluetoothCodecConfig.CHANNEL_MODE_NONE; + mCodecSpecific1 = 0; + mCodecSpecific2 = 0; + mCodecSpecific3 = 0; + mCodecSpecific4 = 0; + } + @Override public boolean equals(Object o) { if (o instanceof BluetoothCodecConfig) { -- cgit v1.2.3 From 13613a3f176ab3e10367685367443dddeee77db5 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 28 Feb 2019 12:06:45 -0700 Subject: All Parcelable CREATOR fields are @NonNull. If they were null, then the Parcelable would fail to work. Bug: 126726802 Test: manual Change-Id: I7929ffa2f20e5de1c8e68e8263cca99496e9d014 Exempt-From-Owner-Approval: Trivial API annotations --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index c9d0ef247c..591c418c93 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -247,7 +247,7 @@ public final class BluetoothCodecConfig implements Parcelable { return 0; } - public static final Parcelable.Creator CREATOR = + public static final @android.annotation.NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { public BluetoothCodecConfig createFromParcel(Parcel in) { final int codecType = in.readInt(); -- cgit v1.2.3 From 38a8716ef8fc33e5c8915311b932d945c864ae85 Mon Sep 17 00:00:00 2001 From: Cheney Ni Date: Thu, 18 Jul 2019 21:45:10 +0800 Subject: Add helpers to check whether the BluetoothCodecConfig instance is selectable There will be a helper in the BluetoothCodecStatus to check whether the codec config is matched the selectable array. It uses 3 smaller helpers to confirm the codec config has none (wildcard matching), or one and only one value for the audio feeding parameters. Besides, this CL also adds a helper to compare whether two codec configs are similar or not, and uses NONE values as wildcard. Bug: 131147224 Bug: 133719424 Test: atest -t BluetoothInstrumentationTests:com.android.bluetooth.a2dp Change-Id: I7d8f1a16b8358c440841801d95471b2d010739ec --- .../android/bluetooth/BluetoothCodecConfig.java | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 79c0a3a207..c79df17434 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -427,6 +427,43 @@ public final class BluetoothCodecConfig implements Parcelable { return mCodecSpecific4; } + /** + * Checks whether a value set presented by a bitmask has zero or single bit + * + * @param valueSet the value set presented by a bitmask + * @return true if the valueSet contains zero or single bit, otherwise false. + */ + private static boolean hasSingleBit(int valueSet) { + return (valueSet == 0 || (valueSet & (valueSet - 1)) == 0); + } + + /** + * Checks whether the object contains none or single sample rate. + * + * @return true if the object contains none or single sample rate, otherwise false. + */ + public boolean hasSingleSampleRate() { + return hasSingleBit(mSampleRate); + } + + /** + * Checks whether the object contains none or single bits per sample. + * + * @return true if the object contains none or single bits per sample, otherwise false. + */ + public boolean hasSingleBitsPerSample() { + return hasSingleBit(mBitsPerSample); + } + + /** + * Checks whether the object contains none or single channel mode. + * + * @return true if the object contains none or single channel mode, otherwise false. + */ + public boolean hasSingleChannelMode() { + return hasSingleBit(mChannelMode); + } + /** * Checks whether the audio feeding parameters are same. * @@ -438,4 +475,58 @@ public final class BluetoothCodecConfig implements Parcelable { && other.mBitsPerSample == mBitsPerSample && other.mChannelMode == mChannelMode); } + + /** + * Checks whether another codec config has the similar feeding parameters. + * Any parameters with NONE value will be considered to be a wildcard matching. + * + * @param other the codec config to compare against + * @return true if the audio feeding parameters are similar, otherwise false. + */ + public boolean similarCodecFeedingParameters(BluetoothCodecConfig other) { + if (other == null || mCodecType != other.mCodecType) { + return false; + } + int sampleRate = other.mSampleRate; + if (mSampleRate == BluetoothCodecConfig.SAMPLE_RATE_NONE + || sampleRate == BluetoothCodecConfig.SAMPLE_RATE_NONE) { + sampleRate = mSampleRate; + } + int bitsPerSample = other.mBitsPerSample; + if (mBitsPerSample == BluetoothCodecConfig.BITS_PER_SAMPLE_NONE + || bitsPerSample == BluetoothCodecConfig.BITS_PER_SAMPLE_NONE) { + bitsPerSample = mBitsPerSample; + } + int channelMode = other.mChannelMode; + if (mChannelMode == BluetoothCodecConfig.CHANNEL_MODE_NONE + || channelMode == BluetoothCodecConfig.CHANNEL_MODE_NONE) { + channelMode = mChannelMode; + } + return sameAudioFeedingParameters(new BluetoothCodecConfig( + mCodecType, /* priority */ 0, sampleRate, bitsPerSample, channelMode, + /* specific1 */ 0, /* specific2 */ 0, /* specific3 */ 0, + /* specific4 */ 0)); + } + + /** + * Checks whether the codec specific parameters are the same. + * + * @param other the codec config to compare against + * @return true if the codec specific parameters are the same, otherwise false. + */ + public boolean sameCodecSpecificParameters(BluetoothCodecConfig other) { + if (other == null && mCodecType != other.mCodecType) { + return false; + } + // Currently we only care about the LDAC Playback Quality at CodecSpecific1 + switch (mCodecType) { + case SOURCE_CODEC_TYPE_LDAC: + if (mCodecSpecific1 != other.mCodecSpecific1) { + return false; + } + // fall through + default: + return true; + } + } } -- cgit v1.2.3 From 4f8a2b36d14cf7beb64a51132d2352a28636eb93 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Fri, 15 Nov 2019 16:08:54 -0800 Subject: Resolve BluetoothA2dp hidden APIs to resolve dependencies Bug: 143240341 Test: Manual Change-Id: Ib55e0fb106fa7b91ef4d3559da12ea2c048f1ae5 --- .../android/bluetooth/BluetoothCodecConfig.java | 179 +++++++++++++++------ 1 file changed, 132 insertions(+), 47 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 36f3a1eeba..08d0797997 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -16,10 +16,15 @@ package android.bluetooth; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.SystemApi; import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.Objects; /** @@ -29,78 +34,131 @@ import java.util.Objects; * * {@hide} */ +@SystemApi public final class BluetoothCodecConfig implements Parcelable { // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: // hardware/libhardware/include/hardware/bt_av.h - @UnsupportedAppUsage + + /** @hide */ + @IntDef(prefix = "SOURCE_CODEC_TYPE_", value = { + SOURCE_CODEC_TYPE_SBC, + SOURCE_CODEC_TYPE_AAC, + SOURCE_CODEC_TYPE_APTX, + SOURCE_CODEC_TYPE_APTX_HD, + SOURCE_CODEC_TYPE_LDAC, + SOURCE_CODEC_TYPE_MAX, + SOURCE_CODEC_TYPE_INVALID + }) + @Retention(RetentionPolicy.SOURCE) + public @interface SourceCodecType {} + public static final int SOURCE_CODEC_TYPE_SBC = 0; - @UnsupportedAppUsage + public static final int SOURCE_CODEC_TYPE_AAC = 1; - @UnsupportedAppUsage + public static final int SOURCE_CODEC_TYPE_APTX = 2; - @UnsupportedAppUsage + public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; - @UnsupportedAppUsage + public static final int SOURCE_CODEC_TYPE_LDAC = 4; - @UnsupportedAppUsage + public static final int SOURCE_CODEC_TYPE_MAX = 5; - @UnsupportedAppUsage + public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; - @UnsupportedAppUsage + /** @hide */ + @IntDef(prefix = "CODEC_PRIORITY_", value = { + CODEC_PRIORITY_DISABLED, + CODEC_PRIORITY_DEFAULT, + CODEC_PRIORITY_HIGHEST + }) + @Retention(RetentionPolicy.SOURCE) + public @interface CodecPriority {} + public static final int CODEC_PRIORITY_DISABLED = -1; - @UnsupportedAppUsage + public static final int CODEC_PRIORITY_DEFAULT = 0; - @UnsupportedAppUsage + public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; - @UnsupportedAppUsage + + /** @hide */ + @IntDef(prefix = "SAMPLE_RATE_", value = { + SAMPLE_RATE_NONE, + SAMPLE_RATE_44100, + SAMPLE_RATE_48000, + SAMPLE_RATE_88200, + SAMPLE_RATE_96000, + SAMPLE_RATE_176400, + SAMPLE_RATE_192000 + }) + @Retention(RetentionPolicy.SOURCE) + public @interface SampleRate {} + public static final int SAMPLE_RATE_NONE = 0; - @UnsupportedAppUsage + public static final int SAMPLE_RATE_44100 = 0x1 << 0; - @UnsupportedAppUsage + public static final int SAMPLE_RATE_48000 = 0x1 << 1; - @UnsupportedAppUsage + public static final int SAMPLE_RATE_88200 = 0x1 << 2; - @UnsupportedAppUsage + public static final int SAMPLE_RATE_96000 = 0x1 << 3; - @UnsupportedAppUsage + public static final int SAMPLE_RATE_176400 = 0x1 << 4; - @UnsupportedAppUsage + public static final int SAMPLE_RATE_192000 = 0x1 << 5; - @UnsupportedAppUsage + + /** @hide */ + @IntDef(prefix = "BITS_PER_SAMPLE_", value = { + BITS_PER_SAMPLE_NONE, + BITS_PER_SAMPLE_16, + BITS_PER_SAMPLE_24, + BITS_PER_SAMPLE_32 + }) + @Retention(RetentionPolicy.SOURCE) + public @interface BitsPerSample {} + public static final int BITS_PER_SAMPLE_NONE = 0; - @UnsupportedAppUsage + public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; - @UnsupportedAppUsage + public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; - @UnsupportedAppUsage + public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; - @UnsupportedAppUsage + + /** @hide */ + @IntDef(prefix = "CHANNEL_MODE_", value = { + CHANNEL_MODE_NONE, + CHANNEL_MODE_MONO, + CHANNEL_MODE_STEREO + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ChannelMode {} + public static final int CHANNEL_MODE_NONE = 0; - @UnsupportedAppUsage + public static final int CHANNEL_MODE_MONO = 0x1 << 0; - @UnsupportedAppUsage + public static final int CHANNEL_MODE_STEREO = 0x1 << 1; - private final int mCodecType; - private int mCodecPriority; - private final int mSampleRate; - private final int mBitsPerSample; - private final int mChannelMode; + private final @SourceCodecType int mCodecType; + private @CodecPriority int mCodecPriority; + private final @SampleRate int mSampleRate; + private final @BitsPerSample int mBitsPerSample; + private final @ChannelMode int mChannelMode; private final long mCodecSpecific1; private final long mCodecSpecific2; private final long mCodecSpecific3; private final long mCodecSpecific4; - @UnsupportedAppUsage - public BluetoothCodecConfig(int codecType, int codecPriority, - int sampleRate, int bitsPerSample, - int channelMode, long codecSpecific1, + public BluetoothCodecConfig(@SourceCodecType int codecType, @CodecPriority int codecPriority, + @SampleRate int sampleRate, @BitsPerSample int bitsPerSample, + @ChannelMode int channelMode, long codecSpecific1, long codecSpecific2, long codecSpecific3, long codecSpecific4) { mCodecType = codecType; @@ -114,8 +172,7 @@ public final class BluetoothCodecConfig implements Parcelable { mCodecSpecific4 = codecSpecific4; } - @UnsupportedAppUsage - public BluetoothCodecConfig(int codecType) { + public BluetoothCodecConfig(@SourceCodecType int codecType) { mCodecType = codecType; mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE; @@ -144,6 +201,12 @@ public final class BluetoothCodecConfig implements Parcelable { return false; } + /** + * Returns a hash based on the config values + * + * @return a hash based on the config values + * @hide + */ @Override public int hashCode() { return Objects.hash(mCodecType, mCodecPriority, mSampleRate, @@ -155,6 +218,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Checks whether the object contains valid codec configuration. * * @return true if the object contains valid codec configuration, otherwise false. + * @hide */ public boolean isValid() { return (mSampleRate != SAMPLE_RATE_NONE) @@ -242,6 +306,12 @@ public final class BluetoothCodecConfig implements Parcelable { + ",mCodecSpecific4:" + mCodecSpecific4 + "}"; } + /** + * Always returns 0 + * + * @return 0 + * @hide + */ @Override public int describeContents() { return 0; @@ -271,6 +341,14 @@ public final class BluetoothCodecConfig implements Parcelable { } }; + /** + * Flattens the object to a parcel + * + * @param out The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. + * + * @hide + */ @Override public void writeToParcel(Parcel out, int flags) { out.writeInt(mCodecType); @@ -289,7 +367,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec name */ - public String getCodecName() { + public @NonNull String getCodecName() { switch (mCodecType) { case SOURCE_CODEC_TYPE_SBC: return "SBC"; @@ -315,8 +393,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec type */ - @UnsupportedAppUsage - public int getCodecType() { + public @SourceCodecType int getCodecType() { return mCodecType; } @@ -336,8 +413,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec priority */ - @UnsupportedAppUsage - public int getCodecPriority() { + public @CodecPriority int getCodecPriority() { return mCodecPriority; } @@ -347,9 +423,10 @@ public final class BluetoothCodecConfig implements Parcelable { * means higher priority. If 0, reset to default. * * @param codecPriority the codec priority + * @hide */ @UnsupportedAppUsage - public void setCodecPriority(int codecPriority) { + public void setCodecPriority(@CodecPriority int codecPriority) { mCodecPriority = codecPriority; } @@ -366,8 +443,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec sample rate */ - @UnsupportedAppUsage - public int getSampleRate() { + public @SampleRate int getSampleRate() { return mSampleRate; } @@ -381,8 +457,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec bits per sample */ - @UnsupportedAppUsage - public int getBitsPerSample() { + public @BitsPerSample int getBitsPerSample() { return mBitsPerSample; } @@ -394,9 +469,10 @@ public final class BluetoothCodecConfig implements Parcelable { * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_STEREO} * * @return the codec channel mode + * @hide */ @UnsupportedAppUsage - public int getChannelMode() { + public @ChannelMode int getChannelMode() { return mChannelMode; } @@ -405,7 +481,6 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value1. */ - @UnsupportedAppUsage public long getCodecSpecific1() { return mCodecSpecific1; } @@ -414,6 +489,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Gets a codec specific value2. * * @return a codec specific value2 + * @hide */ @UnsupportedAppUsage public long getCodecSpecific2() { @@ -424,6 +500,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Gets a codec specific value3. * * @return a codec specific value3 + * @hide */ @UnsupportedAppUsage public long getCodecSpecific3() { @@ -434,6 +511,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Gets a codec specific value4. * * @return a codec specific value4 + * @hide */ @UnsupportedAppUsage public long getCodecSpecific4() { @@ -445,6 +523,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @param valueSet the value set presented by a bitmask * @return true if the valueSet contains zero or single bit, otherwise false. + * @hide */ private static boolean hasSingleBit(int valueSet) { return (valueSet == 0 || (valueSet & (valueSet - 1)) == 0); @@ -454,6 +533,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Checks whether the object contains none or single sample rate. * * @return true if the object contains none or single sample rate, otherwise false. + * @hide */ public boolean hasSingleSampleRate() { return hasSingleBit(mSampleRate); @@ -463,6 +543,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Checks whether the object contains none or single bits per sample. * * @return true if the object contains none or single bits per sample, otherwise false. + * @hide */ public boolean hasSingleBitsPerSample() { return hasSingleBit(mBitsPerSample); @@ -472,6 +553,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Checks whether the object contains none or single channel mode. * * @return true if the object contains none or single channel mode, otherwise false. + * @hide */ public boolean hasSingleChannelMode() { return hasSingleBit(mChannelMode); @@ -482,6 +564,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @param other the codec config to compare against * @return true if the audio feeding parameters are same, otherwise false + * @hide */ public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) { return (other != null && other.mSampleRate == mSampleRate @@ -495,6 +578,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @param other the codec config to compare against * @return true if the audio feeding parameters are similar, otherwise false. + * @hide */ public boolean similarCodecFeedingParameters(BluetoothCodecConfig other) { if (other == null || mCodecType != other.mCodecType) { @@ -526,6 +610,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @param other the codec config to compare against * @return true if the codec specific parameters are the same, otherwise false. + * @hide */ public boolean sameCodecSpecificParameters(BluetoothCodecConfig other) { if (other == null && mCodecType != other.mCodecType) { -- cgit v1.2.3 From cb33332a4259dc9e5cc3833cd3d38c1caa165c7b Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Tue, 10 Dec 2019 17:47:52 +0000 Subject: Use new UnsupportedAppUsage annotation. Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I6ab53570aca580fbee1fcc927871caa09780f58f --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 08d0797997..93e76fa5ba 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -19,7 +19,7 @@ package android.bluetooth; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.SystemApi; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; -- cgit v1.2.3 From 3625be4eb7d52fe10c659b649d945a4cea0d0beb Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Tue, 10 Dec 2019 17:47:52 +0000 Subject: Use new UnsupportedAppUsage annotation. Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I6ab53570aca580fbee1fcc927871caa09780f58f Merged-In: I6ab53570aca580fbee1fcc927871caa09780f58f --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 08d0797997..93e76fa5ba 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -19,7 +19,7 @@ package android.bluetooth; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.SystemApi; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; -- cgit v1.2.3 From 5d71da5f6837ab2c582559d429dcc67354e9911f Mon Sep 17 00:00:00 2001 From: Cheney Ni Date: Fri, 10 Jan 2020 02:32:54 +0800 Subject: A2DP: Check AAC bitrate mode by its CodecSpecific1 Bug: 112325138 Test: manual Change-Id: Ib00dd08df98f16a5d52df52d395bf1cb4aaf914c --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 08d0797997..33cb75ed07 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -616,8 +616,9 @@ public final class BluetoothCodecConfig implements Parcelable { if (other == null && mCodecType != other.mCodecType) { return false; } - // Currently we only care about the LDAC Playback Quality at CodecSpecific1 + // Currently we only care about the AAC VBR and LDAC Playback Quality at CodecSpecific1 switch (mCodecType) { + case SOURCE_CODEC_TYPE_AAC: case SOURCE_CODEC_TYPE_LDAC: if (mCodecSpecific1 != other.mCodecSpecific1) { return false; -- cgit v1.2.3 From ce594994e8aa1b4bf9a6917e18c4f2f3b68c1ddc Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Wed, 18 Mar 2020 17:46:33 -0700 Subject: Add BLUETOOTH_PRIVILEGED permission as a requirement for all new Bluetooth SystemApis and for hidden connect/disconnect APIs. Hide some APIs that were previously marked as @UnsupportedAppUsage and re-add annotation as changing the permissions for these SystemApis would break the unsupported app contract that was previously there. Therefore, we're choosing to hide them until we have a good story on how to deal with them next release. Bug: 148689314 Test: Manual Change-Id: I33ee2c7ccd3827db3d23d6447cf82d9ffc36836a --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 93e76fa5ba..d2a15357aa 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -18,7 +18,6 @@ package android.bluetooth; import android.annotation.IntDef; import android.annotation.NonNull; -import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -34,7 +33,6 @@ import java.util.Objects; * * {@hide} */ -@SystemApi public final class BluetoothCodecConfig implements Parcelable { // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: -- cgit v1.2.3 From c228ce27e2d7fe26193236eb5d4299214deb17ec Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Wed, 18 Mar 2020 17:46:33 -0700 Subject: Add BLUETOOTH_PRIVILEGED permission as a requirement for all new Bluetooth SystemApis and for hidden connect/disconnect APIs. Hide some APIs that were previously marked as @UnsupportedAppUsage and re-add annotation as changing the permissions for these SystemApis would break the unsupported app contract that was previously there. Therefore, we're choosing to hide them until we have a good story on how to deal with them next release. Bug: 148689314 Test: Manual Merged-In: I33ee2c7ccd3827db3d23d6447cf82d9ffc36836a Change-Id: I33ee2c7ccd3827db3d23d6447cf82d9ffc36836a --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 2 -- 1 file changed, 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 93e76fa5ba..d2a15357aa 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -18,7 +18,6 @@ package android.bluetooth; import android.annotation.IntDef; import android.annotation.NonNull; -import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -34,7 +33,6 @@ import java.util.Objects; * * {@hide} */ -@SystemApi public final class BluetoothCodecConfig implements Parcelable { // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: -- cgit v1.2.3 From f12655cc803675060d87665b8f6685d5c4816431 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Mon, 21 Sep 2020 20:50:10 -0700 Subject: Move all BluetoothCodecConfig and BluetoothCodecStatus APIs moved from the non-SDK API list to the blocklist in Android 11 back to the non-SDK API list. Tag: #feature Bug: 168812851 Test: atest BluetoothHostTest#testCodecMethodsAccessible Change-Id: I29983284b1a1c271d983c99b286e204604abdc72 --- .../android/bluetooth/BluetoothCodecConfig.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index d2a15357aa..735980beeb 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -51,19 +51,25 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface SourceCodecType {} + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_SBC = 0; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_AAC = 1; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_APTX = 2; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_LDAC = 4; + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_MAX = 5; - + @UnsupportedAppUsage public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; /** @hide */ @@ -75,10 +81,13 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface CodecPriority {} + @UnsupportedAppUsage public static final int CODEC_PRIORITY_DISABLED = -1; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_DEFAULT = 0; + @UnsupportedAppUsage public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; @@ -95,18 +104,25 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface SampleRate {} + @UnsupportedAppUsage public static final int SAMPLE_RATE_NONE = 0; + @UnsupportedAppUsage public static final int SAMPLE_RATE_44100 = 0x1 << 0; + @UnsupportedAppUsage public static final int SAMPLE_RATE_48000 = 0x1 << 1; + @UnsupportedAppUsage public static final int SAMPLE_RATE_88200 = 0x1 << 2; + @UnsupportedAppUsage public static final int SAMPLE_RATE_96000 = 0x1 << 3; + @UnsupportedAppUsage public static final int SAMPLE_RATE_176400 = 0x1 << 4; + @UnsupportedAppUsage public static final int SAMPLE_RATE_192000 = 0x1 << 5; @@ -120,12 +136,16 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface BitsPerSample {} + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_NONE = 0; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; + @UnsupportedAppUsage public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; @@ -138,10 +158,13 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface ChannelMode {} + @UnsupportedAppUsage public static final int CHANNEL_MODE_NONE = 0; + @UnsupportedAppUsage public static final int CHANNEL_MODE_MONO = 0x1 << 0; + @UnsupportedAppUsage public static final int CHANNEL_MODE_STEREO = 0x1 << 1; private final @SourceCodecType int mCodecType; @@ -154,6 +177,7 @@ public final class BluetoothCodecConfig implements Parcelable { private final long mCodecSpecific3; private final long mCodecSpecific4; + @UnsupportedAppUsage public BluetoothCodecConfig(@SourceCodecType int codecType, @CodecPriority int codecPriority, @SampleRate int sampleRate, @BitsPerSample int bitsPerSample, @ChannelMode int channelMode, long codecSpecific1, @@ -170,6 +194,7 @@ public final class BluetoothCodecConfig implements Parcelable { mCodecSpecific4 = codecSpecific4; } + @UnsupportedAppUsage public BluetoothCodecConfig(@SourceCodecType int codecType) { mCodecType = codecType; mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; @@ -391,6 +416,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec type */ + @UnsupportedAppUsage public @SourceCodecType int getCodecType() { return mCodecType; } @@ -411,6 +437,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec priority */ + @UnsupportedAppUsage public @CodecPriority int getCodecPriority() { return mCodecPriority; } @@ -441,6 +468,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec sample rate */ + @UnsupportedAppUsage public @SampleRate int getSampleRate() { return mSampleRate; } @@ -455,6 +483,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return the codec bits per sample */ + @UnsupportedAppUsage public @BitsPerSample int getBitsPerSample() { return mBitsPerSample; } @@ -479,6 +508,7 @@ public final class BluetoothCodecConfig implements Parcelable { * * @return a codec specific value1. */ + @UnsupportedAppUsage public long getCodecSpecific1() { return mCodecSpecific1; } -- cgit v1.2.3 From 2883f7ab9e740b5da3c872b9fe675691ddfc322d Mon Sep 17 00:00:00 2001 From: Roman Kalukiewicz Date: Wed, 14 Oct 2020 15:59:06 -0700 Subject: Add @Nullable annotation to the parameter of Object.equals() methods. Those annotations could be inferred by some tools (like Kotlin), but the https://checkerframework.org/ doesn't check inherited annotations complaining about all equals() invocations that get nullable argument. The change was generated by running find . -name \*.java | xargs sed -i 's/public boolean equals(Object /public boolean equals(@Nullable Object /' in the frameworks/base directory and by automatically adding and formatting required imports if needed. No manual edits. Bug: 170883422 Test: Annotation change only. Should have not impact. Exempt-From-Owner-Approval: Mechanical change not specific to any component. Change-Id: I5eedb571c9d78862115dfdc5dae1cf2a35343580 --- framework/java/android/bluetooth/BluetoothCodecConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index a52fc89179..1d0bf97c34 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -18,6 +18,7 @@ package android.bluetooth; import android.annotation.IntDef; import android.annotation.NonNull; +import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -208,7 +209,7 @@ public final class BluetoothCodecConfig implements Parcelable { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (o instanceof BluetoothCodecConfig) { BluetoothCodecConfig other = (BluetoothCodecConfig) o; return (other.mCodecType == mCodecType -- cgit v1.2.3 From 55a03869afdab02fd0737daf3f78151959e0d32c Mon Sep 17 00:00:00 2001 From: Etienne Ruffieux Date: Tue, 5 Oct 2021 17:11:45 +0000 Subject: Make BluetoothCodecConfig and BluetoothCodecStatus public. Made BluetoothCodecConfig and BluetoothCodecStatus public, added Builder to BluetoothCodecConfig, added accessor for SOURCE_CODEC_TYPE_MAX and changed Arrays returns to List. Tag: #feature Bug: 200202780 Bug: 170678351 Test: BluetoothCodecConfigTest & BluetoothCodecStatusTest NoNonSdkCheck: Only user actually requested the changes Change-Id: Ic61b7087f53f45781f7e0eecca8b6d983093a22d --- .../android/bluetooth/BluetoothCodecConfig.java | 497 +++++++++++++-------- 1 file changed, 322 insertions(+), 175 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 1d0bf97c34..9a4151adff 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -29,16 +29,14 @@ import java.util.Objects; /** * Represents the codec configuration for a Bluetooth A2DP source device. + *

Contains the source codec type, the codec priority, the codec sample + * rate, the codec bits per sample, and the codec channel mode. + *

The source codec type values are the same as those supported by the + * device hardware. * * {@see BluetoothA2dp} - * - * {@hide} */ public final class BluetoothCodecConfig implements Parcelable { - // Add an entry for each source codec here. - // NOTE: The values should be same as those listed in the following file: - // hardware/libhardware/include/hardware/bt_av.h - /** @hide */ @IntDef(prefix = "SOURCE_CODEC_TYPE_", value = { SOURCE_CODEC_TYPE_SBC, @@ -46,33 +44,49 @@ public final class BluetoothCodecConfig implements Parcelable { SOURCE_CODEC_TYPE_APTX, SOURCE_CODEC_TYPE_APTX_HD, SOURCE_CODEC_TYPE_LDAC, - SOURCE_CODEC_TYPE_MAX, SOURCE_CODEC_TYPE_INVALID }) @Retention(RetentionPolicy.SOURCE) public @interface SourceCodecType {} - @UnsupportedAppUsage + /** + * Source codec type SBC. This is the mandatory source codec + * type. + */ public static final int SOURCE_CODEC_TYPE_SBC = 0; - @UnsupportedAppUsage + /** + * Source codec type AAC. + */ public static final int SOURCE_CODEC_TYPE_AAC = 1; - @UnsupportedAppUsage + /** + * Source codec type APTX. + */ public static final int SOURCE_CODEC_TYPE_APTX = 2; - @UnsupportedAppUsage + /** + * Source codec type APTX HD. + */ public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; - @UnsupportedAppUsage + /** + * Source codec type LDAC. + */ public static final int SOURCE_CODEC_TYPE_LDAC = 4; - @UnsupportedAppUsage - public static final int SOURCE_CODEC_TYPE_MAX = 5; - - @UnsupportedAppUsage + /** + * Source codec type invalid. This is the default value used for codec + * type. + */ public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; + /** + * Represents the count of valid source codec types. Can be accessed via + * {@link #getMaxCodecType}. + */ + private static final int SOURCE_CODEC_TYPE_MAX = 5; + /** @hide */ @IntDef(prefix = "CODEC_PRIORITY_", value = { CODEC_PRIORITY_DISABLED, @@ -82,16 +96,24 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface CodecPriority {} - @UnsupportedAppUsage + /** + * Codec priority disabled. + * Used to indicate that this codec is disabled and should not be used. + */ public static final int CODEC_PRIORITY_DISABLED = -1; - @UnsupportedAppUsage + /** + * Codec priority default. + * Default value used for codec priority. + */ public static final int CODEC_PRIORITY_DEFAULT = 0; - @UnsupportedAppUsage + /** + * Codec priority highest. + * Used to indicate the highest priority a codec can have. + */ public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; - /** @hide */ @IntDef(prefix = "SAMPLE_RATE_", value = { SAMPLE_RATE_NONE, @@ -105,28 +127,42 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface SampleRate {} - @UnsupportedAppUsage + /** + * Codec sample rate 0 Hz. Default value used for + * codec sample rate. + */ public static final int SAMPLE_RATE_NONE = 0; - @UnsupportedAppUsage + /** + * Codec sample rate 44100 Hz. + */ public static final int SAMPLE_RATE_44100 = 0x1 << 0; - @UnsupportedAppUsage + /** + * Codec sample rate 48000 Hz. + */ public static final int SAMPLE_RATE_48000 = 0x1 << 1; - @UnsupportedAppUsage + /** + * Codec sample rate 88200 Hz. + */ public static final int SAMPLE_RATE_88200 = 0x1 << 2; - @UnsupportedAppUsage + /** + * Codec sample rate 96000 Hz. + */ public static final int SAMPLE_RATE_96000 = 0x1 << 3; - @UnsupportedAppUsage + /** + * Codec sample rate 176400 Hz. + */ public static final int SAMPLE_RATE_176400 = 0x1 << 4; - @UnsupportedAppUsage + /** + * Codec sample rate 192000 Hz. + */ public static final int SAMPLE_RATE_192000 = 0x1 << 5; - /** @hide */ @IntDef(prefix = "BITS_PER_SAMPLE_", value = { BITS_PER_SAMPLE_NONE, @@ -137,19 +173,27 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface BitsPerSample {} - @UnsupportedAppUsage + /** + * Codec bits per sample 0. Default value of the codec + * bits per sample. + */ public static final int BITS_PER_SAMPLE_NONE = 0; - @UnsupportedAppUsage + /** + * Codec bits per sample 16. + */ public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; - @UnsupportedAppUsage + /** + * Codec bits per sample 24. + */ public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; - @UnsupportedAppUsage + /** + * Codec bits per sample 32. + */ public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; - /** @hide */ @IntDef(prefix = "CHANNEL_MODE_", value = { CHANNEL_MODE_NONE, @@ -159,13 +203,20 @@ public final class BluetoothCodecConfig implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface ChannelMode {} - @UnsupportedAppUsage + /** + * Codec channel mode NONE. Default value of the + * codec channel mode. + */ public static final int CHANNEL_MODE_NONE = 0; - @UnsupportedAppUsage + /** + * Codec channel mode MONO. + */ public static final int CHANNEL_MODE_MONO = 0x1 << 0; - @UnsupportedAppUsage + /** + * Codec channel mode STEREO. + */ public static final int CHANNEL_MODE_STEREO = 0x1 << 1; private final @SourceCodecType int mCodecType; @@ -178,6 +229,21 @@ public final class BluetoothCodecConfig implements Parcelable { private final long mCodecSpecific3; private final long mCodecSpecific4; + /** + * Creates a new BluetoothCodecConfig. + * + * @param codecType the source codec type + * @param codecPriority the priority of this codec + * @param sampleRate the codec sample rate + * @param bitsPerSample the bits per sample of this codec + * @param channelMode the channel mode of this codec + * @param codecSpecific1 the specific value 1 + * @param codecSpecific2 the specific value 2 + * @param codecSpecific3 the specific value 3 + * @param codecSpecific4 the specific value 4 + * values to 0. + * @hide + */ @UnsupportedAppUsage public BluetoothCodecConfig(@SourceCodecType int codecType, @CodecPriority int codecPriority, @SampleRate int sampleRate, @BitsPerSample int bitsPerSample, @@ -195,17 +261,34 @@ public final class BluetoothCodecConfig implements Parcelable { mCodecSpecific4 = codecSpecific4; } - @UnsupportedAppUsage + /** + * Creates a new BluetoothCodecConfig. + *

By default, the codec priority will be set + * to {@link BluetoothCodecConfig#CODEC_PRIORITY_DEFAULT}, the sample rate to + * {@link BluetoothCodecConfig#SAMPLE_RATE_NONE}, the bits per sample to + * {@link BluetoothCodecConfig#BITS_PER_SAMPLE_NONE}, the channel mode to + * {@link BluetoothCodecConfig#CHANNEL_MODE_NONE}, and all the codec specific + * values to 0. + * + * @param codecType the source codec type + */ public BluetoothCodecConfig(@SourceCodecType int codecType) { - mCodecType = codecType; - mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; - mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE; - mBitsPerSample = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE; - mChannelMode = BluetoothCodecConfig.CHANNEL_MODE_NONE; - mCodecSpecific1 = 0; - mCodecSpecific2 = 0; - mCodecSpecific3 = 0; - mCodecSpecific4 = 0; + this(codecType, BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT, + BluetoothCodecConfig.SAMPLE_RATE_NONE, + BluetoothCodecConfig.BITS_PER_SAMPLE_NONE, + BluetoothCodecConfig.CHANNEL_MODE_NONE, 0, 0, 0, 0); + } + + private BluetoothCodecConfig(Parcel in) { + mCodecType = in.readInt(); + mCodecPriority = in.readInt(); + mSampleRate = in.readInt(); + mBitsPerSample = in.readInt(); + mChannelMode = in.readInt(); + mCodecSpecific1 = in.readLong(); + mCodecSpecific2 = in.readLong(); + mCodecSpecific3 = in.readLong(); + mCodecSpecific4 = in.readLong(); } @Override @@ -226,10 +309,8 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a hash based on the config values - * - * @return a hash based on the config values - * @hide + * Returns a hash representation of this BluetoothCodecConfig + * based on all the config values. */ @Override public int hashCode() { @@ -238,33 +319,25 @@ public final class BluetoothCodecConfig implements Parcelable { mCodecSpecific2, mCodecSpecific3, mCodecSpecific4); } - /** - * Checks whether the object contains valid codec configuration. - * - * @return true if the object contains valid codec configuration, otherwise false. - * @hide - */ - public boolean isValid() { - return (mSampleRate != SAMPLE_RATE_NONE) - && (mBitsPerSample != BITS_PER_SAMPLE_NONE) - && (mChannelMode != CHANNEL_MODE_NONE); - } - /** * Adds capability string to an existing string. * - * @param prevStr the previous string with the capabilities. Can be a null pointer. - * @param capStr the capability string to append to prevStr argument. - * @return the result string in the form "prevStr|capStr". + * @param prevStr the previous string with the capabilities. Can be a {@code null} pointer + * @param capStr the capability string to append to prevStr argument + * @return the result string in the form "prevStr|capStr" */ - private static String appendCapabilityToString(String prevStr, - String capStr) { + private static String appendCapabilityToString(@Nullable String prevStr, + @NonNull String capStr) { if (prevStr == null) { return capStr; } return prevStr + "|" + capStr; } + /** + * Returns a {@link String} that describes each BluetoothCodecConfig parameter + * current value. + */ @Override public String toString() { String sampleRateStr = null; @@ -331,8 +404,6 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Always returns 0 - * * @return 0 * @hide */ @@ -344,20 +415,7 @@ public final class BluetoothCodecConfig implements Parcelable { public static final @android.annotation.NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { public BluetoothCodecConfig createFromParcel(Parcel in) { - final int codecType = in.readInt(); - final int codecPriority = in.readInt(); - final int sampleRate = in.readInt(); - final int bitsPerSample = in.readInt(); - final int channelMode = in.readInt(); - final long codecSpecific1 = in.readLong(); - final long codecSpecific2 = in.readLong(); - final long codecSpecific3 = in.readLong(); - final long codecSpecific4 = in.readLong(); - return new BluetoothCodecConfig(codecType, codecPriority, - sampleRate, bitsPerSample, - channelMode, codecSpecific1, - codecSpecific2, codecSpecific3, - codecSpecific4); + return new BluetoothCodecConfig(in); } public BluetoothCodecConfig[] newArray(int size) { @@ -368,8 +426,8 @@ public final class BluetoothCodecConfig implements Parcelable { /** * Flattens the object to a parcel * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. + * @param out The Parcel in which the object should be written + * @param flags Additional flags about how the object should be written * * @hide */ @@ -387,9 +445,8 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Gets the codec name. - * - * @return the codec name + * Returns the codec name converted to {@link String}. + * @hide */ public @NonNull String getCodecName() { switch (mCodecType) { @@ -412,137 +469,100 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Gets the codec type. - * See {@link android.bluetooth.BluetoothCodecConfig#SOURCE_CODEC_TYPE_SBC}. - * - * @return the codec type + * Returns the source codec type of this config. */ - @UnsupportedAppUsage public @SourceCodecType int getCodecType() { return mCodecType; } + /** + * Returns the valid codec types count. + */ + public static int getMaxCodecType() { + return SOURCE_CODEC_TYPE_MAX; + } + /** * Checks whether the codec is mandatory. + *

The actual mandatory codec type for Android Bluetooth audio is SBC. + * See {@link #SOURCE_CODEC_TYPE_SBC}. * - * @return true if the codec is mandatory, otherwise false. + * @return {@code true} if the codec is mandatory, {@code false} otherwise + * @hide */ public boolean isMandatoryCodec() { return mCodecType == SOURCE_CODEC_TYPE_SBC; } /** - * Gets the codec selection priority. - * The codec selection priority is relative to other codecs: larger value - * means higher priority. If 0, reset to default. - * - * @return the codec priority + * Returns the codec selection priority. + *

The codec selection priority is relative to other codecs: larger value + * means higher priority. */ - @UnsupportedAppUsage public @CodecPriority int getCodecPriority() { return mCodecPriority; } /** * Sets the codec selection priority. - * The codec selection priority is relative to other codecs: larger value - * means higher priority. If 0, reset to default. + *

The codec selection priority is relative to other codecs: larger value + * means higher priority. * - * @param codecPriority the codec priority + * @param codecPriority the priority this codec should have * @hide */ - @UnsupportedAppUsage public void setCodecPriority(@CodecPriority int codecPriority) { mCodecPriority = codecPriority; } /** - * Gets the codec sample rate. The value can be a bitmask with all - * supported sample rates: - * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_NONE} or - * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_44100} or - * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_48000} or - * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_88200} or - * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_96000} or - * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_176400} or - * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_192000} - * - * @return the codec sample rate + * Returns the codec sample rate. The value can be a bitmask with all + * supported sample rates. */ - @UnsupportedAppUsage public @SampleRate int getSampleRate() { return mSampleRate; } /** - * Gets the codec bits per sample. The value can be a bitmask with all - * bits per sample supported: - * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_NONE} or - * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_16} or - * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_24} or - * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_32} - * - * @return the codec bits per sample + * Returns the codec bits per sample. The value can be a bitmask with all + * bits per sample supported. */ - @UnsupportedAppUsage public @BitsPerSample int getBitsPerSample() { return mBitsPerSample; } /** - * Gets the codec channel mode. The value can be a bitmask with all - * supported channel modes: - * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_NONE} or - * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_MONO} or - * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_STEREO} - * - * @return the codec channel mode - * @hide + * Returns the codec channel mode. The value can be a bitmask with all + * supported channel modes. */ - @UnsupportedAppUsage public @ChannelMode int getChannelMode() { return mChannelMode; } /** - * Gets a codec specific value1. - * - * @return a codec specific value1. + * Returns the codec specific value1. */ - @UnsupportedAppUsage public long getCodecSpecific1() { return mCodecSpecific1; } /** - * Gets a codec specific value2. - * - * @return a codec specific value2 - * @hide + * Returns the codec specific value2. */ - @UnsupportedAppUsage public long getCodecSpecific2() { return mCodecSpecific2; } /** - * Gets a codec specific value3. - * - * @return a codec specific value3 - * @hide + * Returns the codec specific value3. */ - @UnsupportedAppUsage public long getCodecSpecific3() { return mCodecSpecific3; } /** - * Gets a codec specific value4. - * - * @return a codec specific value4 - * @hide + * Returns the codec specific value4. */ - @UnsupportedAppUsage public long getCodecSpecific4() { return mCodecSpecific4; } @@ -551,7 +571,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Checks whether a value set presented by a bitmask has zero or single bit * * @param valueSet the value set presented by a bitmask - * @return true if the valueSet contains zero or single bit, otherwise false. + * @return {@code true} if the valueSet contains zero or single bit, {@code false} otherwise * @hide */ private static boolean hasSingleBit(int valueSet) { @@ -559,9 +579,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Checks whether the object contains none or single sample rate. - * - * @return true if the object contains none or single sample rate, otherwise false. + * Returns whether the object contains none or single sample rate. * @hide */ public boolean hasSingleSampleRate() { @@ -569,9 +587,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Checks whether the object contains none or single bits per sample. - * - * @return true if the object contains none or single bits per sample, otherwise false. + * Returns whether the object contains none or single bits per sample. * @hide */ public boolean hasSingleBitsPerSample() { @@ -579,9 +595,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Checks whether the object contains none or single channel mode. - * - * @return true if the object contains none or single channel mode, otherwise false. + * Returns whether the object contains none or single channel mode. * @hide */ public boolean hasSingleChannelMode() { @@ -589,10 +603,10 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Checks whether the audio feeding parameters are same. + * Checks whether the audio feeding parameters are the same. * * @param other the codec config to compare against - * @return true if the audio feeding parameters are same, otherwise false + * @return {@code true} if the audio feeding parameters are same, {@code false} otherwise * @hide */ public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) { @@ -606,7 +620,7 @@ public final class BluetoothCodecConfig implements Parcelable { * Any parameters with NONE value will be considered to be a wildcard matching. * * @param other the codec config to compare against - * @return true if the audio feeding parameters are similar, otherwise false. + * @return {@code true} if the audio feeding parameters are similar, {@code false} otherwise * @hide */ public boolean similarCodecFeedingParameters(BluetoothCodecConfig other) { @@ -614,18 +628,18 @@ public final class BluetoothCodecConfig implements Parcelable { return false; } int sampleRate = other.mSampleRate; - if (mSampleRate == BluetoothCodecConfig.SAMPLE_RATE_NONE - || sampleRate == BluetoothCodecConfig.SAMPLE_RATE_NONE) { + if (mSampleRate == SAMPLE_RATE_NONE + || sampleRate == SAMPLE_RATE_NONE) { sampleRate = mSampleRate; } int bitsPerSample = other.mBitsPerSample; - if (mBitsPerSample == BluetoothCodecConfig.BITS_PER_SAMPLE_NONE - || bitsPerSample == BluetoothCodecConfig.BITS_PER_SAMPLE_NONE) { + if (mBitsPerSample == BITS_PER_SAMPLE_NONE + || bitsPerSample == BITS_PER_SAMPLE_NONE) { bitsPerSample = mBitsPerSample; } int channelMode = other.mChannelMode; - if (mChannelMode == BluetoothCodecConfig.CHANNEL_MODE_NONE - || channelMode == BluetoothCodecConfig.CHANNEL_MODE_NONE) { + if (mChannelMode == CHANNEL_MODE_NONE + || channelMode == CHANNEL_MODE_NONE) { channelMode = mChannelMode; } return sameAudioFeedingParameters(new BluetoothCodecConfig( @@ -636,25 +650,158 @@ public final class BluetoothCodecConfig implements Parcelable { /** * Checks whether the codec specific parameters are the same. + *

Currently, only AAC VBR and LDAC Playback Quality on CodecSpecific1 + * are compared. * * @param other the codec config to compare against - * @return true if the codec specific parameters are the same, otherwise false. + * @return {@code true} if the codec specific parameters are the same, {@code false} otherwise * @hide */ public boolean sameCodecSpecificParameters(BluetoothCodecConfig other) { if (other == null && mCodecType != other.mCodecType) { return false; } - // Currently we only care about the AAC VBR and LDAC Playback Quality at CodecSpecific1 switch (mCodecType) { case SOURCE_CODEC_TYPE_AAC: case SOURCE_CODEC_TYPE_LDAC: if (mCodecSpecific1 != other.mCodecSpecific1) { return false; } - // fall through default: return true; } } + + /** + * Builder for {@link BluetoothCodecConfig}. + *

By default, the codec type will be set to + * {@link BluetoothCodecConfig#SOURCE_CODEC_TYPE_INVALID}, the codec priority + * to {@link BluetoothCodecConfig#CODEC_PRIORITY_DEFAULT}, the sample rate to + * {@link BluetoothCodecConfig#SAMPLE_RATE_NONE}, the bits per sample to + * {@link BluetoothCodecConfig#BITS_PER_SAMPLE_NONE}, the channel mode to + * {@link BluetoothCodecConfig#CHANNEL_MODE_NONE}, and all the codec specific + * values to 0. + */ + public static final class Builder { + private int mCodecType = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID; + private int mCodecPriority = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; + private int mSampleRate = BluetoothCodecConfig.SAMPLE_RATE_NONE; + private int mBitsPerSample = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE; + private int mChannelMode = BluetoothCodecConfig.CHANNEL_MODE_NONE; + private long mCodecSpecific1 = 0; + private long mCodecSpecific2 = 0; + private long mCodecSpecific3 = 0; + private long mCodecSpecific4 = 0; + + /** + * Set codec type for Bluetooth codec config. + * + * @param codecType of this codec + * @return the same Builder instance + */ + public @NonNull Builder setCodecType(@SourceCodecType int codecType) { + mCodecType = codecType; + return this; + } + + /** + * Set codec priority for Bluetooth codec config. + * + * @param codecPriority of this codec + * @return the same Builder instance + */ + public @NonNull Builder setCodecPriority(@CodecPriority int codecPriority) { + mCodecPriority = codecPriority; + return this; + } + + /** + * Set sample rate for Bluetooth codec config. + * + * @param sampleRate of this codec + * @return the same Builder instance + */ + public @NonNull Builder setSampleRate(@SampleRate int sampleRate) { + mSampleRate = sampleRate; + return this; + } + + /** + * Set the bits per sample for Bluetooth codec config. + * + * @param bitsPerSample of this codec + * @return the same Builder instance + */ + public @NonNull Builder setBitsPerSample(@BitsPerSample int bitsPerSample) { + mBitsPerSample = bitsPerSample; + return this; + } + + /** + * Set the channel mode for Bluetooth codec config. + * + * @param channelMode of this codec + * @return the same Builder instance + */ + public @NonNull Builder setChannelMode(@ChannelMode int channelMode) { + mChannelMode = channelMode; + return this; + } + + /** + * Set the first codec specific values for Bluetooth codec config. + * + * @param codecSpecific1 codec specific value or 0 if default + * @return the same Builder instance + */ + public @NonNull Builder setCodecSpecific1(long codecSpecific1) { + mCodecSpecific1 = codecSpecific1; + return this; + } + + /** + * Set the second codec specific values for Bluetooth codec config. + * + * @param codecSpecific2 codec specific value or 0 if default + * @return the same Builder instance + */ + public @NonNull Builder setCodecSpecific2(long codecSpecific2) { + mCodecSpecific2 = codecSpecific2; + return this; + } + + /** + * Set the third codec specific values for Bluetooth codec config. + * + * @param codecSpecific3 codec specific value or 0 if default + * @return the same Builder instance + */ + public @NonNull Builder setCodecSpecific3(long codecSpecific3) { + mCodecSpecific3 = codecSpecific3; + return this; + } + + /** + * Set the fourth codec specific values for Bluetooth codec config. + * + * @param codecSpecific4 codec specific value or 0 if default + * @return the same Builder instance + */ + public @NonNull Builder setCodecSpecific4(long codecSpecific4) { + mCodecSpecific4 = codecSpecific4; + return this; + } + + /** + * Build {@link BluetoothCodecConfig}. + * @return new BluetoothCodecConfig built + */ + public @NonNull BluetoothCodecConfig build() { + return new BluetoothCodecConfig(mCodecType, mCodecPriority, + mSampleRate, mBitsPerSample, + mChannelMode, mCodecSpecific1, + mCodecSpecific2, mCodecSpecific3, + mCodecSpecific4); + } + } } -- cgit v1.2.3