diff options
| author | 2023-05-03 13:59:30 +0200 | |
|---|---|---|
| committer | 2023-05-03 15:38:38 +0200 | |
| commit | 01a8ecfd70a882cccacac9f0ee13b7934e119a8d (patch) | |
| tree | ce398d5dd8b2e223f056fe2f4b25baede2ac6f70 | |
| parent | 12bf1a3388ff2584b03a0bd41318cd6909234a63 (diff) | |
CSD: Add support for csd feature flag
Add the possibility to enable/disable the calculation of sound dose
through the enable_csd flag. This can be interesting for possible
experiments with the droidfood population to assess if we can enable
CSD in the US too (the US is currently disabled by the MCC logic).
Test: enable/disable CSD with mobdog
Bug: 276884465
Change-Id: I7cd70196d6558fd2c5b52dd8e350837904f51829
| -rw-r--r-- | services/core/java/com/android/server/audio/SoundDoseHelper.java | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/audio/SoundDoseHelper.java b/services/core/java/com/android/server/audio/SoundDoseHelper.java index 4984f125b00f..aece17e7a6e6 100644 --- a/services/core/java/com/android/server/audio/SoundDoseHelper.java +++ b/services/core/java/com/android/server/audio/SoundDoseHelper.java @@ -34,11 +34,13 @@ import android.media.ISoundDose; import android.media.ISoundDoseCallback; import android.media.SoundDoseRecord; import android.os.Binder; +import android.os.HandlerExecutor; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; +import android.provider.DeviceConfig; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; @@ -120,6 +122,8 @@ public class SoundDoseHelper { private static final int SAFE_MEDIA_VOLUME_UNINITIALIZED = -1; + private static final String FEATURE_FLAG_ENABLE_CSD = "enable_csd"; + private final EventLogger mLogger = new EventLogger(AudioService.LOG_NB_EVENTS_SOUND_DOSE, "CSD updates"); @@ -290,6 +294,10 @@ public class SoundDoseHelper { mAlarmManager = (AlarmManager) mContext.getSystemService( Context.ALARM_SERVICE); + + DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_MEDIA, + new HandlerExecutor(mAudioHandler), + p -> updateCsdEnabled("onPropertiesChanged")); } void initSafeVolumes() { @@ -864,15 +872,30 @@ public class SoundDoseHelper { mAudioHandler.obtainMessage(MSG_PERSIST_SAFE_VOLUME_STATE, persistedState, /*arg2=*/0, /*obj=*/null), /*delay=*/0); + } + + updateCsdEnabled(caller); + } + } - boolean newEnableCsd = SystemProperties.getBoolean("audio.safemedia.force", false) - || mContext.getResources().getBoolean( + private void updateCsdEnabled(String caller) { + boolean newEnableCsd = SystemProperties.getBoolean("audio.safemedia.force", false); + if (!newEnableCsd) { + final String featureFlagEnableCsdValue = DeviceConfig.getProperty( + DeviceConfig.NAMESPACE_MEDIA, + FEATURE_FLAG_ENABLE_CSD); + if (featureFlagEnableCsdValue != null) { + newEnableCsd = Boolean.parseBoolean(featureFlagEnableCsdValue); + } else { + newEnableCsd = mContext.getResources().getBoolean( R.bool.config_safe_sound_dosage_enabled); - if (mEnableCsd.compareAndSet(!newEnableCsd, newEnableCsd)) { - initCsd(); - } } } + + if (mEnableCsd.compareAndSet(!newEnableCsd, newEnableCsd)) { + Log.i(TAG, caller + ": enable CSD " + newEnableCsd); + initCsd(); + } } private int getTimeoutMsForWarning(@AudioManager.CsdWarning int csdWarning) { |