From 5e7759ba5e699243cc2362edc8fd91ad6c6cf985 Mon Sep 17 00:00:00 2001 From: Vlad Popa Date: Mon, 24 Apr 2023 12:03:05 +0200 Subject: [PATCH] CSD: Fix initial logic for mSafeMediaVolumeState When refactoring the safe hearing logic into the SoundDoseHelper we simplified the msg enum logic for configuring the safe hearing state. This lead to an issue allowing the forced init messages to be removed by the config changed message. Reintroduced the different messages for state configuration which should fix the issue of having devices with MCC 0 not configured for safe hearing. Test: check state in dumpsys Bug: 278822191 Change-Id: I515ca3e5dec3f0d1facf752e6f82886b9760bb04 --- .../android/server/audio/SoundDoseHelper.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/audio/SoundDoseHelper.java b/services/core/java/com/android/server/audio/SoundDoseHelper.java index a57dd403c662e..7cdea8d08c588 100644 --- a/services/core/java/com/android/server/audio/SoundDoseHelper.java +++ b/services/core/java/com/android/server/audio/SoundDoseHelper.java @@ -87,10 +87,11 @@ public class SoundDoseHelper { private static final int SAFE_MEDIA_VOLUME_ACTIVE = 3; // unconfirmed private static final int MSG_CONFIGURE_SAFE_MEDIA = SAFE_MEDIA_VOLUME_MSG_START + 1; - private static final int MSG_PERSIST_SAFE_VOLUME_STATE = SAFE_MEDIA_VOLUME_MSG_START + 2; - private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = SAFE_MEDIA_VOLUME_MSG_START + 3; - private static final int MSG_PERSIST_CSD_VALUES = SAFE_MEDIA_VOLUME_MSG_START + 4; - /*package*/ static final int MSG_CSD_UPDATE_ATTENUATION = SAFE_MEDIA_VOLUME_MSG_START + 5; + private static final int MSG_CONFIGURE_SAFE_MEDIA_FORCED = SAFE_MEDIA_VOLUME_MSG_START + 2; + private static final int MSG_PERSIST_SAFE_VOLUME_STATE = SAFE_MEDIA_VOLUME_MSG_START + 3; + private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = SAFE_MEDIA_VOLUME_MSG_START + 4; + private static final int MSG_PERSIST_CSD_VALUES = SAFE_MEDIA_VOLUME_MSG_START + 5; + /*package*/ static final int MSG_CSD_UPDATE_ATTENUATION = SAFE_MEDIA_VOLUME_MSG_START + 6; private static final int UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX = (20 * 3600 * 1000); // 20 hours @@ -611,8 +612,7 @@ public class SoundDoseHelper { } /*package*/ void configureSafeMedia(boolean forced, String caller) { - int msg = MSG_CONFIGURE_SAFE_MEDIA; - + int msg = forced ? MSG_CONFIGURE_SAFE_MEDIA_FORCED : MSG_CONFIGURE_SAFE_MEDIA; mAudioHandler.removeMessages(msg); long time = 0; @@ -622,7 +622,7 @@ public class SoundDoseHelper { } mAudioHandler.sendMessageAtTime( - mAudioHandler.obtainMessage(msg, /*arg1=*/forced ? 1 : 0, /*arg2=*/0, caller), + mAudioHandler.obtainMessage(msg, /*arg1=*/0, /*arg2=*/0, caller), time); } @@ -664,8 +664,10 @@ public class SoundDoseHelper { /*package*/ void handleMessage(Message msg) { switch (msg.what) { + case MSG_CONFIGURE_SAFE_MEDIA_FORCED: case MSG_CONFIGURE_SAFE_MEDIA: - onConfigureSafeMedia((msg.arg1 == 1), (String) msg.obj); + onConfigureSafeMedia((msg.what == MSG_CONFIGURE_SAFE_MEDIA_FORCED), + (String) msg.obj); break; case MSG_PERSIST_SAFE_VOLUME_STATE: onPersistSafeVolumeState(msg.arg1);