From c55b393efd462490cd5e27fc373bceafdd25662e Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Tue, 5 Jun 2012 11:57:59 -0700 Subject: [PATCH] Configuration for lock and UI sound levels Define two integers in the platform configuration to define the sound level for lock/unlock sounds, and UI sound effects. Use the corresponding value in KeyguardViewMediator for the lock sounds. Use the corresponding value in AudioService when playing sound effects. Bug 6448481 Change-Id: Ie238f5eb1645e395412864d93447ac4049f7e54b --- core/res/res/values/config.xml | 7 +++++++ core/res/res/values/public.xml | 2 ++ media/java/android/media/AudioService.java | 12 ++++-------- .../internal/policy/impl/KeyguardViewMediator.java | 12 ++++++++++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 09e3fbba7ff92..f623d48621eb4 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -76,6 +76,13 @@ 0 5 + + -6 + + + -6 + true diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 801fdf6201ee3..580447d041d93 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -276,6 +276,8 @@ + + diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index a2c20fd032702..dad6d60dddcc7 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -165,7 +165,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished { private SoundPool mSoundPool; private final Object mSoundEffectsLock = new Object(); private static final int NUM_SOUNDPOOL_CHANNELS = 4; - private static final int SOUND_EFFECT_VOLUME = 1000; // Internally master volume is a float in the 0.0 - 1.0 range, // but to support integer based AudioManager API we translate it to 0 - 100 @@ -370,10 +369,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished { private SoundPoolListenerThread mSoundPoolListenerThread; // message looper for SoundPool listener private Looper mSoundPoolLooper = null; - // default volume applied to sound played with playSoundEffect() - private static final int SOUND_EFFECT_DEFAULT_VOLUME_DB = 0; - // volume applied to sound played with playSoundEffect() read from ro.config.sound_fx_volume - private int SOUND_EFFECT_VOLUME_DB; + // volume applied to sound played with playSoundEffect() + private static int SOUND_EFFECT_VOLUME_DB; // getActiveStreamType() will return STREAM_NOTIFICATION during this period after a notification // stopped private static final int NOTIFICATION_VOLUME_DELAY_MS = 5000; @@ -420,9 +417,8 @@ public class AudioService extends IAudioService.Stub implements OnFinished { "ro.config.vc_call_vol_steps", MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]); - SOUND_EFFECT_VOLUME_DB = SystemProperties.getInt( - "ro.config.sound_fx_volume", - SOUND_EFFECT_DEFAULT_VOLUME_DB); + SOUND_EFFECT_VOLUME_DB = context.getResources().getInteger( + com.android.internal.R.integer.config_soundEffectVolumeDb); mVolumePanel = new VolumePanel(context, this); mMode = AudioSystem.MODE_NORMAL; diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java index 11a1cd629660c..85156998a242d 100644 --- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java +++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java @@ -251,7 +251,11 @@ public class KeyguardViewMediator implements KeyguardViewCallback, private int mLockSoundId; private int mUnlockSoundId; private int mLockSoundStreamId; - private int mMasterStreamMaxVolume; + + /** + * The volume applied to the lock/unlock sounds. + */ + private final float mLockSoundVolume; InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() { @@ -329,6 +333,9 @@ public class KeyguardViewMediator implements KeyguardViewCallback, if (soundPath == null || mUnlockSoundId == 0) { if (DEBUG) Log.d(TAG, "failed to load sound from " + soundPath); } + int lockSoundDefaultAttenuation = context.getResources().getInteger( + com.android.internal.R.integer.config_lockSoundVolumeDb); + mLockSoundVolume = (float)Math.pow(10, lockSoundDefaultAttenuation/20); IntentFilter userFilter = new IntentFilter(); userFilter.addAction(Intent.ACTION_USER_SWITCHED); userFilter.addAction(Intent.ACTION_USER_REMOVED); @@ -1117,7 +1124,8 @@ public class KeyguardViewMediator implements KeyguardViewCallback, // If the stream is muted, don't play the sound if (mAudioManager.isStreamMute(mMasterStreamType)) return; - mLockSoundStreamId = mLockSounds.play(whichSound, 1.0f, 1.0f, 1, 0, 1.0f); + mLockSoundStreamId = mLockSounds.play(whichSound, + mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/); } }