Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e9d0c82 authored by Etienne Ruffieux's avatar Etienne Ruffieux Committed by Automerger Merge Worker
Browse files

Merge "Make BluetoothCodecConfig and BluetoothCodecStatus public." am: 1d98292c

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1849460

Change-Id: I3ac378fa125304253ffc8235642c292084af19d1
parents dcad23c6 1d98292c
Loading
Loading
Loading
Loading
+322 −175

File changed.

Preview size limit exceeded, changes collapsed.

+47 −64
Original line number Diff line number Diff line
@@ -16,12 +16,13 @@

package android.bluetooth;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
@@ -29,8 +30,6 @@ import java.util.Objects;
 * A2DP source device.
 *
 * {@see BluetoothA2dp}
 *
 * {@hide}
 */
public final class BluetoothCodecStatus implements Parcelable {
    /**
@@ -39,22 +38,27 @@ public final class BluetoothCodecStatus implements Parcelable {
     * This extra represents the current codec status of the A2DP
     * profile.
     */
    @UnsupportedAppUsage
    public static final String EXTRA_CODEC_STATUS =
            "android.bluetooth.extra.CODEC_STATUS";

    private final @Nullable BluetoothCodecConfig mCodecConfig;
    private final BluetoothCodecConfig[] mCodecsLocalCapabilities;
    private final BluetoothCodecConfig[] mCodecsSelectableCapabilities;
    private final @Nullable List<BluetoothCodecConfig> mCodecsLocalCapabilities;
    private final @Nullable List<BluetoothCodecConfig> mCodecsSelectableCapabilities;

    public BluetoothCodecStatus(@Nullable BluetoothCodecConfig codecConfig,
            @Nullable BluetoothCodecConfig[] codecsLocalCapabilities,
            @Nullable BluetoothCodecConfig[] codecsSelectableCapabilities) {
            @Nullable List<BluetoothCodecConfig> codecsLocalCapabilities,
            @Nullable List<BluetoothCodecConfig> codecsSelectableCapabilities) {
        mCodecConfig = codecConfig;
        mCodecsLocalCapabilities = codecsLocalCapabilities;
        mCodecsSelectableCapabilities = codecsSelectableCapabilities;
    }

    private BluetoothCodecStatus(Parcel in) {
        mCodecConfig = in.readTypedObject(BluetoothCodecConfig.CREATOR);
        mCodecsLocalCapabilities = in.createTypedArrayList(BluetoothCodecConfig.CREATOR);
        mCodecsSelectableCapabilities = in.createTypedArrayList(BluetoothCodecConfig.CREATOR);
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (o instanceof BluetoothCodecStatus) {
@@ -68,26 +72,25 @@ public final class BluetoothCodecStatus implements Parcelable {
    }

    /**
     * Checks whether two arrays of capabilities contain same capabilities.
     * The order of the capabilities in each array is ignored.
     * Checks whether two lists of capabilities contain same capabilities.
     * The order of the capabilities in each list is ignored.
     *
     * @param c1 the first array of capabilities to compare
     * @param c2 the second array of capabilities to compare
     * @return true if both arrays contain same capabilities
     * @hide
     * @param c1 the first list of capabilities to compare
     * @param c2 the second list of capabilities to compare
     * @return {@code true} if both lists contain same capabilities
     */
    public static boolean sameCapabilities(BluetoothCodecConfig[] c1,
                                           BluetoothCodecConfig[] c2) {
    private static boolean sameCapabilities(@Nullable List<BluetoothCodecConfig> c1,
                                           @Nullable List<BluetoothCodecConfig> c2) {
        if (c1 == null) {
            return (c2 == null);
        }
        if (c2 == null) {
            return false;
        }
        if (c1.length != c2.length) {
        if (c1.size() != c2.size()) {
            return false;
        }
        return Arrays.asList(c1).containsAll(Arrays.asList(c2));
        return c1.containsAll(c2);
    }

    /**
@@ -95,10 +98,9 @@ public final class BluetoothCodecStatus implements Parcelable {
     * Any parameters of the codec config with NONE value will be considered a wildcard matching.
     *
     * @param codecConfig the codec config to compare against
     * @return true if the codec config matches, otherwise false
     * @hide
     * @return {@code true} if the codec config matches, {@code false} otherwise
     */
    public boolean isCodecConfigSelectable(BluetoothCodecConfig codecConfig) {
    public boolean isCodecConfigSelectable(@Nullable BluetoothCodecConfig codecConfig) {
        if (codecConfig == null || !codecConfig.hasSingleSampleRate()
                || !codecConfig.hasSingleBitsPerSample() || !codecConfig.hasSingleChannelMode()) {
            return false;
@@ -128,10 +130,7 @@ public final class BluetoothCodecStatus implements Parcelable {
    }

    /**
     * Returns a hash based on the codec config and local capabilities
     *
     * @return a hash based on the config values
     * @hide
     * Returns a hash based on the codec config and local capabilities.
     */
    @Override
    public int hashCode() {
@@ -139,17 +138,19 @@ public final class BluetoothCodecStatus implements Parcelable {
                mCodecsLocalCapabilities);
    }

    /**
     * Returns a {@link String} that describes each BluetoothCodecStatus parameter
     * current value.
     */
    @Override
    public String toString() {
        return "{mCodecConfig:" + mCodecConfig
                + ",mCodecsLocalCapabilities:" + Arrays.toString(mCodecsLocalCapabilities)
                + ",mCodecsSelectableCapabilities:" + Arrays.toString(mCodecsSelectableCapabilities)
                + ",mCodecsLocalCapabilities:" + mCodecsLocalCapabilities
                + ",mCodecsSelectableCapabilities:" + mCodecsSelectableCapabilities
                + "}";
    }

    /**
     * Always returns 0
     *
     * @return 0
     * @hide
     */
@@ -161,16 +162,7 @@ public final class BluetoothCodecStatus implements Parcelable {
    public static final @android.annotation.NonNull Parcelable.Creator<BluetoothCodecStatus> CREATOR =
            new Parcelable.Creator<BluetoothCodecStatus>() {
                public BluetoothCodecStatus createFromParcel(Parcel in) {
                    final BluetoothCodecConfig codecConfig = in.readTypedObject(
                            BluetoothCodecConfig.CREATOR);
                    final BluetoothCodecConfig[] codecsLocalCapabilities = in.createTypedArray(
                            BluetoothCodecConfig.CREATOR);
                    final BluetoothCodecConfig[] codecsSelectableCapabilities = in.createTypedArray(
                            BluetoothCodecConfig.CREATOR);

                    return new BluetoothCodecStatus(codecConfig,
                            codecsLocalCapabilities,
                            codecsSelectableCapabilities);
                    return new BluetoothCodecStatus(in);
                }

                public BluetoothCodecStatus[] newArray(int size) {
@@ -179,47 +171,38 @@ public final class BluetoothCodecStatus 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.
     * Flattens the object to a parcel.
     *
     * @hide
     * @param out The Parcel in which the object should be written
     * @param flags Additional flags about how the object should be written
     */
    @Override
    public void writeToParcel(Parcel out, int flags) {
    public void writeToParcel(@NonNull Parcel out, int flags) {
        out.writeTypedObject(mCodecConfig, 0);
        out.writeTypedArray(mCodecsLocalCapabilities, 0);
        out.writeTypedArray(mCodecsSelectableCapabilities, 0);
        out.writeTypedList(mCodecsLocalCapabilities);
        out.writeTypedList(mCodecsSelectableCapabilities);
    }

    /**
     * Gets the current codec configuration.
     *
     * @return the current codec configuration
     * Returns the current codec configuration.
     */
    @UnsupportedAppUsage
    public @Nullable BluetoothCodecConfig getCodecConfig() {
        return mCodecConfig;
    }

    /**
     * Gets the codecs local capabilities.
     *
     * @return an array with the codecs local capabilities
     * Returns the codecs local capabilities.
     */
    @UnsupportedAppUsage
    public @Nullable BluetoothCodecConfig[] getCodecsLocalCapabilities() {
        return mCodecsLocalCapabilities;
    public @NonNull List<BluetoothCodecConfig> getCodecsLocalCapabilities() {
        return (mCodecsLocalCapabilities == null)
                ? Collections.emptyList() : mCodecsLocalCapabilities;
    }

    /**
     * Gets the codecs selectable capabilities.
     *
     * @return an array with the codecs selectable capabilities
     * Returns the codecs selectable capabilities.
     */
    @UnsupportedAppUsage
    public @Nullable BluetoothCodecConfig[] getCodecsSelectableCapabilities() {
        return mCodecsSelectableCapabilities;
    public @NonNull List<BluetoothCodecConfig> getCodecsSelectableCapabilities() {
        return (mCodecsSelectableCapabilities == null)
                ? Collections.emptyList() : mCodecsSelectableCapabilities;
    }
}
+29 −27
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.bluetooth;

import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;

import junit.framework.TestCase;

@@ -34,7 +33,6 @@ public class BluetoothCodecConfigTest extends TestCase {
        BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX,
        BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD,
        BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC,
        BluetoothCodecConfig.SOURCE_CODEC_TYPE_MAX,
        BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID,
    };
    private static final int[] kCodecPriorityArray = new int[] {
@@ -168,20 +166,11 @@ public class BluetoothCodecConfigTest extends TestCase {
            long codec_specific3 = selectCodecSpecific3(config_id);
            long codec_specific4 = selectCodecSpecific4(config_id);

            BluetoothCodecConfig bcc = new BluetoothCodecConfig(codec_type, codec_priority,
            BluetoothCodecConfig bcc = buildBluetoothCodecConfig(codec_type, codec_priority,
                                                                sample_rate, bits_per_sample,
                                                                channel_mode, codec_specific1,
                                                                codec_specific2, codec_specific3,
                                                                codec_specific4);
            if (sample_rate == BluetoothCodecConfig.SAMPLE_RATE_NONE) {
                assertFalse(bcc.isValid());
            } else if (bits_per_sample == BluetoothCodecConfig.BITS_PER_SAMPLE_NONE) {
                assertFalse(bcc.isValid());
            } else if (channel_mode == BluetoothCodecConfig.CHANNEL_MODE_NONE) {
                assertFalse(bcc.isValid());
            } else {
                assertTrue(bcc.isValid());
            }

            if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC) {
                assertTrue(bcc.isMandatoryCodec());
@@ -204,10 +193,6 @@ public class BluetoothCodecConfigTest extends TestCase {
            if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC) {
                assertEquals("LDAC", bcc.getCodecName());
            }
            if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_MAX) {
                assertEquals("UNKNOWN CODEC(" + BluetoothCodecConfig.SOURCE_CODEC_TYPE_MAX + ")",
                             bcc.getCodecName());
            }
            if (codec_type == BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID) {
                assertEquals("INVALID CODEC", bcc.getCodecName());
            }
@@ -227,7 +212,7 @@ public class BluetoothCodecConfigTest extends TestCase {
    @SmallTest
    public void testBluetoothCodecConfig_equals() {
        BluetoothCodecConfig bcc1 =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -235,7 +220,7 @@ public class BluetoothCodecConfigTest extends TestCase {
                                     1000, 2000, 3000, 4000);

        BluetoothCodecConfig bcc2_same =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -244,7 +229,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertTrue(bcc1.equals(bcc2_same));

        BluetoothCodecConfig bcc3_codec_type =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -253,7 +238,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc3_codec_type));

        BluetoothCodecConfig bcc4_codec_priority =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -262,7 +247,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc4_codec_priority));

        BluetoothCodecConfig bcc5_sample_rate =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_48000,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -271,7 +256,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc5_sample_rate));

        BluetoothCodecConfig bcc6_bits_per_sample =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_24,
@@ -280,7 +265,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc6_bits_per_sample));

        BluetoothCodecConfig bcc7_channel_mode =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -289,7 +274,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc7_channel_mode));

        BluetoothCodecConfig bcc8_codec_specific1 =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -298,7 +283,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc8_codec_specific1));

        BluetoothCodecConfig bcc9_codec_specific2 =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -307,7 +292,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc9_codec_specific2));

        BluetoothCodecConfig bcc10_codec_specific3 =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -316,7 +301,7 @@ public class BluetoothCodecConfigTest extends TestCase {
        assertFalse(bcc1.equals(bcc10_codec_specific3));

        BluetoothCodecConfig bcc11_codec_specific4 =
            new BluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                buildBluetoothCodecConfig(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC,
                                     BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT,
                                     BluetoothCodecConfig.SAMPLE_RATE_44100,
                                     BluetoothCodecConfig.BITS_PER_SAMPLE_16,
@@ -324,4 +309,21 @@ public class BluetoothCodecConfigTest extends TestCase {
                                     1000, 2000, 3000, 4004);
        assertFalse(bcc1.equals(bcc11_codec_specific4));
    }

    private BluetoothCodecConfig buildBluetoothCodecConfig(int sourceCodecType,
            int codecPriority, int sampleRate, int bitsPerSample, int channelMode,
            long codecSpecific1, long codecSpecific2, long codecSpecific3, long codecSpecific4) {
        return new BluetoothCodecConfig.Builder()
                    .setCodecType(sourceCodecType)
                    .setCodecPriority(codecPriority)
                    .setSampleRate(sampleRate)
                    .setBitsPerSample(bitsPerSample)
                    .setChannelMode(channelMode)
                    .setCodecSpecific1(codecSpecific1)
                    .setCodecSpecific2(codecSpecific2)
                    .setCodecSpecific3(codecSpecific3)
                    .setCodecSpecific4(codecSpecific4)
                    .build();

    }
}
+139 −114

File changed.

Preview size limit exceeded, changes collapsed.