auto import from //branches/cupcake/...@130745
diff --git a/src/com/android/settings/SoundAndDisplaySettings.java b/src/com/android/settings/SoundAndDisplaySettings.java
index 134e84f..53912e3 100644
--- a/src/com/android/settings/SoundAndDisplaySettings.java
+++ b/src/com/android/settings/SoundAndDisplaySettings.java
@@ -25,6 +25,7 @@
 import android.content.IntentFilter;
 import android.media.AudioManager;
 import android.os.Bundle;
+import android.os.IMountService;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.preference.ListPreference;
@@ -49,8 +50,21 @@
     private static final String KEY_DTMF_TONE = "dtmf_tone";
     private static final String KEY_SOUND_EFFECTS = "sound_effects";
     private static final String KEY_ANIMATIONS = "animations";
+    private static final String KEY_PLAY_MEDIA_NOTIFICATION_SOUNDS = "play_media_notification_sounds";
     
     private CheckBoxPreference mSilent;
+
+    private CheckBoxPreference mPlayMediaNotificationSounds;
+
+    private IMountService mMountService = null;
+
+    /*
+     * If we are currently in one of the silent modes (the ringer mode is set to either
+     * "silent mode" or "vibrate mode"), then toggling the "Phone vibrate"
+     * preference will switch between "silent mode" and "vibrate mode".
+     * Otherwise, it will adjust the normal ringer mode's ring or ring+vibrate
+     * setting.
+     */
     private CheckBoxPreference mVibrate;
     private CheckBoxPreference mDtmfTone;
     private CheckBoxPreference mSoundEffects;
@@ -64,14 +78,7 @@
     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            
-            int ringerMode = intent
-                    .getIntExtra(AudioManager.EXTRA_RINGER_MODE, AudioManager.RINGER_MODE_NORMAL);
-            boolean isSilentMode = ringerMode != AudioManager.RINGER_MODE_NORMAL;
-            
-            if (mSilent.isChecked() != isSilentMode) {
-                mSilent.setChecked(isSilentMode);
-            }
+            updateState(false);
         }
     };
 
@@ -82,10 +89,14 @@
         
         mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
         mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
+
+        mMountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
         
         addPreferencesFromResource(R.xml.sound_and_display_settings);
         
         mSilent = (CheckBoxPreference) findPreference(KEY_SILENT);
+        mPlayMediaNotificationSounds = (CheckBoxPreference) findPreference(KEY_PLAY_MEDIA_NOTIFICATION_SOUNDS);
+
         mVibrate = (CheckBoxPreference) findPreference(KEY_VIBRATE);
         mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE);
         mDtmfTone.setPersistent(false);
@@ -123,17 +134,28 @@
     }
 
     private void updateState(boolean force) {
-        final boolean silent = mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
-        final boolean phoneVibrate = mAudioManager
-                .getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)
-                        == AudioManager.VIBRATE_SETTING_ON;
+        final int ringerMode = mAudioManager.getRingerMode();
+        final boolean silentOrVibrateMode =
+                ringerMode != AudioManager.RINGER_MODE_NORMAL;
         
-        if (silent != mSilent.isChecked() || force) {
-            mSilent.setChecked(silent);
+        if (silentOrVibrateMode != mSilent.isChecked() || force) {
+            mSilent.setChecked(silentOrVibrateMode);
         }
-        
-        if (phoneVibrate != mVibrate.isChecked() || force) {
-            mVibrate.setChecked(phoneVibrate);
+
+        try {
+            mPlayMediaNotificationSounds.setChecked(mMountService.getPlayNotificationSounds());
+        } catch (RemoteException e) {
+        }
+       
+        boolean vibrateSetting;
+        if (silentOrVibrateMode) {
+            vibrateSetting = ringerMode == AudioManager.RINGER_MODE_VIBRATE;
+        } else {
+            vibrateSetting = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)
+                    == AudioManager.VIBRATE_SETTING_ON;            
+        }
+        if (vibrateSetting != mVibrate.isChecked() || force) {
+            mVibrate.setChecked(vibrateSetting);
         }
         
         boolean animations = true;
@@ -161,12 +183,26 @@
             final boolean silent = mSilent.isChecked();
             mAudioManager.setRingerMode(silent ? AudioManager.RINGER_MODE_SILENT
                     : AudioManager.RINGER_MODE_NORMAL);
+            updateState(false);
             
+        } else if (preference == mPlayMediaNotificationSounds) {
+            try {
+                mMountService.setPlayNotificationSounds(mPlayMediaNotificationSounds.isChecked());
+            } catch (RemoteException e) {
+            }
         } else if (preference == mVibrate) {
             final boolean vibrate = mVibrate.isChecked();
-            mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
-                    vibrate ? AudioManager.VIBRATE_SETTING_ON
-                            : AudioManager.VIBRATE_SETTING_OFF);
+            final boolean silent = mSilent.isChecked();
+            
+            if (silent) {
+                mAudioManager.setRingerMode(vibrate ? AudioManager.RINGER_MODE_VIBRATE :
+                    AudioManager.RINGER_MODE_SILENT);                
+            } else {
+                mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
+                        vibrate ? AudioManager.VIBRATE_SETTING_ON
+                                : AudioManager.VIBRATE_SETTING_OFF);
+            }
+            
         } else if (preference == mDtmfTone) {
             Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING,
                     mDtmfTone.isChecked() ? 1 : 0);