Merge "CSD: enable/disable sound dose based on mcc" into udc-dev
This commit is contained in:
@@ -22,4 +22,7 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">false</bool>
|
<bool name="config_safe_media_volume_enabled">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_mcc_enabled">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -22,4 +22,7 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">false</bool>
|
<bool name="config_safe_media_volume_enabled">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_enabled">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -22,4 +22,7 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">false</bool>
|
<bool name="config_safe_media_volume_enabled">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_enabled">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -22,4 +22,7 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">false</bool>
|
<bool name="config_safe_media_volume_enabled">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_enabled">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -22,4 +22,7 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">false</bool>
|
<bool name="config_safe_media_volume_enabled">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_enabled">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -22,4 +22,7 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">false</bool>
|
<bool name="config_safe_media_volume_enabled">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_enabled">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -22,4 +22,7 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">false</bool>
|
<bool name="config_safe_media_volume_enabled">false</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_enabled">false</bool>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -2105,9 +2105,6 @@
|
|||||||
<!-- The default volume for the ring stream -->
|
<!-- The default volume for the ring stream -->
|
||||||
<integer name="config_audio_ring_vol_default">5</integer>
|
<integer name="config_audio_ring_vol_default">5</integer>
|
||||||
|
|
||||||
<!-- Enable sound dose computation and warnings -->
|
|
||||||
<bool name="config_audio_csd_enabled_default">true</bool>
|
|
||||||
|
|
||||||
<!-- The default value for whether head tracking for
|
<!-- The default value for whether head tracking for
|
||||||
spatial audio is enabled for a newly connected audio device -->
|
spatial audio is enabled for a newly connected audio device -->
|
||||||
<bool name="config_spatial_audio_head_tracking_enabled_default">false</bool>
|
<bool name="config_spatial_audio_head_tracking_enabled_default">false</bool>
|
||||||
@@ -2939,6 +2936,9 @@
|
|||||||
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
<!-- Whether safe headphone volume is enabled or not (country specific). -->
|
||||||
<bool name="config_safe_media_volume_enabled">true</bool>
|
<bool name="config_safe_media_volume_enabled">true</bool>
|
||||||
|
|
||||||
|
<!-- Whether safe headphone sound dosage warning is enabled or not (country specific). -->
|
||||||
|
<bool name="config_safe_sound_dosage_enabled">true</bool>
|
||||||
|
|
||||||
<!-- Whether safe headphone volume warning dialog is disabled on Vol+ (operator specific). -->
|
<!-- Whether safe headphone volume warning dialog is disabled on Vol+ (operator specific). -->
|
||||||
<bool name="config_safe_media_disable_on_volume_up">true</bool>
|
<bool name="config_safe_media_disable_on_volume_up">true</bool>
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,6 @@
|
|||||||
<java-symbol type="attr" name="autofillSaveCustomSubtitleMaxHeight"/>
|
<java-symbol type="attr" name="autofillSaveCustomSubtitleMaxHeight"/>
|
||||||
<java-symbol type="bool" name="action_bar_embed_tabs" />
|
<java-symbol type="bool" name="action_bar_embed_tabs" />
|
||||||
<java-symbol type="bool" name="action_bar_expanded_action_views_exclusive" />
|
<java-symbol type="bool" name="action_bar_expanded_action_views_exclusive" />
|
||||||
<java-symbol type="bool" name="config_audio_csd_enabled_default" />
|
|
||||||
<java-symbol type="integer" name="config_audio_notif_vol_default" />
|
<java-symbol type="integer" name="config_audio_notif_vol_default" />
|
||||||
<java-symbol type="integer" name="config_audio_notif_vol_steps" />
|
<java-symbol type="integer" name="config_audio_notif_vol_steps" />
|
||||||
<java-symbol type="integer" name="config_audio_ring_vol_default" />
|
<java-symbol type="integer" name="config_audio_ring_vol_default" />
|
||||||
@@ -349,6 +348,7 @@
|
|||||||
<java-symbol type="bool" name="config_useDevInputEventForAudioJack" />
|
<java-symbol type="bool" name="config_useDevInputEventForAudioJack" />
|
||||||
<java-symbol type="bool" name="config_safe_media_volume_enabled" />
|
<java-symbol type="bool" name="config_safe_media_volume_enabled" />
|
||||||
<java-symbol type="bool" name="config_safe_media_disable_on_volume_up" />
|
<java-symbol type="bool" name="config_safe_media_disable_on_volume_up" />
|
||||||
|
<java-symbol type="bool" name="config_safe_sound_dosage_enabled" />
|
||||||
<java-symbol type="bool" name="config_camera_sound_forced" />
|
<java-symbol type="bool" name="config_camera_sound_forced" />
|
||||||
<java-symbol type="bool" name="config_dontPreferApn" />
|
<java-symbol type="bool" name="config_dontPreferApn" />
|
||||||
<java-symbol type="bool" name="config_restartRadioAfterProvisioning" />
|
<java-symbol type="bool" name="config_restartRadioAfterProvisioning" />
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -168,7 +169,7 @@ public class SoundDoseHelper {
|
|||||||
@NonNull private final AudioHandler mAudioHandler;
|
@NonNull private final AudioHandler mAudioHandler;
|
||||||
@NonNull private final ISafeHearingVolumeController mVolumeController;
|
@NonNull private final ISafeHearingVolumeController mVolumeController;
|
||||||
|
|
||||||
private final boolean mEnableCsd;
|
private final AtomicBoolean mEnableCsd = new AtomicBoolean(false);
|
||||||
|
|
||||||
private final Object mCsdStateLock = new Object();
|
private final Object mCsdStateLock = new Object();
|
||||||
|
|
||||||
@@ -195,7 +196,7 @@ public class SoundDoseHelper {
|
|||||||
|
|
||||||
private final ISoundDoseCallback.Stub mSoundDoseCallback = new ISoundDoseCallback.Stub() {
|
private final ISoundDoseCallback.Stub mSoundDoseCallback = new ISoundDoseCallback.Stub() {
|
||||||
public void onMomentaryExposure(float currentMel, int deviceId) {
|
public void onMomentaryExposure(float currentMel, int deviceId) {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
Log.w(TAG, "onMomentaryExposure: csd not supported, ignoring callback");
|
Log.w(TAG, "onMomentaryExposure: csd not supported, ignoring callback");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -222,7 +223,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onNewCsdValue(float currentCsd, SoundDoseRecord[] records) {
|
public void onNewCsdValue(float currentCsd, SoundDoseRecord[] records) {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
Log.w(TAG, "onNewCsdValue: csd not supported, ignoring value");
|
Log.w(TAG, "onNewCsdValue: csd not supported, ignoring value");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -272,8 +273,6 @@ public class SoundDoseHelper {
|
|||||||
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
mEnableCsd = mContext.getResources().getBoolean(R.bool.config_audio_csd_enabled_default);
|
|
||||||
initCsd();
|
|
||||||
initSafeVolumes();
|
initSafeVolumes();
|
||||||
|
|
||||||
mSafeMediaVolumeState = mSettings.getGlobalInt(audioService.getContentResolver(),
|
mSafeMediaVolumeState = mSettings.getGlobalInt(audioService.getContentResolver(),
|
||||||
@@ -285,6 +284,10 @@ public class SoundDoseHelper {
|
|||||||
mSafeMediaVolumeIndex = mContext.getResources().getInteger(
|
mSafeMediaVolumeIndex = mContext.getResources().getInteger(
|
||||||
R.integer.config_safe_media_volume_index) * 10;
|
R.integer.config_safe_media_volume_index) * 10;
|
||||||
|
|
||||||
|
mSoundDose.set(AudioSystem.getSoundDoseInterface(mSoundDoseCallback));
|
||||||
|
// Csd will be initially disabled until the mcc is read in onConfigureSafeMedia()
|
||||||
|
initCsd();
|
||||||
|
|
||||||
mAlarmManager = (AlarmManager) mContext.getSystemService(
|
mAlarmManager = (AlarmManager) mContext.getSystemService(
|
||||||
Context.ALARM_SERVICE);
|
Context.ALARM_SERVICE);
|
||||||
}
|
}
|
||||||
@@ -310,7 +313,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float getOutputRs2UpperBound() {
|
float getOutputRs2UpperBound() {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +332,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setOutputRs2UpperBound(float rs2Value) {
|
void setOutputRs2UpperBound(float rs2Value) {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +350,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float getCsd() {
|
float getCsd() {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return -1.f;
|
return -1.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +369,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setCsd(float csd) {
|
void setCsd(float csd) {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +403,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void resetCsdTimeouts() {
|
void resetCsdTimeouts() {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,7 +419,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void forceUseFrameworkMel(boolean useFrameworkMel) {
|
void forceUseFrameworkMel(boolean useFrameworkMel) {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +437,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void forceComputeCsdOnAllDevices(boolean computeCsdOnAllDevices) {
|
void forceComputeCsdOnAllDevices(boolean computeCsdOnAllDevices) {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,7 +457,7 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isCsdEnabled() {
|
boolean isCsdEnabled() {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -697,8 +700,8 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ void dump(PrintWriter pw) {
|
/*package*/ void dump(PrintWriter pw) {
|
||||||
pw.print(" mEnableCsd="); pw.println(mEnableCsd);
|
pw.print(" mEnableCsd="); pw.println(mEnableCsd.get());
|
||||||
if (mEnableCsd) {
|
if (mEnableCsd.get()) {
|
||||||
synchronized (mCsdStateLock) {
|
synchronized (mCsdStateLock) {
|
||||||
pw.print(" mCurrentCsd="); pw.println(mCurrentCsd);
|
pw.print(" mCurrentCsd="); pw.println(mCurrentCsd);
|
||||||
}
|
}
|
||||||
@@ -719,9 +722,11 @@ public class SoundDoseHelper {
|
|||||||
pw.println();
|
pw.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/void reset() {
|
/*package*/void reset() {
|
||||||
Log.d(TAG, "Reset the sound dose helper");
|
Log.d(TAG, "Reset the sound dose helper");
|
||||||
mSoundDose.set(AudioSystem.getSoundDoseInterface(mSoundDoseCallback));
|
|
||||||
|
mSoundDose.compareAndExchange(/*expectedValue=*/null,
|
||||||
|
AudioSystem.getSoundDoseInterface(mSoundDoseCallback));
|
||||||
|
|
||||||
synchronized (mCsdStateLock) {
|
synchronized (mCsdStateLock) {
|
||||||
try {
|
try {
|
||||||
@@ -743,7 +748,7 @@ public class SoundDoseHelper {
|
|||||||
|
|
||||||
private void updateDoseAttenuation(int newIndex, int device, int streamType,
|
private void updateDoseAttenuation(int newIndex, int device, int streamType,
|
||||||
boolean isAbsoluteVolume) {
|
boolean isAbsoluteVolume) {
|
||||||
if (!mEnableCsd) {
|
if (!mEnableCsd.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,17 +780,19 @@ public class SoundDoseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initCsd() {
|
private void initCsd() {
|
||||||
if (!mEnableCsd) {
|
ISoundDose soundDose = mSoundDose.get();
|
||||||
final ISoundDose soundDose = AudioSystem.getSoundDoseInterface(mSoundDoseCallback);
|
if (soundDose == null) {
|
||||||
if (soundDose == null) {
|
Log.w(TAG, "ISoundDose instance is null.");
|
||||||
Log.w(TAG, "ISoundDose instance is null.");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
soundDose.disableCsd();
|
soundDose.setCsdEnabled(mEnableCsd.get());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Cannot disable CSD", e);
|
Log.e(TAG, "Cannot disable CSD", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mEnableCsd.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,7 +836,6 @@ public class SoundDoseHelper {
|
|||||||
SystemProperties.getBoolean("audio.safemedia.force", false)
|
SystemProperties.getBoolean("audio.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);
|
||||||
|
|
||||||
boolean safeMediaVolumeBypass =
|
boolean safeMediaVolumeBypass =
|
||||||
SystemProperties.getBoolean("audio.safemedia.bypass", false);
|
SystemProperties.getBoolean("audio.safemedia.bypass", false);
|
||||||
|
|
||||||
@@ -860,6 +866,13 @@ public class SoundDoseHelper {
|
|||||||
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);
|
||||||
|
|
||||||
|
boolean newEnableCsd = SystemProperties.getBoolean("audio.safemedia.force", false)
|
||||||
|
|| mContext.getResources().getBoolean(
|
||||||
|
R.bool.config_safe_sound_dosage_enabled);
|
||||||
|
if (mEnableCsd.compareAndSet(!newEnableCsd, newEnableCsd)) {
|
||||||
|
initCsd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -913,7 +926,7 @@ public class SoundDoseHelper {
|
|||||||
// legacy implementation uses mSafeMediaVolumeIndex for wired HS/HP
|
// legacy implementation uses mSafeMediaVolumeIndex for wired HS/HP
|
||||||
// instead of computing it from the volume curves
|
// instead of computing it from the volume curves
|
||||||
if ((deviceType == AudioSystem.DEVICE_OUT_WIRED_HEADPHONE
|
if ((deviceType == AudioSystem.DEVICE_OUT_WIRED_HEADPHONE
|
||||||
|| deviceType == AudioSystem.DEVICE_OUT_WIRED_HEADSET) && !mEnableCsd) {
|
|| deviceType == AudioSystem.DEVICE_OUT_WIRED_HEADSET) && !mEnableCsd.get()) {
|
||||||
return mSafeMediaVolumeIndex;
|
return mSafeMediaVolumeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user