Merge 292619a406e1209d62f1ea7de25593e0b11fe671 on remote branch

Change-Id: I869a4ad4411919bac52fcb6312a4ba0472af05e3
diff --git a/configs/anorak/anorak.mk b/configs/anorak/anorak.mk
index 9761370..090ee01 100644
--- a/configs/anorak/anorak.mk
+++ b/configs/anorak/anorak.mk
@@ -54,6 +54,7 @@
 AUDIO_FEATURE_ENABLED_AHAL_EXT := false
 AUDIO_FEATURE_ENABLED_EXTENDED_COMPRESS_FORMAT := true
 DOLBY_ENABLE := false
+AUDIO_FEATURE_ENABLED_SPATIAL_AUDIO := true
 endif
 
 AUDIO_FEATURE_ENABLED_DLKM := true
@@ -127,7 +128,8 @@
     $(CONFIG_PAL_SRC_DIR)/usecaseKvManager.xml:$(TARGET_COPY_OUT_VENDOR)/etc/usecaseKvManager.xml \
     vendor/qcom/opensource/audio-hal/primary-hal/configs/common/media_codecs_vendor_audio.xml:$(TARGET_COPY_OUT_VENDOR)/etc/media_codecs_vendor_audio.xml \
     frameworks/native/data/etc/android.hardware.audio.pro.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.audio.pro.xml \
-    frameworks/native/data/etc/android.hardware.audio.low_latency.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.audio.low_latency.xml
+    frameworks/native/data/etc/android.hardware.audio.low_latency.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.audio.low_latency.xml \
+    frameworks/native/data/etc/android.hardware.sensor.dynamic.head_tracker.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.sensor.dynamic.head_tracker.xml
 
 PRODUCT_COPY_FILES += \
     $(TOPDIR)vendor/qcom/opensource/audio-hal/primary-hal/configs/common/audio_policy_configuration.xml:$(TARGET_COPY_OUT_VENDOR)/etc/audio_policy_configuration.xml \
@@ -434,7 +436,8 @@
 vendor.audio.feature.audiozoom.enable=false \
 vendor.audio.feature.snd_mon.enable=true \
 vendor.audio.feature.dmabuf.cma.memory.enable=true \
-vendor.audio.hdr.record.enable=false
+vendor.audio.hdr.record.enable=false \
+vendor.audio.feature.handset.profile.disable=true
 
 
 PRODUCT_PACKAGES_ENG += \
diff --git a/configs/anorak/audio-modules.mk b/configs/anorak/audio-modules.mk
index 6f03045..c8e2fdc 100644
--- a/configs/anorak/audio-modules.mk
+++ b/configs/anorak/audio-modules.mk
@@ -96,6 +96,8 @@
 AUDIO_MODULES += audiodsd2pcmtest
 AUDIO_MODULES += mm-audio-ftm
 AUDIO_MODULES += libmcs
+AUDIO_MODULES += libquasar
+AUDIO_MODULES += sensors.dynamic_sensor_hal
 
 AUDIO_MODULES += $(AUDIO_AGM)
 AUDIO_MODULES += $(AUDIO_PAL)
diff --git a/configs/anorak/audio_effects.xml b/configs/anorak/audio_effects.xml
index 69f7c0f..152c223 100644
--- a/configs/anorak/audio_effects.xml
+++ b/configs/anorak/audio_effects.xml
@@ -27,7 +27,7 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 * Changes from Qualcomm Innovation Center are provided under the following license:
-* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+* Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
 * SPDX-License-Identifier: BSD-3-Clause-Clear -->
 
 <audio_effects_conf version="2.0" xmlns="http://schemas.android.com/audio/audio_effects_conf/v2_0">
@@ -44,6 +44,7 @@
         <library name="audio_pre_processing" path="libqcomvoiceprocessing.so"/>
         <library name="volume_listener" path="libvolumelistener.so"/>
         <library name="audiosphere" path="libasphere.so"/>
+        <library name="quasar" path="libquasar.so"/>
     </libraries>
     <effects>
         <effectProxy name="bassboost" library="proxy" uuid="14804144-a5ee-4d24-aa88-0002a5d5c51b">
@@ -91,6 +92,7 @@
         <effect name="voice_helper" library="volume_listener" uuid="0ace5c08-0590-11e5-ae9e-0025b32654a0"/>
         <effect name="notification_helper" library="volume_listener" uuid="0b776dde-0590-11e5-81ba-0025b32654a0"/>
         <effect name="audiosphere" library="audiosphere" uuid="184e62ab-2d19-4364-9d1b-c0a40733866c"/>
+        <effect name="quasar" library="quasar" uuid="71d0e2ee-e44d-483d-a809-09e75ee55ecd"/>
     </effects>
     <postprocess>
         <stream type="music">
diff --git a/configs/anorak/audio_policy_configuration.xml b/configs/anorak/audio_policy_configuration.xml
index 7943f99..349057d 100644
--- a/configs/anorak/audio_policy_configuration.xml
+++ b/configs/anorak/audio_policy_configuration.xml
@@ -100,6 +100,10 @@
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
                 </mixPort>
                 <mixPort name="hifi_playback" role="source" />
+                <mixPort name="spatial output" role="source" flags="AUDIO_OUTPUT_FLAG_SPATIALIZER">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+                </mixPort>
                 <mixPort name="direct_pcm" role="source"
                         flags="AUDIO_OUTPUT_FLAG_DIRECT">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
@@ -383,7 +387,7 @@
             <!-- route declaration, i.e. list all available sources for a given sink -->
             <routes>
                 <route type="mix" sink="Speaker"
-                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output,spatial output"/>
                 <route type="mix" sink="Wired Headset"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output"/>
                 <route type="mix" sink="Wired Headphones"
@@ -397,13 +401,13 @@
                 <route type="mix" sink="FM"
                        sources="primary output"/>
                 <route type="mix" sink="BT SCO"
-                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output,spatial output"/>
                 <route type="mix" sink="BT SCO Headset"
-                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output,spatial output"/>
                 <route type="mix" sink="BT BLE Out"
-                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output,spatial output"/>
                 <route type="mix" sink="BT SCO Car Kit"
-                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,haptics output,spatial output"/>
                 <route type="mix" sink="USB Device Out"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,hifi_playback,haptics output"/>
                 <route type="mix" sink="USB Headset Out"
@@ -429,9 +433,9 @@
                 <route type="mix" sink="mmap_no_irq_in"
                        sources="Built-In Mic,Built-In Back Mic,BT SCO Headset Mic,USB Device In,USB Headset In,Wired Headset Mic"/>
                 <route type="mix" sink="BT A2DP Out"
-                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output,spatial output"/>
                 <route type="mix" sink="BT A2DP Headphones"
-                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output,spatial output"/>
                 <route type="mix" sink="BT A2DP Speaker"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx,mmap_no_irq_out,haptics output"/>
                 <route type="mix" sink="BT BLE Speaker"
diff --git a/configs/kalama/kalama.mk b/configs/kalama/kalama.mk
index 55ac0d8..7196d11 100644
--- a/configs/kalama/kalama.mk
+++ b/configs/kalama/kalama.mk
@@ -464,7 +464,8 @@
 vendor.audio.feature.audiozoom.enable=false \
 vendor.audio.feature.snd_mon.enable=true \
 vendor.audio.feature.dmabuf.cma.memory.enable=false \
-vendor.audio.hdr.record.enable=false
+vendor.audio.hdr.record.enable=false \
+vendor.audio.feature.handset.profile.disable=false
 
 # set dynamic sensor operation timeout in ms
 PRODUCT_PROPERTY_OVERRIDES += \
diff --git a/hal/AudioStream.cpp b/hal/AudioStream.cpp
index 20b1126..bb0af27 100644
--- a/hal/AudioStream.cpp
+++ b/hal/AudioStream.cpp
@@ -2348,6 +2348,7 @@
 
 int StreamOutPrimary::RouteStream(const std::set<audio_devices_t>& new_devices, bool force_device_switch __unused) {
     int ret = 0, noPalDevices = 0;
+    bool skipDeviceSet = false;
     pal_device_id_t * deviceId = nullptr;
     struct pal_device* deviceIdConfigs = nullptr;
     pal_param_device_capability_t *device_cap_query = nullptr;
@@ -2427,6 +2428,14 @@
         mAndroidOutDevices = new_devices;
 
         for (int i = 0; i < noPalDevices; i++) {
+            /*Skip device set for Handset profile for targets that do not support Handset profile for VoIP call*/
+            if (noHandsetSupport && (mPalOutDevice[i].id == PAL_DEVICE_OUT_SPEAKER &&
+                streamAttributes_.type == PAL_STREAM_VOIP_RX) &&
+                (mPalOutDeviceIds[i] == PAL_DEVICE_OUT_SPEAKER ||
+                mPalOutDeviceIds[i] == PAL_DEVICE_OUT_HANDSET)) {
+                skipDeviceSet = true;
+                AHAL_DBG("Skip pal_stream_set_device as the stream is already on speaker");
+            }
             mPalOutDevice[i].id = mPalOutDeviceIds[i];
             mPalOutDevice[i].config.sample_rate = mPalOutDevice[0].config.sample_rate;
             mPalOutDevice[i].config.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
@@ -2481,6 +2490,13 @@
                        "hifi-filter_custom_key",
                        sizeof(mPalOutDevice[i].custom_config.custom_key));
             }
+
+            /*For targets that do not support Handset profile for VoIP call, set the speaker profile for VoIP call*/
+            if (noHandsetSupport && mPalOutDevice[i].id == PAL_DEVICE_OUT_HANDSET &&
+                streamAttributes_.type == PAL_STREAM_VOIP_RX && !skipDeviceSet) {
+                mPalOutDevice[i].id = PAL_DEVICE_OUT_SPEAKER;
+                AHAL_DBG("set PAL_DEVICE_OUT_SPEAKER instead of Handset_speaker for VoIP_RX ");
+            }
         }
 
         std::shared_ptr<AudioDevice> adevice = AudioDevice::GetInstance();
@@ -2509,7 +2525,8 @@
             }
         }
 
-        if (pal_stream_handle_) {
+        /*Skip device set for Handset profile for targets that do not support Handset profile for VoIP call*/
+        if (pal_stream_handle_ && !skipDeviceSet)  {
             ret = pal_stream_set_device(pal_stream_handle_, noPalDevices, mPalOutDevice);
             if (!ret) {
                 for (const auto &dev : mAndroidOutDevices)
@@ -3064,6 +3081,12 @@
         }
     }
 
+    /*For targets that do not support Handset profile for VoIP call, set the speaker profile for VoIP call*/
+    if(noHandsetSupport && mPalOutDevice->id == PAL_DEVICE_OUT_HANDSET && streamAttributes_.type == PAL_STREAM_VOIP_RX) {
+        mPalOutDevice->id = PAL_DEVICE_OUT_SPEAKER;
+        AHAL_DBG("set PAL_DEVICE_OUT_SPEAKER instead of Handset_speaker for VoIP_RX");
+    }
+
     ret = pal_stream_open(&streamAttributes_,
                           mAndroidOutDevices.size(),
                           mPalOutDevice,
@@ -3812,6 +3835,7 @@
           address(%s)", handle, config->format, config->sample_rate, config->channel_mask,
           mAndroidOutDevices.size(), flags, address);
 
+    noHandsetSupport = property_get_bool("vendor.audio.feature.handset.profile.disable", false);
     //TODO: check if USB device is connected or not
     if (AudioExtn::audio_devices_cmp(mAndroidOutDevices, audio_is_usb_out_device)){
         // get capability from device of USB
@@ -4361,6 +4385,7 @@
 int StreamInPrimary::RouteStream(const std::set<audio_devices_t>& new_devices, bool force_device_switch) {
     bool is_empty, is_input;
     int ret = 0, noPalDevices = 0;
+    bool skipDeviceSet = false;
     pal_device_id_t * deviceId = nullptr;
     struct pal_device* deviceIdConfigs = nullptr;
     pal_param_device_capability_t *device_cap_query = nullptr;
@@ -4441,6 +4466,14 @@
         }
 
         for (int i = 0; i < noPalDevices; i++) {
+            /*Skip device set for targets that do not support Handset profile for VoIP call*/
+            if (noHandsetSupport && (mPalInDevice[i].id == PAL_DEVICE_IN_SPEAKER_MIC &&
+                streamAttributes_.type == PAL_STREAM_VOIP_TX) &&
+                (mPalInDeviceIds[i] == PAL_DEVICE_IN_SPEAKER_MIC ||
+                mPalInDeviceIds[i] == PAL_DEVICE_IN_HANDSET_MIC)) {
+                skipDeviceSet = true;
+                AHAL_DBG("Skip pal_stream_set_device as the stream is already on speaker");
+            }
             mPalInDevice[i].id = mPalInDeviceIds[i];
             if (((mPalInDeviceIds[i] == PAL_DEVICE_IN_USB_DEVICE) ||
                (mPalInDeviceIds[i] == PAL_DEVICE_IN_USB_HEADSET)) && device_cap_query) {
@@ -4484,6 +4517,13 @@
                 ((get_hdr_mode() == AUDIO_RECORD_SPF_HDR) &&
                 (source_ == AUDIO_SOURCE_CAMCORDER || source_ == AUDIO_SOURCE_MIC)))
                 setup_hdr_usecase(&mPalInDevice[i]);
+
+            /*For targets that do not support Handset profile for VoIP call, set speaker profile for VoIP call*/
+            if (noHandsetSupport && mPalInDevice[i].id == PAL_DEVICE_IN_HANDSET_MIC &&
+                streamAttributes_.type == PAL_STREAM_VOIP_TX && !skipDeviceSet) {
+                mPalInDevice[i].id = PAL_DEVICE_IN_SPEAKER_MIC;
+                AHAL_DBG("set PAL_DEVICE_IN_SPEAKER_MIC instead of Handset_mic for VoIP_TX");
+            }
         }
 
         mAndroidInDevices = new_devices;
@@ -4504,7 +4544,7 @@
             }
         }
 
-        if (pal_stream_handle_)
+        if (pal_stream_handle_ && !skipDeviceSet)
             ret = pal_stream_set_device(pal_stream_handle_, noPalDevices, mPalInDevice);
     }
 
@@ -4755,6 +4795,11 @@
         }
     }
 
+    /* For targets that do no support Handset profile for VoIP call so set the speaker profile for VoIP call*/
+    if (noHandsetSupport && mPalInDevice->id == PAL_DEVICE_IN_HANDSET_MIC &&  streamAttributes_.type == PAL_STREAM_VOIP_TX) {
+        mPalInDevice->id = PAL_DEVICE_IN_SPEAKER_MIC;
+        AHAL_DBG("set PAL_DEVICE_IN_SPEAKER_MIC instead of Handset_mic for VoIP_TX");
+    }
     ret = pal_stream_open(&streamAttributes_,
                          mAndroidInDevices.size(),
                          mPalInDevice,
@@ -5180,6 +5225,7 @@
         AHAL_ERR("stream_ new allocation failed");
         goto error;
     }
+    noHandsetSupport = property_get_bool("vendor.audio.feature.handset.profile.disable", false);
 
     if (AudioExtn::audio_devices_cmp(mAndroidInDevices, audio_is_usb_in_device)) {
         // get capability from device of USB
diff --git a/hal/AudioStream.h b/hal/AudioStream.h
index 969224d..e65ce28 100644
--- a/hal/AudioStream.h
+++ b/hal/AudioStream.h
@@ -598,6 +598,7 @@
     uint32_t convertBufSize;
     uint32_t fragments_ = 0;
     uint32_t fragment_size_ = 0;
+    bool noHandsetSupport = false;
     pal_snd_dec_t palSndDec;
     struct pal_compr_gapless_mdata gaplessMeta = {0, 0};
     uint32_t msample_rate;
@@ -674,6 +675,7 @@
     uint32_t fragments_ = 0;
     uint32_t fragment_size_ = 0;
     int FillHalFnPtrs();
+    bool noHandsetSupport = false;
     std::shared_ptr<audio_stream_in>    stream_;
     audio_source_t                      source_;
     friend class AudioDevice;