Feature #2296147	Settings for Car/Desk Dock on certain devices

This inserts a launcher for the Dock settings dialog, if the
device supports it and is currently docked.
The menu item disappears if the phone is not docked in the car/desk dock.
diff --git a/res/values/bools.xml b/res/values/bools.xml
index cc816c0..61cc79e 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -18,4 +18,6 @@
     <!-- Whether or not there is a notification led that is too intrusive to be pulsing
          constantly -->
     <bool name="has_intrusive_led">false</bool>
+    <!-- Whether or not the dock settings are to be displayed for this device when docked -->
+    <bool name="has_dock_settings">false</bool>
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8ae9209..85ca4d4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -894,6 +894,8 @@
     <string name="media_volume_title">Media volume</string>
     <!-- Sound settings screen, setting option summary text -->
     <string name="media_volume_summary">Set volume for music and videos</string>
+    <!-- Sound settings screen, dock settings -->
+    <string name="dock_settings_title">Dock settings</string>
     <!-- Sound settings screen, setting check box label -->
     <string name="dtmf_tone_enable_title">Audible touch tones</string>
     <!-- Sound settings screen, setting option summary text when check box is selected -->
diff --git a/res/xml/sound_and_display_settings.xml b/res/xml/sound_and_display_settings.xml
index c597a0a..151b0fb 100644
--- a/res/xml/sound_and_display_settings.xml
+++ b/res/xml/sound_and_display_settings.xml
@@ -19,14 +19,15 @@
         
     <PreferenceCategory android:key="sound_settings"
             android:title="@string/sound_settings">
-            
+
         <CheckBoxPreference
                 android:key="silent"
                 android:title="@string/silent_mode_title"
                 android:summary="@string/silent_mode_summary"
                 android:persistent="false"
+                android:order="1"
                 android:disableDependentsState="true" />
-    
+
         <com.android.settings.RingerVolumePreference
                 android:key="ring_volume"
                 android:title="@string/ring_volume_title"
@@ -34,16 +35,28 @@
                 android:dialogTitle="@string/ring_volume_title"
                 android:persistent="false"
                 android:dependency="silent"
+                android:order="2"
                 android:streamType="ring" />
-    
+
         <VolumePreference
                 android:key="media_volume"
                 android:title="@string/media_volume_title"
                 android:summary="@string/media_volume_summary"
                 android:dialogTitle="@string/media_volume_title"
                 android:persistent="false"
+                android:order="3"
                 android:streamType="music" />
-    
+
+        <PreferenceScreen
+                android:key="dock_settings"
+                android:order="4"
+                android:title="@string/dock_settings_title">
+            <intent
+                android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.bluetooth.DockSettingsActivity" />
+        </PreferenceScreen>
+
         <com.android.settings.DefaultRingtonePreference
                 android:key="ringtone"
                 android:title="@string/ringtone_title"
@@ -51,12 +64,14 @@
                 android:dialogTitle="@string/ringtone_title"
                 android:persistent="false"
                 android:dependency="silent"
+                android:order="5"
                 android:ringtoneType="ringtone" />
     
         <CheckBoxPreference
                 android:key="vibrate"
                 android:title="@string/vibrate_title"
                 android:summary="@string/vibrate_summary"
+                android:order="6"
                 android:persistent="false" />
     
         <com.android.settings.DefaultRingtonePreference
@@ -66,12 +81,14 @@
                 android:dialogTitle="@string/notification_sound_dialog_title"
                 android:dependency="silent"
                 android:persistent="false"
+                android:order="7"
                 android:ringtoneType="notification" />
 
         <CheckBoxPreference
                 android:key="notification_pulse"
                 android:title="@string/notification_pulse_title"
                 android:summary="@string/notification_pulse_summary"
+                android:order="8"
                 android:persistent="false" />
 
         <CheckBoxPreference
@@ -80,6 +97,7 @@
                 android:summaryOn="@string/dtmf_tone_enable_summary_on"
                 android:summaryOff="@string/dtmf_tone_enable_summary_off"
                 android:dependency="silent"
+                android:order="9"
                 android:defaultValue="true" />
 
         <CheckBoxPreference
@@ -88,6 +106,7 @@
                 android:summaryOn="@string/sound_effects_enable_summary_on"
                 android:summaryOff="@string/sound_effects_enable_summary_off"
                 android:dependency="silent"
+                android:order="10"
                 android:defaultValue="true" />
 
         <CheckBoxPreference
@@ -96,6 +115,7 @@
                 android:summaryOn="@string/haptic_feedback_enable_summary_on"
                 android:summaryOff="@string/haptic_feedback_enable_summary_off"
                 android:dependency="silent"
+                 android:order="11"
                 android:defaultValue="true" />
 
         <CheckBoxPreference
@@ -104,6 +124,7 @@
                 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" />
 
     </PreferenceCategory>
diff --git a/src/com/android/settings/SoundAndDisplaySettings.java b/src/com/android/settings/SoundAndDisplaySettings.java
index 8c70c91..67fc533 100644
--- a/src/com/android/settings/SoundAndDisplaySettings.java
+++ b/src/com/android/settings/SoundAndDisplaySettings.java
@@ -60,11 +60,15 @@
     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 static final String KEY_DOCK_SETTINGS = "dock_settings";
 
     private CheckBoxPreference mSilent;
 
     private CheckBoxPreference mPlayMediaNotificationSounds;
 
+    private Preference mDockSettings;
+    private boolean mHasDockSettings;
+
     private IMountService mMountService = null;
 
     /*
@@ -90,10 +94,16 @@
     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            updateState(false);
+            if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
+                updateState(false);
+            } else if (intent.getAction().equals(Intent.ACTION_DOCK_EVENT)) {
+                handleDockChange(intent);
+            }
         }
     };
 
+    private PreferenceGroup mSoundSettings;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -147,12 +157,12 @@
             emergencyTonePreference.setOnPreferenceChangeListener(this);
         }
 
-        PreferenceGroup soundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);
+        mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);
         mNotificationPulse = (CheckBoxPreference)
-                soundSettings.findPreference(KEY_NOTIFICATION_PULSE);
-        if (mNotificationPulse != null && soundSettings != null &&
+                mSoundSettings.findPreference(KEY_NOTIFICATION_PULSE);
+        if (mNotificationPulse != null &&
                 getResources().getBoolean(R.bool.has_intrusive_led) == false) {
-            soundSettings.removePreference(mNotificationPulse);
+            mSoundSettings.removePreference(mNotificationPulse);
         } else {
             try {
                 mNotificationPulse.setChecked(Settings.System.getInt(resolver,
@@ -162,6 +172,8 @@
                 Log.e(TAG, Settings.System.NOTIFICATION_LIGHT_PULSE + " not found");
             }
         }
+
+        initDockSettings();
     }
 
     @Override
@@ -171,6 +183,12 @@
         updateState(true);
         
         IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
+        if (mHasDockSettings) {
+            if (mDockSettings != null) {
+                mSoundSettings.removePreference(mDockSettings);
+            }
+            filter.addAction(Intent.ACTION_DOCK_EVENT);
+        }
         registerReceiver(mReceiver, filter);
     }
 
@@ -181,6 +199,31 @@
         unregisterReceiver(mReceiver);
     }
 
+    private void initDockSettings() {
+        mDockSettings = mSoundSettings.findPreference(KEY_DOCK_SETTINGS);
+        mHasDockSettings = getResources().getBoolean(R.bool.has_dock_settings);
+        if (mDockSettings != null) {
+            mSoundSettings.removePreference(mDockSettings);
+            // Don't care even if we dock
+            if (getResources().getBoolean(R.bool.has_dock_settings) == false) {
+                mDockSettings = null;
+            }
+        }
+    }
+
+    private void handleDockChange(Intent intent) {
+        if (mHasDockSettings && mDockSettings != null) {
+            int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, 0);
+            if (dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
+                // Show dock settings item
+                mSoundSettings.addPreference(mDockSettings);
+            } else {
+                // Remove dock settings item
+                mSoundSettings.removePreference(mDockSettings);
+            }
+        }
+    }
+
     private void updateState(boolean force) {
         final int ringerMode = mAudioManager.getRingerMode();
         final boolean silentOrVibrateMode =