diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index e3b89856bd74f..6da3c0b59ffdb 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -36,6 +36,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; +import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.ServiceManager; @@ -1959,7 +1960,42 @@ public class AudioManager { return; } - if (!querySoundEffectsEnabled()) { + if (!querySoundEffectsEnabled(Process.myUserHandle().getIdentifier())) { + return; + } + + IAudioService service = getService(); + try { + service.playSoundEffect(effectType); + } catch (RemoteException e) { + Log.e(TAG, "Dead object in playSoundEffect"+e); + } + } + + /** + * Plays a sound effect (Key clicks, lid open/close...) + * @param effectType The type of sound effect. One of + * {@link #FX_KEY_CLICK}, + * {@link #FX_FOCUS_NAVIGATION_UP}, + * {@link #FX_FOCUS_NAVIGATION_DOWN}, + * {@link #FX_FOCUS_NAVIGATION_LEFT}, + * {@link #FX_FOCUS_NAVIGATION_RIGHT}, + * {@link #FX_KEYPRESS_STANDARD}, + * {@link #FX_KEYPRESS_SPACEBAR}, + * {@link #FX_KEYPRESS_DELETE}, + * {@link #FX_KEYPRESS_RETURN}, + * {@link #FX_KEYPRESS_INVALID}, + * @param userId The current user to pull sound settings from + * NOTE: This version uses the UI settings to determine + * whether sounds are heard or not. + * @hide + */ + public void playSoundEffect(int effectType, int userId) { + if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) { + return; + } + + if (!querySoundEffectsEnabled(userId)) { return; } @@ -2006,8 +2042,9 @@ public class AudioManager { /** * Settings has an in memory cache, so this is fast. */ - private boolean querySoundEffectsEnabled() { - return Settings.System.getInt(mContext.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 0) != 0; + private boolean querySoundEffectsEnabled(int user) { + return Settings.System.getIntForUser(mContext.getContentResolver(), + Settings.System.SOUND_EFFECTS_ENABLED, 0, user) != 0; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java index d9a3e1459ac9e..16c0e66f2dc53 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java @@ -18,10 +18,12 @@ package com.android.systemui.statusbar.policy; import android.animation.Animator; import android.animation.ObjectAnimator; +import android.app.ActivityManager; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.hardware.input.InputManager; +import android.media.AudioManager; import android.os.Bundle; import android.os.SystemClock; import android.util.AttributeSet; @@ -57,6 +59,7 @@ public class KeyButtonView extends ImageView { private boolean mSupportsLongpress = true; private Animator mAnimateToQuiescent = new ObjectAnimator(); private Drawable mBackground; + private AudioManager mAudioManager; private final Runnable mCheckLongPress = new Runnable() { public void run() { @@ -99,6 +102,7 @@ public class KeyButtonView extends ImageView { setClickable(true); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); + mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } @Override @@ -251,6 +255,10 @@ public class KeyButtonView extends ImageView { return true; } + public void playSoundEffect(int soundConstant) { + mAudioManager.playSoundEffect(soundConstant, ActivityManager.getCurrentUser()); + }; + public void sendEvent(int action, int flags) { sendEvent(action, flags, SystemClock.uptimeMillis()); }