Audio V4: Add new Audio HAL API

Add new device to the device factory to allow vendors to split
their HAL implementations more.

AudioDevice bitfield is now 64bit to allow more devices to be added.

Add a new AudioDevice to support playing music to distant during voice
call.

A HAL can now declare if its MMAP buffer can be securely accessed
directly by untrusted apps.

Add AAC_XHE format.

Add BLE input source.

Bug: 38184704
Test: none
Change-Id: Ic2fbec4db71c7f688c8847ba39c72f51480c0727
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/4.0/IDevicesFactory.hal b/audio/4.0/IDevicesFactory.hal
index 5a62422..0e45bc7 100644
--- a/audio/4.0/IDevicesFactory.hal
+++ b/audio/4.0/IDevicesFactory.hal
@@ -22,12 +22,26 @@
 interface IDevicesFactory {
     typedef android.hardware.audio@4.0::Result Result;
 
+    /** Allows a HAL implementation to be split in multiple independent
+     *  devices (called module in the pre-treble API).
+     *  Note that this division is arbitrary and implementation are free
+     *  to only have a Primary.
+     *  The framework will query the devices according to audio_policy_configuration.xml
+     *
+     *  Each Device value is interchangeable with any other and the framework
+     *  does not differentiate between values with the following exceptions:
+     *  - the Primary device must always be present
+     *  - the R_SUBMIX that is used to forward audio of REMOTE_SUBMIX DEVICES
+     */
     enum Device : int32_t {
         PRIMARY,
         A2DP,
         USB,
         R_SUBMIX,
-        STUB
+        STUB,
+        CODEC_OFFLOAD,
+        SECONDARY,
+        AUXILIARY
     };
 
     /**
diff --git a/audio/4.0/types.hal b/audio/4.0/types.hal
index cd9a394..5c95e4b 100644
--- a/audio/4.0/types.hal
+++ b/audio/4.0/types.hal
@@ -73,14 +73,31 @@
     string rSubmixAddress;  // used for REMOTE_SUBMIX
 };
 
+enum MmapBufferFlag : uint32_t {
+    NONE    = 0x0,
+    /**
+     * If the buffer can be securely shared to untrusted applications
+     * through the AAudio exclusive mode.
+     * Only set this flag if applications are restricted from accessing the
+     * memory surrounding the audio data buffer by a kernel mechanism.
+     * See Linux kernel's dma_buf.
+     */
+    APPLICATION_SHAREABLE    = 0x1,
+};
+
 /**
  * Mmap buffer descriptor returned by IStream.createMmapBuffer().
  * Used by streams opened in mmap mode.
  */
 struct MmapBufferInfo {
-    memory  sharedMemory;         // mmap memory buffer
-    int32_t bufferSizeFrames;     // total buffer size in frames
-    int32_t burstSizeFrames;      // transfer size granularity in frames
+    /** Mmap memory buffer */
+    memory  sharedMemory;
+    /** Total buffer size in frames */
+    int32_t bufferSizeFrames;
+    /** Transfer size granularity in frames */
+    int32_t burstSizeFrames;
+    /** Attributes describing the buffer. */
+    bitfield<MmapBufferFlag> flags;
 };
 
 /**
diff --git a/audio/common/4.0/types.hal b/audio/common/4.0/types.hal
index 499356c..953169d 100644
--- a/audio/common/4.0/types.hal
+++ b/audio/common/4.0/types.hal
@@ -248,6 +248,7 @@
     AAC_SUB_LD            = 0x80,
     AAC_SUB_HE_V2         = 0x100,
     AAC_SUB_ELD           = 0x200,
+    AAC_SUB_XHE           = 0x300,
 
     VORBIS_SUB_NONE       = 0x0,
 
@@ -270,6 +271,7 @@
     AAC_LD              = (AAC | AAC_SUB_LD),
     AAC_HE_V2           = (AAC | AAC_SUB_HE_V2),
     AAC_ELD             = (AAC | AAC_SUB_ELD),
+    AAC_XHE             = (AAC | AAC_SUB_XHE),
     AAC_ADTS_MAIN       = (AAC_ADTS | AAC_SUB_MAIN),
     AAC_ADTS_LC         = (AAC_ADTS | AAC_SUB_LC),
     AAC_ADTS_SSR        = (AAC_ADTS | AAC_SUB_SSR),
@@ -279,7 +281,8 @@
     AAC_ADTS_ERLC       = (AAC_ADTS | AAC_SUB_ERLC),
     AAC_ADTS_LD         = (AAC_ADTS | AAC_SUB_LD),
     AAC_ADTS_HE_V2      = (AAC_ADTS | AAC_SUB_HE_V2),
-    AAC_ADTS_ELD        = (AAC_ADTS | AAC_SUB_ELD)
+    AAC_ADTS_ELD        = (AAC_ADTS | AAC_SUB_ELD),
+    AAC_ADTS_XHE        = (AAC_ADTS | AAC_SUB_XHE),
 };
 
 /**
@@ -466,7 +469,7 @@
 };
 
 @export(name="", value_prefix="AUDIO_DEVICE_")
-enum AudioDevice : uint32_t {
+enum AudioDevice : uint64_t {
     NONE                          = 0x0,
     /** reserved bits */
     BIT_IN                        = 0x80000000,
@@ -546,6 +549,7 @@
     IN_BUS                   = BIT_IN | 0x100000,
     IN_PROXY                 = BIT_IN | 0x1000000,
     IN_USB_HEADSET           = BIT_IN | 0x2000000,
+    IN_BLUETOOTH_BLE         = BIT_IN | 0x4000000,
     IN_DEFAULT               = BIT_IN | BIT_DEFAULT,
 
     // Note that the 2.0 IN_ALL* have been moved to helper functions
@@ -590,6 +594,8 @@
                              // to pass through compress path for DSP post proc.
     MMAP_NOIRQ = 0x4000, // output operates in MMAP no IRQ mode.
     VOIP_RX = 0x8000,    // preferred output for VoIP calls.
+    /** preferred output for call music */
+    INCALL_MUSIC = 0x10000,
 };
 
 /**