// the mcc is read by onConfigureSafeVolume()
mSafeMediaVolumeIndex = mContext.getResources().getInteger(
com.android.internal.R.integer.config_safe_media_volume_index) * 10;
- mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();
mUseFixedVolume = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_useFixedVolume);
mSettingsObserver = new SettingsObserver();
createStreamStates();
+ // mSafeUsbMediaVolumeIndex must be initialized after createStreamStates() because it
+ // relies on audio policy having correct ranges for volume indexes.
+ mSafeUsbMediaVolumeIndex = getSafeUsbMediaVolumeIndex();
+
mMediaFocusControl = new MediaFocusControl(mContext, mPlaybackMonitor);
readAndSetLowRamDevice();
int index = (max + min) / 2;
float gainDB = AudioSystem.getStreamVolumeDB(
AudioSystem.STREAM_MUSIC, index, AudioSystem.DEVICE_OUT_USB_HEADSET);
- if (gainDB == Float.NaN) {
+ if (Float.isNaN(gainDB)) {
//keep last min in case of read error
break;
- } else if (gainDB == SAVE_VOLUME_GAIN_DBFS) {
+ } else if (gainDB == SAFE_VOLUME_GAIN_DBFS) {
min = index;
break;
- } else if (gainDB < SAVE_VOLUME_GAIN_DBFS) {
+ } else if (gainDB < SAFE_VOLUME_GAIN_DBFS) {
min = index;
} else {
max = index;
private int mMcc = 0;
// mSafeMediaVolumeIndex is the cached value of config_safe_media_volume_index property
private int mSafeMediaVolumeIndex;
- // mSafeUsbMediaVolumeIndex is used for USB Headsets and is to the music volume
- // UI index corresponding to a gain of -15 dBFS. This corresponds to a loudness of 85 dB SPL
- // if the headset is compliant to EN 60950 with a max loudness of 100dB SPL.
+ // mSafeUsbMediaVolumeIndex is used for USB Headsets and is the music volume UI index
+ // corresponding to a gain of -30 dBFS in audio flinger mixer.
+ // We remove -15 dBs from the theoretical -15dB to account for the EQ boost when bands are set
+ // to max gain.
+ // 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 SAVE_VOLUME_GAIN_DBFS = -15;
+ private static final float SAFE_VOLUME_GAIN_DBFS = -30.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 |