Skip to content

Commit c55b393

Browse files
committed
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
1 parent 3038465 commit c55b393

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

core/res/res/values/config.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@
7676
<item>0</item> <item>5</item> <!-- default: always increase volume by 5% -->
7777
</integer-array>
7878

79+
<!-- The attenuation in dB applied to the sound effects played
80+
through AudioManager.playSoundEffect() when no volume is specified. -->
81+
<integer name="config_soundEffectVolumeDb">-6</integer>
82+
83+
<!-- The attenuation in dB applied to the lock/unlock sounds. -->
84+
<integer name="config_lockSoundVolumeDb">-6</integer>
85+
7986
<!-- Flag indicating whether the AUDIO_BECOMING_NOISY notification should
8087
be sent during a change to the audio output device. -->
8188
<bool name="config_sendAudioBecomingNoisy">true</bool>

core/res/res/values/public.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@
276276
<java-symbol type="integer" name="db_wal_autocheckpoint" />
277277
<java-symbol type="integer" name="max_action_buttons" />
278278
<java-symbol type="integer" name="config_wifi_driver_stop_delay" />
279+
<java-symbol type="integer" name="config_soundEffectVolumeDb" />
280+
<java-symbol type="integer" name="config_lockSoundVolumeDb" />
279281

280282
<java-symbol type="color" name="tab_indicator_text_v4" />
281283

media/java/android/media/AudioService.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
165165
private SoundPool mSoundPool;
166166
private final Object mSoundEffectsLock = new Object();
167167
private static final int NUM_SOUNDPOOL_CHANNELS = 4;
168-
private static final int SOUND_EFFECT_VOLUME = 1000;
169168

170169
// Internally master volume is a float in the 0.0 - 1.0 range,
171170
// but to support integer based AudioManager API we translate it to 0 - 100
@@ -370,10 +369,8 @@ public void onError(int error) {
370369
private SoundPoolListenerThread mSoundPoolListenerThread;
371370
// message looper for SoundPool listener
372371
private Looper mSoundPoolLooper = null;
373-
// default volume applied to sound played with playSoundEffect()
374-
private static final int SOUND_EFFECT_DEFAULT_VOLUME_DB = 0;
375-
// volume applied to sound played with playSoundEffect() read from ro.config.sound_fx_volume
376-
private int SOUND_EFFECT_VOLUME_DB;
372+
// volume applied to sound played with playSoundEffect()
373+
private static int SOUND_EFFECT_VOLUME_DB;
377374
// getActiveStreamType() will return STREAM_NOTIFICATION during this period after a notification
378375
// stopped
379376
private static final int NOTIFICATION_VOLUME_DELAY_MS = 5000;
@@ -420,9 +417,8 @@ public AudioService(Context context) {
420417
"ro.config.vc_call_vol_steps",
421418
MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]);
422419

423-
SOUND_EFFECT_VOLUME_DB = SystemProperties.getInt(
424-
"ro.config.sound_fx_volume",
425-
SOUND_EFFECT_DEFAULT_VOLUME_DB);
420+
SOUND_EFFECT_VOLUME_DB = context.getResources().getInteger(
421+
com.android.internal.R.integer.config_soundEffectVolumeDb);
426422

427423
mVolumePanel = new VolumePanel(context, this);
428424
mMode = AudioSystem.MODE_NORMAL;

policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ public class KeyguardViewMediator implements KeyguardViewCallback,
251251
private int mLockSoundId;
252252
private int mUnlockSoundId;
253253
private int mLockSoundStreamId;
254-
private int mMasterStreamMaxVolume;
254+
255+
/**
256+
* The volume applied to the lock/unlock sounds.
257+
*/
258+
private final float mLockSoundVolume;
255259

256260
InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
257261

@@ -329,6 +333,9 @@ public KeyguardViewMediator(Context context, PhoneWindowManager callback,
329333
if (soundPath == null || mUnlockSoundId == 0) {
330334
if (DEBUG) Log.d(TAG, "failed to load sound from " + soundPath);
331335
}
336+
int lockSoundDefaultAttenuation = context.getResources().getInteger(
337+
com.android.internal.R.integer.config_lockSoundVolumeDb);
338+
mLockSoundVolume = (float)Math.pow(10, lockSoundDefaultAttenuation/20);
332339
IntentFilter userFilter = new IntentFilter();
333340
userFilter.addAction(Intent.ACTION_USER_SWITCHED);
334341
userFilter.addAction(Intent.ACTION_USER_REMOVED);
@@ -1117,7 +1124,8 @@ private void playSounds(boolean locked) {
11171124
// If the stream is muted, don't play the sound
11181125
if (mAudioManager.isStreamMute(mMasterStreamType)) return;
11191126

1120-
mLockSoundStreamId = mLockSounds.play(whichSound, 1.0f, 1.0f, 1, 0, 1.0f);
1127+
mLockSoundStreamId = mLockSounds.play(whichSound,
1128+
mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
11211129
}
11221130
}
11231131

0 commit comments

Comments
 (0)