Settings: Refactor for new API & remove obsolete setting

Signed-off-by: San Mehat <san@google.com>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a27b05b..9c38934 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1070,12 +1070,6 @@
     <string name="haptic_feedback_enable_summary_on">Vibrate when pressing soft keys and on certain UI interactions</string>
     <!-- Sound settings screen, setting option summary text when check box is clear -->
     <string name="haptic_feedback_enable_summary_off">Vibrate when pressing soft keys and on certain UI interactions</string>
-    <!-- Sound settings screen, setting check box label -->
-    <string name="play_media_notification_sounds_enable_title">SD card notifications</string>
-    <!-- Sound settings screen, setting option summary text when check box is selected -->
-    <string name="play_media_notification_sounds_enable_summary_on">Play sound for SD card notifications</string>
-    <!-- Sound settings screen, setting option summary text when check box is clear -->
-    <string name="play_media_notification_sounds_enable_summary_off">Play sound for SD card notifications</string>
     <!-- Sound settings screen, setting option name checkbox to enable/disable audio recording features that improve audio recording in noisy environments -->
     <string name="audio_record_proc_title">Noise cancellation</string>
     <!-- Sound settings screen, setting option summary text -->
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index c8a8d97..08ce0d6 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -97,15 +97,6 @@
                 android:order="11"
                 android:defaultValue="true" />
 
-        <CheckBoxPreference
-                android:key="play_media_notification_sounds"
-                android:title="@string/play_media_notification_sounds_enable_title"
-                android:summaryOn="@string/play_media_notification_sounds_enable_summary_on"
-                android:summaryOff="@string/play_media_notification_sounds_enable_summary_off"
-                android:dependency="silent"
-                android:order="12"
-                android:defaultValue="true" />
-
         <ListPreference
                 android:key="emergency_tone"
                 android:title="@string/emergency_tone_title"
diff --git a/src/com/android/settings/SdCardSettings.java b/src/com/android/settings/SdCardSettings.java
index 75f02e7..4a83843 100644
--- a/src/com/android/settings/SdCardSettings.java
+++ b/src/com/android/settings/SdCardSettings.java
@@ -103,9 +103,13 @@
     }
 
     private void update() {
+
         try {
-            mMassStorage.setChecked(mMountService.getMassStorageEnabled());
-        } catch (RemoteException ex) {
+            String path = Environment.getExternalStorageDirectory().getPath();
+            mMassStorage.setChecked(
+                    mMountService.getVolumeShared(
+                            Environment.getExternalStorageDirectory().getPath(), "ums"));
+        } catch (Exception ex) {
         }
 
         String status = Environment.getExternalStorageState();
@@ -153,8 +157,14 @@
     OnClickListener mMassStorageListener = new OnClickListener() {
         public void onClick(View v) {
             try {
-                mMountService.setMassStorageEnabled(mMassStorage.isChecked());
-            } catch (RemoteException ex) {
+                if (mMassStorage.isChecked()) {
+                    mMountService.shareVolume(
+                            Environment.getExternalStorageDirectory().getPath(), "ums");
+                } else {
+                    mMountService.unshareVolume(
+                            Environment.getExternalStorageDirectory().getPath(), "ums");
+                }
+            } catch (Exception ex) {
             }
         }
     };
diff --git a/src/com/android/settings/SoundSettings.java b/src/com/android/settings/SoundSettings.java
index 9ac2fe1..fb78a80 100644
--- a/src/com/android/settings/SoundSettings.java
+++ b/src/com/android/settings/SoundSettings.java
@@ -53,16 +53,12 @@
     private static final String KEY_DTMF_TONE = "dtmf_tone";
     private static final String KEY_SOUND_EFFECTS = "sound_effects";
     private static final String KEY_HAPTIC_FEEDBACK = "haptic_feedback";
-    private static final String KEY_PLAY_MEDIA_NOTIFICATION_SOUNDS =
-            "play_media_notification_sounds";
     private static final String KEY_EMERGENCY_TONE = "emergency_tone";
     private static final String KEY_SOUND_SETTINGS = "sound_settings";
     private static final String KEY_NOTIFICATION_PULSE = "notification_pulse";
 
     private CheckBoxPreference mSilent;
 
-    private CheckBoxPreference mPlayMediaNotificationSounds;
-
     private IMountService mMountService = null;
 
     /*
@@ -109,7 +105,6 @@
         }
 
         mSilent = (CheckBoxPreference) findPreference(KEY_SILENT);
-        mPlayMediaNotificationSounds = (CheckBoxPreference) findPreference(KEY_PLAY_MEDIA_NOTIFICATION_SOUNDS);
 
         mVibrate = (CheckBoxPreference) findPreference(KEY_VIBRATE);
         mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE);
@@ -177,11 +172,6 @@
             mSilent.setChecked(silentOrVibrateMode);
         }
 
-        try {
-            mPlayMediaNotificationSounds.setChecked(mMountService.getPlayNotificationSounds());
-        } catch (RemoteException e) {
-        }
-
         boolean vibrateSetting;
         if (silentOrVibrateMode) {
             vibrateSetting = ringerMode == AudioManager.RINGER_MODE_VIBRATE;
@@ -219,11 +209,6 @@
         if (preference == mSilent || preference == mVibrate) {
             setRingerMode(mSilent.isChecked(), mVibrate.isChecked());
             if (preference == mSilent) updateState(false);
-        } else if (preference == mPlayMediaNotificationSounds) {
-            try {
-                mMountService.setPlayNotificationSounds(mPlayMediaNotificationSounds.isChecked());
-            } catch (RemoteException e) {
-            }
         } else if (preference == mDtmfTone) {
             Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING,
                     mDtmfTone.isChecked() ? 1 : 0);
diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java
index 422b5fe..a27aed4 100644
--- a/src/com/android/settings/deviceinfo/Memory.java
+++ b/src/com/android/settings/deviceinfo/Memory.java
@@ -26,6 +26,8 @@
 import android.os.RemoteException;
 import android.os.Environment;
 import android.os.IMountService;
+import android.os.StorageManager;
+import android.os.StorageEventListener;
 import android.os.ServiceManager;
 import android.os.StatFs;
 import android.preference.Preference;
@@ -60,10 +62,17 @@
     // Access using getMountService()
     private IMountService mMountService = null;
 
+    private StorageManager mStorageManager = null;
+
     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
-        
+
+        if (mStorageManager == null) {
+            mStorageManager = (StorageManager) getSystemService(Context.STORAGE_SERVICE);
+            mStorageManager.registerListener(mStorageListener);
+        }
+
         addPreferencesFromResource(R.xml.device_info_memory);
         
         mRes = getResources();
@@ -77,20 +86,31 @@
     protected void onResume() {
         super.onResume();
         
-        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED);
-        intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
-        intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
-        intentFilter.addAction(Intent.ACTION_MEDIA_SHARED);
-        intentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
-        intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
-        intentFilter.addAction(Intent.ACTION_MEDIA_NOFS);
-        intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
+        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED);
         intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
         intentFilter.addDataScheme("file");
         registerReceiver(mReceiver, intentFilter);
 
         updateMemoryStatus();
     }
+
+    StorageEventListener mStorageListener = new StorageEventListener() {
+        public void onShareAvailabilityChanged(String method, boolean available) {
+        }
+
+        public void onMediaInserted(String label, String path, int major, int minor) {
+            updateMemoryStatus();
+        }
+
+        public void onMediaRemoved(String label, String path, int major, int minor, boolean clean) {
+            updateMemoryStatus();
+        }
+
+        public void onVolumeStateChanged(
+                String label, String path, String oldState, String newState) {
+            updateMemoryStatus();
+        }
+    };
     
     @Override
     protected void onPause() {