summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothCodecConfig.java
diff options
context:
space:
mode:
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothCodecConfig.java179
1 files changed, 132 insertions, 47 deletions
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) {