Skip to content

Commit 6a5f9f6

Browse files
jmtriviAndroid (Google) Code Review
authored andcommitted
Merge "Configuration for lock and UI sound levels" into jb-dev
2 parents 906272b + c55b393 commit 6a5f9f6

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
@@ -167,7 +167,6 @@ public class AudioService extends IAudioService.Stub implements OnFinished {
167167
private SoundPool mSoundPool;
168168
private final Object mSoundEffectsLock = new Object();
169169
private static final int NUM_SOUNDPOOL_CHANNELS = 4;
170-
private static final int SOUND_EFFECT_VOLUME = 1000;
171170

172171
// Internally master volume is a float in the 0.0 - 1.0 range,
173172
// but to support integer based AudioManager API we translate it to 0 - 100
@@ -372,10 +371,8 @@ public void onError(int error) {
372371
private SoundPoolListenerThread mSoundPoolListenerThread;
373372
// message looper for SoundPool listener
374373
private Looper mSoundPoolLooper = null;
375-
// default volume applied to sound played with playSoundEffect()
376-
private static final int SOUND_EFFECT_DEFAULT_VOLUME_DB = 0;
377-
// volume applied to sound played with playSoundEffect() read from ro.config.sound_fx_volume
378-
private int SOUND_EFFECT_VOLUME_DB;
374+
// volume applied to sound played with playSoundEffect()
375+
private static int SOUND_EFFECT_VOLUME_DB;
379376
// getActiveStreamType() will return STREAM_NOTIFICATION during this period after a notification
380377
// stopped
381378
private static final int NOTIFICATION_VOLUME_DELAY_MS = 5000;
@@ -422,9 +419,8 @@ public AudioService(Context context) {
422419
"ro.config.vc_call_vol_steps",
423420
MAX_STREAM_VOLUME[AudioSystem.STREAM_VOICE_CALL]);
424421

425-
SOUND_EFFECT_VOLUME_DB = SystemProperties.getInt(
426-
"ro.config.sound_fx_volume",
427-
SOUND_EFFECT_DEFAULT_VOLUME_DB);
422+
SOUND_EFFECT_VOLUME_DB = context.getResources().getInteger(
423+
com.android.internal.R.integer.config_soundEffectVolumeDb);
428424

429425
mVolumePanel = new VolumePanel(context, this);
430426
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)