diff options
| -rw-r--r-- | core/res/res/values/config.xml | 4 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 1 | ||||
| -rw-r--r-- | services/core/java/com/android/server/audio/AudioService.java | 15 |
3 files changed, 16 insertions, 4 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 091129858736..01da14f277b3 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2190,6 +2190,10 @@ players. --> <integer name="config_safe_media_volume_index">10</integer> + <!-- Safe USB headset gain. This value is used to ensure that the SPL on the USB + headset output is compliant to EN 60950 requirements for portable music players. --> + <integer name="config_safe_media_volume_usb_mB">-3700</integer> + <!-- Configure mobile network MTU. The standard default is set here but each carrier may have a specific value set in an overlay config.xml file. --> <integer name="config_mobile_mtu">1500</integer> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 9995642ba455..91ef3b4c6ec1 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -453,6 +453,7 @@ <java-symbol type="integer" name="config_multiuserMaximumUsers" /> <java-symbol type="integer" name="config_multiuserMaxRunningUsers" /> <java-symbol type="integer" name="config_safe_media_volume_index" /> + <java-symbol type="integer" name="config_safe_media_volume_usb_mB" /> <java-symbol type="integer" name="config_mobile_mtu" /> <java-symbol type="array" name="config_mobile_tcp_buffers" /> <java-symbol type="integer" name="config_volte_replacement_rat"/> diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 76e0d8984cb8..0ce4dc5260bb 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -3706,6 +3706,9 @@ public class AudioService extends IAudioService.Stub int min = MIN_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]; int max = MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]; + mSafeUsbMediaVolumeDbfs = mContext.getResources().getInteger( + com.android.internal.R.integer.config_safe_media_volume_usb_mB) / 100.0f; + while (Math.abs(max-min) > 1) { int index = (max + min) / 2; float gainDB = AudioSystem.getStreamVolumeDB( @@ -3713,10 +3716,10 @@ public class AudioService extends IAudioService.Stub if (Float.isNaN(gainDB)) { //keep last min in case of read error break; - } else if (gainDB == SAFE_VOLUME_GAIN_DBFS) { + } else if (gainDB == mSafeUsbMediaVolumeDbfs) { min = index; break; - } else if (gainDB < SAFE_VOLUME_GAIN_DBFS) { + } else if (gainDB < mSafeUsbMediaVolumeDbfs) { min = index; } else { max = index; @@ -6310,14 +6313,17 @@ public class AudioService extends IAudioService.Stub private int mMcc = 0; // mSafeMediaVolumeIndex is the cached value of config_safe_media_volume_index property private int mSafeMediaVolumeIndex; + // mSafeUsbMediaVolumeDbfs is the cached value of the config_safe_media_volume_usb_mB + // property, divided by 100.0. + private float mSafeUsbMediaVolumeDbfs; // mSafeUsbMediaVolumeIndex is used for USB Headsets and is the music volume UI index - // corresponding to a gain of -30 dBFS in audio flinger mixer. + // corresponding to a gain of mSafeUsbMediaVolumeDbfs (defaulting to -37dB) in audio + // flinger mixer. // We remove -22 dBs from the theoretical -15dB to account for the EQ + bass boost // amplification when both effects are on with all band gains at maximum. // This level corresponds to a loudness of 85 dB SPL for the warning to be displayed when // the headset is compliant to EN 60950 with a max loudness of 100dB SPL. private int mSafeUsbMediaVolumeIndex; - private static final float SAFE_VOLUME_GAIN_DBFS = -37.0f; // mSafeMediaVolumeDevices lists the devices for which safe media volume is enforced, private final int mSafeMediaVolumeDevices = AudioSystem.DEVICE_OUT_WIRED_HEADSET | AudioSystem.DEVICE_OUT_WIRED_HEADPHONE | @@ -6647,6 +6653,7 @@ public class AudioService extends IAudioService.Stub pw.println(safeMediaVolumeStateToString(mSafeMediaVolumeState)); pw.print(" mSafeMediaVolumeIndex="); pw.println(mSafeMediaVolumeIndex); pw.print(" mSafeUsbMediaVolumeIndex="); pw.println(mSafeUsbMediaVolumeIndex); + pw.print(" mSafeUsbMediaVolumeDbfs="); pw.println(mSafeUsbMediaVolumeDbfs); pw.print(" sIndependentA11yVolume="); pw.println(sIndependentA11yVolume); pw.print(" mPendingVolumeCommand="); pw.println(mPendingVolumeCommand); pw.print(" mMusicActiveMs="); pw.println(mMusicActiveMs); |