CSD: fix the logic for setting RS2 max value

The RS2 value is used for sendin momentary exposure warnings.

Test: atest SoundDoseHelperTest
Bug: 248565894
Change-Id: Ia4567e8a0efe55c75bd58d41a08c064534dd6813
diff --git a/services/audioflinger/sounddose/SoundDoseManager.cpp b/services/audioflinger/sounddose/SoundDoseManager.cpp
index df6eb5b..ad65612 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.cpp
+++ b/services/audioflinger/sounddose/SoundDoseManager.cpp
@@ -116,23 +116,26 @@
     ALOGV("%s", __func__);
     std::lock_guard _l(mLock);
 
-    mRs2Value = rs2Value;
     if (mHalSoundDose != nullptr) {
         // using the HAL sound dose interface
-        if (!mHalSoundDose->setOutputRs2(mRs2Value).isOk()) {
-            ALOGE("%s: Cannot set RS2 value for momentary exposure %f", __func__, mRs2Value);
+        if (!mHalSoundDose->setOutputRs2(rs2Value).isOk()) {
+            ALOGE("%s: Cannot set RS2 value for momentary exposure %f", __func__, rs2Value);
+            return;
         }
+        mRs2Value = rs2Value;
         return;
     }
 
     for (auto& streamProcessor : mActiveProcessors) {
         sp<audio_utils::MelProcessor> processor = streamProcessor.second.promote();
         if (processor != nullptr) {
-            status_t result = processor->setOutputRs2(mRs2Value);
+            status_t result = processor->setOutputRs2(rs2Value);
             if (result != NO_ERROR) {
-                ALOGW("%s: could not set RS2 value %f for stream %d", __func__, mRs2Value,
+                ALOGW("%s: could not set RS2 value %f for stream %d", __func__, rs2Value,
                       streamProcessor.first);
+                return;
             }
+            mRs2Value = rs2Value;
         }
     }
 }