Loading services/core/java/com/android/server/audio/AudioService.java +1 −1 Original line number Diff line number Diff line Loading @@ -11698,7 +11698,7 @@ public class AudioService extends IAudioService.Stub static final int LOG_NB_EVENTS_VOLUME = 100; static final int LOG_NB_EVENTS_DYN_POLICY = 10; static final int LOG_NB_EVENTS_SPATIAL = 30; static final int LOG_NB_EVENTS_SOUND_DOSE = 30; static final int LOG_NB_EVENTS_SOUND_DOSE = 50; static final int LOG_NB_EVENTS_LOUDNESS_CODEC = 30; Loading services/core/java/com/android/server/audio/AudioServiceEvents.java +9 −0 Original line number Diff line number Diff line Loading @@ -577,6 +577,7 @@ public class AudioServiceEvents { static final int DOSE_REPEAT_5X = 2; static final int DOSE_ACCUMULATION_START = 3; static final int LOWER_VOLUME_TO_RS1 = 4; static final int UPDATE_ABS_VOLUME_ATTENUATION = 5; final int mEventType; final float mFloatValue; Loading Loading @@ -608,6 +609,10 @@ public class AudioServiceEvents { return new SoundDoseEvent(LOWER_VOLUME_TO_RS1, 0 /*ignored*/, 0 /*ignored*/); } static SoundDoseEvent getAbsVolumeAttenuationEvent(float attenuation, int device) { return new SoundDoseEvent(UPDATE_ABS_VOLUME_ATTENUATION, attenuation, device); } @Override public String eventToString() { switch (mEventType) { Loading @@ -623,6 +628,10 @@ public class AudioServiceEvents { return "CSD accumulating: RS2 entered"; case LOWER_VOLUME_TO_RS1: return "CSD lowering volume to RS1"; case UPDATE_ABS_VOLUME_ATTENUATION: return String.format(java.util.Locale.US, "Updating CSD absolute volume attenuation on device %d with %.2f dB ", mLongValue, mFloatValue); } return new StringBuilder("FIXME invalid event type:").append(mEventType).toString(); } Loading services/core/java/com/android/server/audio/SoundDoseHelper.java +29 −17 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.media.AudioSystem; import android.media.ISoundDose; import android.media.ISoundDoseCallback; import android.media.SoundDoseRecord; import android.media.VolumeInfo; import android.os.Binder; import android.os.Message; import android.os.RemoteException; Loading Loading @@ -895,6 +896,8 @@ public class SoundDoseHelper { try { if (!isAbsoluteVolume) { mLogger.enqueue( SoundDoseEvent.getAbsVolumeAttenuationEvent(/*attenuation=*/0.f, device)); // remove any possible previous attenuation soundDose.updateAttenuation(/* attenuationDB= */0.f, device); Loading @@ -903,10 +906,11 @@ public class SoundDoseHelper { if (AudioService.mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC && safeDevicesContains(device)) { soundDose.updateAttenuation( -AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_MUSIC, (newIndex + 5) / 10, device), device); float attenuationDb = -AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_MUSIC, (newIndex + 5) / 10, device); mLogger.enqueue( SoundDoseEvent.getAbsVolumeAttenuationEvent(attenuationDb, device)); soundDose.updateAttenuation(attenuationDb, device); } } catch (RemoteException e) { Log.e(TAG, "Could not apply the attenuation for MEL calculation with volume index " Loading Loading @@ -1313,22 +1317,30 @@ public class SoundDoseHelper { /** Called when handling MSG_LOWER_VOLUME_TO_RS1 */ private void onLowerVolumeToRs1() { mLogger.enqueue(SoundDoseEvent.getLowerVolumeToRs1Event()); final ArrayList<AudioDeviceAttributes> devices = mAudioService.getDevicesForAttributesInt( new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(), true); final int nativeDeviceType; final AudioDeviceAttributes ada; if (!devices.isEmpty()) { ada = devices.get(0); nativeDeviceType = ada.getInternalType(); } else { nativeDeviceType = AudioSystem.DEVICE_OUT_USB_HEADSET; ada = new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_USB_HEADSET, ""); new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_MEDIA).build(), /*forVolume=*/true); if (devices.isEmpty()) { Log.e(TAG, "Cannot lower the volume to RS1, no devices registered for USAGE_MEDIA"); return; } final int index = safeMediaVolumeIndex(nativeDeviceType); mAudioService.setStreamVolumeWithAttributionInt(STREAM_MUSIC, index / 10, /*flags*/ 0, ada, final AudioDeviceAttributes ada = devices.get(0); final int nativeDeviceType = ada.getInternalType(); final int index = safeMediaVolumeIndex(nativeDeviceType) / 10; final VolumeInfo curVolume = mAudioService.getDeviceVolume( new VolumeInfo.Builder(STREAM_MUSIC).build(), ada, /*callingPackage=*/"sounddosehelper"); if (index < curVolume.getVolumeIndex()) { mLogger.enqueue(SoundDoseEvent.getLowerVolumeToRs1Event()); mAudioService.setStreamVolumeWithAttributionInt(STREAM_MUSIC, index, /*flags*/ 0, ada, mContext.getOpPackageName(), /*attributionTag=*/null, true /*canChangeMuteAndUpdateController*/); /*canChangeMuteAndUpdateController=*/true); } else { Log.i(TAG, "The current volume " + curVolume.getVolumeIndex() + " for device type " + nativeDeviceType + " is already smaller or equal to the safe index volume " + index); } } // StreamVolumeCommand contains the information needed to defer the process of Loading Loading
services/core/java/com/android/server/audio/AudioService.java +1 −1 Original line number Diff line number Diff line Loading @@ -11698,7 +11698,7 @@ public class AudioService extends IAudioService.Stub static final int LOG_NB_EVENTS_VOLUME = 100; static final int LOG_NB_EVENTS_DYN_POLICY = 10; static final int LOG_NB_EVENTS_SPATIAL = 30; static final int LOG_NB_EVENTS_SOUND_DOSE = 30; static final int LOG_NB_EVENTS_SOUND_DOSE = 50; static final int LOG_NB_EVENTS_LOUDNESS_CODEC = 30; Loading
services/core/java/com/android/server/audio/AudioServiceEvents.java +9 −0 Original line number Diff line number Diff line Loading @@ -577,6 +577,7 @@ public class AudioServiceEvents { static final int DOSE_REPEAT_5X = 2; static final int DOSE_ACCUMULATION_START = 3; static final int LOWER_VOLUME_TO_RS1 = 4; static final int UPDATE_ABS_VOLUME_ATTENUATION = 5; final int mEventType; final float mFloatValue; Loading Loading @@ -608,6 +609,10 @@ public class AudioServiceEvents { return new SoundDoseEvent(LOWER_VOLUME_TO_RS1, 0 /*ignored*/, 0 /*ignored*/); } static SoundDoseEvent getAbsVolumeAttenuationEvent(float attenuation, int device) { return new SoundDoseEvent(UPDATE_ABS_VOLUME_ATTENUATION, attenuation, device); } @Override public String eventToString() { switch (mEventType) { Loading @@ -623,6 +628,10 @@ public class AudioServiceEvents { return "CSD accumulating: RS2 entered"; case LOWER_VOLUME_TO_RS1: return "CSD lowering volume to RS1"; case UPDATE_ABS_VOLUME_ATTENUATION: return String.format(java.util.Locale.US, "Updating CSD absolute volume attenuation on device %d with %.2f dB ", mLongValue, mFloatValue); } return new StringBuilder("FIXME invalid event type:").append(mEventType).toString(); } Loading
services/core/java/com/android/server/audio/SoundDoseHelper.java +29 −17 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.media.AudioSystem; import android.media.ISoundDose; import android.media.ISoundDoseCallback; import android.media.SoundDoseRecord; import android.media.VolumeInfo; import android.os.Binder; import android.os.Message; import android.os.RemoteException; Loading Loading @@ -895,6 +896,8 @@ public class SoundDoseHelper { try { if (!isAbsoluteVolume) { mLogger.enqueue( SoundDoseEvent.getAbsVolumeAttenuationEvent(/*attenuation=*/0.f, device)); // remove any possible previous attenuation soundDose.updateAttenuation(/* attenuationDB= */0.f, device); Loading @@ -903,10 +906,11 @@ public class SoundDoseHelper { if (AudioService.mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC && safeDevicesContains(device)) { soundDose.updateAttenuation( -AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_MUSIC, (newIndex + 5) / 10, device), device); float attenuationDb = -AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_MUSIC, (newIndex + 5) / 10, device); mLogger.enqueue( SoundDoseEvent.getAbsVolumeAttenuationEvent(attenuationDb, device)); soundDose.updateAttenuation(attenuationDb, device); } } catch (RemoteException e) { Log.e(TAG, "Could not apply the attenuation for MEL calculation with volume index " Loading Loading @@ -1313,22 +1317,30 @@ public class SoundDoseHelper { /** Called when handling MSG_LOWER_VOLUME_TO_RS1 */ private void onLowerVolumeToRs1() { mLogger.enqueue(SoundDoseEvent.getLowerVolumeToRs1Event()); final ArrayList<AudioDeviceAttributes> devices = mAudioService.getDevicesForAttributesInt( new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA).build(), true); final int nativeDeviceType; final AudioDeviceAttributes ada; if (!devices.isEmpty()) { ada = devices.get(0); nativeDeviceType = ada.getInternalType(); } else { nativeDeviceType = AudioSystem.DEVICE_OUT_USB_HEADSET; ada = new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_USB_HEADSET, ""); new AudioAttributes.Builder().setUsage( AudioAttributes.USAGE_MEDIA).build(), /*forVolume=*/true); if (devices.isEmpty()) { Log.e(TAG, "Cannot lower the volume to RS1, no devices registered for USAGE_MEDIA"); return; } final int index = safeMediaVolumeIndex(nativeDeviceType); mAudioService.setStreamVolumeWithAttributionInt(STREAM_MUSIC, index / 10, /*flags*/ 0, ada, final AudioDeviceAttributes ada = devices.get(0); final int nativeDeviceType = ada.getInternalType(); final int index = safeMediaVolumeIndex(nativeDeviceType) / 10; final VolumeInfo curVolume = mAudioService.getDeviceVolume( new VolumeInfo.Builder(STREAM_MUSIC).build(), ada, /*callingPackage=*/"sounddosehelper"); if (index < curVolume.getVolumeIndex()) { mLogger.enqueue(SoundDoseEvent.getLowerVolumeToRs1Event()); mAudioService.setStreamVolumeWithAttributionInt(STREAM_MUSIC, index, /*flags*/ 0, ada, mContext.getOpPackageName(), /*attributionTag=*/null, true /*canChangeMuteAndUpdateController*/); /*canChangeMuteAndUpdateController=*/true); } else { Log.i(TAG, "The current volume " + curVolume.getVolumeIndex() + " for device type " + nativeDeviceType + " is already smaller or equal to the safe index volume " + index); } } // StreamVolumeCommand contains the information needed to defer the process of Loading