<!-- Whether safe headphone volume is enabled or not (country specific). --><boolname="config_safe_media_volume_enabled">true</bool>
1
2
3
4
<!-- Safe headphone volume index. When music stream volume is below this index
the SPL on headphone output is compliant to EN 60950 requirements for portable music
players. --><integername="config_safe_media_volume_index">10</integer>
privatevoidonConfigureSafeVolume(booleanforce,Stringcaller){synchronized(mSafeMediaVolumeStateLock){//Mobile contry code,国家代码,主要用来区分不同国家,部分国家策略可能会不一致
intmcc=mContext.getResources().getConfiguration().mcc;if((mMcc!=mcc)||((mMcc==0)&&force)){//从config_safe_media_volume_index中获取回来的安全音量触发阈值
mSafeMediaVolumeIndex=mContext.getResources().getInteger(com.android.internal.R.integer.config_safe_media_volume_index)*10;mSafeUsbMediaVolumeIndex=getSafeUsbMediaVolumeIndex();//根据audio.safemedia.force属性值或者value配置的值来决定是否使能安全音量
booleansafeMediaVolumeEnabled=SystemProperties.getBoolean("audio.safemedia.force",false)||mContext.getResources().getBoolean(com.android.internal.R.bool.config_safe_media_volume_enabled);//确认是否需要bypass掉安全音量功能
booleansafeMediaVolumeBypass=SystemProperties.getBoolean("audio.safemedia.bypass",false);// The persisted state is either "disabled" or "active": this is the state applied
// next time we boot and cannot be "inactive"
intpersistedState;if(safeMediaVolumeEnabled&&!safeMediaVolumeBypass){persistedState=SAFE_MEDIA_VOLUME_ACTIVE;//这个值只能是disable或者active,不能是inactive,主要用于下次启动。
// The state can already be "inactive" here if the user has forced it before
// the 30 seconds timeout for forced configuration. In this case we don't reset
// it to "active".
if(mSafeMediaVolumeState!=SAFE_MEDIA_VOLUME_INACTIVE){if(mMusicActiveMs==0){//mMusicActiveMs主要用于计数,当安全音量弹框弹出时,如果按了确定,这个值便开始递增,当其达到UNSAFE_VOLUME_MUSIC_ACTIVE_MS_MAX时,则重新使能安全音量
mSafeMediaVolumeState=SAFE_MEDIA_VOLUME_ACTIVE;enforceSafeMediaVolume(caller);}else{//跑到这里则表示已经弹过安全音量警示了,并且按了确定,所以把值设置为inactive
// We have existing playback time recorded, already confirmed.
mSafeMediaVolumeState=SAFE_MEDIA_VOLUME_INACTIVE;}}}else{persistedState=SAFE_MEDIA_VOLUME_DISABLED;mSafeMediaVolumeState=SAFE_MEDIA_VOLUME_DISABLED;}mMcc=mcc;//持久化当前安全音量的状态
sendMsg(mAudioHandler,MSG_PERSIST_SAFE_VOLUME_STATE,SENDMSG_QUEUE,persistedState,0,null,0);}}}
publicvoiddisableSafeMediaVolume(StringcallingPackage){enforceVolumeController("disable the safe media volume");synchronized(mSafeMediaVolumeStateLock){setSafeMediaVolumeEnabled(false,callingPackage);if(mPendingVolumeCommand!=null){onSetStreamVolume(mPendingVolumeCommand.mStreamType,mPendingVolumeCommand.mIndex,mPendingVolumeCommand.mFlags,mPendingVolumeCommand.mDevice,callingPackage);mPendingVolumeCommand=null;}}}