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

Commit 893fdced authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

BluetoothLeAudio: Add MONO location

Due to errata audio location 0x0000 is not "invalid" anymore but
instead "Mono Audio (no specified Audio Location)"

https://www.bluetooth.com/specifications/assigned-numbers/
6.12.1 Audio Location Definitions

Also new Unknown location is added which is used only when Bluetooth is
not available.

Bug: 330847930
Bug: 331139722
Test: mmm packages/modules/Bluetooth

Change-Id: Ibadaee63edd123ba4b31edade524344d6689135e
parent e7a55e26
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -483,6 +483,7 @@ package android.bluetooth {
    field public static final int AUDIO_LOCATION_LEFT_SURROUND = 67108864; // 0x4000000
    field public static final int AUDIO_LOCATION_LOW_FREQ_EFFECTS_ONE = 8; // 0x8
    field public static final int AUDIO_LOCATION_LOW_FREQ_EFFECTS_TWO = 512; // 0x200
    field @FlaggedApi("com.android.bluetooth.flags.leaudio_mono_location_errata") public static final int AUDIO_LOCATION_MONO = 0; // 0x0
    field public static final int AUDIO_LOCATION_RIGHT_SURROUND = 134217728; // 0x8000000
    field public static final int AUDIO_LOCATION_SIDE_LEFT = 1024; // 0x400
    field public static final int AUDIO_LOCATION_SIDE_RIGHT = 2048; // 0x800
@@ -495,6 +496,7 @@ package android.bluetooth {
    field public static final int AUDIO_LOCATION_TOP_FRONT_RIGHT = 8192; // 0x2000
    field public static final int AUDIO_LOCATION_TOP_SIDE_LEFT = 262144; // 0x40000
    field public static final int AUDIO_LOCATION_TOP_SIDE_RIGHT = 524288; // 0x80000
    field @FlaggedApi("com.android.bluetooth.flags.leaudio_mono_location_errata") public static final int AUDIO_LOCATION_UNKNOWN = -2147483648; // 0x80000000
    field public static final String EXTRA_LE_AUDIO_GROUP_ID = "android.bluetooth.extra.LE_AUDIO_GROUP_ID";
    field public static final int GROUP_STREAM_STATUS_IDLE = 0; // 0x0
    field public static final int GROUP_STREAM_STATUS_STREAMING = 1; // 0x1
+42 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.Manifest.permission.BLUETOOTH_PRIVILEGED;
import static java.util.Objects.requireNonNull;

import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
@@ -33,8 +34,11 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.app.compat.CompatChanges;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.content.AttributionSource;
import android.content.Context;
import android.os.IBinder;
@@ -43,6 +47,8 @@ import android.os.RemoteException;
import android.util.CloseGuard;
import android.util.Log;

import com.android.bluetooth.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
@@ -346,6 +352,14 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
    /** This represents an invalid group ID. */
    public static final int GROUP_ID_INVALID = IBluetoothLeAudio.LE_AUDIO_GROUP_ID_INVALID;

    /**
     * This ChangeId allows to use new Mono audio location as per
     * https://www.bluetooth.com/specifications/assigned-numbers/ 6.12.1 Audio Location Definitions
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.VANILLA_ICE_CREAM)
    static final long LEAUDIO_MONO_LOCATION_ERRATA = 330847930L;

    /**
     * This represents an invalid audio location.
     *
@@ -353,6 +367,24 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
     */
    @SystemApi public static final int AUDIO_LOCATION_INVALID = 0;

    /**
     * This represents an Mono audio location.
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_LEAUDIO_MONO_LOCATION_ERRATA)
    @SystemApi
    public static final int AUDIO_LOCATION_MONO = 0;

    /**
     * This represents an Unknown audio location which will be returned only when Bluetooth is OFF.
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_LEAUDIO_MONO_LOCATION_ERRATA)
    @SystemApi
    public static final int AUDIO_LOCATION_UNKNOWN = 0x01 << 31;

    /**
     * This represents an audio location front left.
     *
@@ -550,11 +582,13 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
    @SystemApi public static final int AUDIO_LOCATION_RIGHT_SURROUND = 0x01 << 27;

    /** @hide */
    @SuppressLint("UniqueConstants")
    @IntDef(
            flag = true,
            prefix = "AUDIO_LOCATION_",
            value = {
                AUDIO_LOCATION_INVALID,
                AUDIO_LOCATION_MONO,
                AUDIO_LOCATION_FRONT_LEFT,
                AUDIO_LOCATION_FRONT_RIGHT,
                AUDIO_LOCATION_FRONT_CENTER,
@@ -583,6 +617,7 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
                AUDIO_LOCATION_FRONT_RIGHT_WIDE,
                AUDIO_LOCATION_LEFT_SURROUND,
                AUDIO_LOCATION_RIGHT_SURROUND,
                AUDIO_LOCATION_UNKNOWN,
            })
    @Retention(RetentionPolicy.SOURCE)
    public @interface AudioLocation {}
@@ -1140,8 +1175,7 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
     * Front Left: 0x00000001 Front Right: 0x00000002 Front Left | Front Right: 0x00000003
     *
     * @param device the bluetooth device
     * @return The bit field of audio location for the device, if bluetooth is off, return
     *     AUDIO_LOCATION_INVALID.
     * @return The bit field of audio location for the device.
     * @hide
     */
    @SystemApi
@@ -1160,6 +1194,12 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
            }
        }

        if (Flags.leaudioMonoLocationErrata()
                && CompatChanges.isChangeEnabled(LEAUDIO_MONO_LOCATION_ERRATA)) {
            return AUDIO_LOCATION_UNKNOWN;
        }

        return AUDIO_LOCATION_INVALID;
    }