Merge "CSD: Remove volume based warning when CSD is enabled" into udc-dev

This commit is contained in:
Vlad Popa
2023-05-05 17:17:43 +00:00
committed by Android (Google) Code Review

View File

@@ -78,6 +78,23 @@ public class SoundDoseHelper {
/*package*/ static final String ACTION_CHECK_MUSIC_ACTIVE = /*package*/ static final String ACTION_CHECK_MUSIC_ACTIVE =
"com.android.server.audio.action.CHECK_MUSIC_ACTIVE"; "com.android.server.audio.action.CHECK_MUSIC_ACTIVE";
/**
* Property to force the index based safe volume warnings. Note that usually when the
* CSD warnings are active the safe volume warnings are deactivated. In combination with
* {@link SoundDoseHelper#SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE} both approaches can be active
* at the same time.
*/
private static final String SYSTEM_PROPERTY_SAFEMEDIA_FORCE = "audio.safemedia.force";
/** Property for bypassing the index based safe volume approach. */
private static final String SYSTEM_PROPERTY_SAFEMEDIA_BYPASS = "audio.safemedia.bypass";
/**
* Property to force the CSD warnings. Note that usually when the CSD warnings are active the
* safe volume warnings are deactivated. In combination with
* {@link SoundDoseHelper#SYSTEM_PROPERTY_SAFEMEDIA_FORCE} both approaches can be active
* at the same time.
*/
private static final String SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE = "audio.safemedia.csd.force";
// mSafeMediaVolumeState indicates whether the media volume is limited over headphones. // mSafeMediaVolumeState indicates whether the media volume is limited over headphones.
// It is SAFE_MEDIA_VOLUME_NOT_CONFIGURED at boot time until a network service is connected // It is SAFE_MEDIA_VOLUME_NOT_CONFIGURED at boot time until a network service is connected
// or the configure time is elapsed. It is then set to SAFE_MEDIA_VOLUME_ACTIVE or // or the configure time is elapsed. It is then set to SAFE_MEDIA_VOLUME_ACTIVE or
@@ -830,20 +847,31 @@ public class SoundDoseHelper {
} }
private void onConfigureSafeMedia(boolean force, String caller) { private void onConfigureSafeMedia(boolean force, String caller) {
updateCsdEnabled(caller);
synchronized (mSafeMediaVolumeStateLock) { synchronized (mSafeMediaVolumeStateLock) {
int mcc = mContext.getResources().getConfiguration().mcc; int mcc = mContext.getResources().getConfiguration().mcc;
if ((mMcc != mcc) || ((mMcc == 0) && force)) { if ((mMcc != mcc) || ((mMcc == 0) && force)) {
mSafeMediaVolumeIndex = mContext.getResources().getInteger( mSafeMediaVolumeIndex = mContext.getResources().getInteger(
com.android.internal.R.integer.config_safe_media_volume_index) * 10; com.android.internal.R.integer.config_safe_media_volume_index) * 10;
initSafeMediaVolumeIndex(); initSafeMediaVolumeIndex();
updateSafeMediaVolume_l(caller);
mMcc = mcc;
}
}
}
@GuardedBy("mSafeMediaVolumeStateLock")
private void updateSafeMediaVolume_l(String caller) {
boolean safeMediaVolumeEnabled = boolean safeMediaVolumeEnabled =
SystemProperties.getBoolean("audio.safemedia.force", false) SystemProperties.getBoolean(SYSTEM_PROPERTY_SAFEMEDIA_FORCE, false)
|| mContext.getResources().getBoolean( || (mContext.getResources().getBoolean(
com.android.internal.R.bool.config_safe_media_volume_enabled); com.android.internal.R.bool.config_safe_media_volume_enabled)
&& !mEnableCsd.get());
boolean safeMediaVolumeBypass = boolean safeMediaVolumeBypass =
SystemProperties.getBoolean("audio.safemedia.bypass", false); SystemProperties.getBoolean(SYSTEM_PROPERTY_SAFEMEDIA_BYPASS, false);
// The persisted state is either "disabled" or "active": this is the state applied // The persisted state is either "disabled" or "active": this is the state applied
// next time we boot and cannot be "inactive" // next time we boot and cannot be "inactive"
@@ -867,19 +895,16 @@ public class SoundDoseHelper {
persistedState = SAFE_MEDIA_VOLUME_DISABLED; persistedState = SAFE_MEDIA_VOLUME_DISABLED;
mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED; mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_DISABLED;
} }
mMcc = mcc;
mAudioHandler.sendMessageAtTime( mAudioHandler.sendMessageAtTime(
mAudioHandler.obtainMessage(MSG_PERSIST_SAFE_VOLUME_STATE, mAudioHandler.obtainMessage(MSG_PERSIST_SAFE_VOLUME_STATE,
persistedState, /*arg2=*/0, persistedState, /*arg2=*/0,
/*obj=*/null), /*delay=*/0); /*obj=*/null), /*delay=*/0);
} }
updateCsdEnabled(caller);
}
}
private void updateCsdEnabled(String caller) { private void updateCsdEnabled(String caller) {
boolean newEnableCsd = SystemProperties.getBoolean("audio.safemedia.force", false); boolean newEnableCsd = SystemProperties.getBoolean(SYSTEM_PROPERTY_SAFEMEDIA_CSD_FORCE,
false);
if (!newEnableCsd) { if (!newEnableCsd) {
final String featureFlagEnableCsdValue = DeviceConfig.getProperty( final String featureFlagEnableCsdValue = DeviceConfig.getProperty(
DeviceConfig.NAMESPACE_MEDIA, DeviceConfig.NAMESPACE_MEDIA,
@@ -895,6 +920,10 @@ public class SoundDoseHelper {
if (mEnableCsd.compareAndSet(!newEnableCsd, newEnableCsd)) { if (mEnableCsd.compareAndSet(!newEnableCsd, newEnableCsd)) {
Log.i(TAG, caller + ": enable CSD " + newEnableCsd); Log.i(TAG, caller + ": enable CSD " + newEnableCsd);
initCsd(); initCsd();
synchronized (mSafeMediaVolumeStateLock) {
updateSafeMediaVolume_l(caller);
}
} }
} }