Loading services/core/java/com/android/server/audio/SoundDoseHelper.java +38 −11 Original line number Diff line number Diff line Loading @@ -189,6 +189,8 @@ public class SoundDoseHelper { private final AtomicBoolean mEnableCsd = new AtomicBoolean(false); private final AtomicBoolean mForceCsdProperty = new AtomicBoolean(false); private final Object mCsdAsAFeatureLock = new Object(); @GuardedBy("mCsdAsAFeatureLock") Loading Loading @@ -375,10 +377,22 @@ public class SoundDoseHelper { } } private boolean updateCsdForTestApi() { if (mForceCsdProperty.get() != SystemProperties.getBoolean( SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE, false)) { updateCsdEnabled("SystemPropertiesChangeCallback"); } return mEnableCsd.get(); } float getCsd() { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return -1.f; } } final ISoundDose soundDose = mSoundDose.get(); if (soundDose == null) { Loading @@ -396,8 +410,11 @@ public class SoundDoseHelper { void setCsd(float csd) { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } SoundDoseRecord[] doseRecordsArray; synchronized (mCsdStateLock) { Loading Loading @@ -430,8 +447,11 @@ public class SoundDoseHelper { void resetCsdTimeouts() { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } synchronized (mCsdStateLock) { mLastMomentaryExposureTimeMs = MOMENTARY_EXPOSURE_TIMEOUT_UNINITIALIZED; Loading @@ -440,8 +460,11 @@ public class SoundDoseHelper { void forceUseFrameworkMel(boolean useFrameworkMel) { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } final ISoundDose soundDose = mSoundDose.get(); if (soundDose == null) { Loading @@ -458,8 +481,11 @@ public class SoundDoseHelper { void forceComputeCsdOnAllDevices(boolean computeCsdOnAllDevices) { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } final ISoundDose soundDose = mSoundDose.get(); if (soundDose == null) { Loading Loading @@ -488,7 +514,7 @@ public class SoundDoseHelper { try { return soundDose.isSoundDoseHalSupported(); } catch (RemoteException e) { Log.e(TAG, "Exception while forcing CSD computation on all devices", e); Log.e(TAG, "Exception while querying the csd enabled status", e); } return false; } Loading Loading @@ -544,7 +570,7 @@ public class SoundDoseHelper { audioDeviceCategory.csdCompatible = isHeadphone; soundDose.setAudioDeviceCategory(audioDeviceCategory); } catch (RemoteException e) { Log.e(TAG, "Exception while forcing the internal MEL computation", e); Log.e(TAG, "Exception while setting the audio device category", e); } } Loading Loading @@ -894,7 +920,7 @@ public class SoundDoseHelper { mCachedAudioDeviceCategories.clear(); } } catch (RemoteException e) { Log.e(TAG, "Exception while forcing the internal MEL computation", e); Log.e(TAG, "Exception while initializing the cached audio device categories", e); } synchronized (mCsdAsAFeatureLock) { Loading Loading @@ -991,19 +1017,20 @@ public class SoundDoseHelper { } private void updateCsdEnabled(String caller) { boolean csdForce = SystemProperties.getBoolean(SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE, false); mForceCsdProperty.set(SystemProperties.getBoolean(SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE, false)); // we are using the MCC overlaid legacy flag used for the safe volume enablement // to determine whether the MCC enforces any safe hearing standard. boolean mccEnforcedSafeMedia = mContext.getResources().getBoolean( com.android.internal.R.bool.config_safe_media_volume_enabled); boolean csdEnable = mContext.getResources().getBoolean( R.bool.config_safe_sound_dosage_enabled); boolean newEnabledCsd = (mccEnforcedSafeMedia && csdEnable) || csdForce; boolean newEnabledCsd = (mccEnforcedSafeMedia && csdEnable) || mForceCsdProperty.get(); synchronized (mCsdAsAFeatureLock) { if (!mccEnforcedSafeMedia && csdEnable) { mIsCsdAsAFeatureAvailable = true; newEnabledCsd = mIsCsdAsAFeatureEnabled || csdForce; newEnabledCsd = mIsCsdAsAFeatureEnabled || mForceCsdProperty.get(); Log.v(TAG, caller + ": CSD as a feature is not enforced and enabled: " + newEnabledCsd); } else { Loading Loading
services/core/java/com/android/server/audio/SoundDoseHelper.java +38 −11 Original line number Diff line number Diff line Loading @@ -189,6 +189,8 @@ public class SoundDoseHelper { private final AtomicBoolean mEnableCsd = new AtomicBoolean(false); private final AtomicBoolean mForceCsdProperty = new AtomicBoolean(false); private final Object mCsdAsAFeatureLock = new Object(); @GuardedBy("mCsdAsAFeatureLock") Loading Loading @@ -375,10 +377,22 @@ public class SoundDoseHelper { } } private boolean updateCsdForTestApi() { if (mForceCsdProperty.get() != SystemProperties.getBoolean( SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE, false)) { updateCsdEnabled("SystemPropertiesChangeCallback"); } return mEnableCsd.get(); } float getCsd() { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return -1.f; } } final ISoundDose soundDose = mSoundDose.get(); if (soundDose == null) { Loading @@ -396,8 +410,11 @@ public class SoundDoseHelper { void setCsd(float csd) { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } SoundDoseRecord[] doseRecordsArray; synchronized (mCsdStateLock) { Loading Loading @@ -430,8 +447,11 @@ public class SoundDoseHelper { void resetCsdTimeouts() { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } synchronized (mCsdStateLock) { mLastMomentaryExposureTimeMs = MOMENTARY_EXPOSURE_TIMEOUT_UNINITIALIZED; Loading @@ -440,8 +460,11 @@ public class SoundDoseHelper { void forceUseFrameworkMel(boolean useFrameworkMel) { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } final ISoundDose soundDose = mSoundDose.get(); if (soundDose == null) { Loading @@ -458,8 +481,11 @@ public class SoundDoseHelper { void forceComputeCsdOnAllDevices(boolean computeCsdOnAllDevices) { if (!mEnableCsd.get()) { // since this will only be called by a test api enable csd if system property is set if (!updateCsdForTestApi()) { return; } } final ISoundDose soundDose = mSoundDose.get(); if (soundDose == null) { Loading Loading @@ -488,7 +514,7 @@ public class SoundDoseHelper { try { return soundDose.isSoundDoseHalSupported(); } catch (RemoteException e) { Log.e(TAG, "Exception while forcing CSD computation on all devices", e); Log.e(TAG, "Exception while querying the csd enabled status", e); } return false; } Loading Loading @@ -544,7 +570,7 @@ public class SoundDoseHelper { audioDeviceCategory.csdCompatible = isHeadphone; soundDose.setAudioDeviceCategory(audioDeviceCategory); } catch (RemoteException e) { Log.e(TAG, "Exception while forcing the internal MEL computation", e); Log.e(TAG, "Exception while setting the audio device category", e); } } Loading Loading @@ -894,7 +920,7 @@ public class SoundDoseHelper { mCachedAudioDeviceCategories.clear(); } } catch (RemoteException e) { Log.e(TAG, "Exception while forcing the internal MEL computation", e); Log.e(TAG, "Exception while initializing the cached audio device categories", e); } synchronized (mCsdAsAFeatureLock) { Loading Loading @@ -991,19 +1017,20 @@ public class SoundDoseHelper { } private void updateCsdEnabled(String caller) { boolean csdForce = SystemProperties.getBoolean(SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE, false); mForceCsdProperty.set(SystemProperties.getBoolean(SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE, false)); // we are using the MCC overlaid legacy flag used for the safe volume enablement // to determine whether the MCC enforces any safe hearing standard. boolean mccEnforcedSafeMedia = mContext.getResources().getBoolean( com.android.internal.R.bool.config_safe_media_volume_enabled); boolean csdEnable = mContext.getResources().getBoolean( R.bool.config_safe_sound_dosage_enabled); boolean newEnabledCsd = (mccEnforcedSafeMedia && csdEnable) || csdForce; boolean newEnabledCsd = (mccEnforcedSafeMedia && csdEnable) || mForceCsdProperty.get(); synchronized (mCsdAsAFeatureLock) { if (!mccEnforcedSafeMedia && csdEnable) { mIsCsdAsAFeatureAvailable = true; newEnabledCsd = mIsCsdAsAFeatureEnabled || csdForce; newEnabledCsd = mIsCsdAsAFeatureEnabled || mForceCsdProperty.get(); Log.v(TAG, caller + ": CSD as a feature is not enforced and enabled: " + newEnabledCsd); } else { Loading