Merge "audio-effects: Fix out-of-bound read"
diff --git a/configs/parrot/parrot.mk b/configs/parrot/parrot.mk
index a78985e..6e989a5 100644
--- a/configs/parrot/parrot.mk
+++ b/configs/parrot/parrot.mk
@@ -84,6 +84,7 @@
 AUDIO_FEATURE_ENABLED_USB_BURST_MODE := true
 AUDIO_FEATURE_ENABLED_SVA_MULTI_STAGE := true
 AUDIO_FEATURE_ENABLED_BATTERY_LISTENER := true
+AUDIO_FEATURE_ENABLED_DYNAMIC_SR := false 
 BUILD_AUDIO_TECHPACK_SOURCE := true
 AUDIO_FEATURE_ENABLED_MCS := true
 ##AUDIO_FEATURE_FLAGS
diff --git a/hal/Android.mk b/hal/Android.mk
index bcc5f21..5514ae6 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -33,6 +33,10 @@
 LOCAL_CFLAGS += -DEC_REF_CAPTURE_ENABLED
 endif
 
+ifeq ($(strip $(AUDIO_FEATURE_ENABLED_DYNAMIC_SR)),true)
+LOCAL_CFLAGS += -DDYNAMIC_SR_ENABLED
+endif
+
 LOCAL_CFLAGS += -Wno-macro-redefined
 LOCAL_CFLAGS += -DSOUND_TRIGGER_PLATFORM_NAME=$(TARGET_BOARD_PLATFORM)
 LOCAL_CFLAGS += -D_GNU_SOURCE
diff --git a/hal/AudioStream.cpp b/hal/AudioStream.cpp
index 2f53666..ab8d53d 100644
--- a/hal/AudioStream.cpp
+++ b/hal/AudioStream.cpp
@@ -2235,6 +2235,7 @@
                        sizeof(mPalOutDevice[i].custom_config.custom_key));
             }
 
+#ifdef DYNAMIC_SR_ENABLED
             if (((usecase_ == USECASE_AUDIO_PLAYBACK_VOIP) ||
                   (usecase_ == USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) ||
                   (isOffloadUsecase())) &&
@@ -2295,6 +2296,7 @@
                 }
                 AHAL_DBG("setting SR for usecase %d as %d", usecase_, config_.sample_rate);
             }
+#endif
         }
 
         mAndroidOutDevices = new_devices;
@@ -3567,6 +3569,7 @@
             AHAL_INFO("Setting custom key as %s", mPalOutDevice[i].custom_config.custom_key);
         }
 
+#ifdef DYNAMIC_SR_ENABLED
         if (((usecase_ == USECASE_AUDIO_PLAYBACK_VOIP) ||
               (usecase_ == USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) ||
               (isOffloadUsecase())) &&
@@ -3627,6 +3630,7 @@
             }
             AHAL_DBG("setting SR for usecase %d as %d", usecase_, config_.sample_rate);
         }
+#endif
     }
 
     if (flags & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) {
@@ -4112,6 +4116,7 @@
                 AHAL_INFO("Setting custom key as %s", mPalInDevice[i].custom_config.custom_key);
             }
 
+#ifdef DYNAMIC_SR_ENABLED
             if (((usecase_ == USECASE_AUDIO_RECORD_VOIP) ||
                  (usecase_ == USECASE_AUDIO_RECORD)) &&
                 ((mPalInDevice[i].id == PAL_DEVICE_IN_HANDSET_MIC) ||
@@ -4135,6 +4140,7 @@
                 }
                 AHAL_DBG("setting SR for usecase %d as %d", usecase_, config_.sample_rate);
             }
+#endif
         }
 
         mAndroidInDevices = new_devices;
@@ -4948,6 +4954,7 @@
             AHAL_INFO("Setting custom key as %s", mPalInDevice[i].custom_config.custom_key);
         }
 
+#ifdef DYNAMIC_SR_ENABLED
         if (((usecase_ == USECASE_AUDIO_RECORD_VOIP) ||
              (usecase_ == USECASE_AUDIO_RECORD)) &&
             ((mPalInDevice[i].id == PAL_DEVICE_IN_HANDSET_MIC) ||
@@ -4971,6 +4978,7 @@
             }
             AHAL_DBG("setting SR for usecase %d as %d", usecase_, config_.sample_rate);
         }
+#endif
     }
 
     if (flags & AUDIO_INPUT_FLAG_MMAP_NOIRQ) {